def test_comparison(): foo = URI.parse(b"foo:opaque") # TODO if this is even a thing i want #assert foo == "Foo:opaque" assert foo == URI.parse(b"FOO:opaque") #assert foo == "foo:opaque" assert foo != "Bar:opaque" assert foo != "foo:opaque#"
def test_fragment(): uri = URI.parse(b'http://foo#bar') assert uri.fragment == 'bar' del uri.fragment assert str(uri) == b'http://foo' uri = URI.parse(b'http://foo#where%20am%20i...') assert uri.fragment == 'where am i...' uri.fragment = 'right here' assert str(uri) == b'http://foo#right%20here'
def test_simple(): uri = URI.parse("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html") assert str(uri) == "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" assert uri.host == "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210" assert uri.host_port == "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80" assert uri.port == 80 del uri.port assert str(uri) == "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]/index.html" # TODO not clear if this should include the port even when it doesn't exist # in the URI #assert uri.host_port == "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80" uri.port = 80 uri.host = 'host' assert str(uri) == "http://host:80/index.html" uri.host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210" assert str(uri) == "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html" uri.host_port = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:88" assert str(uri) == "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:88/index.html" uri.host_port = "[::1]:80" assert str(uri) == "http://[::1]:80/index.html" uri.host = "::1:80" assert str(uri) == "http://[::1:80]:80/index.html" uri.host = "[::1:80]" assert str(uri) == "http://[::1:80]:80/index.html"
def test_ftp(): uri = URI.parse("ftp://ftp:@[3ffe:2a00:100:7031::1]") assert str(uri) == "ftp://ftp:@[3ffe:2a00:100:7031::1]" assert uri.port == 21 assert not uri._port assert uri.host == "3ffe:2a00:100:7031::1" uri.host = "ftp" assert str(uri) == "ftp://ftp:@ftp"
def test_authority(): uri = URI.parse(b'what://*****:*****@host:/') assert uri.userinfo == 'foo:bar' assert uri.host == 'host' assert uri.port == None assert str(uri) == b'what://*****:*****@host/' # Play with the userinfo # TODO split this into user/password? seems scheme-specific. uri.userinfo = u'hello world' assert str(uri) == b'what://hello%20world@host/' del uri.userinfo assert str(uri) == b'what://host/'
def test_buildup(): foo = URI() # DEVIATION: lurid refuses to magically change relative paths to absolute foo.path_string = "/path" foo.parse_authority(b"auth") assert str(foo) == b"//auth/path" # TODO: $foo = URI->new("", "http:"); foo = URI() foo.query = "query" foo.parse_authority(b"auth") assert str(foo) == b"//auth?query" foo.path_string = "/path" assert str(foo) == b"//auth/path?query" foo = URI.parse(b"") assert foo.path_string == "" foo.parse_path(b"foo") assert foo.path_string == "foo" assert str(foo) == b"foo" foo.parse_path(b"bar") assert foo.path_string == "bar" assert foo.opaque == "bar" assert str(foo) == b"bar" foo.parse_opaque(b"foo") assert foo.path_string == "foo" assert foo.opaque == "foo" assert str(foo) == b"foo" foo.parse_path(b"") assert str(foo) == b"" assert foo.query == None foo.query = "q" assert str(foo) == b"?q"
def test_scheme(): uri = URI.parse(b'http://foo') assert uri.scheme == 'http' uri.scheme = 'foo' assert uri.scheme == 'foo' assert str(uri) == b'foo://foo' del uri.scheme assert str(uri) == b'//foo' uri.scheme = 'HTTP' assert str(uri) == 'http://foo' # Must use unicode to set properties with pytest.raises(TypeError): uri.scheme = b'foo' # Scheme must be /[a-z][a-z0-9.-+]+/i for bad_scheme in ('', '+ssh', 'foo bar', 'http:', 'ftp%20'): with pytest.raises(InvalidURIError): uri.scheme = bad_scheme
def test_hierarchy(): foo = URI.parse(b"foo://*****:*****@&") assert foo.authority == "%2F%3F%20%23;@&" assert str(foo) == b"foo://%2F%3F%20%23;@&/path?query#frag" foo.parse_authority(b"host:80") assert foo.authority == "host:80" assert str(foo) == b"foo://*****:*****@;/?#" assert foo.path_escaped == "/@;/%3F%23" assert str(foo) == b"foo://*****:*****@;/%3F%23?query#frag" foo.path_string = "/path" assert foo.path_string == "/path" assert str(foo) == b"foo://host:80/path?query#frag" # Query foo.query = "foo" assert foo.query == "foo" assert str(foo) == b"foo://host:80/path?foo#frag" foo.query = "" assert foo.query == "" assert str(foo) == b"foo://host:80/path?#frag" foo.query = None assert foo.query == None assert str(foo) == b"foo://host:80/path#frag" foo.query = "/?&=# " assert foo.query == "/?&=%23%20" assert str(foo) == b"foo://host:80/path?/?&=%23%20#frag" foo.query = "query" assert foo.query == "query" assert str(foo) == b"foo://host:80/path?query#frag"
def test_simple(): foo = URI.parse(b'Foo:opaque#frag') # TODO this is testing for the uri subclass #print "not " unless ref($foo) eq "URI::_foreign"; # DEVIATION: lurid canonicalizes the scheme assert str(foo) == b'foo:opaque#frag' assert foo.scheme == 'foo' assert foo.opaque == 'opaque' assert foo.fragment == 'frag' assert foo.serialize() == 'foo:opaque#frag' # Scheme foo.scheme = "bar" assert str(foo) == b"bar:opaque#frag" # TODO unclear if this should work or be allowed or what # TODO there's no actual parsing or other checking for the scheme, bleh #foo.scheme = "" #assert str(foo) == "opaque#frag" del foo.scheme assert str(foo) == b"opaque#frag" foo.scheme = "foo" # Opaque stuff foo.parse_opaque(b"xxx") assert foo.opaque == "xxx" assert str(foo) == b"foo:xxx#frag" foo.parse_opaque(b"") assert foo.opaque == "" assert str(foo) == b"foo:#frag" # TODO unclear what sort of auto-escaping opaque should do; this is clearly # not a parse #foo.opaque = " #?/" #assert foo.opaque == "%20%23?/" del foo.opaque assert foo.opaque == "" assert str(foo) == b"foo:#frag" foo.parse_opaque(b"opaque") # Fragments assert foo.fragment == "frag" foo.fragment = "x" assert foo.fragment == "x" assert str(foo) == b"foo:opaque#x" foo.fragment = "" assert foo.fragment == "" assert str(foo) == b"foo:opaque#" del foo.fragment assert foo.fragment == None assert str(foo) == b"foo:opaque"
def test_localhost(): uri = URI.parse("http://[::1]") assert uri.host == "::1"