diff --git a/django/test/client.py b/django/test/client.py
index 166e6ef..843c01c 100644
a
|
b
|
from django.utils.encoding import force_bytes, force_str, uri_to_iri
|
26 | 26 | from django.utils.functional import SimpleLazyObject, curry |
27 | 27 | from django.utils.http import urlencode |
28 | 28 | from django.utils.itercompat import is_iterable |
29 | | from django.utils.six.moves.urllib.parse import urlparse, urlsplit |
| 29 | from django.utils.six.moves.urllib.parse import urlparse, urlsplit, urljoin |
30 | 30 | |
31 | 31 | __all__ = ('Client', 'RedirectCycleError', 'RequestFactory', 'encode_file', 'encode_multipart') |
32 | 32 | |
… |
… |
class Client(RequestFactory):
|
699 | 699 | if url.port: |
700 | 700 | extra['SERVER_PORT'] = str(url.port) |
701 | 701 | |
702 | | response = self.get(url.path, QueryDict(url.query), follow=False, **extra) |
| 702 | # Prepend the request path to handle relative path redirects |
| 703 | path = url.path |
| 704 | if not path.startswith('/'): |
| 705 | path = urljoin(response.request['PATH_INFO'], path) |
| 706 | |
| 707 | response = self.get(path, QueryDict(url.query), follow=False, **extra) |
703 | 708 | response.redirect_chain = redirect_chain |
704 | 709 | |
705 | 710 | if redirect_chain[-1] in redirect_chain[:-1]: |
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 5c37356..dff7e39 100644
a
|
b
|
class ClientTest(TestCase):
|
198 | 198 | self.assertRedirects(response, '/get_view/', status_code=302, target_status_code=200) |
199 | 199 | self.assertEqual(len(response.redirect_chain), 2) |
200 | 200 | |
| 201 | def test_follow_relative_redirect(self): |
| 202 | "A URL with a relative redirect can be followed." |
| 203 | response = self.client.get('/accounts/', follow=True) |
| 204 | self.assertEqual(response.status_code, 200) |
| 205 | self.assertEqual(response.request['PATH_INFO'], '/accounts/login/') |
| 206 | |
| 207 | def test_follow_relative_redirect_no_trailing_slash(self): |
| 208 | "A URL with a relative redirect with no trailing slash can be followed." |
| 209 | response = self.client.get('/accounts/no_trailing_slash', follow=True) |
| 210 | self.assertEqual(response.status_code, 200) |
| 211 | self.assertEqual(response.request['PATH_INFO'], '/accounts/login/') |
| 212 | |
201 | 213 | def test_redirect_http(self): |
202 | 214 | "GET a URL that redirects to an http URI" |
203 | 215 | response = self.client.get('/http_redirect_view/', follow=True) |