From 3a5d85246868a1f39bbdbd268511df18fb461244 Mon Sep 17 00:00:00 2001 From: ludehon Date: Sun, 1 Sep 2019 19:22:18 +0200 Subject: [PATCH 01/13] Added vcr support for consistent tests --- .gitignore | 7 +++++++ tests/test_genius.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0619f86..d8b4dec 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,10 @@ __pycache__ dist build .idea + +# VCR cache files +test_get_annotation +test_get_referents_web_page +test_get_song_annotations +test_search_genius_web +test_search_song \ No newline at end of file diff --git a/tests/test_genius.py b/tests/test_genius.py index a980d2e..28e5ea9 100644 --- a/tests/test_genius.py +++ b/tests/test_genius.py @@ -3,6 +3,9 @@ from lyricsgenius.api import Genius from lyricsgenius.song import Song from lyricsgenius.artist import Artist +import vcr +import sys +sys.path.append('..') # Import client access token from environment variable client_access_token = os.environ.get("GENIUS_CLIENT_ACCESS_TOKEN", None) @@ -18,12 +21,14 @@ def setUpClass(cls): cls.search_term = "Ezra Furman" cls.song_title_only = "99 Problems" + @vcr.use_cassette() def test_search_genius_web(self): # TODO: test more than just a 200 response msg = "Response was None." r = genius.search_genius_web(self.search_term) self.assertTrue(r is not None, msg) + @vcr.use_cassette() def test_search_song(self): artist = "Jay-Z" drake_song = "All Me" @@ -47,6 +52,7 @@ def test_search_song(self): response = genius.search_song(self.song_title_only, artist="Drake") self.assertFalse(response.title.lower() == self.song_title_only.lower()) + @vcr.use_cassette() def test_get_referents_web_page(self): msg = "Returned referent API path is different than expected." id_ = 10347 @@ -65,6 +71,7 @@ def test_get_referents_no_inputs(self): with self.assertRaises(AssertionError): genius.get_referents() + @vcr.use_cassette() def test_get_annotation(self): msg = "Returned annotation API path is different than expected." id_ = 10225840 @@ -73,10 +80,11 @@ def test_get_annotation(self): expected = '/annotations/10225840' self.assertEqual(real, expected, msg) + @vcr.use_cassette() def test_get_song_annotations(self): msg = "Incorrect song annotation response." id_ = 1 - r = sorted(genius.get_song_annotations(1)) + r = sorted(genius.get_song_annotations(id_)) real = r[0][0] expected = "And I’ma keep ya fresh" self.assertEqual(real, expected, msg) @@ -85,6 +93,7 @@ def test_get_song_annotations(self): class TestArtist(unittest.TestCase): @classmethod + @vcr.use_cassette() def setUpClass(cls): print("\n---------------------\nSetting up Artist tests...\n") cls.artist_name = "The Beatles" @@ -97,6 +106,7 @@ def test_artist(self): msg = "The returned object is not an instance of the Artist class." self.assertIsInstance(self.artist, Artist, msg) + @vcr.use_cassette() def test_correct_artist_name(self): msg = "Returned artist name does not match searched artist." name = "Queen" @@ -107,11 +117,13 @@ def test_name(self): msg = "The artist object name does not match the requested artist name." self.assertEqual(self.artist.name, self.artist_name, msg) + @vcr.use_cassette() def test_add_song_from_same_artist(self): msg = "The new song was not added to the artist object." self.artist.add_song(genius.search_song(self.new_song, self.artist_name)) self.assertEqual(self.artist.num_songs, self.max_songs+1, msg) + @vcr.use_cassette() def test_add_song_from_different_artist(self): msg = "A song from a different artist was incorrectly allowed to be added." self.artist.add_song(genius.search_song("These Days", "Jackson Browne")) @@ -180,6 +192,7 @@ def test_saving_txt_file(self): class TestSong(unittest.TestCase): @classmethod + @vcr.use_cassette() def setUpClass(cls): print("\n---------------------\nSetting up Song tests...\n") cls.artist_name = 'Andy Shauf' From 69dc4c3fe9db20d9835e7b9f18c5b4b245c9c22b Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 12:52:41 +0330 Subject: [PATCH 02/13] added vcr to tests --- tests/test_album.py | 8 +++-- tests/test_api.py | 9 +++-- tests/test_artist.py | 18 ++++++++-- tests/test_base.py | 5 +-- tests/test_genius.py | 18 ++++++++++ tests/test_public_methods.py | 66 ++++++++++++++++++++++++++++++++++++ tests/test_song.py | 24 ++++--------- 7 files changed, 122 insertions(+), 26 deletions(-) diff --git a/tests/test_album.py b/tests/test_album.py index e387e23..f5d8e01 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -1,16 +1,20 @@ import unittest import os +import vcr + try: - from .test_genius import genius + from .test_genius import genius, test_vcr except ModuleNotFoundError: - from test_genius import genius + from test_genius import genius, test_vcr from lyricsgenius.types import Album class TestAlbum(unittest.TestCase): @classmethod + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix(' album.yaml'), + serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Album tests...\n") cls.album_name = "The Party" diff --git a/tests/test_api.py b/tests/test_api.py index 41170c9..bdd2e6c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,9 +1,9 @@ import unittest try: - from .test_genius import genius + from .test_genius import genius, test_vcr except ModuleNotFoundError: - from test_genius import genius + from test_genius import genius, test_vcr class TestAPI(unittest.TestCase): @@ -12,12 +12,14 @@ class TestAPI(unittest.TestCase): def setUpClass(cls): print("\n---------------------\nSetting up API tests...\n") + @test_vcr.use_cassette def test_account(self): msg = ("No user detail was returned. " "Are you sure you're using a user access token?") r = genius.account() self.assertTrue("user" in r, msg) + @test_vcr.use_cassette def test_annotation(self): msg = "Returned annotation API path is different than expected." id_ = 10225840 @@ -26,6 +28,7 @@ def test_annotation(self): expected = '/annotations/10225840' self.assertEqual(real, expected, msg) + @test_vcr.use_cassette def test_manage_annotation(self): example_text = 'The annotation' new_annotation = genius.create_annotation( @@ -64,6 +67,7 @@ def test_manage_annotation(self): r = genius.delete_annotation(new_annotation['id']) self.assertEqual(r, 204, msg) + @test_vcr.use_cassette def test_referents_web_page(self): msg = "Returned referent API path is different than expected." id_ = 10347 @@ -82,6 +86,7 @@ def test_referents_invalid_input(self): with self.assertRaises(AssertionError): genius.referents(song_id=1, web_page_id=1) + @test_vcr.use_cassette def test_web_page(self): msg = "Returned web page API path is different than expected." url = "https://docs.genius.com" diff --git a/tests/test_artist.py b/tests/test_artist.py index 82eafcb..e4dce9e 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -1,10 +1,12 @@ import unittest import os +import vcr + try: - from .test_genius import genius + from .test_genius import genius, test_vcr except ModuleNotFoundError: - from test_genius import genius + from test_genius import genius, test_vcr from lyricsgenius.types import Artist from lyricsgenius.utils import sanitize_filename @@ -12,6 +14,8 @@ class TestArtist(unittest.TestCase): @classmethod + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix(' artist.yaml'), + serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Artist tests...\n") cls.artist_name = "The Beatles" @@ -24,12 +28,15 @@ def test_artist(self): msg = "The returned object is not an instance of the Artist class." self.assertIsInstance(self.artist, Artist, msg) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_correct_artist_name(self): msg = "Returned artist name does not match searched artist." name = "Queen" result = genius.search_artist(name, max_songs=1).name self.assertEqual(name, result, msg) + @test_vcr.use_cassette def test_zero_songs(self): msg = "Songs were downloaded even though 0 songs was requested." name = "Queen" @@ -40,21 +47,28 @@ def test_name(self): msg = "The artist object name does not match the requested artist name." self.assertEqual(self.artist.name, self.artist_name, msg) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_add_song_from_same_artist(self): msg = "The new song was not added to the artist object." self.artist.add_song(genius.search_song(self.new_song, self.artist_name)) self.assertEqual(self.artist.num_songs, self.max_songs + 1, msg) + @test_vcr.use_cassette def test_song(self): msg = "Song was not in artist's songs." song = self.artist.song(self.new_song) self.assertIsNotNone(song, msg) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_add_song_from_different_artist(self): msg = "A song from a different artist was incorrectly allowed to be added." self.artist.add_song(genius.search_song("These Days", "Jackson Browne")) self.assertEqual(self.artist.num_songs, self.max_songs, msg) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_artist_with_includes_features(self): # The artist did not get songs returned that they were featured in. name = "Swae Lee" diff --git a/tests/test_base.py b/tests/test_base.py index 9ae7ff5..31dabed 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -3,9 +3,9 @@ from requests.exceptions import HTTPError try: - from .test_genius import genius + from .test_genius import genius, test_vcr except ModuleNotFoundError: - from test_genius import genius + from test_genius import genius, test_vcr class TestAPIBase(unittest.TestCase): @@ -14,6 +14,7 @@ class TestAPIBase(unittest.TestCase): def setUpClass(cls): print("\n---------------------\nSetting up API base tests...\n") + @test_vcr.use_cassette def test_http_error_handler(self): status_code = None try: diff --git a/tests/test_genius.py b/tests/test_genius.py index 717e486..ffd48ee 100644 --- a/tests/test_genius.py +++ b/tests/test_genius.py @@ -1,6 +1,8 @@ import os import unittest +import vcr + from lyricsgenius import Genius @@ -10,16 +12,27 @@ "Must declare environment variable: GENIUS_ACCESS_TOKEN") genius = Genius(access_token, sleep_time=1.0, timeout=15) +test_vcr = vcr.VCR( + path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml', + cassette_library_dir='tests/fixtures/cassettes', + filter_headers=['authorization'] +) + class TestEndpoints(unittest.TestCase): @classmethod + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix(' endpoints.yaml'), + serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Endpoint tests...\n") cls.search_term = "Ezra Furman" cls.song_title_only = "99 Problems" cls.tag = genius.tag('pop') + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_search_song(self): artist = "Jay-Z" # Empty response @@ -50,6 +63,7 @@ def test_search_song(self): response = genius.search_song(self.song_title_only, artist="Drake") self.assertFalse(response.title.lower() == self.song_title_only.lower()) + @test_vcr.use_cassette def test_song_annotations(self): msg = "Incorrect song annotation response." r = sorted(genius.song_annotations(1)) @@ -95,10 +109,14 @@ def setUpClass(cls): "\nI wonder who you’re thinking of" ) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_lyrics_with_url(self): lyrics = genius.lyrics(self.song_url) self.assertTrue(lyrics.endswith(self.lyrics_ending)) + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml') def test_lyrics_with_id(self): lyrics = genius.lyrics(self.song_id) self.assertTrue(lyrics.endswith(self.lyrics_ending)) diff --git a/tests/test_public_methods.py b/tests/test_public_methods.py index 6a260b5..d7e504f 100644 --- a/tests/test_public_methods.py +++ b/tests/test_public_methods.py @@ -1,7 +1,14 @@ import unittest +import vcr + from lyricsgenius import PublicAPI +try: + from .test_genius import test_vcr +except ModuleNotFoundError: + from test_genius import test_vcr + client = PublicAPI() @@ -12,31 +19,37 @@ def setUpClass(cls): print("\n---------------------\nSetting up album methods tests...\n") cls.album_id = 104614 + @test_vcr.use_cassette def test_album(self): msg = "Album ID did not match." r = client.album(self.album_id) self.assertEqual(r['album']['id'], self.album_id, msg) + @test_vcr.use_cassette def test_albums_charts(self): msg = "Album charts were empty." r = client.albums_charts() self.assertTrue("chart_items" in r, msg) + @test_vcr.use_cassette def test_album_comments(self): msg = "Album comments were empty." r = client.album_comments(self.album_id) self.assertTrue("comments" in r, msg) + @test_vcr.use_cassette def test_album_cover_arts(self): msg = "Album cover arts were empty." r = client.album_cover_arts(self.album_id) self.assertTrue("cover_arts" in r, msg) + @test_vcr.use_cassette def test_album_leaderboard(self): msg = "Album leaderboard was empty." r = client.album_leaderboard(self.album_id) self.assertTrue("leaderboard" in r, msg) + @test_vcr.use_cassette def test_album_tracks(self): msg = "Album tracks were empty." r = client.album_tracks(self.album_id) @@ -50,16 +63,20 @@ def setUpClass(cls): print("\n---------------------\nSetting up annotation methods tests...\n") cls.annotation_id = 10225840 + @test_vcr.use_cassette( + path_transformer=vcr.VCR.ensure_suffix(' public' + '.' + test_vcr.serializer)) def test_annotation(self): msg = "annotation ID did not match." r = client.annotation(self.annotation_id) self.assertEqual(r['annotation']['id'], self.annotation_id, msg) + @test_vcr.use_cassette def test_annotation_edits(self): msg = "annotation edits were empty." r = client.annotation_edits(self.annotation_id) self.assertTrue("versions" in r, msg) + @test_vcr.use_cassette def test_annotation_comments(self): msg = "annotation comments were empty." r = client.annotation_comments(self.annotation_id) @@ -73,16 +90,19 @@ def setUpClass(cls): print("\n---------------------\nSetting up article methods tests...\n") cls.article_id = 11880 + @test_vcr.use_cassette def test_article(self): msg = "article ID did not match." r = client.article(self.article_id) self.assertEqual(r['article']['id'], self.article_id, msg) + @test_vcr.use_cassette def test_article_comments(self): msg = "article comments were empty." r = client.article_comments(self.article_id) self.assertTrue("comments" in r, msg) + @test_vcr.use_cassette def test_latest_articles(self): msg = "latest articles were empty." r = client.latest_articles() @@ -96,34 +116,42 @@ def setUpClass(cls): print("\n---------------------\nSetting up artist methods tests...\n") cls.artist_id = 1665 + @test_vcr.use_cassette def test_artist(self): r = client.artist(self.artist_id) self.assertEqual(r['artist']['id'], self.artist_id) + @test_vcr.use_cassette def test_artist_activity(self): r = client.artist_activity(self.artist_id) self.assertTrue("line_items" in r) + @test_vcr.use_cassette def test_artist_albums(self): r = client.artist_albums(self.artist_id) self.assertTrue("albums" in r) + # @test_vcr.use_cassette # def test_artist_contribution_opportunities(self): # r = client.artist_contribution_opportunities(self.artist_id) # self.assertIsNotNone(r.get('contribution_opportunities')) + @test_vcr.use_cassette def test_artist_followers(self): r = client.artist_followers(self.artist_id) self.assertTrue("followers" in r) + @test_vcr.use_cassette def test_artist_leaderboard(self): r = client.artist_leaderboard(self.artist_id) self.assertTrue("leaderboard" in r) + @test_vcr.use_cassette def test_artist_songs(self): r = client.artist_songs(self.artist_id) self.assertTrue("songs" in r) + @test_vcr.use_cassette def test_search_artist_songs(self): r = client.search_artist_songs(self.artist_id, 'test') self.assertTrue("songs" in r) @@ -136,6 +164,7 @@ def setUpClass(cls): print("\n---------------------\nSetting up cover arts methods tests...\n") cls.album_id = 104614 + @test_vcr.use_cassette def test_cover_arts(self): r = client.cover_arts(self.album_id) self.assertTrue("cover_arts" in r) @@ -148,14 +177,17 @@ def setUpClass(cls): print("\n---------------------\nSetting up discussion methods tests...\n") # cls.discussion_id = 123 # +# @test_vcr.use_cassette # def test_discussion(self): # r = client.discussion(self.discussion_id) # self.assertEqual(r['discussion']['id'], self.discussion_id) # +# @test_vcr.use_cassette # def test_discussion_replies(self): # r = client.discussion_replies(self.discussion_id) # self.assertTrue("forum_posts" in r) + @test_vcr.use_cassette def test_discussions(self): r = client.discussions() self.assertTrue("discussions" in r) @@ -167,10 +199,12 @@ class TestLeaderboardMethods(unittest.TestCase): def setUpClass(cls): print("\n---------------------\nSetting up leaerboard methods tests...\n") + @test_vcr.use_cassette def test_leaderboard(self): r = client.leaderboard() self.assertTrue("leaderboard" in r) + @test_vcr.use_cassette def test_charts(self): r = client.charts() self.assertTrue("chart_items" in r) @@ -183,6 +217,7 @@ def setUpClass(cls): print("\n---------------------\nSetting up question methods tests...\n") cls.album_id = 104614 + @test_vcr.use_cassette def test_questions(self): r = client.questions(self.album_id) self.assertIsNotNone(r.get('questions')) @@ -196,11 +231,13 @@ def setUpClass(cls): cls.web_page_id = 10347 cls.referent_ids = [20793764, 20641014] + @test_vcr.use_cassette def test_referent(self): r = client.referent(self.referent_ids) self.assertTrue(str(self.referent_ids[0]) in r['referents']) self.assertTrue(str(self.referent_ids[1]) in r['referents']) + @test_vcr.use_cassette def test_referents(self): r = client.referents(web_page_id=self.web_page_id) self.assertIsNotNone(r.get('referents')) @@ -213,38 +250,47 @@ def setUpClass(cls): print("\n---------------------\nSetting up search methods tests...\n") cls.search_term = 'test' + @test_vcr.use_cassette def test_search(self): r = client.search(self.search_term) self.assertIsNotNone(r['hits']) + @test_vcr.use_cassette def test_search_albums(self): r = client.search_albums(self.search_term) self.assertEqual(r['sections'][0]['type'], 'album') + @test_vcr.use_cassette def test_search_articles(self): r = client.search_articles(self.search_term) self.assertEqual(r['sections'][0]['type'], 'article') + @test_vcr.use_cassette def test_search_artists(self): r = client.search_artists(self.search_term) self.assertEqual(r['sections'][0]['type'], 'artist') + @test_vcr.use_cassette def test_search_lyrics(self): r = client.search_lyrics(self.search_term) self.assertEqual(r['sections'][0]['type'], 'lyric') + @test_vcr.use_cassette def test_search_songs(self): r = client.search_songs(self.search_term) self.assertEqual(r['sections'][0]['type'], 'song') + @test_vcr.use_cassette def test_search_users(self): r = client.search_users(self.search_term) self.assertEqual(r['sections'][0]['type'], 'user') + @test_vcr.use_cassette def test_search_videos(self): r = client.search_videos(self.search_term) self.assertEqual(r['sections'][0]['type'], 'video') + @test_vcr.use_cassette def test_search_all(self): r = client.search_all(self.search_term) self.assertEqual(r['sections'][0]['type'], 'top_hit') @@ -257,18 +303,22 @@ def setUpClass(cls): print("\n---------------------\nSetting up song methods tests...\n") cls.song_id = 378195 + @test_vcr.use_cassette def test_song(self): r = client.song(self.song_id) self.assertEqual(r['song']['id'], self.song_id) + @test_vcr.use_cassette def test_song_activity(self): r = client.song_activity(self.song_id) self.assertTrue("line_items" in r) + @test_vcr.use_cassette def test_song_comments(self): r = client.song_comments(self.song_id) self.assertTrue("comments" in r) + @test_vcr.use_cassette def test_song_contributors(self): r = client.song_contributors(self.song_id) self.assertTrue("contributors" in r) @@ -281,56 +331,68 @@ def setUpClass(cls): print("\n---------------------\nSetting up user methods tests...\n") cls.user_id = 1 + @test_vcr.use_cassette def test_user(self): r = client.user(self.user_id) self.assertEqual(r['user']['id'], self.user_id) + @test_vcr.use_cassette def test_user_accomplishments(self): r = client.user_accomplishments(self.user_id) self.assertTrue("accomplishments" in r) + @test_vcr.use_cassette def test_user_following(self): r = client.user_following(self.user_id) self.assertTrue("followed_users" in r) + @test_vcr.use_cassette def test_user_followers(self): r = client.user_followers(self.user_id) self.assertTrue("followers" in r) + @test_vcr.use_cassette def test_user_contributions(self): r = client.user_contributions(self.user_id) self.assertTrue("contribution_groups" in r) + @test_vcr.use_cassette def test_user_annotations(self): r = client.user_annotations(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'annotation') + @test_vcr.use_cassette def test_user_articles(self): r = client.user_articles(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'article') + @test_vcr.use_cassette def test_user_pyongs(self): r = client.user_pyongs(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'pyong') + @test_vcr.use_cassette def test_user_questions_and_answers(self): r = client.user_questions_and_answers(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'answer') + @test_vcr.use_cassette def test_user_suggestions(self): r = client.user_suggestions(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'comment') + @test_vcr.use_cassette def test_user_transcriptions(self): r = client.user_transcriptions(self.user_id) type = r['contribution_groups'][0]['contribution_type'] self.assertEqual(type, 'song') + @test_vcr.use_cassette def test_user_unreviewed(self): r = client.user_unreviewed(self.user_id) type = r['contribution_groups'][0]['contribution_type'] @@ -344,10 +406,12 @@ def setUpClass(cls): print("\n---------------------\nSetting up video methods tests...\n") cls.video_id = 18681 + @test_vcr.use_cassette def test_video(self): r = client.video(self.video_id) self.assertEqual(r['video']['id'], self.video_id) + @test_vcr.use_cassette def test_videos(self): r = client.videos(video_id=self.video_id, series=True) self.assertTrue("video_lists" in r) @@ -364,10 +428,12 @@ def setUpClass(cls): # cls.line_item_id = 146262999 cls.annotation_id = 10225840 + # @test_vcr.use_cassette # def test_line_item(self): # r = client.line_item(self.line_item_id) # self.assertTrue("line_item" in r) + @test_vcr.use_cassette def test_voters(self): r = client.voters(annotation_id=self.annotation_id) self.assertTrue("voters" in r) diff --git a/tests/test_song.py b/tests/test_song.py index edbbe59..2c8b406 100644 --- a/tests/test_song.py +++ b/tests/test_song.py @@ -1,10 +1,12 @@ import os import unittest +import vcr + try: - from .test_genius import genius + from .test_genius import genius, test_vcr except ModuleNotFoundError: - from test_genius import genius + from test_genius import genius, test_vcr from lyricsgenius.types import Song from lyricsgenius.utils import clean_str @@ -12,6 +14,8 @@ class TestSong(unittest.TestCase): @classmethod + @test_vcr.use_cassette(path_transformer=vcr.VCR.ensure_suffix(' song.yaml'), + serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Song tests...\n") cls.artist_name = 'Andy Shauf' @@ -35,14 +39,6 @@ def test_artist(self): # The returned artist name does not match the artist of the requested song. self.assertEqual(self.song.artist, self.artist_name) - # def test_album(self): - # msg = "The returned album name does not match the album of the requested song." - # self.assertEqual(self.song.album, self.album, msg) - - # def test_year(self): - # msg = "The returned year does not match the year of the requested song" - # self.assertEqual(self.song.year, self.year, msg) - def test_lyrics_raw(self): lyrics = '[Verse 1: Andy Shauf]' self.assertTrue(self.song.lyrics.startswith(lyrics)) @@ -51,17 +47,9 @@ def test_lyrics_no_section_headers(self): lyrics = 'Begin again\nThis time you should take a bow at the' self.assertTrue(self.song_trimmed.lyrics.startswith(lyrics)) - # def test_media(self): - # msg = "The returned song does not have a media attribute." - # self.assertTrue(hasattr(self.song, 'media'), msg) - def test_result_is_lyrics(self): self.assertTrue(genius._result_is_lyrics(self.song.to_dict())) - # def test_producer_artists(self): - # # Producer artist should be 'Andy Shauf'. - # self.assertEqual(self.song.producer_artists[0]["name"], "Andy Shauf") - def test_saving_json_file(self): print('\n') extension = 'json' From 92a3d694bf72ea7a1822192167b09982caa03360 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 14:36:17 +0330 Subject: [PATCH 03/13] changed displaying types attributes as table in docs --- docs/src/reference/types.rst | 145 +++++++++++++++++++++++++++++++++++ lyricsgenius/types/album.py | 18 +---- lyricsgenius/types/artist.py | 17 +--- lyricsgenius/types/song.py | 27 +------ 4 files changed, 148 insertions(+), 59 deletions(-) diff --git a/docs/src/reference/types.rst b/docs/src/reference/types.rst index bfcbfbb..75e16c8 100644 --- a/docs/src/reference/types.rst +++ b/docs/src/reference/types.rst @@ -36,6 +36,50 @@ Album ------ An album from Genius that has the album's songs and their lyrics. +Attributes +^^^^^^^^^^ +.. list-table:: + :header-rows: 1 + + * - Attribute + - Type + + * - _type + - :obj:`str` + + * - api_path + - :obj:`str` + + * - artist + - :class:`Artist` + + * - cover_art_thumbnail_url + - :obj:`str` + + * - cover_art_url + - :obj:`str` + + * - full_title + - :obj:`str` + + * - id + - :obj:`int` + + * - name + - :obj:`str` + + * - name_with_artist + - :obj:`str` + + * - release_date_components + - :class:`datetime` + + * - songs + - :obj:`list` + + * - url + - :obj:`str` + Methods ^^^^^^^^ @@ -59,6 +103,41 @@ Artist The Artist object which holds the details of the artist and the `Song`_ objects of that artist. +Attributes +^^^^^^^^^^ +.. list-table:: + :header-rows: 1 + + * - Attribute + - Type + + + * - api_path + - :obj:`str` + + * - header_image_url + - :obj:`str` + + * - id + - :obj:`int` + + * - image_url + - :obj:`str` + + * - is_meme_verified + - :obj:`bool` + + * - is_verified + - :obj:`bool` + + * - name + - :obj:`str` + + * - songs + - :obj:`list` + + * - url + - :obj:`str` Methods ^^^^^^^^ @@ -83,6 +162,72 @@ Song ---- This is the Song object which holds the details of the song. +Attributes +^^^^^^^^^^ +.. list-table:: + :header-rows: 1 + + * - Attribute + - Type + + + * - annotation_count + - :obj:`int` + + * - api_path + - :obj:`str` + + * - artist + - :obj:`str` + + * - full_title + - :obj:`str` + + * - header_image_thumbnail_url + - :obj:`str` + + * - header_image_url + - :obj:`str` + + * - id + - :obj:`int` + + * - lyrics + - :obj:`str` + + * - lyrics_owner_id + - :obj:`int` + + * - lyrics_state + - :obj:`str` + + * - path + - :obj:`str` + + * - primary_artist + - :class:`Artist` + + * - pyongs_count + - :obj:`int` + + * - song_art_image_thumbnail_url + - :obj:`str` + + * - song_art_image_url + - :obj:`str` + + * - stats + - :class:`Stats` + + * - title + - :obj:`str` + + * - title_with_featured + - :obj:`str` + + * - url + - :obj:`str` + Methods ^^^^^^^^ .. autosummary:: diff --git a/lyricsgenius/types/album.py b/lyricsgenius/types/album.py index 30cf23c..3de4783 100644 --- a/lyricsgenius/types/album.py +++ b/lyricsgenius/types/album.py @@ -4,23 +4,7 @@ class Album(BaseEntity): - """An album from the Genius.com database. - - Attributes: - _type (:obj:`str`) - api_path (:obj:`str`) - artist (:class:`Artist`) - cover_art_thumbnail_url (:obj:`str`) - cover_art_url (:obj:`str`) - full_title (:obj:`str`) - id (:obj:`int`) - name (:obj:`str`) - name_with_artist (:obj:`str`) - release_date_components (:class:`datetime`) - songs (:obj:`list`): - A list of :class:`Song` objects. - url (:obj:`str`) - """ + """An album from the Genius.com database.""" def __init__(self, client, json_dict, songs): body = json_dict diff --git a/lyricsgenius/types/artist.py b/lyricsgenius/types/artist.py index f3dce53..0c4350d 100644 --- a/lyricsgenius/types/artist.py +++ b/lyricsgenius/types/artist.py @@ -9,22 +9,7 @@ class Artist(BaseEntity): - """An artist with songs from the Genius.com database. - - Attributes: - api_path (:obj:`str`) - header_image_url (:obj:`str`) - id (:obj:`int`) - image_url (:obj:`str`) - is_meme_verified (:obj:`bool`) - is_verified (:obj:`bool`) - name (:obj:`str`) - songs (:obj:`list`): - A list of :class:`Song` objects - or an empty list. - url (:obj:`str`) - - """ + """An artist with songs from the Genius.com database.""" def __init__(self, client, json_dict): # Artist Constructor diff --git a/lyricsgenius/types/song.py b/lyricsgenius/types/song.py index b7c8e8d..bb0e5a2 100644 --- a/lyricsgenius/types/song.py +++ b/lyricsgenius/types/song.py @@ -9,32 +9,7 @@ class Song(BaseEntity): - """A song from the Genius.com database. - - Attributes: - annotation_count (:obj:`int`) - api_path (:obj:`str`) - artist (:obj:`str`): - Primary artist's name - (Same as ``Song.primary_artist.name``) - full_title (:obj:`str`) - header_image_thumbnail_url (:obj:`str`) - header_image_url (:obj:`str`) - id (:obj:`int`) - lyrics (:obj:`str`) - lyrics_owner_id (:obj:`int`) - lyrics_state (:obj:`str`) - path (:obj:`str`) - primary_artist (:class:`Artist`) - pyongs_count (:obj:`int`) - song_art_image_thumbnail_url (:obj:`str`) - song_art_image_url (:obj:`str`) - stats (:class:`Stats`) - title (:obj:`str`) - title_with_featured (:obj:`str`) - url (:obj:`str`) - - """ + """A song from the Genius.com database.""" def __init__(self, client, json_dict, lyrics=""): body = json_dict From 612060f087bfc7197bf9fc4bd2a1dc34e3a26c94 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 14:41:58 +0330 Subject: [PATCH 04/13] setup.py: added vcrpy to extras_require and bumped sphinx to 3.3 --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 7f9c012..c4869c9 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ extras_require = { 'docs': [ - 'sphinx~=3.2', + 'sphinx~=3.3', 'sphinx-rtd-theme', ], 'checks': [ @@ -35,10 +35,13 @@ 'flake8', 'flake8-bugbear', 'pygments', + ], + 'tests': [ + 'vcrpy~=4.1' ] } extras_require['dev'] = ( - extras_require['docs'] + extras_require['checks'] + extras_require['docs'] + extras_require['checks'] + extras_require['tests'] ) setup( From 55c13db540a2c26d3ea9e339560144bf8226718c Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 14:51:12 +0330 Subject: [PATCH 05/13] removed redundant lines --- .gitignore | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.gitignore b/.gitignore index 4f4fa9c..875743d 100644 --- a/.gitignore +++ b/.gitignore @@ -28,10 +28,3 @@ __pycache__ dist build .idea - -# VCR cache files -test_get_annotation -test_get_referents_web_page -test_get_song_annotations -test_search_genius_web -test_search_song \ No newline at end of file From 92816fd5c4d315ceba8912c1c48f84c827642e52 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 15:28:06 +0330 Subject: [PATCH 06/13] add vcrpy to requirements --- setup.py | 5 ++++- tox.ini | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7f9c012..9db7904 100644 --- a/setup.py +++ b/setup.py @@ -35,10 +35,13 @@ 'flake8', 'flake8-bugbear', 'pygments', + ], + 'tests': [ + 'vcrpy~=4.1' ] } extras_require['dev'] = ( - extras_require['docs'] + extras_require['checks'] + extras_require['docs'] + extras_require['checks'] + extras_require['tests'] ) setup( diff --git a/tox.ini b/tox.ini index a783bad..2bc0c2e 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,8 @@ passenv = GENIUS* [testenv:test] ; Inherit everything from testenv +extras = tests + [testenv:docs] description = Build Sphinx HTML documentation From 33f096c9233ac07b059857c85de58345651bab3a Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 15:39:19 +0330 Subject: [PATCH 07/13] test tox.ini --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2bc0c2e..43ecca8 100644 --- a/tox.ini +++ b/tox.ini @@ -22,7 +22,6 @@ passenv = GENIUS* [testenv:test] ; Inherit everything from testenv -extras = tests [testenv:docs] From cfe657e0dc34db5873f6466d202f45098b117b98 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 15:40:45 +0330 Subject: [PATCH 08/13] Revert "test tox.ini" This reverts commit 33f096c9233ac07b059857c85de58345651bab3a. --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index 43ecca8..2bc0c2e 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ passenv = GENIUS* [testenv:test] ; Inherit everything from testenv +extras = tests [testenv:docs] From 862b0428c1caf4137749611d1d515dbfe532aee1 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Sun, 8 Nov 2020 15:41:35 +0330 Subject: [PATCH 09/13] add vcrpy to tox requirements --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index a783bad..a0c750f 100644 --- a/tox.ini +++ b/tox.ini @@ -22,6 +22,7 @@ passenv = GENIUS* [testenv:test] ; Inherit everything from testenv +extras = tests [testenv:docs] description = Build Sphinx HTML documentation From 99bf0096073f7a19b8ed81616f123515fae97fbb Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Mon, 9 Nov 2020 23:08:58 +0330 Subject: [PATCH 10/13] removed except in tests --- tests/__init__.py | 3 +++ tests/test_album.py | 5 +---- tests/test_api.py | 5 +---- tests/test_artist.py | 5 +---- tests/test_base.py | 5 +---- tests/test_public_methods.py | 6 ++---- tests/test_song.py | 5 +---- tests/test_utils.py | 6 ++---- 8 files changed, 12 insertions(+), 28 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..2bcece0 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,3 @@ +import sys + +sys.path.append('.') \ No newline at end of file diff --git a/tests/test_album.py b/tests/test_album.py index f5d8e01..ddaa816 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -3,10 +3,7 @@ import vcr -try: - from .test_genius import genius, test_vcr -except ModuleNotFoundError: - from test_genius import genius, test_vcr +from .test_genius import genius, test_vcr from lyricsgenius.types import Album diff --git a/tests/test_api.py b/tests/test_api.py index bdd2e6c..5109fbe 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,9 +1,6 @@ import unittest -try: - from .test_genius import genius, test_vcr -except ModuleNotFoundError: - from test_genius import genius, test_vcr +from .test_genius import genius, test_vcr class TestAPI(unittest.TestCase): diff --git a/tests/test_artist.py b/tests/test_artist.py index e4dce9e..b30bda5 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -3,10 +3,7 @@ import vcr -try: - from .test_genius import genius, test_vcr -except ModuleNotFoundError: - from test_genius import genius, test_vcr +from .test_genius import genius, test_vcr from lyricsgenius.types import Artist from lyricsgenius.utils import sanitize_filename diff --git a/tests/test_base.py b/tests/test_base.py index 31dabed..d38b380 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -2,10 +2,7 @@ from requests.exceptions import HTTPError -try: - from .test_genius import genius, test_vcr -except ModuleNotFoundError: - from test_genius import genius, test_vcr +from .test_genius import genius, test_vcr class TestAPIBase(unittest.TestCase): diff --git a/tests/test_public_methods.py b/tests/test_public_methods.py index d7e504f..be4b861 100644 --- a/tests/test_public_methods.py +++ b/tests/test_public_methods.py @@ -4,10 +4,8 @@ from lyricsgenius import PublicAPI -try: - from .test_genius import test_vcr -except ModuleNotFoundError: - from test_genius import test_vcr +from .test_genius import test_vcr + client = PublicAPI() diff --git a/tests/test_song.py b/tests/test_song.py index 2c8b406..e1a101e 100644 --- a/tests/test_song.py +++ b/tests/test_song.py @@ -3,10 +3,7 @@ import vcr -try: - from .test_genius import genius, test_vcr -except ModuleNotFoundError: - from test_genius import genius, test_vcr +from .test_genius import genius, test_vcr from lyricsgenius.types import Song from lyricsgenius.utils import clean_str diff --git a/tests/test_utils.py b/tests/test_utils.py index 6f6eb1c..8221d70 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -5,10 +5,8 @@ sanitize_filename, auth_from_environment ) -try: - from .test_genius import genius -except ModuleNotFoundError: - from test_genius import genius + +from .test_genius import genius class TestUtils(unittest.TestCase): From 6fb48f911b2b875272ff33cacbfb0f1b8dfcf0a2 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Mon, 9 Nov 2020 23:14:30 +0330 Subject: [PATCH 11/13] remove appending tests/ to sys --- tests/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 2bcece0..e69de29 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +0,0 @@ -import sys - -sys.path.append('.') \ No newline at end of file From ad7bfb42254c71dcb661c610b54ac0d35be49820 Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Mon, 9 Nov 2020 23:49:37 +0330 Subject: [PATCH 12/13] fix --- tests/test_genius.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_genius.py b/tests/test_genius.py index ffd48ee..4c8aaac 100644 --- a/tests/test_genius.py +++ b/tests/test_genius.py @@ -12,10 +12,15 @@ "Must declare environment variable: GENIUS_ACCESS_TOKEN") genius = Genius(access_token, sleep_time=1.0, timeout=15) +cassettes_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'fixtures/cassettes' +) + test_vcr = vcr.VCR( path_transformer=vcr.VCR.ensure_suffix('.yaml'), serializer='yaml', - cassette_library_dir='tests/fixtures/cassettes', + cassette_library_dir=cassettes_path, filter_headers=['authorization'] ) From 4ec19ef5cb87630eda0224a664ffa6f3eefc551e Mon Sep 17 00:00:00 2001 From: Allerter <45076212+Allerter@users.noreply.github.com> Date: Tue, 10 Nov 2020 02:04:56 +0330 Subject: [PATCH 13/13] - moved configs to __init__ - ignored ResourceWarning --- tests/__init__.py | 27 +++++++++++++++++++++++++++ tests/test_album.py | 4 +++- tests/test_api.py | 3 ++- tests/test_artist.py | 4 +++- tests/test_auth.py | 1 + tests/test_base.py | 2 +- tests/test_genius.py | 24 +++--------------------- tests/test_public_methods.py | 16 +++++++++++++++- tests/test_song.py | 4 +++- tests/test_utils.py | 2 +- 10 files changed, 59 insertions(+), 28 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index e69de29..1f97eaf 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,27 @@ +import os + +import vcr + +from lyricsgenius import Genius + + +# Import client access token from environment variable +access_token = os.environ.get("GENIUS_ACCESS_TOKEN", None) +assert access_token is not None, ( + "Must declare environment variable: GENIUS_ACCESS_TOKEN") + +# Genius client +genius = Genius(access_token, sleep_time=1.0, timeout=15) + +cassettes_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + 'fixtures/cassettes' +) + +# VCR Configs +test_vcr = vcr.VCR( + path_transformer=vcr.VCR.ensure_suffix('.yaml'), + serializer='yaml', + cassette_library_dir=cassettes_path, + filter_headers=['authorization'] +) diff --git a/tests/test_album.py b/tests/test_album.py index ddaa816..280d1ca 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -1,9 +1,10 @@ import unittest import os +import warnings import vcr -from .test_genius import genius, test_vcr +from . import genius, test_vcr from lyricsgenius.types import Album @@ -14,6 +15,7 @@ class TestAlbum(unittest.TestCase): serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Album tests...\n") + warnings.simplefilter("ignore", ResourceWarning) cls.album_name = "The Party" cls.artist_name = "Andy Shauf" cls.num_songs = 10 diff --git a/tests/test_api.py b/tests/test_api.py index 5109fbe..9711bd6 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,6 +1,7 @@ import unittest -from .test_genius import genius, test_vcr + +from . import genius, test_vcr class TestAPI(unittest.TestCase): diff --git a/tests/test_artist.py b/tests/test_artist.py index b30bda5..a830e4f 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -1,9 +1,10 @@ import unittest import os + import vcr -from .test_genius import genius, test_vcr +from . import genius, test_vcr from lyricsgenius.types import Artist from lyricsgenius.utils import sanitize_filename @@ -15,6 +16,7 @@ class TestArtist(unittest.TestCase): serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Artist tests...\n") + cls.artist_name = "The Beatles" cls.new_song = "Paperback Writer" cls.max_songs = 2 diff --git a/tests/test_auth.py b/tests/test_auth.py index fe359a6..2bac457 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -2,6 +2,7 @@ import unittest from unittest.mock import MagicMock, patch + from lyricsgenius import OAuth2 client_id = os.environ["GENIUS_CLIENT_ID"] diff --git a/tests/test_base.py b/tests/test_base.py index d38b380..e52ec24 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -2,7 +2,7 @@ from requests.exceptions import HTTPError -from .test_genius import genius, test_vcr +from . import genius, test_vcr class TestAPIBase(unittest.TestCase): diff --git a/tests/test_genius.py b/tests/test_genius.py index 4c8aaac..1949f63 100644 --- a/tests/test_genius.py +++ b/tests/test_genius.py @@ -1,28 +1,8 @@ -import os import unittest import vcr -from lyricsgenius import Genius - - -# Import client access token from environment variable -access_token = os.environ.get("GENIUS_ACCESS_TOKEN", None) -assert access_token is not None, ( - "Must declare environment variable: GENIUS_ACCESS_TOKEN") -genius = Genius(access_token, sleep_time=1.0, timeout=15) - -cassettes_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - 'fixtures/cassettes' -) - -test_vcr = vcr.VCR( - path_transformer=vcr.VCR.ensure_suffix('.yaml'), - serializer='yaml', - cassette_library_dir=cassettes_path, - filter_headers=['authorization'] -) +from . import genius, test_vcr class TestEndpoints(unittest.TestCase): @@ -32,6 +12,7 @@ class TestEndpoints(unittest.TestCase): serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Endpoint tests...\n") + cls.search_term = "Ezra Furman" cls.song_title_only = "99 Problems" cls.tag = genius.tag('pop') @@ -105,6 +86,7 @@ class TestLyrics(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up lyrics tests...\n") + cls.song_url = "https://genius.com/Andy-shauf-begin-again-lyrics" cls.song_id = 2885745 cls.lyrics_ending = ( diff --git a/tests/test_public_methods.py b/tests/test_public_methods.py index be4b861..dcb96af 100644 --- a/tests/test_public_methods.py +++ b/tests/test_public_methods.py @@ -1,10 +1,11 @@ import unittest + import vcr from lyricsgenius import PublicAPI -from .test_genius import test_vcr +from . import test_vcr client = PublicAPI() @@ -15,6 +16,7 @@ class TestAlbumMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up album methods tests...\n") + cls.album_id = 104614 @test_vcr.use_cassette @@ -59,6 +61,7 @@ class TestAnnotationMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up annotation methods tests...\n") + cls.annotation_id = 10225840 @test_vcr.use_cassette( @@ -86,6 +89,7 @@ class TestArticleMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up article methods tests...\n") + cls.article_id = 11880 @test_vcr.use_cassette @@ -112,6 +116,7 @@ class TestArtistMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up artist methods tests...\n") + cls.artist_id = 1665 @test_vcr.use_cassette @@ -160,6 +165,7 @@ class TestCoverArtMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up cover arts methods tests...\n") + cls.album_id = 104614 @test_vcr.use_cassette @@ -173,6 +179,7 @@ class TestDiscussionMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up discussion methods tests...\n") + # cls.discussion_id = 123 # # @test_vcr.use_cassette @@ -213,6 +220,7 @@ class TestQuestionMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up question methods tests...\n") + cls.album_id = 104614 @test_vcr.use_cassette @@ -226,6 +234,7 @@ class TestReferentMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up referent methods tests...\n") + cls.web_page_id = 10347 cls.referent_ids = [20793764, 20641014] @@ -246,6 +255,7 @@ class TestSearchMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up search methods tests...\n") + cls.search_term = 'test' @test_vcr.use_cassette @@ -299,6 +309,7 @@ class TestSongMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up song methods tests...\n") + cls.song_id = 378195 @test_vcr.use_cassette @@ -327,6 +338,7 @@ class TestUserMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up user methods tests...\n") + cls.user_id = 1 @test_vcr.use_cassette @@ -402,6 +414,7 @@ class TestVideoMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up video methods tests...\n") + cls.video_id = 18681 @test_vcr.use_cassette @@ -423,6 +436,7 @@ class TestMiscMethods(unittest.TestCase): @classmethod def setUpClass(cls): print("\n---------------------\nSetting up misc methods tests...\n") + # cls.line_item_id = 146262999 cls.annotation_id = 10225840 diff --git a/tests/test_song.py b/tests/test_song.py index e1a101e..db26bc1 100644 --- a/tests/test_song.py +++ b/tests/test_song.py @@ -1,9 +1,10 @@ import os import unittest + import vcr -from .test_genius import genius, test_vcr +from . import genius, test_vcr from lyricsgenius.types import Song from lyricsgenius.utils import clean_str @@ -15,6 +16,7 @@ class TestSong(unittest.TestCase): serializer='yaml') def setUpClass(cls): print("\n---------------------\nSetting up Song tests...\n") + cls.artist_name = 'Andy Shauf' cls.song_title = 'begin again' # Lowercase is intentional cls.album = 'The Party' diff --git a/tests/test_utils.py b/tests/test_utils.py index 8221d70..e666143 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,7 +6,7 @@ auth_from_environment ) -from .test_genius import genius +from . import genius class TestUtils(unittest.TestCase):