Introduce typed config objects, optional adapter injection, and .env loading to simplify testing while preserving env-based defaults for production usage. Co-authored-by: Cursor <[email protected]>
83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
"""Unit tests for JsonRepositoryInterface."""
|
|
|
|
import pytest
|
|
from python_repositories.interfaces.json_repository_interface import (
|
|
JsonRepositoryInterface,
|
|
)
|
|
|
|
|
|
def test_instantiation_fails_when_get_not_implemented() -> None:
|
|
"""Test that instantiation fails if get is not implemented."""
|
|
|
|
class Incomplete(JsonRepositoryInterface):
|
|
"""A class that does not implement get."""
|
|
|
|
def set(self, key: str, data: dict) -> None:
|
|
pass
|
|
|
|
def delete(self, key: str) -> None:
|
|
pass
|
|
|
|
def list_keys(self, pattern: str) -> list[str]:
|
|
return []
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete() # type: ignore
|
|
|
|
|
|
def test_instantiation_fails_when_set_not_implemented() -> None:
|
|
"""Test that instantiation fails if set is not implemented."""
|
|
|
|
class Incomplete(JsonRepositoryInterface):
|
|
"""A class that does not implement set."""
|
|
|
|
def get(self, key: str) -> dict | None:
|
|
return None
|
|
|
|
def delete(self, key: str) -> None:
|
|
pass
|
|
|
|
def list_keys(self, pattern: str) -> list[str]:
|
|
return []
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete() # type: ignore
|
|
|
|
|
|
def test_instantiation_fails_when_delete_not_implemented() -> None:
|
|
"""Test that instantiation fails if delete is not implemented."""
|
|
|
|
class Incomplete(JsonRepositoryInterface):
|
|
"""A class that does not implement delete."""
|
|
|
|
def get(self, key: str) -> dict | None:
|
|
return None
|
|
|
|
def set(self, key: str, data: dict) -> None:
|
|
pass
|
|
|
|
def list_keys(self, pattern: str) -> list[str]:
|
|
return []
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete() # type: ignore
|
|
|
|
|
|
def test_instantiation_fails_when_list_keys_not_implemented() -> None:
|
|
"""Test that instantiation fails if list_keys is not implemented."""
|
|
|
|
class Incomplete(JsonRepositoryInterface):
|
|
"""A class that does not implement list_keys."""
|
|
|
|
def get(self, key: str) -> dict | None:
|
|
return None
|
|
|
|
def set(self, key: str, data: dict) -> None:
|
|
pass
|
|
|
|
def delete(self, key: str) -> None:
|
|
pass
|
|
|
|
with pytest.raises(TypeError):
|
|
_ = Incomplete() # type: ignore
|