diff --git a/tests/aws_mocks.py b/tests/aws_mocks.py index 89e8735..9924584 100644 --- a/tests/aws_mocks.py +++ b/tests/aws_mocks.py @@ -1,9 +1,19 @@ from typing import TypedDict +from .boto3_mocks import ClientMock + TARGET_SESSION = "pydantic_settings_aws.aws.boto3.Session" +TARGET_BOTO3_CLIENT = "pydantic_settings_aws.aws._get_boto3_client" + TARGET_SECRETS_CLIENT = "pydantic_settings_aws.aws._create_secrets_client" +TARGET_SECRET_CONTENT = "pydantic_settings_aws.aws._get_secrets_content" + + +def mock_secrets_content_empty(*args): + return ClientMock(secret_string=None) + def mock_create_client(*args): return object() diff --git a/tests/aws_test.py b/tests/aws_test.py index 32be2c2..1e9a9f5 100644 --- a/tests/aws_test.py +++ b/tests/aws_test.py @@ -1,12 +1,17 @@ from unittest import mock +import pytest + from pydantic_settings_aws import aws from .aws_mocks import ( + TARGET_BOTO3_CLIENT, + TARGET_SECRET_CONTENT, TARGET_SECRETS_CLIENT, TARGET_SESSION, BaseSettingsMock, mock_create_client, + mock_secrets_content_empty, ) from .boto3_mocks import SessionMock @@ -27,3 +32,19 @@ def test_get_boto3_client_must_create_a_client_if_its_not_given(*args): client = aws._get_boto3_client(settings) assert client is not None + + +@mock.patch(TARGET_BOTO3_CLIENT, mock_secrets_content_empty) +@mock.patch(TARGET_SECRET_CONTENT, lambda *args: None) +def test_get_secrets_content_must_raise_value_error_if_secrets_content_is_none( + *args, +): + settings = BaseSettingsMock() + settings.model_config = { + "secrets_name": "secrets/name", + "aws_region": "region", + "aws_profile": "profile", + } + + with pytest.raises(ValueError): + aws.get_secrets_content(settings)