Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiamatrix committed Jan 3, 2024
1 parent 4ec6a1e commit ab03c45
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_credentials.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from unittest.mock import patch

import pytest
from boto3.session import Session
from botocore.client import BaseClient
from moto import mock_s3

from prefect_aws.credentials import AwsCredentials, ClientType, MinIOCredentials
from prefect_aws.credentials import (
AwsCredentials,
ClientType,
MinIOCredentials,
_get_client_cached,
)


def test_aws_credentials_get_boto3_session():
Expand Down Expand Up @@ -44,3 +51,27 @@ def test_minio_credentials_get_boto3_session():
def test_credentials_get_client(credentials, client_type):
with mock_s3():
assert isinstance(credentials.get_client(client_type), BaseClient)


@patch("prefect_aws.credentials._get_client_cached")
def test_get_client_cached(mock_get_client_cached):
"""
Test to ensure that _get_client_cached function returns the same instance
for multiple calls with the same parameters and properly utilizes lru_cache.
"""

# Create a mock AwsCredentials instance
aws_credentials_block = AwsCredentials()

# Call _get_client_cached multiple times with the same parameters
_get_client_cached(aws_credentials_block, ClientType.S3)
_get_client_cached(aws_credentials_block, ClientType.S3)

# Verify that _get_client_cached is called only once due to caching
mock_get_client_cached.assert_called_once_with(aws_credentials_block, ClientType.S3)

# Test with different parameters to ensure they are cached separately
_get_client_cached(aws_credentials_block, ClientType.ECS)
assert (
mock_get_client_cached.call_count == 2
), "Should be called twice with different parameters"

0 comments on commit ab03c45

Please sign in to comment.