-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check python version and enable https where it's possible #2307
Changes from 14 commits
43fcb3d
6ba5099
0fb19cf
f60c911
73a7a4f
d065b33
5ae1376
25ebf89
91819b2
efa9041
420c451
9bba178
21208b8
b65a7da
68b4a03
0868299
471f875
5ca664e
dd115b1
1c5c74f
f941fd4
33a8e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,17 +68,21 @@ 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() | ||
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) | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this test controls the URL on "both ends," i.e. the request and the response, I'm not sure it needs updating. Was it failing before? |
||
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,13 +165,21 @@ 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any way we can avoid copying and pasting here? For example, we could put most of the URLs (starting with |
||
|
||
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) | ||
album = _common.Bag(asin=self.ASIN) | ||
candidate = self.plugin.art_for_album(album, None) | ||
self.assertIsNotNone(candidate) | ||
|
@@ -176,38 +192,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(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) | ||
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) | ||
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) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to assert that the requested URL is equal to two different URLs, which probably isn't what you meant—instead, you probably want to write an assertion that says that the requested URL is either the HTTP one or the HTTPS one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The next couple of tests seem to have the same issue.) |
||
|
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https => http ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's less readable.