From c8cf2256655ee4b34ec501325b9016608b5cce5f Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 15 Jan 2009 00:20:04 +0000 Subject: - Instead of invariably using ``webob.Request`` as the "request factory" (e.g. in the ``Router`` class) and ``webob.Response`` and the "response factory" (e.g. in ``render_template_to_response``), allow both to be overridden via a ZCML utility hook. See the "Using ZCML Hooks" chapter of the documentation for more information. --- repoze/bfg/tests/test_wsgi.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'repoze/bfg/tests/test_wsgi.py') diff --git a/repoze/bfg/tests/test_wsgi.py b/repoze/bfg/tests/test_wsgi.py index 4c36850b6..ac02ec49f 100644 --- a/repoze/bfg/tests/test_wsgi.py +++ b/repoze/bfg/tests/test_wsgi.py @@ -1,6 +1,13 @@ import unittest +from zope.testing.cleanup import cleanUp class WSGIAppTests(unittest.TestCase): + def setUp(self): + cleanUp() + + def tearDown(self): + cleanUp() + def test_decorator(self): body = 'Unauthorized' headerlist = [ ('Content-Type', 'text/plain'), @@ -18,6 +25,28 @@ class WSGIAppTests(unittest.TestCase): self.assertEqual(response.headerlist, headerlist) self.assertEqual(response.app_iter, [body]) + def test_decorator_alternate_iresponsefactory(self): + body = 'Unauthorized' + headerlist = [ ('Content-Type', 'text/plain'), + ('Content-Length', len(body)) ] + status = '401 Unauthorized' + def real_wsgiapp(environ, start_response): + start_response(status, headerlist) + return [body] + from repoze.bfg.wsgi import wsgiapp + wrapped = wsgiapp(real_wsgiapp) + context = DummyContext() + request = DummyRequest({}) + from repoze.bfg.interfaces import IResponseFactory + from zope.component import getGlobalSiteManager + from webob import Response + class Response2(Response): + pass + gsm = getGlobalSiteManager() + gsm.registerUtility(Response2, IResponseFactory) + response = wrapped(context, request) + self.failUnless(isinstance(response, Response2)) + def test_decorator_startresponse_uncalled(self): body = 'Unauthorized' headerlist = [ ('Content-Type', 'text/plain'), -- cgit v1.2.3