MCPcopy
hub / github.com/pallets/werkzeug / test_dispatch

Function test_dispatch

tests/test_routing.py:462–483  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

460
461
462def test_dispatch():
463 env = create_environ("/")
464 map = r.Map([r.Rule("/", endpoint="root"), r.Rule("/foo/", endpoint="foo")])
465 adapter = map.bind_to_environ(env)
466
467 raise_this = None
468
469 def view_func(endpoint, values):
470 if raise_this is not None:
471 raise raise_this
472 return Response(repr((endpoint, values)))
473
474 def dispatch(path, quiet=False):
475 return Response.force_type(
476 adapter.dispatch(view_func, path, catch_http_exceptions=quiet), env
477 )
478
479 assert dispatch("/").data == b"('root', {})"
480 assert dispatch("/foo").status_code == 308
481 raise_this = NotFound()
482 pytest.raises(NotFound, lambda: dispatch("/bar"))
483 assert dispatch("/bar", True).status_code == 404
484
485
486def test_http_host_before_server_name():

Callers

nothing calls this directly

Calls 4

bind_to_environMethod · 0.95
create_environFunction · 0.90
NotFoundClass · 0.90
dispatchFunction · 0.85

Tested by

no test coverage detected