From 595f4cc8b876479bd5e673ecbb2ed916748f23d5 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Mon, 24 Jul 2023 15:54:56 -0400 Subject: [PATCH] test: fastapi and flask authz middleware logger init --- tests/test_platform_fastapi.py | 6 ++++++ tests/test_platform_flask.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/tests/test_platform_fastapi.py b/tests/test_platform_fastapi.py index 94c6649..f02d7c9 100644 --- a/tests/test_platform_fastapi.py +++ b/tests/test_platform_fastapi.py @@ -205,6 +205,12 @@ def _expect_error(r: HttpxResponse, code: int, msg: str): assert data["errors"][0]["message"] == msg +def test_fastapi_middleware_init_logger(): + inst = FastApiAuthMiddleware(bento_authz_service_url="https://bento-auth.local") + inst.attach(FastAPI()) # should create a logger if not specified + assert inst._logger is not None + + def test_fastapi_http_exception_404(test_client: TestClient): _expect_error(test_client.get("/get-404"), 404, "Hello") diff --git a/tests/test_platform_flask.py b/tests/test_platform_flask.py index 86c82f1..94e999b 100644 --- a/tests/test_platform_flask.py +++ b/tests/test_platform_flask.py @@ -148,6 +148,13 @@ def auth_disabled_post_private(): # ----------------------------------------------------------------------------- +def test_flask_middleware_init_logger(): + inst = FlaskAuthMiddleware(bento_authz_service_url="https://bento-auth.local") + app = Flask(__name__) + inst.attach(app) + assert inst._logger == app.logger + + def test_flask_errors(flask_client): # non-existent endpoint