|
@@ -10,7 +10,7 @@ from django.core.exceptions import SuspiciousOperation
|
|
|
from django.core.handlers.wsgi import WSGIRequest, LimitedStream
|
|
|
from django.http import (HttpRequest, HttpResponse, parse_cookie,
|
|
|
build_request_repr, UnreadablePostError, RawPostDataException)
|
|
|
-from django.test import SimpleTestCase, override_settings
|
|
|
+from django.test import SimpleTestCase, RequestFactory, override_settings
|
|
|
from django.test.client import FakePayload
|
|
|
from django.test.utils import str_prefix
|
|
|
from django.utils import six
|
|
@@ -693,3 +693,64 @@ class HostValidationTests(SimpleTestCase):
|
|
|
msg_suggestion2 % "invalid_hostname.com",
|
|
|
request.get_host
|
|
|
)
|
|
|
+
|
|
|
+
|
|
|
+class BuildAbsoluteURITestCase(SimpleTestCase):
|
|
|
+ """
|
|
|
+ Regression tests for ticket #18314.
|
|
|
+ """
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ self.factory = RequestFactory()
|
|
|
+
|
|
|
+ def test_build_absolute_uri_no_location(self):
|
|
|
+ """
|
|
|
+ Ensures that ``request.build_absolute_uri()`` returns the proper value
|
|
|
+ when the ``location`` argument is not provided, and ``request.path``
|
|
|
+ begins with //.
|
|
|
+ """
|
|
|
+ # //// is needed to create a request with a path beginning with //
|
|
|
+ request = self.factory.get('////absolute-uri')
|
|
|
+ self.assertEqual(
|
|
|
+ request.build_absolute_uri(),
|
|
|
+ 'http://testserver//absolute-uri'
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_build_absolute_uri_absolute_location(self):
|
|
|
+ """
|
|
|
+ Ensures that ``request.build_absolute_uri()`` returns the proper value
|
|
|
+ when an absolute URL ``location`` argument is provided, and
|
|
|
+ ``request.path`` begins with //.
|
|
|
+ """
|
|
|
+ # //// is needed to create a request with a path beginning with //
|
|
|
+ request = self.factory.get('////absolute-uri')
|
|
|
+ self.assertEqual(
|
|
|
+ request.build_absolute_uri(location='http://example.com/?foo=bar'),
|
|
|
+ 'http://example.com/?foo=bar'
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_build_absolute_uri_schema_relative_location(self):
|
|
|
+ """
|
|
|
+ Ensures that ``request.build_absolute_uri()`` returns the proper value
|
|
|
+ when a schema-relative URL ``location`` argument is provided, and
|
|
|
+ ``request.path`` begins with //.
|
|
|
+ """
|
|
|
+ # //// is needed to create a request with a path beginning with //
|
|
|
+ request = self.factory.get('////absolute-uri')
|
|
|
+ self.assertEqual(
|
|
|
+ request.build_absolute_uri(location='//example.com/?foo=bar'),
|
|
|
+ 'http://example.com/?foo=bar'
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_build_absolute_uri_relative_location(self):
|
|
|
+ """
|
|
|
+ Ensures that ``request.build_absolute_uri()`` returns the proper value
|
|
|
+ when a relative URL ``location`` argument is provided, and
|
|
|
+ ``request.path`` begins with //.
|
|
|
+ """
|
|
|
+ # //// is needed to create a request with a path beginning with //
|
|
|
+ request = self.factory.get('////absolute-uri')
|
|
|
+ self.assertEqual(
|
|
|
+ request.build_absolute_uri(location='/foo/bar/'),
|
|
|
+ 'http://testserver/foo/bar/'
|
|
|
+ )
|