From 1512ed22b264a04feef5823c7661db7ab3093507 Mon Sep 17 00:00:00 2001 From: Akshay Sharma Date: Sun, 25 Jul 2021 19:42:27 +0530 Subject: [PATCH] Pre n post xtractmime tests --- tests/test_responsetypes.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/test_responsetypes.py b/tests/test_responsetypes.py index 26d4a097d..2d8f1b082 100644 --- a/tests/test_responsetypes.py +++ b/tests/test_responsetypes.py @@ -72,23 +72,35 @@ class ResponseTypesTest(unittest.TestCase): retcls = responsetypes.from_headers(source) assert retcls is cls, f"{source} ==> {retcls} != {cls}" - def test_from_args(self): + def test_from_args_pre_xtractmime(self): mappings = [ ({'url': 'http://www.example.com/data.csv'}, TextResponse), - ({'headers': Headers({'Content-Type': ['text/plain; charset=utf-8']}), - 'url': 'http://www.example.com/item/'}, TextResponse), + ({'headers': Headers({'Content-Type': ['text/html; charset=utf-8']}), + 'url': 'http://www.example.com/item/'}, HtmlResponse), # Failing with xtractmime, returning TextResponse expected HtmlResponse + ({'headers': Headers({'Content-Disposition': ['attachment; filename="data.xml.gz"']}), + 'url': 'http://www.example.com/page/'}, Response), # Failing with xtractmime, returning TextResponse expected Response + ] + for source, cls in mappings: + retcls = responsetypes.from_args(**source) + assert retcls is cls, f"{source} ==> {retcls} != {cls}" + + def test_from_args_post_xtractmime(self): + mappings = [ ({'body': b'Some plain text data with tabs and null bytes', - 'url': 'http://www.example.com/item/', 'headers': Headers({'Content-Type': ['text/html; charset=utf-8'], })}, TextResponse), - ({'body': b'\x03\x02\xdf\xdd\x23', 'url': '://www.example.com/item/', - 'headers': Headers({'Content-Encoding': 'UTF-8'})}, Response), - ({'body': b'Some plain text data with tabs and null bytes'}, TextResponse), + ({'body': b'\x03\x02\xdf\xdd\x23', 'headers': Headers({'Content-Encoding': 'UTF-8'})}, + Response), + # different behaviour with http and non-http urls + ({'body': b'\x00\xfe\xff', 'url': 'http://www.example.com/item/', + 'headers': Headers({'Content-Type': b'text/plain'})}, Response), + ({'body': b'\x00\xfe\xff', 'url': '://www.example.com/item/', + 'headers': Headers({'Content-Type': b'text/plain'})}, TextResponse), + ({'url': 'http://www.example.com/item/file.html'}, HtmlResponse), # Failing with xtractmime, return TextResponse expected HtmlResponse + ({'body': b'Some plain text\ndata with tabs\t and null bytes\0'}, Response), # earlier expected to be binary response, refer "test_from_body()" ({'body': b'Hello'}, HtmlResponse), ({'body': b'