summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2013-03-31 00:54:52 -0700
committerJulien Phalip <jphalip@gmail.com>2013-04-01 12:04:44 -0700
commit2f81a0ca6543f4f7b59bf6cd9aeb8ae87f1e968e (patch)
treeff94dd3a365cf202ec6f07a693497fac64beb526 /tests
parent8c41bd93c2412ddeb9dbe8bd73e1d3c3427d171b (diff)
Fixed #20169 -- Ensured that the WSGI request's path is correctly based on the `SCRIPT_NAME` environment parameter or the `FORCE_SCRIPT_NAME` setting, regardless of whether or not those have a trailing slash. Thanks to bmispelon for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/requests/tests.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index 2803d7995b..e176775449 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -50,6 +50,44 @@ class RequestsTests(unittest.TestCase):
self.assertEqual(request.META['REQUEST_METHOD'], 'bogus')
self.assertEqual(request.META['SCRIPT_NAME'], '')
+ def test_wsgirequest_with_script_name(self):
+ """
+ Ensure that the request's path is correctly assembled, regardless of
+ whether or not the SCRIPT_NAME has a trailing slash.
+ Refs #20169.
+ """
+ # With trailing slash
+ request = WSGIRequest({'PATH_INFO': '/somepath/', 'SCRIPT_NAME': '/PREFIX/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
+ self.assertEqual(request.path, '/PREFIX/somepath/')
+ # Without trailing slash
+ request = WSGIRequest({'PATH_INFO': '/somepath/', 'SCRIPT_NAME': '/PREFIX', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
+ self.assertEqual(request.path, '/PREFIX/somepath/')
+
+ def test_wsgirequest_with_force_script_name(self):
+ """
+ Ensure that the FORCE_SCRIPT_NAME setting takes precedence over the
+ request's SCRIPT_NAME environment parameter.
+ Refs #20169.
+ """
+ with override_settings(FORCE_SCRIPT_NAME='/FORCED_PREFIX/'):
+ request = WSGIRequest({'PATH_INFO': '/somepath/', 'SCRIPT_NAME': '/PREFIX/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
+ self.assertEqual(request.path, '/FORCED_PREFIX/somepath/')
+
+ def test_wsgirequest_path_with_force_script_name_trailing_slash(self):
+ """
+ Ensure that the request's path is correctly assembled, regardless of
+ whether or not the FORCE_SCRIPT_NAME setting has a trailing slash.
+ Refs #20169.
+ """
+ # With trailing slash
+ with override_settings(FORCE_SCRIPT_NAME='/FORCED_PREFIX/'):
+ request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
+ self.assertEqual(request.path, '/FORCED_PREFIX/somepath/')
+ # Without trailing slash
+ with override_settings(FORCE_SCRIPT_NAME='/FORCED_PREFIX'):
+ request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
+ self.assertEqual(request.path, '/FORCED_PREFIX/somepath/')
+
def test_wsgirequest_repr(self):
request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
request.GET = {'get-key': 'get-value'}