diff --git a/tests/httpmocks.py b/tests/httpmocks.py index da9d2b108..b506f8c61 100644 --- a/tests/httpmocks.py +++ b/tests/httpmocks.py @@ -26,8 +26,8 @@ def _content(name): @lru_cache() -def _img(): - with open(_file('empty.png'), 'rb') as f: +def _img(name): + with open(_file(name + '.png'), 'rb') as f: return f.read() @@ -35,12 +35,12 @@ def page(url, pagename): add(GET, url, _content(pagename)) -def png(url): - add(GET, url, _img(), content_type='image/jpeg') +def png(url, name='empty'): + add(GET, url, _img(name), content_type='image/jpeg') -def jpeg(url): - add(GET, url, _img(), content_type='image/jpeg') +def jpeg(url, name='empty'): + add(GET, url, _img(name), content_type='image/jpeg') def xkcd(): diff --git a/tests/responses/tall.png b/tests/responses/tall.png new file mode 100644 index 000000000..cdd2f5ef1 Binary files /dev/null and b/tests/responses/tall.png differ diff --git a/tests/test_dosage.py b/tests/test_dosage.py index fa522da5c..2bd840c40 100644 --- a/tests/test_dosage.py +++ b/tests/test_dosage.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2019 Tobias Gruetzmacher +# Copyright (C) 2015-2020 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function @@ -89,18 +89,35 @@ class TestDosage(object): def test_fetch_html_and_rss_json(self, tmpdir): httpmocks.xkcd() cmd_ok("-n", "2", "-v", "-b", str(tmpdir), "-o", "html", "-o", "rss", - "-o", "json", "xkcd") + "-o", "json", "--no-downscale", "xkcd") @responses.activate - def test_fetch_html_and_rss_2(self, tmpdir): + def test_fetch_html_and_rss_2(self, tmp_path): httpmocks.page('http://www.bloomingfaeries.com/', 'bf-home') httpmocks.page(re.compile('http://www.*faeries-405/'), 'bf-405') - httpmocks.png(re.compile(r'http://www\.bloomingfaeries\.com/.*\.jpg')) + httpmocks.png(re.compile(r'http://www\.blooming.*405.*jpg')) + httpmocks.png(re.compile(r'http://www\.blooming.*406.*jpg'), 'tall') cmd_ok("--numstrips", "2", "--baseurl", "bla", "--basepath", - str(tmpdir), "--output", "rss", "--output", "html", "--adult", + str(tmp_path), "--output", "rss", "--output", "html", "--adult", "BloomingFaeries") + html = next((tmp_path / 'html').glob('*.html')).read_text() + assert "width=" in html + + @responses.activate + def test_fetch_html_broken_img(self, tmp_path): + httpmocks.page('http://www.bloomingfaeries.com/', 'bf-home') + httpmocks.page(re.compile('http://www.*faeries-405/'), 'bf-405') + responses.add(responses.GET, re.compile(r'.*\.jpg'), body=b'\377\330', + content_type='image/jpeg') + + cmd_ok("--numstrips", "2", "--baseurl", "bla", "--basepath", + str(tmp_path), "--output", "html", "--adult", "BloomingFaeries") + + html = next((tmp_path / 'html').glob('*.html')).read_text() + assert "width=" not in html + @responses.activate def test_fetch_indexed(self, tmpdir): httpmocks.xkcd()