diff --git a/tests/test_store_and_config.py b/tests/test_store_and_config.py new file mode 100644 index 0000000..0e3ae5c --- /dev/null +++ b/tests/test_store_and_config.py @@ -0,0 +1,32 @@ +from uuid import uuid4 + +import pytest +from pydantic import ValidationError + +from app.config import Settings +from app.models import MonitorCreate, MonitorState, StatusSnapshot +from app.store import MonitorStore + +pytestmark = pytest.mark.anyio + + +async def test_revision_prevents_stale_check_write() -> None: + store = MonitorStore() + monitor = await store.create(MonitorCreate(name="a", url="https://example.com")) + pending = await store.begin_check(monitor.id) + assert pending is not None + _, revision = pending + await store.update(monitor.id, MonitorCreate(name="b", url="https://example.org")) + saved = await store.finish_check( + monitor.id, revision, StatusSnapshot(state=MonitorState.UP), + ) + assert saved is False + assert (await store.get(monitor.id)).status.state is MonitorState.UNKNOWN # type: ignore[union-attr] + assert await store.begin_check(uuid4()) is None + + +async def test_settings_validation() -> None: + with pytest.raises(ValidationError): + Settings(check_timeout_seconds=0) + with pytest.raises(ValidationError): + Settings(max_redirects=99)