Skip to content

Commit

Permalink
Add new tests to verify we get what we ask for
Browse files Browse the repository at this point in the history
This simply makes sure we get back the appropriate Content-Type based
upon our Accept header.
  • Loading branch information
digitalresistor committed Apr 13, 2016
1 parent 4061d5b commit a66ce9e
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pyramid/tests/test_httpexceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,49 @@ def test__default_app_iter_no_comment_html(self):
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')
Expand Down

0 comments on commit a66ce9e

Please sign in to comment.