From 844e98b01c5c6aa1585a76ac77f92bb8c1ef9d90 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 5 Sep 2010 04:58:23 +0000 Subject: Documentation ------------- - Add an API chapter for the ``repoze.bfg.request`` module, which includes documentation for the ``repoze.bfg.request.Request`` class (the "request object"). - Modify the "Request and Response" narrative chapter to reference the new ``repoze.bfg.request`` API chapter. Some content was moved from this chapter into the API documentation itself. Features -------- - A new ``repoze.bfg.request.Request.add_response_callback`` API has been added. This method is documented in the new ``repoze.bfg.request`` API chapter. It can be used to influence response values before a concrete response object has been created. Internal -------- - The (internal) feature which made it possible to attach a ``global_response_headers`` attribute to the request (which was assumed to contain a sequence of header key/value pairs which would later be added to the response by the router), has been removed. The functionality of ``repoze.bfg.request.Request.add_response_callback`` takes its place. --- repoze/bfg/tests/test_authentication.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'repoze/bfg/tests/test_authentication.py') diff --git a/repoze/bfg/tests/test_authentication.py b/repoze/bfg/tests/test_authentication.py index a6f34970f..bce80ca20 100644 --- a/repoze/bfg/tests/test_authentication.py +++ b/repoze/bfg/tests/test_authentication.py @@ -416,9 +416,11 @@ class TestAuthTktCookieHelper(unittest.TestCase): request = self._makeRequest({'HTTP_COOKIE':'auth_tkt=bogus'}) result = plugin.identify(request) self.failUnless(result) - response_headers = request.global_response_headers - self.assertEqual(len(response_headers), 3) - self.assertEqual(response_headers[0][0], 'Set-Cookie') + self.assertEqual(len(request.callbacks), 1) + response = DummyResponse() + request.callbacks[0](None, response) + self.assertEqual(len(response.headers.added), 3) + self.assertEqual(response.headers.added[0][0], 'Set-Cookie') def test_remember(self): plugin = self._makeOne('secret') @@ -595,6 +597,10 @@ class DummyContext: class DummyRequest: def __init__(self, environ): self.environ = environ + self.callbacks = [] + + def add_response_callback(self, callback): + self.callbacks.append(callback) class DummyWhoPlugin: def remember(self, environ, identity): @@ -652,3 +658,14 @@ class DummyAuthTktModule(object): class BadTicket(Exception): pass +class DummyHeaders: + def __init__(self): + self.added = [] + + def add(self, k, v): + self.added.append((k, v)) + +class DummyResponse: + def __init__(self): + self.headers = DummyHeaders() + -- cgit v1.2.3