Unit tests for fetchart plugin iTunes source

This commit is contained in:
Reg 2018-12-23 17:48:44 +01:00
parent 8cfbc8274e
commit 5d1c97824c

View file

@ -274,6 +274,88 @@ class AAOTest(UseThePlugin):
next(self.source.get(album, self.settings, []))
class ITunesStoreTest(UseThePlugin):
def setUp(self):
super(ITunesStoreTest, self).setUp()
self.source = fetchart.ITunesStore(logger, self.plugin.config)
self.settings = Settings()
self.album = _common.Bag(albumartist="some artist", album="some album")
@responses.activate
def run(self, *args, **kwargs):
super(ITunesStoreTest, self).run(*args, **kwargs)
def mock_response(self, url, json):
responses.add(responses.GET, url, body=json,
content_type='application/json')
def test_itunesstore_finds_image(self):
json = """{
"results":
[
{
"artistName": "some artist",
"collectionName": "some album",
"artworkUrl100": "url_to_the_image"
}
]
}"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
candidate = next(self.source.get(self.album, self.settings, []))
self.assertEqual(candidate.url, 'url_to_the_image')
def test_itunesstore_no_result(self):
json = '{"results": []}'
self.mock_response(fetchart.ITunesStore.API_URL, json)
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
def test_itunesstore_bad_url(self):
self.mock_response(u'https://www.apple.com', "")
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
def test_itunesstore_returns_result_without_artist(self):
json = """{
"results":
[
{
"collectionName": "some album",
"artworkUrl100": "url_to_the_image"
}
]
}"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
candidate = next(self.source.get(self.album, self.settings, []))
self.assertEqual(candidate.url, 'url_to_the_image')
def test_itunesstore_returns_result_without_artwork(self):
json = """{
"results":
[
{
"artistName": "some artist",
"collectionName": "some album"
}
]
}"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
def test_itunesstore_returns_no_result_when_error_received(self):
json = '{"error": {"errors": [{"reason": "some reason"}]}}'
self.mock_response(fetchart.ITunesStore.API_URL, json)
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
def test_itunesstore_returns_no_result_with_malformed_response(self):
json = """bla blup"""
self.mock_response(fetchart.ITunesStore.API_URL, json)
with self.assertRaises(StopIteration):
next(self.source.get(self.album, self.settings, []))
class GoogleImageTest(UseThePlugin):
def setUp(self):
super(GoogleImageTest, self).setUp()