def test_relative_prefix_extension(self): url = Url("..") self.assertEqual(url["foo"](), "../foo") self.assertEqual(url["foo"]("bar"), "../foo/bar") self.assertEqual(url[42]("bar"), "../42/bar") self.assertEqual(url["foo"](42), "../foo/42") self.assertEqual(url["foo"][42]("bar"), "../foo/42/bar")
def test_prefix_extension(self): url = Url("/prefix") self.assertEqual(url["foo"](), "/prefix/foo") self.assertEqual(url["foo"]("bar"), "/prefix/foo/bar") self.assertEqual(url[42]("bar"), "/prefix/42/bar") self.assertEqual(url["foo"](42), "/prefix/foo/42") self.assertEqual(url["foo"][42]("bar"), "/prefix/foo/42/bar")
def test_top_level_extension(self): url = Url("/") self.assertEqual(url["foo"](), "/foo") self.assertEqual(url["foo"]("bar"), "/foo/bar") self.assertEqual(url[42]("bar"), "/42/bar") self.assertEqual(url["foo"](42), "/foo/42") self.assertEqual(url["foo"][42]("bar"), "/foo/42/bar")
def test_escape(self): url = Url("/") self.assertEqual(url("foo/bar"), "/foo%2Fbar") self.assertEqual(url("foo?bar"), "/foo%3Fbar") self.assertEqual(url("foo&bar"), "/foo%26bar") self.assertEqual(url("foo#bar"), "/foo%23bar") kwargs = {"?foo": "/bar#", "f=o?o": "?b=a&r"} self.assertEqual(url(**kwargs), "/?%3Ffoo=%2Fbar%23&f%3Do%3Fo=%3Fb%3Da%26r")
def test_query(self): url = Url("/foo")["bar"] self.assertEqual(url("baz", a="b"), "/foo/bar/baz?a=b") self.assertEqual(url("baz", a=42), "/foo/bar/baz?a=42") self.assertEqual(url("baz", a="b", b="a"), "/foo/bar/baz?a=b&b=a")
def test_relative_prefix(self): url = Url("..") self.assertEqual(url(), "..") self.assertEqual(url("foo"), "../foo") self.assertEqual(url("foo", "bar"), "../foo/bar") self.assertEqual(url("foo", 42), "../foo/42")
def test_prefix(self): url = Url("/prefix") self.assertEqual(url(), "/prefix") self.assertEqual(url("foo"), "/prefix/foo") self.assertEqual(url("foo", "bar"), "/prefix/foo/bar") self.assertEqual(url("foo", 42), "/prefix/foo/42")
def test_top_level(self): url = Url("/") self.assertEqual(url(), "/") self.assertEqual(url("foo"), "/foo") self.assertEqual(url("foo", "bar"), "/foo/bar") self.assertEqual(url("foo", 42), "/foo/42")