diff options
| author | Tim Graham <timograham@gmail.com> | 2016-04-29 08:55:36 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-29 09:16:31 -0400 |
| commit | d2338bae786f2fabfd01c30522fda9d79e02eb45 (patch) | |
| tree | d3e8ef4c5966c07cc8c3ea83c01d32e413b68871 /django | |
| parent | 2d78b46d299da7d604a9fbf8c853d272ccd45fc2 (diff) | |
[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
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/client.py | 9 |
1 files changed, 7 insertions, 2 deletions
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]: |
