(test_client_factory: TestClientFactory)
| 315 | |
| 316 | |
| 317 | def 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 | |
| 337 | def http_endpoint(request: Request) -> Response: |
nothing calls this directly
no test coverage detected