Ejemplo n.º 1
0
 def test__exception_view__http_exc_body_already_set(
         self, exc_to_http_exc_mock):
     http_exc = HTTPNotFound('FOO', body='SPAM', content_type='text/spam')
     exc_to_http_exc_mock.return_value = http_exc
     assert http_exc.code == 404
     assert http_exc.content_type == 'text/spam'
     assert http_exc.body == 'SPAM'
     request = MagicMock()
     request.environ = {'HTTP_ACCEPT': 'text/html'}
     result = ConfigHelper.exception_view(sen.exc, request)
     self.assertIs(result, http_exc)
     self.assertEqual(http_exc.content_type, 'text/spam')
     self.assertEqual(http_exc.body, 'SPAM')
     self.assertEqual(exc_to_http_exc_mock.mock_calls, [
         call(sen.exc),
     ])
Ejemplo n.º 2
0
 def test__exception_view(self, exc_to_http_exc_mock):
     http_exc = HTTPNotFound('FOO')
     exc_to_http_exc_mock.return_value = http_exc
     assert http_exc.code == 404
     assert http_exc.content_type == 'text/html'
     assert http_exc.body == ''
     request = MagicMock()
     request.environ = {'HTTP_ACCEPT': 'text/html'}
     result = ConfigHelper.exception_view(sen.exc, request)
     self.assertIs(result, http_exc)
     self.assertEqual(http_exc.content_type, 'text/plain')  # no HTML
     self.assertNotIn('<', http_exc.body)  # no HTML
     self.assertIn('404', http_exc.body)
     self.assertIn('FOO', http_exc.body)
     self.assertEqual(exc_to_http_exc_mock.mock_calls, [
         call(sen.exc),
     ])