diff options
| author | Chris McDonough <chrism@agendaless.com> | 2010-04-25 18:49:29 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2010-04-25 18:49:29 +0000 |
| commit | 30e64f38f3a01d71f8a728df9d56f31d950ebd20 (patch) | |
| tree | ebfdc1c832713e2ea737794fe090b766d3422407 /repoze/bfg/tests/test_view.py | |
| parent | 36ca7c9f7f1b177d69be792f98fda054d7c36c45 (diff) | |
| download | pyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.tar.gz pyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.tar.bz2 pyramid-30e64f38f3a01d71f8a728df9d56f31d950ebd20.zip | |
Make default_notfound_view and default_forbidden_view expect an exception as
a context.
Cause append_slash_notfound_view to work in case it is registered via
set_notfound_view.
Diffstat (limited to 'repoze/bfg/tests/test_view.py')
| -rw-r--r-- | repoze/bfg/tests/test_view.py | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/repoze/bfg/tests/test_view.py b/repoze/bfg/tests/test_view.py index 76a218cf6..94366ecbe 100644 --- a/repoze/bfg/tests/test_view.py +++ b/repoze/bfg/tests/test_view.py @@ -413,17 +413,23 @@ class TestDefaultForbiddenView(BaseTest, unittest.TestCase): from repoze.bfg.view import default_forbidden_view return default_forbidden_view(context, request) + def test_no_registry_on_request(self): + request = None + context = Exception() + response = self._callFUT(context, request) + self.assertEqual(response.status, '401 Unauthorized') + self.failUnless('<code></code>' in response.body) + def test_nomessage(self): request = self._makeRequest() - context = self._makeContext() + context = Exception() response = self._callFUT(context, request) self.assertEqual(response.status, '401 Unauthorized') self.failUnless('<code></code>' in response.body) def test_withmessage(self): request = self._makeRequest() - request.environ['repoze.bfg.message'] = 'abc&123' - context = self._makeContext() + context = Exception('abc&123') response = self._callFUT(context, request) self.assertEqual(response.status, '401 Unauthorized') self.failUnless('<code>abc&123</code>' in response.body) @@ -433,17 +439,23 @@ class TestDefaultNotFoundView(BaseTest, unittest.TestCase): from repoze.bfg.view import default_notfound_view return default_notfound_view(context, request) + def test_no_registry_on_request(self): + request = None + context = Exception() + response = self._callFUT(context, request) + self.assertEqual(response.status, '404 Not Found') + self.failUnless('<code></code>' in response.body) + def test_nomessage(self): request = self._makeRequest() - context = self._makeContext() + context = Exception() response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') self.failUnless('<code></code>' in response.body) def test_withmessage(self): request = self._makeRequest() - request.environ['repoze.bfg.message'] = 'abc&123' - context = self._makeContext() + context = Exception('abc&123') response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') self.failUnless('<code>abc&123</code>' in response.body) @@ -469,29 +481,37 @@ class AppendSlashNotFoundView(BaseTest, unittest.TestCase): reg.registerUtility(mapper, IRoutesMapper) return mapper - def test_no_mapper(self): + def test_context_is_not_exception(self): request = self._makeRequest(PATH_INFO='/abc') + request.exception = Exception('halloo') context = DummyContext() response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') + self.failUnless('halloo' in response.body) + + def test_no_mapper(self): + request = self._makeRequest(PATH_INFO='/abc') + context = Exception() + response = self._callFUT(context, request) + self.assertEqual(response.status, '404 Not Found') def test_no_path(self): request = self._makeRequest() - context = self._makeContext() + context = Exception() self._registerMapper(request.registry, True) response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') def test_mapper_path_already_slash_ending(self): request = self._makeRequest(PATH_INFO='/abc/') - context = DummyContext() + context = Exception() self._registerMapper(request.registry, True) response = self._callFUT(context, request) self.assertEqual(response.status, '404 Not Found') def test_matches(self): request = self._makeRequest(PATH_INFO='/abc') - context = DummyContext() + context = Exception() self._registerMapper(request.registry, True) response = self._callFUT(context, request) self.assertEqual(response.status, '302 Found') |
