From 43fcb3d908cdc73314030f48527b142fb97d2041 Mon Sep 17 00:00:00 2001 From: tigranl Date: Mon, 5 Dec 2016 19:09:44 +0300 Subject: [PATCH 01/21] Check python version and enable https where it's possible --- beets/autotag/mb.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 78d382d878..8ceec9d87e 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -28,9 +28,14 @@ from beets import util from beets import config import six +import sys VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377' -BASE_URL = 'http://musicbrainz.org/' + +if sys.version_info > (2, 7, 9): + BASE_URL = 'https://musicbrainz.org/' +else: + BASE_URL = 'http://musicbrainz.org/' musicbrainzngs.set_useragent('beets', beets.__version__, 'http://beets.io/') From 6ba5099034358675d4a3cd71db5b6c38a722b38e Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 16:17:25 +0300 Subject: [PATCH 02/21] Python version check for lyrics.py --- beetsplug/lyrics.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 645d525598..7cd65b0455 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -648,7 +648,8 @@ def get_bing_access_token(self): params = { 'client_id': 'beets', 'client_secret': self.config['bing_client_secret'], - 'scope': 'http://api.microsofttranslator.com', + 'scope': 'https://api.microsofttranslator.com' if sys.version_info >= (2, 7, 9) else + 'http://api.microsofttranslator.com', 'grant_type': 'client_credentials', } From f60c911ffc0b5dca7247c7ed2d136decbbbf940c Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 17:10:35 +0300 Subject: [PATCH 03/21] Add SNI_SUPPORTED variable for https check --- beets/ui/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index ae30a9c60f..5e852262b0 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -43,6 +43,8 @@ from beets.dbcore import query as db_query import six +SNI_SUPPORTED = sys.version_info + # On Windows platforms, use colorama to support "ANSI" terminal colors. if sys.platform == 'win32': try: From 73a7a4ff675894a542a5eade7c27be30d0c58a6a Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 17:10:35 +0300 Subject: [PATCH 04/21] Add SNI_SUPPORTED variable for https check --- beetsplug/fetchart.py | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 27ffa49cb7..b03ed97886 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -292,8 +292,12 @@ def fetch_image(self, candidate, extra): class CoverArtArchive(RemoteArtSource): NAME = u"Cover Art Archive" - URL = 'http://coverartarchive.org/release/{mbid}/front' - GROUP_URL = 'http://coverartarchive.org/release-group/{mbid}/front' + if ui.SNI_SUPPORTED >= (2, 7, 9): + URL = 'https://coverartarchive.org/release/{mbid}/front' + GROUP_URL = 'https://coverartarchive.org/release-group/{mbid}/front' + else: + URL = 'http://coverartarchive.org/release/{mbid}/front' + GROUP_URL = 'http://coverartarchive.org/release-group/{mbid}/front' def get(self, album, extra): """Return the Cover Art Archive and Cover Art Archive release group URLs @@ -310,7 +314,10 @@ def get(self, album, extra): class Amazon(RemoteArtSource): NAME = u"Amazon" - URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' + if ui.SNI_SUPPORTED >= (2, 7, 9): + URL = 'https://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' + else: + URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' INDICES = (1, 2) def get(self, album, extra): @@ -324,7 +331,10 @@ def get(self, album, extra): class AlbumArtOrg(RemoteArtSource): NAME = u"AlbumArt.org scraper" - URL = 'http://www.albumart.org/index_detail.php' + if ui.SNI_SUPPORTED >= (2, 7, 9): + URL = 'https://www.albumart.org/index_detail.php' + else: + URL = 'http://www.albumart.org/index_detail.php' PAT = r'href\s*=\s*"([^>"]*)"[^>]*title\s*=\s*"View larger image"' def get(self, album, extra): @@ -394,8 +404,10 @@ def get(self, album, extra): class FanartTV(RemoteArtSource): """Art from fanart.tv requested using their API""" NAME = u"fanart.tv" - - API_URL = 'http://webservice.fanart.tv/v3/' + if ui.SNI_SUPPORTED >= (2, 7, 9): + API_URL = 'https://webservice.fanart.tv/v3/' + else: + API_URL = 'htts://webservice.fanart.tv/v3/' API_ALBUMS = API_URL + 'music/albums/' PROJECT_KEY = '61a7d0ab4e67162b7a0c7c35915cd48e' @@ -488,8 +500,12 @@ def get(self, album, extra): class Wikipedia(RemoteArtSource): NAME = u"Wikipedia (queried through DBpedia)" - DBPEDIA_URL = 'http://dbpedia.org/sparql' - WIKIPEDIA_URL = 'http://en.wikipedia.org/w/api.php' + if ui.SNI_SUPPORTED >= (2, 7, 9): + DBPEDIA_URL = 'https://dbpedia.org/sparql' + WIKIPEDIA_URL = 'https://en.wikipedia.org/w/api.php' + else: + DBPEDIA_URL = 'http://dbpedia.org/sparql' + WIKIPEDIA_URL = 'http://en.wikipedia.org/w/api.php' SPARQL_QUERY = u'''PREFIX rdf: PREFIX dbpprop: PREFIX owl: From d065b33a816fa3aceef1aae214957a1c40d4b978 Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 17:10:35 +0300 Subject: [PATCH 05/21] Add SNI_SUPPORTED variable for https check --- beetsplug/lastimport.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/beetsplug/lastimport.py b/beetsplug/lastimport.py index 0ed9daf3c5..1bf21c7d42 100644 --- a/beetsplug/lastimport.py +++ b/beetsplug/lastimport.py @@ -23,7 +23,10 @@ from beets import plugins from beets.dbcore import types -API_URL = 'http://ws.audioscrobbler.com/2.0/' +if ui.SNI_SUPPORTED >= (2, 7, 9): + API_URL = 'https://ws.audioscrobbler.com/2.0/' +else: + API_URL = 'https://ws.audioscrobbler.com/2.0/' class LastImportPlugin(plugins.BeetsPlugin): From 5ae13764d88adcc9159c2ef8cdc40115a3ab23c4 Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 17:10:35 +0300 Subject: [PATCH 06/21] Add SNI_SUPPORTED variable for https check --- beets/util/artresizer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index 4c2e925321..4cedf96d36 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -25,6 +25,7 @@ from six.moves.urllib.parse import urlencode from beets import logging from beets import util +from beets import ui import six # Resizing methods @@ -32,7 +33,10 @@ IMAGEMAGICK = 2 WEBPROXY = 3 -PROXY_URL = 'http://images.weserv.nl/' +if ui.SNI_SUPPORTED >= (2, 7, 9): + PROXY_URL = 'https://images.weserv.nl/' +else: + PROXY_URL = 'http://images.weserv.nl/' log = logging.getLogger('beets') From 25ebf8948fcbf5d003a699be3aab8467fd095304 Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 17:10:35 +0300 Subject: [PATCH 07/21] Revert "Add SNI_SUPPORTED variable for https check" This reverts commit f60c911ffc0b5dca7247c7ed2d136decbbbf940c. --- beets/ui/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/beets/ui/__init__.py b/beets/ui/__init__.py index 5e852262b0..ae30a9c60f 100644 --- a/beets/ui/__init__.py +++ b/beets/ui/__init__.py @@ -43,8 +43,6 @@ from beets.dbcore import query as db_query import six -SNI_SUPPORTED = sys.version_info - # On Windows platforms, use colorama to support "ANSI" terminal colors. if sys.platform == 'win32': try: From 91819b2c80799aa9cb6f942676b4150f8356bc6f Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 19:31:42 +0300 Subject: [PATCH 08/21] Add SNI_SUPPORTED --- beets/util/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beets/util/__init__.py b/beets/util/__init__.py index 5e1c30df19..dec97153ed 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -33,6 +33,7 @@ MAX_FILENAME_LENGTH = 200 WINDOWS_MAGIC_PREFIX = u'\\\\?\\' +SNI_SUPPORTED = sys.version_info >= (2, 7, 9) class HumanReadableException(Exception): From efa90416a0437859c12a29709feaa1f01de3c030 Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 19:31:42 +0300 Subject: [PATCH 09/21] Add SNI_SUPPORTED Add SNI_SUPPORTED --- beetsplug/fetchart.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index b03ed97886..b852eba17c 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -292,7 +292,7 @@ def fetch_image(self, candidate, extra): class CoverArtArchive(RemoteArtSource): NAME = u"Cover Art Archive" - if ui.SNI_SUPPORTED >= (2, 7, 9): + if uti.SNI_SUPPORTED: URL = 'https://coverartarchive.org/release/{mbid}/front' GROUP_URL = 'https://coverartarchive.org/release-group/{mbid}/front' else: @@ -314,7 +314,7 @@ def get(self, album, extra): class Amazon(RemoteArtSource): NAME = u"Amazon" - if ui.SNI_SUPPORTED >= (2, 7, 9): + if util.SNI_SUPPORTED: URL = 'https://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' else: URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' @@ -331,7 +331,7 @@ def get(self, album, extra): class AlbumArtOrg(RemoteArtSource): NAME = u"AlbumArt.org scraper" - if ui.SNI_SUPPORTED >= (2, 7, 9): + if util.SNI_SUPPORTED: URL = 'https://www.albumart.org/index_detail.php' else: URL = 'http://www.albumart.org/index_detail.php' @@ -404,7 +404,7 @@ def get(self, album, extra): class FanartTV(RemoteArtSource): """Art from fanart.tv requested using their API""" NAME = u"fanart.tv" - if ui.SNI_SUPPORTED >= (2, 7, 9): + if util.SNI_SUPPORTED: API_URL = 'https://webservice.fanart.tv/v3/' else: API_URL = 'htts://webservice.fanart.tv/v3/' @@ -500,7 +500,7 @@ def get(self, album, extra): class Wikipedia(RemoteArtSource): NAME = u"Wikipedia (queried through DBpedia)" - if ui.SNI_SUPPORTED >= (2, 7, 9): + if uti.SNI_SUPPORTED: DBPEDIA_URL = 'https://dbpedia.org/sparql' WIKIPEDIA_URL = 'https://en.wikipedia.org/w/api.php' else: From 420c451928840f9fe824351361e63935a40cfa00 Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 19:31:42 +0300 Subject: [PATCH 10/21] Add SNI_SUPPORTED Add SNI_SUPPORTED Add SNI_SUPPORTED --- beets/autotag/mb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 8ceec9d87e..8d5641ca43 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -32,7 +32,7 @@ VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377' -if sys.version_info > (2, 7, 9): +if util.SNI_SUPPORTED: BASE_URL = 'https://musicbrainz.org/' else: BASE_URL = 'http://musicbrainz.org/' From 9bba178b5cf06df29afb73b71d5782c12ab8b0ed Mon Sep 17 00:00:00 2001 From: tigranl Date: Tue, 6 Dec 2016 19:31:42 +0300 Subject: [PATCH 11/21] Add tests for https --- test/test_art.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/test_art.py b/test/test_art.py index aba1807805..393527eef5 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -68,6 +68,7 @@ def mock_response(self, url, content_type='image/jpeg', file_type=None): class FetchImageTest(FetchImageHelper, UseThePlugin): URL = 'http://example.com/test.jpg' + URL_HTTPS = 'https://example.com/test.jpg' def setUp(self): super(FetchImageTest, self).setUp() @@ -75,10 +76,13 @@ def setUp(self): self.source = fetchart.RemoteArtSource(logger, self.plugin.config) self.extra = {'maxwidth': 0} self.candidate = fetchart.Candidate(logger, url=self.URL) + self.candidate_https = fetchart.Candidate(logger, url=self.URL_HTTPS) def test_invalid_type_returns_none(self): self.mock_response(self.URL, 'image/watercolour') + self.mock_response(self.URL_HTTPS, 'image/watercolour') self.source.fetch_image(self.candidate, self.extra) + self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(self.candidate.path, None) def test_jpeg_type_returns_path(self): @@ -88,13 +92,17 @@ def test_jpeg_type_returns_path(self): def test_extension_set_by_content_type(self): self.mock_response(self.URL, 'image/png') + self.mock_response(self.URL_HTTPS, 'image/png') self.source.fetch_image(self.candidate, self.extra) + self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) def test_does_not_rely_on_server_content_type(self): self.mock_response(self.URL, 'image/jpeg', 'image/png') + self.mock_response(self.URL_HTTPS, 'image/jpeg', 'imsge/png') self.source.fetch_image(self.candidate, self.extra) + self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) @@ -157,6 +165,13 @@ class CombinedTest(FetchImageHelper, UseThePlugin): CAA_URL = 'http://coverartarchive.org/release/{0}/front' \ .format(MBID) + AMAZON_URL_HTTPS = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ + .format(ASIN) + AAO_URL_HTTPS = 'http://www.albumart.org/index_detail.php?asin={0}' \ + .format(ASIN) + CAA_URL_HTTPS = 'http://coverartarchive.org/release/{0}/front' \ + .format(MBID) + def setUp(self): super(CombinedTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') @@ -164,6 +179,7 @@ def setUp(self): def test_main_interface_returns_amazon_art(self): self.mock_response(self.AMAZON_URL) + self.mock_response(self.AMAZON_URL_HTTPS) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) @@ -176,6 +192,7 @@ def test_main_interface_returns_none_for_missing_asin_and_path(self): def test_main_interface_gives_precedence_to_fs_art(self): _common.touch(os.path.join(self.dpath, b'art.jpg')) self.mock_response(self.AMAZON_URL) + self.mock_response(self.AMAZON_URL_HTTPS) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) @@ -183,6 +200,7 @@ def test_main_interface_gives_precedence_to_fs_art(self): def test_main_interface_falls_back_to_amazon(self): self.mock_response(self.AMAZON_URL) + self.mock_response(self.AMAZON_URL_HTTPS) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) @@ -190,24 +208,30 @@ def test_main_interface_falls_back_to_amazon(self): def test_main_interface_tries_amazon_before_aao(self): self.mock_response(self.AMAZON_URL) + self.mock_response(self.AMAZON_URL_HTTPS) album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL) + self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL_HTTPS) def test_main_interface_falls_back_to_aao(self): self.mock_response(self.AMAZON_URL, content_type='text/html') + self.mock_response(self.AMAZON_URL_HTTPS, content_type='text/html') album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(responses.calls[-1].request.url, self.AAO_URL) + self.assertEqual(responses.calls[-1].request.url, self.AAO_URL_HTTPS) def test_main_interface_uses_caa_when_mbid_available(self): self.mock_response(self.CAA_URL) + self.mock_response(self.CAA_URL_HTTPS) album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) self.assertEqual(len(responses.calls), 1) self.assertEqual(responses.calls[0].request.url, self.CAA_URL) + self.assertEqual(responses.calls[0].request.url, self.CAA_URL_HTTPS) def test_local_only_does_not_access_network(self): album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) From 21208b8c399287185a98aab9a85543dd6408e082 Mon Sep 17 00:00:00 2001 From: tigranl Date: Thu, 8 Dec 2016 19:09:15 +0300 Subject: [PATCH 12/21] Add SNI_SUPPORTED --- beets/util/artresizer.py | 3 +-- beetsplug/fetchart.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/beets/util/artresizer.py b/beets/util/artresizer.py index 4cedf96d36..e84b775dce 100644 --- a/beets/util/artresizer.py +++ b/beets/util/artresizer.py @@ -25,7 +25,6 @@ from six.moves.urllib.parse import urlencode from beets import logging from beets import util -from beets import ui import six # Resizing methods @@ -33,7 +32,7 @@ IMAGEMAGICK = 2 WEBPROXY = 3 -if ui.SNI_SUPPORTED >= (2, 7, 9): +if util.SNI_SUPPORTED: PROXY_URL = 'https://images.weserv.nl/' else: PROXY_URL = 'http://images.weserv.nl/' diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index b852eba17c..8af29ae753 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -292,7 +292,7 @@ def fetch_image(self, candidate, extra): class CoverArtArchive(RemoteArtSource): NAME = u"Cover Art Archive" - if uti.SNI_SUPPORTED: + if util.SNI_SUPPORTED: URL = 'https://coverartarchive.org/release/{mbid}/front' GROUP_URL = 'https://coverartarchive.org/release-group/{mbid}/front' else: @@ -500,7 +500,7 @@ def get(self, album, extra): class Wikipedia(RemoteArtSource): NAME = u"Wikipedia (queried through DBpedia)" - if uti.SNI_SUPPORTED: + if util.SNI_SUPPORTED: DBPEDIA_URL = 'https://dbpedia.org/sparql' WIKIPEDIA_URL = 'https://en.wikipedia.org/w/api.php' else: From b65a7da8e2e6497ab1ef168e2073545875ec39d7 Mon Sep 17 00:00:00 2001 From: tigranl Date: Thu, 8 Dec 2016 19:20:18 +0300 Subject: [PATCH 13/21] Add SNI_SUPPORTED --- beetsplug/lastimport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/lastimport.py b/beetsplug/lastimport.py index 1bf21c7d42..c9cadc6a00 100644 --- a/beetsplug/lastimport.py +++ b/beetsplug/lastimport.py @@ -17,13 +17,13 @@ import pylast from pylast import TopItem, _extract, _number -from beets import ui +from beets import util from beets import dbcore from beets import config from beets import plugins from beets.dbcore import types -if ui.SNI_SUPPORTED >= (2, 7, 9): +if util.SNI_SUPPORTED: API_URL = 'https://ws.audioscrobbler.com/2.0/' else: API_URL = 'https://ws.audioscrobbler.com/2.0/' From 68b4a03ecd96fa42b7afcedeb00e8859b43569fa Mon Sep 17 00:00:00 2001 From: tigranl Date: Sat, 10 Dec 2016 19:54:44 +0300 Subject: [PATCH 14/21] Add tests for https --- beetsplug/fetchart.py | 10 ++----- test/test_art.py | 69 +++++++++++++++++-------------------------- 2 files changed, 29 insertions(+), 50 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 8af29ae753..2ba5bcb7ee 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -314,10 +314,7 @@ def get(self, album, extra): class Amazon(RemoteArtSource): NAME = u"Amazon" - if util.SNI_SUPPORTED: - URL = 'https://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' - else: - URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' + URL = 'http://images.amazon.com/images/P/%s.%02i.LZZZZZZZ.jpg' INDICES = (1, 2) def get(self, album, extra): @@ -331,10 +328,7 @@ def get(self, album, extra): class AlbumArtOrg(RemoteArtSource): NAME = u"AlbumArt.org scraper" - if util.SNI_SUPPORTED: - URL = 'https://www.albumart.org/index_detail.php' - else: - URL = 'http://www.albumart.org/index_detail.php' + URL = 'http://www.albumart.org/index_detail.php' PAT = r'href\s*=\s*"([^>"]*)"[^>]*title\s*=\s*"View larger image"' def get(self, album, extra): diff --git a/test/test_art.py b/test/test_art.py index 393527eef5..694d9a05c0 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -67,42 +67,38 @@ def mock_response(self, url, content_type='image/jpeg', file_type=None): class FetchImageTest(FetchImageHelper, UseThePlugin): - URL = 'http://example.com/test.jpg' - URL_HTTPS = 'https://example.com/test.jpg' + URL = '{0}example.com/test.jpg' def setUp(self): super(FetchImageTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') self.source = fetchart.RemoteArtSource(logger, self.plugin.config) self.extra = {'maxwidth': 0} - self.candidate = fetchart.Candidate(logger, url=self.URL) - self.candidate_https = fetchart.Candidate(logger, url=self.URL_HTTPS) + self.candidate = fetchart.Candidate(logger, url=self.URL.format('http://')) def test_invalid_type_returns_none(self): - self.mock_response(self.URL, 'image/watercolour') - self.mock_response(self.URL_HTTPS, 'image/watercolour') + self.mock_response(self.URL.format('http://'), 'image/watercolour') + self.mock_response(self.URL.format('https://'), 'image/watercolour') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(self.candidate.path, None) def test_jpeg_type_returns_path(self): - self.mock_response(self.URL, 'image/jpeg') + self.mock_response(self.URL.format('http://'), 'image/jpeg') + self.mock_response(self.URL.format('https://')) self.source.fetch_image(self.candidate, self.extra) self.assertNotEqual(self.candidate.path, None) def test_extension_set_by_content_type(self): - self.mock_response(self.URL, 'image/png') - self.mock_response(self.URL_HTTPS, 'image/png') + self.mock_response(self.URL.format('http://'), 'image/png') + self.mock_response(self.URL.format('https://'), 'image/png') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) def test_does_not_rely_on_server_content_type(self): - self.mock_response(self.URL, 'image/jpeg', 'image/png') - self.mock_response(self.URL_HTTPS, 'image/jpeg', 'imsge/png') + self.mock_response(self.URL.format('http://'), 'image/jpeg', 'image/png') + self.mock_response(self.URL.format('https://'), 'image/jpeg', 'imsge/png') self.source.fetch_image(self.candidate, self.extra) - self.source.fetch_image(self.candidate_https, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) @@ -158,28 +154,20 @@ def test_precedence_amongst_correct_files(self): class CombinedTest(FetchImageHelper, UseThePlugin): ASIN = 'xxxx' MBID = 'releaseid' - AMAZON_URL = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ + AMAZON_URL = 'images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ .format(ASIN) - AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}' \ + AAO_URL = 'www.albumart.org/index_detail.php?asin={0}' \ .format(ASIN) - CAA_URL = 'http://coverartarchive.org/release/{0}/front' \ + CAA_URL = 'coverartarchive.org/release/{0}/front' \ .format(MBID) - AMAZON_URL_HTTPS = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ - .format(ASIN) - AAO_URL_HTTPS = 'http://www.albumart.org/index_detail.php?asin={0}' \ - .format(ASIN) - CAA_URL_HTTPS = 'http://coverartarchive.org/release/{0}/front' \ - .format(MBID) - def setUp(self): super(CombinedTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') os.mkdir(self.dpath) def test_main_interface_returns_amazon_art(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) @@ -191,47 +179,44 @@ def test_main_interface_returns_none_for_missing_asin_and_path(self): def test_main_interface_gives_precedence_to_fs_art(self): _common.touch(os.path.join(self.dpath, b'art.jpg')) - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg')) def test_main_interface_falls_back_to_amazon(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertFalse(candidate.path.startswith(self.dpath)) def test_main_interface_tries_amazon_before_aao(self): - self.mock_response(self.AMAZON_URL) - self.mock_response(self.AMAZON_URL_HTTPS) + self.mock_response("http://"+self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL) - self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL_HTTPS) + self.assertEqual(responses.calls[0].request.url, "http://"+self.AMAZON_URL) def test_main_interface_falls_back_to_aao(self): - self.mock_response(self.AMAZON_URL, content_type='text/html') - self.mock_response(self.AMAZON_URL_HTTPS, content_type='text/html') + self.mock_response("http://"+self.AMAZON_URL, content_type='text/html') album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) - self.assertEqual(responses.calls[-1].request.url, self.AAO_URL) - self.assertEqual(responses.calls[-1].request.url, self.AAO_URL_HTTPS) + self.assertEqual(responses.calls[-1].request.url, "http://"+self.AAO_URL) def test_main_interface_uses_caa_when_mbid_available(self): - self.mock_response(self.CAA_URL) - self.mock_response(self.CAA_URL_HTTPS) + self.mock_response("http://"+self.CAA_URL) + self.mock_response("https://"+self.CAA_URL) album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, self.CAA_URL) - self.assertEqual(responses.calls[0].request.url, self.CAA_URL_HTTPS) + if util.SNI_SUPPORTED: + url = "https://"+self.CAA_URL + else: + url = "http://"+self.CAA_URL + self.assertEqual(responses.calls[0].request.url, url) def test_local_only_does_not_access_network(self): album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) From 0868299e92fb966c7d9c3351a7697693a74248eb Mon Sep 17 00:00:00 2001 From: tigranl Date: Sat, 10 Dec 2016 20:08:27 +0300 Subject: [PATCH 15/21] PEP8 corrections --- test/test_art.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/test/test_art.py b/test/test_art.py index 694d9a05c0..bc3319cc23 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -74,7 +74,8 @@ def setUp(self): self.dpath = os.path.join(self.temp_dir, b'arttest') self.source = fetchart.RemoteArtSource(logger, self.plugin.config) self.extra = {'maxwidth': 0} - self.candidate = fetchart.Candidate(logger, url=self.URL.format('http://')) + self.candidate = fetchart.Candidate(logger, + url=self.URL.format('http://')) def test_invalid_type_returns_none(self): self.mock_response(self.URL.format('http://'), 'image/watercolour') @@ -96,8 +97,10 @@ def test_extension_set_by_content_type(self): self.assertExists(self.candidate.path) def test_does_not_rely_on_server_content_type(self): - self.mock_response(self.URL.format('http://'), 'image/jpeg', 'image/png') - self.mock_response(self.URL.format('https://'), 'image/jpeg', 'imsge/png') + self.mock_response(self.URL.format('http://'), + 'image/jpeg', 'image/png') + self.mock_response(self.URL.format('https://'), + 'image/jpeg', 'imsge/png') self.source.fetch_image(self.candidate, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) @@ -167,7 +170,7 @@ def setUp(self): os.mkdir(self.dpath) def test_main_interface_returns_amazon_art(self): - self.mock_response("http://"+self.AMAZON_URL) + self.mock_response("http://" + self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) @@ -179,43 +182,46 @@ def test_main_interface_returns_none_for_missing_asin_and_path(self): def test_main_interface_gives_precedence_to_fs_art(self): _common.touch(os.path.join(self.dpath, b'art.jpg')) - self.mock_response("http://"+self.AMAZON_URL) + self.mock_response("http://" + self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg')) def test_main_interface_falls_back_to_amazon(self): - self.mock_response("http://"+self.AMAZON_URL) + self.mock_response("http://" + self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertFalse(candidate.path.startswith(self.dpath)) def test_main_interface_tries_amazon_before_aao(self): - self.mock_response("http://"+self.AMAZON_URL) + self.mock_response("http://" + self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, "http://"+self.AMAZON_URL) + self.assertEqual(responses.calls[0].request.url, + "http://" + self.AMAZON_URL) def test_main_interface_falls_back_to_aao(self): - self.mock_response("http://"+self.AMAZON_URL, content_type='text/html') + self.mock_response("http://" + self.AMAZON_URL, + content_type='text/html') album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) - self.assertEqual(responses.calls[-1].request.url, "http://"+self.AAO_URL) + self.assertEqual(responses.calls[-1].request.url, + "http://" + self.AAO_URL) def test_main_interface_uses_caa_when_mbid_available(self): - self.mock_response("http://"+self.CAA_URL) - self.mock_response("https://"+self.CAA_URL) + self.mock_response("http://" + self.CAA_URL) + self.mock_response("https://" + self.CAA_URL) album = _common.Bag(mb_albumid=self.MBID, asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) self.assertEqual(len(responses.calls), 1) if util.SNI_SUPPORTED: - url = "https://"+self.CAA_URL + url = "https://" + self.CAA_URL else: - url = "http://"+self.CAA_URL + url = "http://" + self.CAA_URL self.assertEqual(responses.calls[0].request.url, url) def test_local_only_does_not_access_network(self): From 471f875dc17bbd9bad0388671d51a828f0039073 Mon Sep 17 00:00:00 2001 From: tigranl Date: Sat, 10 Dec 2016 21:26:51 +0300 Subject: [PATCH 16/21] Fix typo --- beetsplug/fetchart.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 2ba5bcb7ee..855a1df10a 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -401,7 +401,7 @@ class FanartTV(RemoteArtSource): if util.SNI_SUPPORTED: API_URL = 'https://webservice.fanart.tv/v3/' else: - API_URL = 'htts://webservice.fanart.tv/v3/' + API_URL = 'https://webservice.fanart.tv/v3/' API_ALBUMS = API_URL + 'music/albums/' PROJECT_KEY = '61a7d0ab4e67162b7a0c7c35915cd48e' From 5ca664e4aaeb9c666f7d95af85f73c356309406a Mon Sep 17 00:00:00 2001 From: tigranl Date: Sun, 11 Dec 2016 00:25:37 +0300 Subject: [PATCH 17/21] Fix typos --- beets/autotag/mb.py | 1 - beetsplug/lastimport.py | 1 + beetsplug/lyrics.py | 7 ++++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 8d5641ca43..88fa16c3a5 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -28,7 +28,6 @@ from beets import util from beets import config import six -import sys VARIOUS_ARTISTS_ID = '89ad4ac3-39f7-470e-963a-56509c546377' diff --git a/beetsplug/lastimport.py b/beetsplug/lastimport.py index c9cadc6a00..25624731e6 100644 --- a/beetsplug/lastimport.py +++ b/beetsplug/lastimport.py @@ -18,6 +18,7 @@ import pylast from pylast import TopItem, _extract, _number from beets import util +from beets import ui from beets import dbcore from beets import config from beets import plugins diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index 7cd65b0455..b837aef15d 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -50,7 +50,7 @@ class HTMLParseError(Exception): pass from beets import plugins -from beets import ui +from beets import util DIV_RE = re.compile(r'<(/?)div>?', re.I) @@ -645,11 +645,12 @@ def __init__(self): for source in sources] def get_bing_access_token(self): + url = "{0}api.microsofttranslator.com" params = { 'client_id': 'beets', 'client_secret': self.config['bing_client_secret'], - 'scope': 'https://api.microsofttranslator.com' if sys.version_info >= (2, 7, 9) else - 'http://api.microsofttranslator.com', + 'scope': url.format('https://') if util.SNI_SUPPORTED + else url.format('http://'), 'grant_type': 'client_credentials', } From dd115b13106ee9755ac2796179c91bde0b4545db Mon Sep 17 00:00:00 2001 From: tigranl Date: Sun, 11 Dec 2016 00:35:51 +0300 Subject: [PATCH 18/21] Add ui import --- beetsplug/lyrics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index b837aef15d..feab2180e0 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -51,6 +51,7 @@ class HTMLParseError(Exception): from beets import plugins from beets import util +from beets import ui DIV_RE = re.compile(r'<(/?)div>?', re.I) From 1c5c74f1d73fdb943074c6e89d2affb44511aa71 Mon Sep 17 00:00:00 2001 From: Tigran Kostandyan Date: Sat, 31 Dec 2016 18:46:01 +0300 Subject: [PATCH 19/21] Fix a typo --- beetsplug/lastimport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/lastimport.py b/beetsplug/lastimport.py index 25624731e6..238e447bc4 100644 --- a/beetsplug/lastimport.py +++ b/beetsplug/lastimport.py @@ -27,7 +27,7 @@ if util.SNI_SUPPORTED: API_URL = 'https://ws.audioscrobbler.com/2.0/' else: - API_URL = 'https://ws.audioscrobbler.com/2.0/' + API_URL = 'http://ws.audioscrobbler.com/2.0/' class LastImportPlugin(plugins.BeetsPlugin): From f941fd42de2966686301ceb657bd10b89febea08 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 2 Jan 2017 20:39:10 -0500 Subject: [PATCH 20/21] Always use SSL on servers that don't require SNI I did a little audit using the `openssl` command-line tool to find the servers that don't require SNI. Here's what I found: icbrainz.org: SNI images.weserv.nl: inconclusive, but docs say yes SNI coverartarchive.org: SNI webservice.fanart.tv: *no* SNI dbpedia.org: *no* SNI en.wikipedia.org: *no* SNI ws.audioscrobbler.com: *no* SNI api.microsofttranslator.com: *no* SNI In summary, *only* MusicBrainz and CoverArtArchive were found to require SNI. So I'm using SSL unconditionally on all the other sites. --- beetsplug/fetchart.py | 13 +++---------- beetsplug/lastimport.py | 6 +----- beetsplug/lyrics.py | 5 +---- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/beetsplug/fetchart.py b/beetsplug/fetchart.py index 855a1df10a..d87a5dc487 100644 --- a/beetsplug/fetchart.py +++ b/beetsplug/fetchart.py @@ -398,10 +398,7 @@ def get(self, album, extra): class FanartTV(RemoteArtSource): """Art from fanart.tv requested using their API""" NAME = u"fanart.tv" - if util.SNI_SUPPORTED: - API_URL = 'https://webservice.fanart.tv/v3/' - else: - API_URL = 'https://webservice.fanart.tv/v3/' + API_URL = 'https://webservice.fanart.tv/v3/' API_ALBUMS = API_URL + 'music/albums/' PROJECT_KEY = '61a7d0ab4e67162b7a0c7c35915cd48e' @@ -494,12 +491,8 @@ def get(self, album, extra): class Wikipedia(RemoteArtSource): NAME = u"Wikipedia (queried through DBpedia)" - if util.SNI_SUPPORTED: - DBPEDIA_URL = 'https://dbpedia.org/sparql' - WIKIPEDIA_URL = 'https://en.wikipedia.org/w/api.php' - else: - DBPEDIA_URL = 'http://dbpedia.org/sparql' - WIKIPEDIA_URL = 'http://en.wikipedia.org/w/api.php' + DBPEDIA_URL = 'https://dbpedia.org/sparql' + WIKIPEDIA_URL = 'https://en.wikipedia.org/w/api.php' SPARQL_QUERY = u'''PREFIX rdf: PREFIX dbpprop: PREFIX owl: diff --git a/beetsplug/lastimport.py b/beetsplug/lastimport.py index 238e447bc4..d7b84b0aa0 100644 --- a/beetsplug/lastimport.py +++ b/beetsplug/lastimport.py @@ -17,17 +17,13 @@ import pylast from pylast import TopItem, _extract, _number -from beets import util from beets import ui from beets import dbcore from beets import config from beets import plugins from beets.dbcore import types -if util.SNI_SUPPORTED: - API_URL = 'https://ws.audioscrobbler.com/2.0/' -else: - API_URL = 'http://ws.audioscrobbler.com/2.0/' +API_URL = 'https://ws.audioscrobbler.com/2.0/' class LastImportPlugin(plugins.BeetsPlugin): diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index feab2180e0..bce95759eb 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -50,7 +50,6 @@ class HTMLParseError(Exception): pass from beets import plugins -from beets import util from beets import ui @@ -646,12 +645,10 @@ def __init__(self): for source in sources] def get_bing_access_token(self): - url = "{0}api.microsofttranslator.com" params = { 'client_id': 'beets', 'client_secret': self.config['bing_client_secret'], - 'scope': url.format('https://') if util.SNI_SUPPORTED - else url.format('http://'), + 'scope': "https://api.microsofttranslator.com", 'grant_type': 'client_credentials', } From 33a8e81f08641b4dee8a1767ab45646271222f58 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 2 Jan 2017 20:49:12 -0500 Subject: [PATCH 21/21] Simplify test changes We don't need quite so many checks now that SSL isn't conditional most of the time. --- test/test_art.py | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/test/test_art.py b/test/test_art.py index bc3319cc23..50ff26b002 100644 --- a/test/test_art.py +++ b/test/test_art.py @@ -67,40 +67,33 @@ def mock_response(self, url, content_type='image/jpeg', file_type=None): class FetchImageTest(FetchImageHelper, UseThePlugin): - URL = '{0}example.com/test.jpg' + URL = 'http://example.com/test.jpg' def setUp(self): super(FetchImageTest, self).setUp() self.dpath = os.path.join(self.temp_dir, b'arttest') self.source = fetchart.RemoteArtSource(logger, self.plugin.config) self.extra = {'maxwidth': 0} - self.candidate = fetchart.Candidate(logger, - url=self.URL.format('http://')) + self.candidate = fetchart.Candidate(logger, url=self.URL) def test_invalid_type_returns_none(self): - self.mock_response(self.URL.format('http://'), 'image/watercolour') - self.mock_response(self.URL.format('https://'), 'image/watercolour') + self.mock_response(self.URL, 'image/watercolour') self.source.fetch_image(self.candidate, self.extra) self.assertEqual(self.candidate.path, None) def test_jpeg_type_returns_path(self): - self.mock_response(self.URL.format('http://'), 'image/jpeg') - self.mock_response(self.URL.format('https://')) + self.mock_response(self.URL, 'image/jpeg') self.source.fetch_image(self.candidate, self.extra) self.assertNotEqual(self.candidate.path, None) def test_extension_set_by_content_type(self): - self.mock_response(self.URL.format('http://'), 'image/png') - self.mock_response(self.URL.format('https://'), 'image/png') + self.mock_response(self.URL, 'image/png') self.source.fetch_image(self.candidate, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) def test_does_not_rely_on_server_content_type(self): - self.mock_response(self.URL.format('http://'), - 'image/jpeg', 'image/png') - self.mock_response(self.URL.format('https://'), - 'image/jpeg', 'imsge/png') + self.mock_response(self.URL, 'image/jpeg', 'image/png') self.source.fetch_image(self.candidate, self.extra) self.assertEqual(os.path.splitext(self.candidate.path)[1], b'.png') self.assertExists(self.candidate.path) @@ -157,9 +150,9 @@ def test_precedence_amongst_correct_files(self): class CombinedTest(FetchImageHelper, UseThePlugin): ASIN = 'xxxx' MBID = 'releaseid' - AMAZON_URL = 'images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ + AMAZON_URL = 'http://images.amazon.com/images/P/{0}.01.LZZZZZZZ.jpg' \ .format(ASIN) - AAO_URL = 'www.albumart.org/index_detail.php?asin={0}' \ + AAO_URL = 'http://www.albumart.org/index_detail.php?asin={0}' \ .format(ASIN) CAA_URL = 'coverartarchive.org/release/{0}/front' \ .format(MBID) @@ -170,7 +163,7 @@ def setUp(self): os.mkdir(self.dpath) def test_main_interface_returns_amazon_art(self): - self.mock_response("http://" + self.AMAZON_URL) + self.mock_response(self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, None) self.assertIsNotNone(candidate) @@ -182,34 +175,31 @@ def test_main_interface_returns_none_for_missing_asin_and_path(self): def test_main_interface_gives_precedence_to_fs_art(self): _common.touch(os.path.join(self.dpath, b'art.jpg')) - self.mock_response("http://" + self.AMAZON_URL) + self.mock_response(self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertEqual(candidate.path, os.path.join(self.dpath, b'art.jpg')) def test_main_interface_falls_back_to_amazon(self): - self.mock_response("http://" + self.AMAZON_URL) + self.mock_response(self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) candidate = self.plugin.art_for_album(album, [self.dpath]) self.assertIsNotNone(candidate) self.assertFalse(candidate.path.startswith(self.dpath)) def test_main_interface_tries_amazon_before_aao(self): - self.mock_response("http://" + self.AMAZON_URL) + self.mock_response(self.AMAZON_URL) album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) self.assertEqual(len(responses.calls), 1) - self.assertEqual(responses.calls[0].request.url, - "http://" + self.AMAZON_URL) + self.assertEqual(responses.calls[0].request.url, self.AMAZON_URL) def test_main_interface_falls_back_to_aao(self): - self.mock_response("http://" + self.AMAZON_URL, - content_type='text/html') + self.mock_response(self.AMAZON_URL, content_type='text/html') album = _common.Bag(asin=self.ASIN) self.plugin.art_for_album(album, [self.dpath]) - self.assertEqual(responses.calls[-1].request.url, - "http://" + self.AAO_URL) + self.assertEqual(responses.calls[-1].request.url, self.AAO_URL) def test_main_interface_uses_caa_when_mbid_available(self): self.mock_response("http://" + self.CAA_URL)