summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Abramowitz <marca@surveymonkey.com>2013-02-12 17:08:10 -0800
committerMarc Abramowitz <marca@surveymonkey.com>2013-02-12 17:08:10 -0800
commite100873f6422b20d6bfda78abd684d7908d8a825 (patch)
tree2be857942fff66b1c8dc7c558b66f4d1eb89c8c0
parentcaf63baba3460f7d70e20494a91774cb9c3368a9 (diff)
downloadpyramid-e100873f6422b20d6bfda78abd684d7908d8a825.tar.gz
pyramid-e100873f6422b20d6bfda78abd684d7908d8a825.tar.bz2
pyramid-e100873f6422b20d6bfda78abd684d7908d8a825.zip
Add some tests for how content types and HTTP "Accept" header handling
behave.
-rw-r--r--pyramid/tests/test_integration.py26
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