diff options
| author | Michael Merickel <michael@merickel.org> | 2013-03-19 10:22:19 -0700 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2013-03-19 10:22:19 -0700 |
| commit | 28b233f95b33efe8c3cab1fc5fd4f5a6b31e0319 (patch) | |
| tree | 3d2f6a0ba7a0a1f18c29a0632100f71a18d7808b | |
| parent | 69c3ad9896ae3ef82fa458629bc2213fd7b8de84 (diff) | |
| parent | e100873f6422b20d6bfda78abd684d7908d8a825 (diff) | |
| download | pyramid-28b233f95b33efe8c3cab1fc5fd4f5a6b31e0319.tar.gz pyramid-28b233f95b33efe8c3cab1fc5fd4f5a6b31e0319.tar.bz2 pyramid-28b233f95b33efe8c3cab1fc5fd4f5a6b31e0319.zip | |
Merge pull request #920 from msabramo/accept-tests
Add some tests for how content types and HTTP "Accept" header handling behave.
| -rw-r--r-- | pyramid/tests/test_integration.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py index bf3960b2d..b880cd741 100644 --- a/pyramid/tests/test_integration.py +++ b/pyramid/tests/test_integration.py @@ -634,6 +634,32 @@ class RendererScanAppTest(IntegrationBase, unittest.TestCase): res = testapp.get('/two', status=200) self.assertTrue(b'Two!' in res.body) +class AcceptContentTypeTest(unittest.TestCase): + def setUp(self): + def hello_view(request): + return {'message': 'Hello!'} + from pyramid.config import Configurator + config = Configurator() + config.add_route('hello', '/hello') + config.add_view(hello_view, route_name='hello', accept='text/plain', renderer='string') + config.add_view(hello_view, route_name='hello', accept='application/json', renderer='json') + app = config.make_wsgi_app() + from webtest import TestApp + self.testapp = TestApp(app) + + def test_ordering(self): + res = self.testapp.get('/hello', headers={'Accept': 'application/json; q=1.0, text/plain; q=0.9'}, status=200) + self.assertEqual(res.content_type, 'application/json') + res = self.testapp.get('/hello', headers={'Accept': 'text/plain; q=0.9, application/json; q=1.0'}, status=200) + self.assertEqual(res.content_type, 'application/json') + + def test_wildcards(self): + res = self.testapp.get('/hello', headers={'Accept': 'application/*'}, status=200) + self.assertEqual(res.content_type, 'application/json') + res = self.testapp.get('/hello', headers={'Accept': 'text/*'}, status=200) + self.assertEqual(res.content_type, 'text/plain') + + class DummyContext(object): pass |
