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

Method test_processors

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

Source from the content-addressed store, hash-verified

234 self.assertEqual(response.headers["Location"], "http://0.0.0.0:8080/x/blog/bar")
235
236 def test_processors(self):
237 urls = ("/(.*)", "blog")
238
239 class blog:
240 def GET(self, path):
241 return "blog " + path
242
243 state = web.storage(x=0, y=0)
244
245 def f():
246 state.x += 1
247
248 app_blog = web.application(urls, locals())
249 app_blog.add_processor(web.loadhook(f))
250
251 # fmt: off
252 urls = (
253 "/blog", app_blog,
254 "/(.*)", "index"
255 )
256 # fmt: on
257
258 class index:
259 def GET(self, path):
260 return "hello " + path
261
262 app = web.application(urls, locals())
263
264 def g():
265 state.y += 1
266
267 app.add_processor(web.loadhook(g))
268
269 app.request("/blog/foo")
270 assert state.x == 1 and state.y == 1, repr(state)
271 app.request("/foo")
272 assert state.x == 1 and state.y == 2, repr(state)
273
274 def testUnicodeInput(self):
275 urls = ("(/.*)", "foo")

Callers

nothing calls this directly

Calls 2

add_processorMethod · 0.80
requestMethod · 0.80

Tested by

no test coverage detected