예제 #1
0
    def test_modpythonrequest_repr(self):
        class Dummy:
            def get_options(self):
                return {}

        req = Dummy()
        req.uri = '/somepath/'
        request = ModPythonRequest(req)
        request._get = {u'get-key': u'get-value'}
        request._post = {u'post-key': u'post-value'}
        request._cookies = {u'post-key': u'post-value'}
        request._meta = {u'post-key': u'post-value'}
        self.assertEqual(
            repr(request),
            u"<ModPythonRequest\npath:/somepath/,\nGET:{u'get-key': u'get-value'},\nPOST:{u'post-key': u'post-value'},\nCOOKIES:{u'post-key': u'post-value'},\nMETA:{u'post-key': u'post-value'}>"
        )
        self.assertEqual(build_request_repr(request), repr(request))
        self.assertEqual(
            build_request_repr(request,
                               path_override='/otherpath/',
                               GET_override={u'a': u'b'},
                               POST_override={u'c': u'd'},
                               COOKIES_override={u'e': u'f'},
                               META_override={u'g': u'h'}),
            u"<ModPythonRequest\npath:/otherpath/,\nGET:{u'a': u'b'},\nPOST:{u'c': u'd'},\nCOOKIES:{u'e': u'f'},\nMETA:{u'g': u'h'}>"
        )
예제 #2
0
    def __call__(self, req):
        from django.conf import settings
        # set up middleware
        if self._request_middleware is None:
            self.load_middleware()

# populate the request object
        request = ModPythonRequest(req)
        # and apply the middleware to it
        # actually only session and auth middleware would be needed here
        for middleware_method in self._request_middleware:
            middleware_method(request)
        return request