MCPcopy
hub / github.com/encode/starlette / test_router_middleware

Function test_router_middleware

tests/test_routing.py:317–334  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

315
316
317def test_router_middleware(test_client_factory: TestClientFactory) -> None:
318 class CustomMiddleware:
319 def __init__(self, app: ASGIApp) -> None:
320 self.app = app
321
322 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
323 response = PlainTextResponse("OK")
324 await response(scope, receive, send)
325
326 app = Router(
327 routes=[Route("/", homepage)],
328 middleware=[Middleware(CustomMiddleware)],
329 )
330
331 client = test_client_factory(app)
332 response = client.get("/")
333 assert response.status_code == 200
334 assert response.text == "OK"
335
336
337def http_endpoint(request: Request) -> Response:

Callers

nothing calls this directly

Calls 5

RouterClass · 0.90
RouteClass · 0.90
MiddlewareClass · 0.90
test_client_factoryFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected