34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import json
|
|
import os
|
|
|
|
import pytest
|
|
from sqlalchemy import select
|
|
|
|
from monlet_server.models import Agent, Check, Incident
|
|
|
|
EXAMPLES = os.path.join(os.path.dirname(__file__), "..", "..", "examples")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_examples_payload(app_client, auth_headers, session):
|
|
with open(os.path.join(EXAMPLES, "heartbeat.json")) as f:
|
|
hb = json.load(f)
|
|
with open(os.path.join(EXAMPLES, "event-batch.json")) as f:
|
|
batch = json.load(f)
|
|
|
|
r = await app_client.post("/api/v1/heartbeat", json=hb, headers=auth_headers)
|
|
assert r.status_code == 202
|
|
|
|
r = await app_client.post("/api/v1/events", json=batch, headers=auth_headers)
|
|
assert r.status_code == 202
|
|
|
|
agents = (await session.execute(select(Agent))).scalars().all()
|
|
assert len(agents) == 1
|
|
checks = (await session.execute(select(Check))).scalars().all()
|
|
assert {c.check_id for c in checks} == {"disk_root", "postgres_up"}
|
|
open_inc = (
|
|
(await session.execute(select(Incident).where(Incident.state == "open"))).scalars().all()
|
|
)
|
|
assert len(open_inc) == 1
|
|
assert open_inc[0].check_id == "postgres_up"
|