summaryrefslogtreecommitdiff
path: root/tests/test_integration.py
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2019-12-23 14:07:56 -0600
committerMichael Merickel <michael@merickel.org>2019-12-23 14:07:56 -0600
commite46d009954e89be393d748b9e97b1202ece3eafe (patch)
treec1b2565b27da44efefdab57294f78025ebad53e1 /tests/test_integration.py
parent570243fcf3f9bb7b3da78404b0598011791ac882 (diff)
parent912dc539ca793959d7465995f906279dad21ccc9 (diff)
downloadpyramid-e46d009954e89be393d748b9e97b1202ece3eafe.tar.gz
pyramid-e46d009954e89be393d748b9e97b1202ece3eafe.tar.bz2
pyramid-e46d009954e89be393d748b9e97b1202ece3eafe.zip
Merge branch 'master' into luhn-authenticated-userid
Diffstat (limited to 'tests/test_integration.py')
-rw-r--r--tests/test_integration.py55
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)