From d13113c7fe891d497ca7f5724f213dc44b48ae26 Mon Sep 17 00:00:00 2001 From: Ritiek Date: Sun, 25 Jun 2017 12:47:56 +0530 Subject: [PATCH] Add username and list test --- test/{test_defaults.py => test_single.py} | 0 test/test_username.py | 42 +++++++++++++++++++++++ 2 files changed, 42 insertions(+) rename test/{test_defaults.py => test_single.py} (100%) create mode 100644 test/test_username.py diff --git a/test/test_defaults.py b/test/test_single.py similarity index 100% rename from test/test_defaults.py rename to test/test_single.py diff --git a/test/test_username.py b/test/test_username.py new file mode 100644 index 0000000..16c608c --- /dev/null +++ b/test/test_username.py @@ -0,0 +1,42 @@ +# -*- coding: UTF-8 -*- + +import spotdl + +username = 'alex' + +def test_user(): + expect_playlists = 7 + playlists = spotdl.spotify.user_playlists(username) + playlists = len(playlists['items']) + assert playlists == expect_playlists + +def test_playlist(): + expect_tracks = 14 + playlist = spotdl.spotify.user_playlists(username)['items'][0] + tracks = playlist['tracks']['total'] + assert tracks == expect_tracks + +def test_list(): + playlist = spotdl.spotify.user_playlists(username)['items'][0] + expect_lines = playlist['tracks']['total'] + result = spotdl.spotify.user_playlist(playlist['owner']['id'], playlist['id'], fields='tracks,next') + tracks = result['tracks'] + spotdl.misc.feed_tracks('list.txt', tracks) + + while tracks['next']: + tracks = spotify.next(tracks) + misc.feed_tracks('list.txt', tracks) + + with open('list.txt', 'r') as listed: + expect_song = (listed.read()).splitlines()[0] + + spotdl.misc.trim_song('list.txt') + with open('list.txt', 'a') as myfile: + myfile.write(expect_song) + + with open('list.txt', 'r') as listed: + songs = (listed.read()).splitlines() + + lines = len(songs) + song = songs[-1] + assert (expect_lines == lines and expect_song == song)