diff options
| author | Michael Merickel <michael@merickel.org> | 2019-12-04 01:13:52 -0600 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2019-12-04 23:53:31 -0600 |
| commit | f6cb1efa8fba683bdc5c9b4a645f9357fe2e6208 (patch) | |
| tree | c78f1d8c1c2d695b14f1bfd5358ca05e0c5b2ee0 /tests/test_integration.py | |
| parent | 4d276efe5fd806b74d604c3c8817c0c72808c491 (diff) | |
| download | pyramid-f6cb1efa8fba683bdc5c9b4a645f9357fe2e6208.tar.gz pyramid-f6cb1efa8fba683bdc5c9b4a645f9357fe2e6208.tar.bz2 pyramid-f6cb1efa8fba683bdc5c9b4a645f9357fe2e6208.zip | |
negotiate the best static asset using supported encodings
Diffstat (limited to 'tests/test_integration.py')
| -rw-r--r-- | tests/test_integration.py | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/tests/test_integration.py b/tests/test_integration.py index 331542d7d..8a4575d7b 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -73,8 +73,8 @@ class IntegrationBase(object): root_factory=self.root_factory, package=self.package ) config.include(self.package) - app = config.make_wsgi_app() - self.testapp = TestApp(app) + self.app = config.make_wsgi_app() + self.testapp = TestApp(self.app) self.config = config def tearDown(self): @@ -227,6 +227,57 @@ class TestStaticAppUsingAssetSpec(StaticAppBase, unittest.TestCase): package = 'tests.pkgs.static_assetspec' +class TestStaticAppWithEncodings(IntegrationBase, unittest.TestCase): + package = 'tests.pkgs.static_encodings' + + # XXX webtest actually runs response.decode_content() and so we can't + # use it to test gzip- or deflate-encoded responses to see if they + # were transferred correctly + def _getResponse(self, *args, **kwargs): + from pyramid.request import Request + + req = Request.blank(*args, **kwargs) + return req.get_response(self.app) + + def test_no_accept(self): + res = self._getResponse('/static/encoded.html') + self.assertEqual(res.headers['Vary'], 'Accept-Encoding') + self.assertNotIn('Content-Encoding', res.headers) + _assertBody( + res.body, os.path.join(here, 'fixtures/static/encoded.html') + ) + + def test_unsupported_accept(self): + res = self._getResponse( + '/static/encoded.html', + headers={'Accept-Encoding': 'br, foo, bar'}, + ) + self.assertEqual(res.headers['Vary'], 'Accept-Encoding') + self.assertNotIn('Content-Encoding', res.headers) + _assertBody( + res.body, os.path.join(here, 'fixtures/static/encoded.html') + ) + + def test_accept_gzip(self): + res = self._getResponse( + '/static/encoded.html', + headers={'Accept-Encoding': 'br, foo, gzip'}, + ) + self.assertEqual(res.headers['Vary'], 'Accept-Encoding') + self.assertEqual(res.headers['Content-Encoding'], 'gzip') + _assertBody( + res.body, os.path.join(here, 'fixtures/static/encoded.html.gz') + ) + + def test_accept_gzip_returns_identity(self): + res = self._getResponse( + '/static/index.html', headers={'Accept-Encoding': 'gzip'} + ) + self.assertNotIn('Vary', res.headers) + self.assertNotIn('Content-Encoding', res.headers) + _assertBody(res.body, os.path.join(here, 'fixtures/static/index.html')) + + class TestStaticAppNoSubpath(unittest.TestCase): staticapp = static_view(os.path.join(here, 'fixtures'), use_subpath=False) |
