[tor-commits] [bridgedb/master] Add class wrapper for requesthelper.DummyRequest to support redirects.

isis at torproject.org isis at torproject.org
Wed Mar 26 05:49:32 UTC 2014


commit ad774181faa5cd367e4173ce14a4449a3164abeb
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Mar 19 17:57:09 2014 +0000

    Add class wrapper for requesthelper.DummyRequest to support redirects.
---
 lib/bridgedb/test/test_HTTPServer.py |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/lib/bridgedb/test/test_HTTPServer.py b/lib/bridgedb/test/test_HTTPServer.py
index e2856c7..73297de 100644
--- a/lib/bridgedb/test/test_HTTPServer.py
+++ b/lib/bridgedb/test/test_HTTPServer.py
@@ -445,3 +445,23 @@ class DummyIPBasedDistributor(object):
         :meth:`WebResourceBridges.getBridgesForIP`.
         """
         return [DummyBridge() for _ in xrange(N)]
+
+
+class DummyRequest(requesthelper.DummyRequest):
+    """Wrapper for :api:`twisted.test.requesthelper.DummyRequest` to add
+    redirect support.
+    """
+
+    def __init__(self, *args, **kwargs):
+        requesthelper.DummyRequest.__init__(self, *args, **kwargs)
+        self.redirect = self._redirect(self)
+
+    def URLPath(self):
+        """Fake the missing Request.URLPath too."""
+        return self.uri
+
+    def _redirect(self, request):
+        """Stub method to add a redirect() method to DummyResponse."""
+        newRequest = type(request)
+        newRequest.uri = request.uri
+        return newRequest





More information about the tor-commits mailing list