From d2338bae786f2fabfd01c30522fda9d79e02eb45 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Fri, 29 Apr 2016 08:55:36 -0400 Subject: [1.9.x] Refs #26428 -- Added support for relative path redirects to the test client. Thanks iktyrrell for the patch. Backport of 2f698cd9916cb3d64932248c7114049e02b74fb3 from master --- django/test/client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/test/client.py b/django/test/client.py index 6730ac7acd..8f2e6f3963 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -27,7 +27,7 @@ from django.utils.encoding import force_bytes, force_str, uri_to_iri from django.utils.functional import SimpleLazyObject, curry from django.utils.http import urlencode from django.utils.itercompat import is_iterable -from django.utils.six.moves.urllib.parse import urlparse, urlsplit +from django.utils.six.moves.urllib.parse import urljoin, urlparse, urlsplit __all__ = ('Client', 'RedirectCycleError', 'RequestFactory', 'encode_file', 'encode_multipart') @@ -678,7 +678,12 @@ class Client(RequestFactory): if url.port: extra['SERVER_PORT'] = str(url.port) - response = self.get(url.path, QueryDict(url.query), follow=False, **extra) + # Prepend the request path to handle relative path redirects + path = url.path + if not path.startswith('/'): + path = urljoin(response.request['PATH_INFO'], path) + + response = self.get(path, QueryDict(url.query), follow=False, **extra) response.redirect_chain = redirect_chain if redirect_chain[-1] in redirect_chain[:-1]: -- cgit v1.3