diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-06-25 23:10:53 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-06-25 23:10:53 +0000 |
commit | 7d5b94e2f68aa254d4905e90572aa7dc5e04ab28 (patch) | |
tree | c69493c40902d41692f45883c262e40c99c772ea /pecan/tests/test_base.py | |
parent | 9017d113cdd9cddb53894fbba67227e94755a509 (diff) | |
parent | 7df71f31ae70f0d6e4e6c7511f5ba35c2977af5e (diff) | |
download | pecan-7d5b94e2f68aa254d4905e90572aa7dc5e04ab28.tar.gz |
Merge "Serialize WebOb errors as JSON if the client requests it via an Accept header."
Diffstat (limited to 'pecan/tests/test_base.py')
-rw-r--r-- | pecan/tests/test_base.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index c6f9024..44a6861 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -8,6 +8,7 @@ else: import unittest # pragma: nocover import webob +from webob.exc import HTTPNotFound from webtest import TestApp import six from six import b as b_ @@ -760,6 +761,42 @@ class TestControllerArguments(PecanTestCase): assert r.body == b_('eater: 10, dummy, day=12, month=1') +class TestDefaultErrorRendering(PecanTestCase): + + def test_plain_error(self): + class RootController(object): + pass + + app = TestApp(Pecan(RootController())) + r = app.get('/', status=404) + assert r.status_int == 404 + assert r.content_type == 'text/plain' + assert r.body == b_(HTTPNotFound().plain_body({})) + + def test_html_error(self): + class RootController(object): + pass + + app = TestApp(Pecan(RootController())) + r = app.get('/', headers={'Accept': 'text/html'}, status=404) + assert r.status_int == 404 + assert r.content_type == 'text/html' + assert r.body == b_(HTTPNotFound().html_body({})) + + def test_json_error(self): + class RootController(object): + pass + + app = TestApp(Pecan(RootController())) + r = app.get('/', headers={'Accept': 'application/json'}, status=404) + assert r.status_int == 404 + json_resp = json.loads(r.body.decode()) + assert json_resp['code'] == 404 + assert json_resp['description'] is None + assert json_resp['title'] == 'Not Found' + assert r.content_type == 'application/json' + + class TestAbort(PecanTestCase): def test_abort(self): |