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

Method test_redirect

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

Source from the content-addressed store, hash-verified

197 test("d.example.com", b"*")
198
199 def test_redirect(self):
200 urls = ("/(.*)", "blog")
201
202 class blog:
203 def GET(self, path):
204 if path == "foo":
205 raise web.seeother("/login", absolute=True)
206 else:
207 raise web.seeother("/bar")
208
209 app_blog = web.application(urls, locals())
210
211 # fmt: off
212 urls = (
213 "/blog", app_blog,
214 "/(.*)", "index"
215 )
216 # fmt: on
217
218 class index:
219 def GET(self, path):
220 return "hello " + path
221
222 app = web.application(urls, locals())
223
224 response = app.request("/blog/foo")
225 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/login")
226
227 response = app.request("/blog/foo", env={"SCRIPT_NAME": "/x"})
228 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/x/login")
229
230 response = app.request("/blog/foo2")
231 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/blog/bar")
232
233 response = app.request("/blog/foo2", env={"SCRIPT_NAME": "/x"})
234 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/x/blog/bar")
235
236 def test_processors(self):
237 urls = ("/(.*)", "blog")

Callers

nothing calls this directly

Calls 1

requestMethod · 0.80

Tested by

no test coverage detected