From 708a7222e1c9a808bf798cb9cb4f3d251086592f Mon Sep 17 00:00:00 2001 From: ljnsn Date: Sun, 13 Oct 2024 00:13:56 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test(utils):=20more=20coverage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index f8a878e..345fe65 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -80,6 +80,8 @@ class Security(msgspec.Struct): }, ), ] + field_with_no_meta: str = "test" + none_field: str | None = None security = Security(api_key="test_key") client = utils.configure_security_client(None, security) @@ -143,6 +145,41 @@ class Security(msgspec.Struct): client = utils.configure_security_client(None, security) assert client.headers == {"Authorization": "Bearer test_token"} + def test_configure_security_client_with_option(self) -> None: + """Test configuring security client with security option.""" + + class SecurityOption(msgspec.Struct): + api_key: Annotated[ + str, + msgspec.Meta( + extra={ + "security": { + "scheme": True, + "type": "apiKey", + "sub_type": "header", + "field_name": "X-API-Key", + }, + }, + ), + ] + other_field: str = "test" + + class Security(msgspec.Struct): + option: Annotated[ + SecurityOption, + msgspec.Meta( + extra={ + "security": { + "option": True, + }, + }, + ), + ] + + security = Security(option=SecurityOption(api_key="test_option_key")) + client = utils.configure_security_client(None, security) + assert client.headers == {"X-API-Key": "test_option_key"} + class TestPathParamHandlers: """Tests for path param handlers."""