Skip to content

Commit

Permalink
Add aws tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Marques committed Jul 14, 2024
1 parent 3797d43 commit 6a7fb2c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/aws_mocks.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
21 changes: 21 additions & 0 deletions tests/aws_test.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)

0 comments on commit 6a7fb2c

Please sign in to comment.