diff --git a/tests/fixtures/dummies.py b/tests/fixtures/dummies.py index 63c4c52..ac84c5e 100644 --- a/tests/fixtures/dummies.py +++ b/tests/fixtures/dummies.py @@ -21,28 +21,6 @@ from sms.models import Criteria, UpsertionDetails from sms.ports.inbound.docs_handler import DocsHandlerPort from sms.ports.inbound.objects_handler import ObjectsHandlerPort, S3ObjectStoragesPort -from sms.ports.inbound.secrets_handler import SecretsHandlerPort - - -class DummySecretsHandler(SecretsHandlerPort): - """Dummy SecretsHandler implementation for testing. - - `secrets` is a dictionary that maps vault paths to lists of secrets. - """ - - def __init__( - self, - secrets: dict[str, list[str]] | None = None, - ): - self.secrets = secrets if secrets else {} - - def get_secrets(self, vault_path: str) -> list[str]: - """Get all secrets currently stored for the specified vault.""" - return self.secrets.get(vault_path, []) - - def delete_secrets(self, vault_path: str) -> None: - """Delete all secrets stored in the vault.""" - self.secrets.pop(vault_path, None) @dataclass diff --git a/tests/unit/secrets/test_rest_secrets.py b/tests/unit/secrets/test_rest_secrets.py index a8a0949..8d620b3 100644 --- a/tests/unit/secrets/test_rest_secrets.py +++ b/tests/unit/secrets/test_rest_secrets.py @@ -15,11 +15,11 @@ """Unit tests for the Vault part of the SMS REST API.""" from typing import Any +from unittest.mock import Mock import pytest from tests.fixtures.config import DEFAULT_TEST_CONFIG -from tests.fixtures.dummies import DummySecretsHandler from tests.fixtures.utils import VALID_BEARER_TOKEN, get_rest_client_with_mocks from tests.fixtures.vault import DEFAULT_VAULT_PATH @@ -44,8 +44,8 @@ ) async def test_get_secrets(stored_secrets: list[str]): """Test the GET secrets endpoint without errors.""" - vault_path_and_secrets = {DEFAULT_VAULT_PATH: stored_secrets} - secrets_handler = DummySecretsHandler(secrets=vault_path_and_secrets) + secrets_handler = Mock() + secrets_handler.get_secrets.return_value = stored_secrets async with get_rest_client_with_mocks( config=DEFAULT_TEST_CONFIG, secrets_handler_override=secrets_handler ) as client: @@ -53,24 +53,16 @@ async def test_get_secrets(stored_secrets: list[str]): assert response.status_code == 200 assert response.json() == stored_secrets + secrets_handler.get_secrets.assert_called_once_with(DEFAULT_VAULT_PATH) -@pytest.mark.parametrize( - "stored_secrets", - [ - [], - ["secret1", "secret2", "secret3"], - ], - ids=["VaultIsEmpty", "VaultHasThreeSecrets"], -) -async def test_delete_secrets(stored_secrets: list[str]): +async def test_delete_secrets(): """Test the DELETE secrets endpoint without errors.""" - vault_path_and_secrets = {DEFAULT_VAULT_PATH: stored_secrets} - secrets_handler = DummySecretsHandler(secrets=vault_path_and_secrets) + secrets_handler = Mock() async with get_rest_client_with_mocks( config=DEFAULT_TEST_CONFIG, secrets_handler_override=secrets_handler ) as client: response = await client.delete(TEST_URL, headers=HEADERS) assert response.status_code == 204 - assert secrets_handler.secrets.get(DEFAULT_VAULT_PATH, []) == [] + secrets_handler.delete_secrets.assert_called_once_with(DEFAULT_VAULT_PATH)