From 30e64f38f3a01d71f8a728df9d56f31d950ebd20 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 25 Apr 2010 18:49:29 +0000 Subject: 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. --- repoze/bfg/tests/test_view.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'repoze/bfg/tests/test_view.py') 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('' 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('' 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('abc&123' 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('' 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('' 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('abc&123' 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') -- cgit v1.2.3