From 989f6b8843c949aa2ce3839a37399fcada442ac7 Mon Sep 17 00:00:00 2001 From: Joakim Uddholm Date: Sun, 12 Jun 2016 01:38:01 +0200 Subject: [PATCH] Test to show bug with is_gzipped and Content-Type: application/gzip;charset. --- tests/test_utils_gz.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/test_utils_gz.py b/tests/test_utils_gz.py index 8fb1e414d..e107615f3 100644 --- a/tests/test_utils_gz.py +++ b/tests/test_utils_gz.py @@ -1,7 +1,8 @@ import unittest from os.path import join -from scrapy.utils.gz import gunzip +from scrapy.utils.gz import gunzip, is_gzipped +from scrapy.http import Response, Headers from tests import tests_datadir SAMPLEDIR = join(tests_datadir, 'compressed') @@ -27,3 +28,16 @@ class GunzipTest(unittest.TestCase): with open(join(SAMPLEDIR, 'truncated-crc-error-short.gz'), 'rb') as f: text = gunzip(f.read()) assert text.endswith(b'') + + def test_is_gzipped(self): + hdrs = Headers({"Content-Type": "application/x-gzip"}) + r1 = Response("http://www.example.com", headers=hdrs) + self.assertTrue(is_gzipped(r1)) + r2 = Response("http://www.example.com") + self.assertTrue(not is_gzipped(r2)) + hdrs = Headers({"Content-Type": "application/javascript"}) + r3 = Response("http://www.example.com", headers=hdrs) + self.assertTrue(not is_gzipped(r3)) + hdrs = Headers({"Content-Type": "application/x-gzip;charset=utf-8"}) + r1 = Response("http://www.example.com", headers=hdrs) + self.assertTrue(is_gzipped(r1))