Пример #1
0
    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",
            ))
Пример #2
0
    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",
            ))
Пример #3
0
 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",
         ),
     )
Пример #4
0
 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",
         ),
     )
Пример #5
0
 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"]},
         ),
     )
Пример #6
0
 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")
Пример #7
0
 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")
Пример #8
0
 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")
Пример #9
0
 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"*****@*****.**")
Пример #10
0
 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")
Пример #11
0
 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",
         ))
Пример #12
0
 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)
Пример #13
0
    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/")
Пример #14
0
 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)
Пример #15
0
 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")
Пример #16
0
 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",
     )
Пример #17
0
 def test_to_bytes_no_scheme_or_authority(self):
     url = http.URL(path=b"/hello")
     self.assertEqual(url.to_bytes(), b"/hello")
Пример #18
0
 def test_to_bytes_no_components(self):
     self.assertEqual(http.URL().to_bytes(), b"")
Пример #19
0
 def test_userinfo_no_user(self):
     url = http.URL(password=b"pass", host=b"example.com", port=8080)
     self.assertEqual(url.userinfo, b":pass")
Пример #20
0
 def test_userinfo_no_password(self):
     url = http.URL(username=b"user", host=b"example.com", port=8080)
     self.assertEqual(url.userinfo, b"user")
Пример #21
0
 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")
Пример #22
0
 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")
Пример #23
0
 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")
Пример #24
0
 def test_empty_is_relative(self):
     url = http.URL()
     self.assertFalse(url.is_absolute)
Пример #25
0
 def test_to_bytes_no_scheme(self):
     url = http.URL(host=b"example.com")
     self.assertEqual(url.to_bytes(), b"//example.com")