summaryrefslogtreecommitdiff
path: root/tests/requests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-01-10 10:56:02 -0500
committerTim Graham <timograham@gmail.com>2018-01-10 11:32:15 -0500
commit366451880abc7f4d3c9b40e5640e1b75fe7b14dc (patch)
treec5d144c49f9aedd2926bbf93ddd91e7ca63c098a /tests/requests
parent66d74676e23c32bc676fb0706af8580b391953b6 (diff)
downloaddjango-366451880abc7f4d3c9b40e5640e1b75fe7b14dc.tar.gz
Updated HttpRequest.build_absolute_uri() tests to use subTest().
Diffstat (limited to 'tests/requests')
-rw-r--r--tests/requests/tests.py92
1 files changed, 26 insertions, 66 deletions
diff --git a/tests/requests/tests.py b/tests/requests/tests.py
index 7acfa3b291..9df81230a0 100644
--- a/tests/requests/tests.py
+++ b/tests/requests/tests.py
@@ -179,20 +179,6 @@ class RequestsTests(SimpleTestCase):
# left percent-encoded in the path.
self.assertEqual(request.path, "/caf%E9/")
- def test_httprequest_location(self):
- request = HttpRequest()
- self.assertEqual(
- request.build_absolute_uri(location="https://www.example.com/asdf"),
- 'https://www.example.com/asdf'
- )
-
- request.get_host = lambda: 'www.example.com'
- request.path = ''
- self.assertEqual(
- request.build_absolute_uri(location="/path/with:colons"),
- 'http://www.example.com/path/with:colons'
- )
-
def test_limited_stream(self):
# Read all of a limited stream
stream = LimitedStream(BytesIO(b'test'), 2)
@@ -784,62 +770,36 @@ class HostValidationTests(SimpleTestCase):
self.assertEqual(port, '8080')
-class BuildAbsoluteURITestCase(SimpleTestCase):
- """
- Regression tests for ticket #18314.
- """
-
- def setUp(self):
- self.factory = RequestFactory()
-
- def test_build_absolute_uri_no_location(self):
- """
- ``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'
- )
+class BuildAbsoluteURITests(SimpleTestCase):
+ factory = RequestFactory()
- def test_build_absolute_uri_absolute_location(self):
- """
- ``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_absolute_url(self):
+ request = HttpRequest()
+ url = 'https://www.example.com/asdf'
+ self.assertEqual(request.build_absolute_uri(location=url), url)
- def test_build_absolute_uri_schema_relative_location(self):
- """
- ``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')
+ def test_host_retrieval(self):
+ request = HttpRequest()
+ request.get_host = lambda: 'www.example.com'
+ request.path = ''
self.assertEqual(
- request.build_absolute_uri(location='//example.com/?foo=bar'),
- 'http://example.com/?foo=bar'
+ request.build_absolute_uri(location='/path/with:colons'),
+ 'http://www.example.com/path/with:colons'
)
- def test_build_absolute_uri_relative_location(self):
- """
- ``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 //
+ def test_request_path_begins_with_two_slashes(self):
+ # //// creates 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/'
+ tests = (
+ # location isn't provided
+ (None, 'http://testserver//absolute-uri'),
+ # An absolute URL
+ ('http://example.com/?foo=bar', 'http://example.com/?foo=bar'),
+ # A schema-relative URL
+ ('//example.com/?foo=bar', 'http://example.com/?foo=bar'),
+ # A relative URL
+ ('/foo/bar/', 'http://testserver/foo/bar/'),
)
+ for location, expected_url in tests:
+ with self.subTest(location=location):
+ self.assertEqual(request.build_absolute_uri(location=location), expected_url)