diff options
| author | Tim Graham <timograham@gmail.com> | 2016-04-02 10:35:33 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-04-02 10:35:33 -0400 |
| commit | d2569f89f28883d07ede0e44a0a69ae678d3b35f (patch) | |
| tree | de95ca89c52894f4fa10ce6e177d6f29d1c8ce7b /django | |
| parent | 55c843f2ef702b4ebcd024920d4193bdf4c3fe07 (diff) | |
Fixed #26428 -- Added support for relative path redirects in assertRedirects().
Thanks Trac alias master for the report and review.
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 9de29fff68..3abd8f0f71 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -41,7 +41,7 @@ from django.utils.decorators import classproperty from django.utils.deprecation import RemovedInDjango20Warning from django.utils.encoding import force_text from django.utils.six.moves.urllib.parse import ( - unquote, urlparse, urlsplit, urlunsplit, + unquote, urljoin, urlparse, urlsplit, urlunsplit, ) from django.utils.six.moves.urllib.request import url2pathname from django.views.static import serve @@ -291,6 +291,11 @@ class SimpleTestCase(unittest.TestCase): url = response.url scheme, netloc, path, query, fragment = urlsplit(url) + # Prepend the request path to handle relative path redirects. + if not path.startswith('/'): + url = urljoin(response.request['PATH_INFO'], url) + path = urljoin(response.request['PATH_INFO'], path) + if fetch_redirect_response: redirect_response = response.client.get(path, QueryDict(query), secure=(scheme == 'https')) |
