improve test coverage
This commit is contained in:
parent
d0ec2bbf72
commit
4594a748e3
3 changed files with 101 additions and 95 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
[auth]
|
[auth]
|
||||||
brand_account = 101234229123420379537
|
brand_account = 101234229123420379537
|
||||||
|
brand_account_empty = 1123456629123420379537
|
||||||
headers = headers_auth_json_as_string
|
headers = headers_auth_json_as_string
|
||||||
|
headers_empty = headers_account_with_empty_library_as_json_as_string
|
||||||
headers_file = ./headers_auth.json
|
headers_file = ./headers_auth.json
|
||||||
headers_raw = raw_headers_pasted_from_browser
|
headers_raw = raw_headers_pasted_from_browser
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ class TestYTMusic(unittest.TestCase):
|
||||||
cls.yt = YTMusic(requests_session=False)
|
cls.yt = YTMusic(requests_session=False)
|
||||||
cls.yt_auth = YTMusic(config['auth']['headers_file'])
|
cls.yt_auth = YTMusic(config['auth']['headers_file'])
|
||||||
cls.yt_brand = YTMusic(config['auth']['headers'], config['auth']['brand_account'])
|
cls.yt_brand = YTMusic(config['auth']['headers'], config['auth']['brand_account'])
|
||||||
|
cls.yt_empty = YTMusic(config['auth']['headers_empty'],
|
||||||
|
config['auth']['brand_account_empty'])
|
||||||
|
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
self.assertRaises(Exception, YTMusic, "{}")
|
self.assertRaises(Exception, YTMusic, "{}")
|
||||||
|
|
@ -232,6 +234,9 @@ class TestYTMusic(unittest.TestCase):
|
||||||
playlists = self.yt_auth.get_library_playlists(None)
|
playlists = self.yt_auth.get_library_playlists(None)
|
||||||
self.assertGreaterEqual(len(playlists), config.getint('limits', 'library_playlists'))
|
self.assertGreaterEqual(len(playlists), config.getint('limits', 'library_playlists'))
|
||||||
|
|
||||||
|
playlists = self.yt_empty.get_library_playlists()
|
||||||
|
self.assertEqual(len(playlists), 0)
|
||||||
|
|
||||||
def test_get_library_songs(self):
|
def test_get_library_songs(self):
|
||||||
self.assertRaises(Exception, self.yt_auth.get_library_songs, None, True)
|
self.assertRaises(Exception, self.yt_auth.get_library_songs, None, True)
|
||||||
songs = self.yt_auth.get_library_songs(100)
|
songs = self.yt_auth.get_library_songs(100)
|
||||||
|
|
@ -240,6 +245,8 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreaterEqual(len(songs), config.getint('limits', 'library_songs'))
|
self.assertGreaterEqual(len(songs), config.getint('limits', 'library_songs'))
|
||||||
songs = self.yt_auth.get_library_songs(order='a_to_z')
|
songs = self.yt_auth.get_library_songs(order='a_to_z')
|
||||||
self.assertGreaterEqual(len(songs), 25)
|
self.assertGreaterEqual(len(songs), 25)
|
||||||
|
songs = self.yt_empty.get_library_songs()
|
||||||
|
self.assertEqual(len(songs), 0)
|
||||||
|
|
||||||
def test_get_library_albums(self):
|
def test_get_library_albums(self):
|
||||||
albums = self.yt_auth.get_library_albums(100)
|
albums = self.yt_auth.get_library_albums(100)
|
||||||
|
|
@ -252,6 +259,8 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(albums), 50)
|
self.assertGreater(len(albums), 50)
|
||||||
albums = self.yt_brand.get_library_albums(100, order='recently_added')
|
albums = self.yt_brand.get_library_albums(100, order='recently_added')
|
||||||
self.assertGreater(len(albums), 50)
|
self.assertGreater(len(albums), 50)
|
||||||
|
albums = self.yt_empty.get_library_albums()
|
||||||
|
self.assertEqual(len(albums), 0)
|
||||||
|
|
||||||
def test_get_library_artists(self):
|
def test_get_library_artists(self):
|
||||||
artists = self.yt_auth.get_library_artists(50)
|
artists = self.yt_auth.get_library_artists(50)
|
||||||
|
|
@ -260,6 +269,8 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(artists), 40)
|
self.assertGreater(len(artists), 40)
|
||||||
artists = self.yt_brand.get_library_artists(limit=None)
|
artists = self.yt_brand.get_library_artists(limit=None)
|
||||||
self.assertGreater(len(artists), config.getint('limits', 'library_artists'))
|
self.assertGreater(len(artists), config.getint('limits', 'library_artists'))
|
||||||
|
artists = self.yt_empty.get_library_artists()
|
||||||
|
self.assertEqual(len(artists), 0)
|
||||||
|
|
||||||
def test_get_library_subscriptions(self):
|
def test_get_library_subscriptions(self):
|
||||||
artists = self.yt_brand.get_library_subscriptions(50)
|
artists = self.yt_brand.get_library_subscriptions(50)
|
||||||
|
|
@ -268,10 +279,14 @@ class TestYTMusic(unittest.TestCase):
|
||||||
self.assertGreater(len(artists), 20)
|
self.assertGreater(len(artists), 20)
|
||||||
artists = self.yt_brand.get_library_subscriptions(limit=None)
|
artists = self.yt_brand.get_library_subscriptions(limit=None)
|
||||||
self.assertGreater(len(artists), config.getint('limits', 'library_subscriptions'))
|
self.assertGreater(len(artists), config.getint('limits', 'library_subscriptions'))
|
||||||
|
artists = self.yt_empty.get_library_subscriptions()
|
||||||
|
self.assertEqual(len(artists), 0)
|
||||||
|
|
||||||
def test_get_liked_songs(self):
|
def test_get_liked_songs(self):
|
||||||
songs = self.yt_brand.get_liked_songs(200)
|
songs = self.yt_brand.get_liked_songs(200)
|
||||||
self.assertGreater(len(songs['tracks']), 100)
|
self.assertGreater(len(songs['tracks']), 100)
|
||||||
|
songs = self.yt_empty.get_liked_songs()
|
||||||
|
self.assertEqual(songs['trackCount'], 0)
|
||||||
|
|
||||||
def test_get_history(self):
|
def test_get_history(self):
|
||||||
songs = self.yt_auth.get_history()
|
songs = self.yt_auth.get_history()
|
||||||
|
|
@ -383,12 +398,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
results = self.yt_auth.get_library_upload_songs(50, order='z_to_a')
|
results = self.yt_auth.get_library_upload_songs(50, order='z_to_a')
|
||||||
self.assertGreater(len(results), 25)
|
self.assertGreater(len(results), 25)
|
||||||
|
|
||||||
# songs = self.yt_auth.get_library_upload_songs(None)
|
results = self.yt_empty.get_library_upload_songs(100)
|
||||||
# self.assertEqual(len(songs), 1000)
|
|
||||||
|
|
||||||
@unittest.skip("Must not have any uploaded songs to pass")
|
|
||||||
def test_get_library_upload_songs_empty(self):
|
|
||||||
results = self.yt_auth.get_library_upload_songs(100)
|
|
||||||
self.assertEqual(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_get_library_upload_albums(self):
|
def test_get_library_upload_albums(self):
|
||||||
|
|
@ -398,9 +408,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
albums = self.yt_auth.get_library_upload_albums(None)
|
albums = self.yt_auth.get_library_upload_albums(None)
|
||||||
self.assertGreaterEqual(len(albums), config.getint('limits', 'library_upload_albums'))
|
self.assertGreaterEqual(len(albums), config.getint('limits', 'library_upload_albums'))
|
||||||
|
|
||||||
@unittest.skip("Must not have any uploaded albums to pass")
|
results = self.yt_empty.get_library_upload_albums(100)
|
||||||
def test_get_library_upload_albums_empty(self):
|
|
||||||
results = self.yt_auth.get_library_upload_albums(100)
|
|
||||||
self.assertEqual(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_get_library_upload_artists(self):
|
def test_get_library_upload_artists(self):
|
||||||
|
|
@ -410,9 +418,7 @@ class TestYTMusic(unittest.TestCase):
|
||||||
results = self.yt_auth.get_library_upload_artists(50, order='recently_added')
|
results = self.yt_auth.get_library_upload_artists(50, order='recently_added')
|
||||||
self.assertGreaterEqual(len(results), 25)
|
self.assertGreaterEqual(len(results), 25)
|
||||||
|
|
||||||
@unittest.skip("Must not have any uploaded artsts to pass")
|
results = self.yt_empty.get_library_upload_artists(100)
|
||||||
def test_get_library_upload_artists_empty(self):
|
|
||||||
results = self.yt_auth.get_library_upload_artists(100)
|
|
||||||
self.assertEqual(len(results), 0)
|
self.assertEqual(len(results), 0)
|
||||||
|
|
||||||
def test_upload_song(self):
|
def test_upload_song(self):
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
continue
|
continue
|
||||||
data = result[MRLIR]
|
data = result[MRLIR]
|
||||||
|
|
||||||
try:
|
|
||||||
videoId = setVideoId = None
|
videoId = setVideoId = None
|
||||||
like = None
|
like = None
|
||||||
feedback_tokens = None
|
feedback_tokens = None
|
||||||
|
|
@ -32,7 +31,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
feedback_tokens = parse_song_menu_tokens(item)
|
feedback_tokens = parse_song_menu_tokens(item)
|
||||||
|
|
||||||
# if item is not playable, the videoId was retrieved above
|
# if item is not playable, the videoId was retrieved above
|
||||||
if nav(data, PLAY_BUTTON, none_if_absent=True) != None:
|
if nav(data, PLAY_BUTTON, none_if_absent=True) is not None:
|
||||||
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
if 'playNavigationEndpoint' in nav(data, PLAY_BUTTON):
|
||||||
videoId = nav(data,
|
videoId = nav(data,
|
||||||
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
PLAY_BUTTON)['playNavigationEndpoint']['watchEndpoint']['videoId']
|
||||||
|
|
@ -66,7 +65,9 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
|
|
||||||
isExplicit = nav(data, BADGE_LABEL, True) is not None
|
isExplicit = nav(data, BADGE_LABEL, True) is not None
|
||||||
|
|
||||||
videoType = nav(data, MENU_ITEMS + [0, 'menuNavigationItemRenderer', 'navigationEndpoint'] + NAVIGATION_VIDEO_TYPE, True)
|
videoType = nav(
|
||||||
|
data, MENU_ITEMS + [0, 'menuNavigationItemRenderer', 'navigationEndpoint']
|
||||||
|
+ NAVIGATION_VIDEO_TYPE, True)
|
||||||
|
|
||||||
song = {
|
song = {
|
||||||
'videoId': videoId,
|
'videoId': videoId,
|
||||||
|
|
@ -93,9 +94,6 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
|
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print("Item " + str(count) + ": " + str(e))
|
|
||||||
|
|
||||||
return songs
|
return songs
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue