Files
crucible-agent-build-fastap…/tests/test_store.py

28 lines
942 B
Python

import asyncio
import pytest
from app.models import CurrentStatus, MonitorCreate, MonitorUpdate, State
from app.store import MonitorNotFoundError, MonitorStore
async def test_atomic_update_does_not_lose_status() -> None:
store = MonitorStore()
monitor = await store.create(MonitorCreate(name="one", url="https://example.com"))
status = CurrentStatus(state=State.UP)
await asyncio.gather(
store.update(monitor.id, MonitorUpdate(name="two")),
store.set_status(monitor.id, status),
)
result = await store.get(monitor.id)
assert result.name == "two"
assert result.current_status.state == State.UP
async def test_delete_is_locked_and_missing_is_typed() -> None:
store = MonitorStore()
monitor = await store.create(MonitorCreate(name="one", url="https://example.com"))
await store.delete(monitor.id)
with pytest.raises(MonitorNotFoundError):
await store.get(monitor.id)