def test_no_scheme_ip(self): u = Url("127.0.0.1:8080?query=val") self.assertEqual("http", u.scheme) self.assertEqual(8080, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("//127.0.0.1:8080?query=val") self.assertEqual("http", u.scheme) self.assertEqual(8080, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("127.0.0.1:8080/foo/bar?query=val") self.assertEqual("http", u.scheme) self.assertEqual(8080, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("foo/bar", u.path) u = Url("127.0.0.1?query=val") self.assertEqual("http", u.scheme) self.assertEqual(80, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("127.0.0.1/foo/bar?query=val") self.assertEqual("http", u.scheme) self.assertEqual(80, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("foo/bar", u.path)
def test_client_netloc(self): u = Url("0.0.0.0:546") self.assertFalse("0.0.0.0" in u.client_netloc) self.assertTrue("0.0.0.0" in u.netloc) u = Url("0.0.0.0") self.assertFalse("0.0.0.0" in u.client_netloc) self.assertTrue("0.0.0.0" in u.netloc)
def test_host_trailing_slash(self): u = Url("example.com/foo/bar") self.assertEqual("example.com", u.hostloc) self.assertEqual("foo/bar", u.path) u = Url("example.com/") self.assertEqual("example.com", u.hostloc) self.assertEqual("", u.path)
def test_override(self): host = "0.0.0.0:4000" u = Url(host, hostname=Host(host).client()) self.assertFalse(host in u) host = "https://0.0.0.0:4000" u = Url(host, hostname=Host(host).client()) self.assertFalse(host in u) self.assertTrue("https://" in u)
def test_base(self): u = Url("http://example.com/path/part") u2 = u.base(che=4) self.assertEqual("http://example.com/path/part?che=4", u2) u = Url("http://example.com/path/part/?che=3") u2 = u.base("foo", "bar", che=4) self.assertEqual("http://example.com/path/part/foo/bar?che=4", u2) u = Url("http://example.com/") u2 = u.base("foo", "bar", che=4) self.assertEqual("http://example.com/foo/bar?che=4", u2)
def test_parent(self): u = Url("http://example.com/foo/bar/che") u2 = u.parent(che=4) self.assertEqual("http://example.com/foo/bar?che=4", u2) u2 = u.parent("baz", che=4) self.assertEqual("http://example.com/foo/bar/baz?che=4", u2) u = Url("http://example.com/") u2 = u.parent("baz", che=5) self.assertEqual("http://example.com/baz?che=5", u2)
def test_default_port(self): u = Url("http://example.com:1000", default_port=22) self.assertEqual(1000, u.port) u = Url("http://example.com", default_port=22) self.assertEqual(22, u.port) u = Url("http://example.com", port=8080, default_port=22) self.assertEqual(8080, u.port) u = Url("http://example.com:1000", port=8080, default_port=22) self.assertEqual(8080, u.port)
def test_scheme_with_path(self): u = Url("scheme:///foo/bar?query=val") self.assertEqual("", u.hostloc) self.assertEqual("foo/bar", u.path) self.assertEqual("scheme", u.scheme) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) u = Url("scheme:///foo/bar") self.assertEqual("", u.hostloc) self.assertEqual("foo/bar", u.path) self.assertEqual("scheme", u.scheme)
def test_no_scheme(self): h = Url("localhost:8080/foo/bar?che=1") self.assertEqual(8080, h.port) self.assertEqual("localhost", h.hostname) self.assertEqual("foo/bar", h.path) self.assertEqual("che=1", h.query) h = Url("localhost:8080/foo/bar") self.assertEqual(8080, h.port) self.assertEqual("localhost", h.hostname) h = Url("localhost:8080") self.assertEqual(8080, h.port) self.assertEqual("localhost", h.hostname) h = Url("localhost") self.assertEqual(80, h.port) self.assertEqual("localhost", h.hostname)
def test_hostloc_netloc(self): scheme = "http" host = "localhost" path = "/path/part" query = "query1=val1" port = "80" u = Url(scheme=scheme, hostname=host, path=path, query=query, port=port) self.assertEqual(host, u.netloc) self.assertEqual(host, u.hostloc) u = Url("http://*****:*****@example.com:1000", port=8080) self.assertEqual("username:[email protected]:8080", u.netloc) self.assertEqual("example.com:8080", u.hostloc)
def test_no_scheme_domain(self): u = Url("example.com:8080?query=val") self.assertEqual("http", u.scheme) self.assertEqual(8080, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("//example.com:8080?query=val") self.assertEqual("http", u.scheme) self.assertEqual(8080, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("example.com?query=val") self.assertEqual("http", u.scheme) self.assertEqual(80, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("", u.path) u = Url("example.com/foo/bar") self.assertEqual("http", u.scheme) self.assertEqual(80, u.port) self.assertEqual({}, u.query_kwargs) self.assertEqual("foo/bar", u.path) u = Url("example.com/foo/bar?query=val") self.assertEqual("http", u.scheme) self.assertEqual(80, u.port) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs)) self.assertEqual("foo/bar", u.path) u = Url("/foo/bar?query=val") self.assertEqual("http", u.scheme) self.assertTrue("query" in u.query_kwargs) self.assertEqual(1, len(u.query_kwargs))
def test_query(self): h = Url(query="foo=bar") self.assertEqual({"foo": "bar"}, h.query_kwargs)
def test_copy(self): u = Url("http://example.com/path/part/?che=3") u2 = u.copy() self.assertEqual(u, u2)
def test_host(self): u = Url("http://example.com/path/part/?che=3") u2 = u.host("foo", "bar", che=4) self.assertEqual("http://example.com/foo/bar?che=4", u2) self.assertEqual(u2.host(), u.host())