MCPcopy Index your code
hub / github.com/webpy/webpy / testRedirect

Method testRedirect

tests/test_application.py:98–126  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

96 self.assertEqual(response.status, "405 Method Not Allowed")
97
98 def testRedirect(self):
99 # fmt: off
100 urls = (
101 "/a", "redirect /hello/",
102 "/b/(.*)", r"redirect /hello/\1",
103 "/hello/(.*)", "hello"
104 )
105 # fmt: on
106
107 app = web.application(urls, locals())
108
109 class hello:
110 def GET(self, name):
111 name = name or "world"
112 return "hello " + name
113
114 response = app.request("/a")
115 self.assertEqual(response.status, "301 Moved Permanently")
116 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/hello/")
117
118 response = app.request("/a?x=2")
119 self.assertEqual(response.status, "301 Moved Permanently")
120 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/hello/?x=2")
121
122 response = app.request("/b/foo?x=2")
123 self.assertEqual(response.status, "301 Moved Permanently")
124 self.assertEqual(
125 response.headers["Location"], "http://0.0.0.0:8080/hello/foo?x=2"
126 )
127
128 def test_routing(self):
129 urls = ("/foo", "foo")

Callers

nothing calls this directly

Calls 1

requestMethod · 0.80

Tested by

no test coverage detected