diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-11 03:54:21 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-11-11 03:54:21 +0000 |
| commit | 30848dfe34bb027c40ae1902623bd2fb675f6424 (patch) | |
| tree | b68948bfaa24e5c4774e9f5191549ee14e24e265 /django | |
| parent | 1eecc5a47e650e842231e5082c8f1f5a79a40afb (diff) | |
When using assertRedirect(), allow the caller to specify relative URLs and
automatically fill in the hostname and scheme (host can be passed in, if
different from the default).
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6661 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 732e713d4a..2aa0a0783d 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -1,6 +1,6 @@ import re import unittest -from urlparse import urlsplit +from urlparse import urlsplit, urlunsplit from django.http import QueryDict from django.db import transaction @@ -74,7 +74,7 @@ class TestCase(unittest.TestCase): super(TestCase, self).__call__(result) def assertRedirects(self, response, expected_url, status_code=302, - target_status_code=200): + target_status_code=200, host=None): """Asserts that a response redirected to a specific URL, and that the redirect URL can be loaded. @@ -86,6 +86,10 @@ class TestCase(unittest.TestCase): " (expected %d)" % (response.status_code, status_code))) url = response['Location'] scheme, netloc, path, query, fragment = urlsplit(url) + e_scheme, e_netloc, e_path, e_query, e_fragment = urlsplit(expected_url) + if not (e_scheme or e_netloc): + expected_url = urlunsplit(('http', host or 'testserver', e_path, + e_query, e_fragment)) self.assertEqual(url, expected_url, "Response redirected to '%s', expected '%s'" % (url, expected_url)) |
