33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
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)
|