diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-11-19 18:21:09 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-11-19 18:21:09 +0000 |
| commit | 1c02105e4fce880bca80e58be3191d2e1368596a (patch) | |
| tree | 6c0858b9ad1924e03a8f230d3762ee29d8cbd0d4 /repoze/bfg/tests/test_testing.py | |
| parent | a664df6400b3721a40f665d04b751e7a50b42ebc (diff) | |
| download | pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.tar.gz pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.tar.bz2 pyramid-1c02105e4fce880bca80e58be3191d2e1368596a.zip | |
- Each of the ``repoze.bfg.view.render_view``,
``repoze.bfg.view.render_view_to_iterable``,
``repoze.bfg.view.render_view_to_response``,
``repoze.bfg.view.append_slash_notfound_view``,
``repoze.bfg.view.default_notfound_view``,
``repoze.bfg.view.default_forbidden_view``, and the
``repoze.bfg.configuration.rendered_response`` functions now expects
to be called with a request object that has a ``registry`` attribute
which represents the current ZCA registry. This should only be a
problem when passing a custom request object to code which ends up
calling these functions in a unit test. To retrofit tests that end
up calling these functions which expect to be able to use a
non-registry-aware request object, use the
``repoze.bfg.threadlocal.get_current_request`` API in the test to
create the request; this will return a
``repoze.bfg.testing.DummyRequest`` that has the current registry as
its ``registry`` attribute. Alternatively, use the
``repoze.bfg.threadlocal.get_current_registry`` API: call this
function and add an attribute to your unit test request object named
``registry`` with the result.
- The ``repoze.bfg.view.derive_view`` callable has been removed. Use
``repoze.bfg.configuration.Configurator.derive_view`` instead (still
not an API, however).
Diffstat (limited to 'repoze/bfg/tests/test_testing.py')
| -rw-r--r-- | repoze/bfg/tests/test_testing.py | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/repoze/bfg/tests/test_testing.py b/repoze/bfg/tests/test_testing.py index 4981b6d68..8bd31050a 100644 --- a/repoze/bfg/tests/test_testing.py +++ b/repoze/bfg/tests/test_testing.py @@ -1,17 +1,25 @@ -from repoze.bfg.testing import cleanUp +from repoze.bfg.testing import setUp +from repoze.bfg.testing import tearDown + import unittest class TestTestingFunctions(unittest.TestCase): def setUp(self): - cleanUp() + setUp() from zope.deprecation import __show__ __show__.off() def tearDown(self): - cleanUp() + tearDown() from zope.deprecation import __show__ __show__.on() + def _makeRequest(self, **extra_environ): + from repoze.bfg.threadlocal import get_current_request + request = get_current_request() + request.environ.update(extra_environ) + return request + def test_registerDummySecurityPolicy(self): from repoze.bfg import testing testing.registerDummySecurityPolicy('user', ('group1', 'group2'), @@ -123,7 +131,8 @@ class TestTestingFunctions(unittest.TestCase): import types self.failUnless(isinstance(view, types.FunctionType)) from repoze.bfg.view import render_view_to_response - response = render_view_to_response(None, None, 'moo.html') + request = self._makeRequest() + response = render_view_to_response(None, request, 'moo.html') self.assertEqual(view(None, None).body, response.body) def test_registerView_withresult(self): @@ -132,7 +141,8 @@ class TestTestingFunctions(unittest.TestCase): import types self.failUnless(isinstance(view, types.FunctionType)) from repoze.bfg.view import render_view_to_response - response = render_view_to_response(None, None, 'moo.html') + request = self._makeRequest() + response = render_view_to_response(None, request, 'moo.html') self.assertEqual(response.body, 'yo') def test_registerView_custom(self): @@ -144,7 +154,8 @@ class TestTestingFunctions(unittest.TestCase): import types self.failUnless(isinstance(view, types.FunctionType)) from repoze.bfg.view import render_view_to_response - response = render_view_to_response(None, None, 'moo.html') + request = self._makeRequest() + response = render_view_to_response(None, request, 'moo.html') self.assertEqual(response.body, '123') def test_registerView_with_permission_denying(self): @@ -157,8 +168,9 @@ class TestTestingFunctions(unittest.TestCase): import types self.failUnless(isinstance(view, types.FunctionType)) from repoze.bfg.view import render_view_to_response + request = self._makeRequest() self.assertRaises(Forbidden, render_view_to_response, - None, None, 'moo.html') + None, request, 'moo.html') def test_registerView_with_permission_denying2(self): from repoze.bfg import testing @@ -182,7 +194,8 @@ class TestTestingFunctions(unittest.TestCase): import types self.failUnless(isinstance(view, types.FunctionType)) from repoze.bfg.view import render_view_to_response - result = render_view_to_response(None, None, 'moo.html') + request = self._makeRequest() + result = render_view_to_response(None, request, 'moo.html') self.assertEqual(result.app_iter, ['123']) def test_registerViewPermission_defaults(self): |
