26 lines
902 B
Python
26 lines
902 B
Python
from collections.abc import AsyncIterator
|
|
|
|
import httpx
|
|
import pytest
|
|
from httpx import ASGITransport, AsyncClient
|
|
|
|
from monitor_service.api import create_app
|
|
from monitor_service.checker import CheckOutcome
|
|
from monitor_service.config import Settings
|
|
from monitor_service.models import CurrentStatus, MonitorState, utc_now
|
|
|
|
|
|
class StubChecker:
|
|
async def check(self, monitor_id: object, url: str) -> CheckOutcome:
|
|
return CheckOutcome(url.split("?", 1)[0], CurrentStatus(
|
|
state=MonitorState.up, checked_at=utc_now(), latency_ms=1.25, http_status=204
|
|
))
|
|
|
|
|
|
@pytest.fixture
|
|
async def client() -> AsyncIterator[AsyncClient]:
|
|
app = create_app(Settings(), checker=StubChecker()) # type: ignore[arg-type]
|
|
async with app.router.lifespan_context(app):
|
|
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as api:
|
|
yield api
|