From db2ff4c3c132407da05dec29294bf7b6aaba8d03 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Sat, 4 Jan 2020 15:51:01 +0100 Subject: [PATCH] Test image "resizing" --- tests/httpmocks.py | 12 ++++++------ tests/responses/tall.png | Bin 0 -> 347 bytes tests/test_dosage.py | 27 ++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 11 deletions(-) create mode 100644 tests/responses/tall.png 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 0000000000000000000000000000000000000000..cdd2f5ef186360c8a2c703a3e7c2e7609dee7261 GIT binary patch literal 347 zcmeAS@N?(olHy`uVBq!ia0y~yV6k9eU~gaq3NSEB-C7Q$m`Z~Df*BafCZ7dLF^YJ) wIEGZ*dV8=Dq~!2|-@)?}*sg-uBNiND{G-djcs=5n9ViGqUHx3vIVCg!0F&ey3;+NC literal 0 HcmV?d00001 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()