summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2016-04-12 20:14:01 -0600
committerBert JW Regeer <bertjw@regeer.org>2016-04-12 20:21:53 -0600
commita66ce9e5330abbe5de85b4de49f905293804be0a (patch)
treef8d68327e2eb4657aa1496b5911fff627e2d071f
parent4061d5bc2a8c066e811388070033946d80eaccb7 (diff)
downloadpyramid-a66ce9e5330abbe5de85b4de49f905293804be0a.tar.gz
pyramid-a66ce9e5330abbe5de85b4de49f905293804be0a.tar.bz2
pyramid-a66ce9e5330abbe5de85b4de49f905293804be0a.zip
Add new tests to verify we get what we ask for
This simply makes sure we get back the appropriate Content-Type based upon our Accept header.
-rw-r--r--pyramid/tests/test_httpexceptions.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/pyramid/tests/test_httpexceptions.py b/pyramid/tests/test_httpexceptions.py
index a4b936a38..223f8ab35 100644
--- a/pyramid/tests/test_httpexceptions.py
+++ b/pyramid/tests/test_httpexceptions.py
@@ -239,6 +239,49 @@ class TestHTTPException(unittest.TestCase):
self.assertEqual(header[1], 'text/plain; charset=UTF-8')
self.assertFalse(b'<!-- ' in body)
+ def test__content_type(self):
+ cls = self._getTargetSubclass()
+ exc = cls()
+ environ = _makeEnviron()
+ start_response = DummyStartResponse()
+ exc(environ, start_response)
+ for header in start_response.headerlist:
+ if header[0] == 'Content-Type':
+ self.assertEqual(header[1], 'text/plain; charset=UTF-8')
+
+ def test__content_type_default_is_plain(self):
+ cls = self._getTargetSubclass()
+ exc = cls()
+ environ = _makeEnviron()
+ environ['HTTP_ACCEPT'] = '*/*'
+ start_response = DummyStartResponse()
+ exc(environ, start_response)
+ for header in start_response.headerlist:
+ if header[0] == 'Content-Type':
+ self.assertEqual(header[1], 'text/plain; charset=UTF-8')
+
+ def test__content_type_text_html(self):
+ cls = self._getTargetSubclass()
+ exc = cls()
+ environ = _makeEnviron()
+ environ['HTTP_ACCEPT'] = 'text/html'
+ start_response = DummyStartResponse()
+ exc(environ, start_response)
+ for header in start_response.headerlist:
+ if header[0] == 'Content-Type':
+ self.assertEqual(header[1], 'text/html; charset=UTF-8')
+
+ def test__content_type_application_json(self):
+ cls = self._getTargetSubclass()
+ exc = cls()
+ environ = _makeEnviron()
+ environ['HTTP_ACCEPT'] = 'application/json'
+ start_response = DummyStartResponse()
+ exc(environ, start_response)
+ for header in start_response.headerlist:
+ if header[0] == 'Content-Type':
+ self.assertEqual(header[1], 'application/json')
+
def test__default_app_iter_with_comment_ampersand(self):
cls = self._getTargetSubclass()
exc = cls(comment='comment & comment')