Move tests to unittest

This commit is contained in:
sigma67 2020-03-20 17:02:21 +01:00
commit cc47ad7473
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0

View file

@ -1,49 +1,44 @@
import unittest
from ytmusicapi.ytmusic import YTMusic from ytmusicapi.ytmusic import YTMusic
youtube = YTMusic() youtube = YTMusic()
youtube_auth = YTMusic('../headers_auth.json') youtube_auth = YTMusic('../headers_auth.json')
def get_playlists(): class TestYTMusic(unittest.TestCase):
playlists = youtube.get_playlists() def test_get_playlists(self):
print(playlists) playlists = youtube_auth.get_playlists()
self.assertGreater(len(playlists), 0)
def test_get_foreign_playlist(self):
songs = youtube.get_playlist_items("PLw-VjHDlEOgs658kAHR_LAaILBXb-s6Q5")
self.assertEqual(len(songs), 200)
def get_foreign_playlist(): def test_get_owned_playlist(self):
songs = youtube.get_playlist_items("PLw-VjHDlEOgs658kAHR_LAaILBXb-s6Q5") songs = youtube_auth.get_playlist_items('PLQwVIlKxHM6oCeKLTsUx_w9CmWjHKdg68')
assert (len(songs) == 200) self.assertEqual(len(songs), 64)
def test_get_history(self):
songs = youtube_auth.get_history()
self.assertGreater(len(songs), 0)
def get_owned_playlist(): def test_search(self):
songs = youtube_auth.get_playlist_items('PLQwVIlKxHM6oCeKLTsUx_w9CmWjHKdg68') results = youtube_auth.search("Oasis Wonderwall")
assert (len(songs) == 64) self.assertGreater(len(results), 0)
# end to end test adding playlist, adding item, deleting item, deleting playlist
def get_history(): def test_end2end(self):
songs = youtube_auth.get_history() playlist = youtube_auth.create_playlist("test", "test description")
assert (len(songs) > 0) self.assertEqual(len(playlist), 34, "Playlist creation failed")
response = youtube_auth.add_playlist_items(playlist, ['y0Hhvtmv0gk'])
def search(): self.assertEqual(response, 'STATUS_SUCCEEDED', "Adding playlist item failed")
results = youtube_auth.search("Oasis Wonderwall") items = youtube_auth.get_playlist_items(playlist)
print(results) self.assertEqual(len(items), 1, "Getting playlist items failed")
response = youtube_auth.remove_playlist_items(playlist, items)
self.assertEqual(response, 'STATUS_SUCCEEDED', "Playlist item removal failed")
#end to end test adding playlist, adding item, deleting item, deleting playlist response = youtube_auth.delete_playlist(playlist)
def end2end(): self.assertEqual(response['command']['handlePlaylistDeletionCommand']['playlistId'], playlist, "Playlist removal failed")
playlist = youtube_auth.create_playlist("test", "test description")
print(playlist)
response = youtube_auth.add_playlist_items(playlist,['y0Hhvtmv0gk'])
assert(response == 'STATUS_SUCCEEDED')
items = youtube_auth.get_playlist_items(playlist)
assert(len(items) == 1)
response = youtube_auth.remove_playlist_items(playlist, items)
assert(response == 'STATUS_SUCCEEDED')
response = youtube_auth.delete_playlist(playlist)
assert(response['command']['handlePlaylistDeletionCommand']['playlistId'] == playlist)
if __name__ == '__main__': if __name__ == '__main__':
end2end() unittest.main()
#get_history()
#search()
#get_owned_playlist()