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

Function test_middleware_args

tests/test_applications.py:507–526  ·  view source on GitHub ↗
(test_client_factory: TestClientFactory)

Source from the content-addressed store, hash-verified

505
506
507def test_middleware_args(test_client_factory: TestClientFactory) -> None:
508 calls: list[str] = []
509
510 class MiddlewareWithArgs:
511 def __init__(self, app: ASGIApp, arg: str) -> None:
512 self.app = app
513 self.arg = arg
514
515 async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
516 calls.append(self.arg)
517 await self.app(scope, receive, send)
518
519 app = Starlette()
520 app.add_middleware(MiddlewareWithArgs, "foo")
521 app.add_middleware(MiddlewareWithArgs, "bar")
522
523 with test_client_factory(app):
524 pass
525
526 assert calls == ["bar", "foo"]
527
528
529def test_middleware_factory(test_client_factory: TestClientFactory) -> None:

Callers

nothing calls this directly

Calls 3

add_middlewareMethod · 0.95
StarletteClass · 0.90
test_client_factoryFunction · 0.85

Tested by

no test coverage detected