def test_get_loved_tracks(self): """Method testing get_loved_tracks method of lastfm module - tests if the returned value is not None.""" user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) loved_tracks = lastfm.get_loved_tracks(user) self.assertIsNotNone(loved_tracks)
def test_get_loved_tracks(self): """Method testing get_loved_tracks method of lastfm module - tests if the returned value is not None.""" user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) loved_tracks = lastfm.get_loved_tracks(user) self.assertIsNotNone(loved_tracks)
def test_get_loved_tracks_list(self): """Method testing get_loved_tracks method which retrives loved tracks for a given user and creates a list of dictionaries.""" user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) loved_tracks_list = lastfm.get_loved_tracks_list(user) expected_output = [{'artist': 'Freddy The Flying Dutchman & The Sistina Band', 'title': 'Wojtyla Disco Dance'}, {'artist': 'Desire', 'title': 'Under Your Spell'}] for output in expected_output: self.assertTrue(output in loved_tracks_list)
def test_get_lastfm_user(self): """Method testing the connection to the LastFM API and to the given account.""" self.assertRaises(lastfm.WrongCredentialsException, lastfm.get_lastfm_user, properties.LASTFM_TEST_USERNAME, 'wrong_password') user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) self.assertIsNotNone(user) name = user.get_name() playcount = user.get_playcount() self.assertEqual(name, properties.LASTFM_TEST_USERNAME) self.assertEqual(playcount, 0)
def test_get_lastfm_user(self): """Method testing the connection to the LastFM API and to the given account.""" self.assertRaises(lastfm.WrongCredentialsException, lastfm.get_lastfm_user, properties.LASTFM_TEST_USERNAME, 'wrong_password') user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) self.assertIsNotNone(user) name = user.get_name() playcount = user.get_playcount() self.assertEqual(name, properties.LASTFM_TEST_USERNAME) self.assertEqual(playcount, 0)
def test_get_loved_tracks_list(self): """Method testing get_loved_tracks method which retrives loved tracks for a given user and creates a list of dictionaries.""" user = lastfm.get_lastfm_user(properties.LASTFM_TEST_USERNAME, properties.LASTFM_TEST_PASSWORD) loved_tracks_list = lastfm.get_loved_tracks_list(user) expected_output = [{ 'artist': 'Freddy The Flying Dutchman & The Sistina Band', 'title': 'Wojtyla Disco Dance' }, { 'artist': 'Desire', 'title': 'Under Your Spell' }] for output in expected_output: self.assertTrue(output in loved_tracks_list)
def extract_variables(): """Method that extracts variables given as arguments when running the script and returns: - loved_tracks (list of dictionaries - read the doc of lastfm.get_loved_tracks_list method for further information) - spotify_username (given as argument) - playlist_name (given as argument) """ try: lastfm_user = lastfm.get_lastfm_user(sys.argv[1], sys.argv[2]) except lastfm.WrongCredentialsException: print('Wrong LastFM credentials.') # GUI => dialog window input('Press any key.') return loved_tracks = lastfm.get_loved_tracks_list(lastfm_user) spotify_username = sys.argv[3] playlist_name = sys.argv[4] return loved_tracks, spotify_username, playlist_name