From 0e5441806857e3c1ef59d1b2075d6e4238587804 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 18 Nov 2011 05:48:30 -0500 Subject: add tests for content encoding feature --- pyramid/static.py | 3 +- pyramid/tests/fixtures/static/arcs.svg.tgz | 73 ++++++++++++++++++++++++++++++ pyramid/tests/test_static.py | 18 ++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 pyramid/tests/fixtures/static/arcs.svg.tgz diff --git a/pyramid/static.py b/pyramid/static.py index 2a9abbd8f..ba4ac0fa1 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -43,7 +43,8 @@ class _FileResponse(Response): def __init__(self, path, cache_max_age): super(_FileResponse, self).__init__(conditional_response=True) self.last_modified = getmtime(path) - content_type, content_encoding = mimetypes.guess_type(path, strict=False) + content_type, content_encoding = mimetypes.guess_type(path, + strict=False) if content_type is None: content_type = 'application/octet-stream' self.content_type = content_type diff --git a/pyramid/tests/fixtures/static/arcs.svg.tgz b/pyramid/tests/fixtures/static/arcs.svg.tgz new file mode 100644 index 000000000..376c42ac8 --- /dev/null +++ b/pyramid/tests/fixtures/static/arcs.svg.tgz @@ -0,0 +1,73 @@ + + + + + + + + diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py index a04a47397..bd2c2adef 100644 --- a/pyramid/tests/test_static.py +++ b/pyramid/tests/test_static.py @@ -160,6 +160,24 @@ class Test_static_view_use_subpath_False(unittest.TestCase): response = inst(context, request) self.assertEqual(response.status, '404 Not Found') + def test_resource_with_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/arcs.svg.tgz'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'application/x-tar') + self.assertEqual(response.content_encoding, 'gzip') + + def test_resource_no_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/index.html'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'text/html') + self.assertEqual(response.content_encoding, None) + class Test_static_view_use_subpath_True(unittest.TestCase): def _getTargetClass(self): from pyramid.static import static_view -- cgit v1.2.3