Commit e2f9c117 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

Fixed #16705 - Made the test client adhere to the WSGI spec -- in particular,...

Fixed #16705 - Made the test client adhere to the WSGI spec -- in particular, removed the assumption that environ['QUERY_STRING'] exists.



git-svn-id: http://code.djangoproject.com/svn/django/trunk@16933 bcc190cf-cafb-0310-a4f2-bffc1f526a37
parent 9279dce1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ class CommonMiddleware(object):
                new_url[0], urlquote(new_url[1]))
        else:
            newurl = urlquote(new_url[1])
        if request.GET:
        if request.META.get('QUERY_STRING', ''):
            newurl += '?' + request.META['QUERY_STRING']
        return http.HttpResponsePermanentRedirect(newurl)

+4 −8
Original line number Diff line number Diff line
@@ -182,18 +182,18 @@ class RequestFactory(object):
        """
        The base environment for a request.
        """
        # This is a minimal valid WSGI environ dictionary, plus HTTP_COOKIE
        # for cookie support. Empty strings are omitted.
        # See http://www.python.org/dev/peps/pep-3333/#environ-variables
        environ = {
            'HTTP_COOKIE':       self.cookies.output(header='', sep='; '),
            'PATH_INFO':         '/',
            'QUERY_STRING':      '',
            'REMOTE_ADDR':       '127.0.0.1',
            'REQUEST_METHOD':    'GET',
            'SCRIPT_NAME':       '',
            'SERVER_NAME':       'testserver',
            'SERVER_PORT':       '80',
            'SERVER_PROTOCOL':   'HTTP/1.1',
            'wsgi.version':      (1,0),
            'wsgi.url_scheme':   'http',
            'wsgi.input':        FakePayload(''),
            'wsgi.errors':       self.errors,
            'wsgi.multiprocess': True,
            'wsgi.multithread':  False,
@@ -235,7 +235,6 @@ class RequestFactory(object):
            'PATH_INFO':       self._get_path(parsed),
            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
            'REQUEST_METHOD': 'GET',
            'wsgi.input':      FakePayload('')
        }
        r.update(extra)
        return self.request(**r)
@@ -267,7 +266,6 @@ class RequestFactory(object):
            'PATH_INFO':       self._get_path(parsed),
            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
            'REQUEST_METHOD': 'HEAD',
            'wsgi.input':      FakePayload('')
        }
        r.update(extra)
        return self.request(**r)
@@ -280,7 +278,6 @@ class RequestFactory(object):
            'PATH_INFO':       self._get_path(parsed),
            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
            'REQUEST_METHOD': 'OPTIONS',
            'wsgi.input':      FakePayload('')
        }
        r.update(extra)
        return self.request(**r)
@@ -311,7 +308,6 @@ class RequestFactory(object):
            'PATH_INFO':       self._get_path(parsed),
            'QUERY_STRING':    urlencode(data, doseq=True) or parsed[4],
            'REQUEST_METHOD': 'DELETE',
            'wsgi.input':      FakePayload('')
        }
        r.update(extra)
        return self.request(**r)
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ class RedirectView(View):
        are provided as kwargs to this method.
        """
        if self.url:
            args = self.request.META["QUERY_STRING"]
            args = self.request.META.get('QUERY_STRING', '')
            if args and self.query_string:
                url = "%s?%s" % (self.url, args)
            else:
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ def redirect_to(request, url, permanent=True, query_string=False, **kwargs):
    from the request is appended to the URL.

    """
    args = request.META["QUERY_STRING"]
    args = request.META.get('QUERY_STRING', '')
    if args and query_string and url is not None:
        url = "%s?%s" % (url, args)

+7 −1
Original line number Diff line number Diff line
@@ -248,7 +248,7 @@ class RedirectViewTest(unittest.TestCase):
        response = RedirectView.as_view()(self.rf.get('/foo/'))
        self.assertEqual(response.status_code, 410)

    def test_permanaent_redirect(self):
    def test_permanent_redirect(self):
        "Default is a permanent redirect"
        response = RedirectView.as_view(url='/bar/')(self.rf.get('/foo/'))
        self.assertEqual(response.status_code, 301)
@@ -305,3 +305,9 @@ class RedirectViewTest(unittest.TestCase):
        response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))
        self.assertEqual(response.status_code, 301)
        self.assertEqual(response['Location'], '/bar/')

    def test_redirect_when_meta_contains_no_query_string(self):
        "regression for #16705"
        # we can't use self.rf.get because it always sets QUERY_STRING
        response = RedirectView.as_view(url='/bar/')(self.rf.request(PATH_INFO='/foo/'))
        self.assertEqual(response.status_code, 301)
Loading