def test_child_with_query_string(self): """ Query strings are stripped when accessing children. """ url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query={b"query": [b"value"]}, ) self.assertEqual( url.child("child"), http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path/child", ))
def test_child_with_fragment(self): """ Fragments are stripped too. """ url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query={b"query": [b"value"]}, fragment=b"fragment", ) self.assertEqual( url.child("child"), http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path/child", ))
def test_child(self): url = http.URL(scheme=b"http", host=b"example.com", path=b"/foo/") self.assertEqual( url.child("bar"), http.URL( scheme=b"http", host=b"example.com", path=b"/foo/bar", ), )
def test_child_no_trailing_slash(self): url = http.URL(scheme=b"http", host=b"example.com", path=b"/bar") self.assertEqual( url.child("baz"), http.URL( scheme=b"http", host=b"example.com", path=b"/bar/baz", ), )
def test_child_with_additional_args(self): url = http.URL(scheme=b"http", host=b"example.com", path=b"/bar") self.assertEqual( url.child("baz", query={b"foo": [b"bar"]}), http.URL( scheme=b"http", host=b"example.com", path=b"/bar/baz", query={b"foo": [b"bar"]}, ), )
def test_query_string(self): url = http.URL( host=b"example.com", query=OrderedDict([(b"foo", [b"bar"]), (b"baz", [b"spam", b"eggs"])], ), ) self.assertEqual(url.query_string, b"foo=bar&baz=spam&baz=eggs")
def test_authority_no_user(self): url = http.URL( scheme=b"http", password=b"pass", host=b"example.com", port=8080, ) self.assertEqual(url.authority, b":[email protected]:8080")
def test_authority_no_password(self): url = http.URL( scheme=b"http", username=b"user", host=b"example.com", port=8080, ) self.assertEqual(url.authority, b"[email protected]:8080")
def test_authority_user_no_port(self): url = http.URL( scheme=b"https", username=b"foo", host=b"example.org", path=b"/path", ) self.assertEqual(url.authority, b"*****@*****.**")
def test_userinfo(self): url = http.URL( username=b"user", password=b"password", host=b"example.com", port=8080, ) self.assertEqual(url.userinfo, b"user:password")
def test_child_of_root(self): url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, ) self.assertEqual( url.child("child"), http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/child", ))
def test_URLs_without_schemes_are_not_absolute(self): url = http.URL( username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query={b"query": [b"value"]}, fragment=b"fragment", ) self.assertFalse(url.is_absolute)
def test_child_cannot_contain_slashes(self): """ Since /foo/ and /foo%2F are generally treated as the same path, child should not contain slashes. """ url = http.URL(scheme=b"http", host=b"example.com", path=b"/bar") with self.assertRaises(ValueError): url.child("foo/")
def test_absolute_URLs_are_absolute(self): url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query=[(b"query", b"value")], fragment=b"fragment", ) self.assertTrue(url.is_absolute)
def test_authority(self): url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query=[(b"query", b"value")], fragment=b"fragment", ) self.assertEqual(url.authority, b"user:[email protected]:8080")
def test_to_bytes_all_components(self): url = http.URL( scheme=b"http", username=b"user", password=b"password", host=b"example.com", port=8080, path=b"/path", query={b"query": [b"value"]}, fragment=b"fragment", ) self.assertEqual( url.to_bytes(), b"http://*****:*****@example.com:8080/path?query=value#fragment", )
def test_to_bytes_no_scheme_or_authority(self): url = http.URL(path=b"/hello") self.assertEqual(url.to_bytes(), b"/hello")
def test_to_bytes_no_components(self): self.assertEqual(http.URL().to_bytes(), b"")
def test_userinfo_no_user(self): url = http.URL(password=b"pass", host=b"example.com", port=8080) self.assertEqual(url.userinfo, b":pass")
def test_userinfo_no_password(self): url = http.URL(username=b"user", host=b"example.com", port=8080) self.assertEqual(url.userinfo, b"user")
def test_to_bytes_scheme_and_host(self): url = http.URL(scheme=b"http", host=b"example.net") self.assertEqual(url.to_bytes(), b"http://example.net")
def test_authority_no_userinfo(self): url = http.URL(scheme=b"http", host=b"example.com", port=8080) self.assertEqual(url.authority, b"example.com:8080")
def test_authority_no_user_no_port(self): url = http.URL(scheme=b"https", host=b"example.net", path=b"/path") self.assertEqual(url.authority, b"example.net")
def test_empty_is_relative(self): url = http.URL() self.assertFalse(url.is_absolute)
def test_to_bytes_no_scheme(self): url = http.URL(host=b"example.com") self.assertEqual(url.to_bytes(), b"//example.com")