test: complete control panel fixture UX coverage
This commit is contained in:
@@ -1,15 +1,43 @@
|
||||
from central.tests.test_control_plane import setup_db
|
||||
import uuid
|
||||
|
||||
from central.scripts.generate_control_panel_fixture import generate_fixture
|
||||
from central.app.models import AgentEvent, AgentSnapshot, Installation, Job
|
||||
from central.app.models import AgentEvent, AgentSnapshot, BlockedProduct, Installation, Job
|
||||
from central.tests.test_control_plane import setup_db
|
||||
|
||||
|
||||
def test_fixture_creates_one_hundred_varied_installations_and_events():
|
||||
session_factory = setup_db()
|
||||
with session_factory() as session:
|
||||
result = generate_fixture(session, agent_count=100, seed=11)
|
||||
assert result == {"agents": 100, "events": 500, "blockers": 50, "jobs": 100}
|
||||
assert result == {"agents": 100, "events": 500, "blockers": 51, "jobs": 100}
|
||||
assert session.query(Installation).count() == 100
|
||||
assert session.query(AgentEvent).count() == 500
|
||||
assert session.query(Job).count() == 100
|
||||
assert {row.agent_health for row in session.query(AgentSnapshot).all()} == {"ONLINE", "DEGRADED", "OFFLINE", "FAILED", "UNKNOWN"}
|
||||
assert {row.version_drift for row in session.query(AgentSnapshot).all()} == {"CURRENT", "OUTDATED", "UNKNOWN"}
|
||||
snapshots = session.query(AgentSnapshot).all()
|
||||
assert {row.agent_health for row in snapshots} == {"ONLINE", "DEGRADED", "OFFLINE", "FAILED", "UNKNOWN"}
|
||||
assert {row.version_drift for row in snapshots} == {"CURRENT", "OUTDATED", "UNKNOWN"}
|
||||
assert {row.installation_id for row in session.query(Installation).all()} == {str(uuid.uuid5(uuid.NAMESPACE_DNS, f"fixture-{index}")) for index in range(100)}
|
||||
|
||||
blockers = session.query(BlockedProduct).all()
|
||||
assert len({row.blocker_fingerprint for row in blockers}) == len(blockers)
|
||||
for snapshot in snapshots:
|
||||
product_codes = {row.product_code for row in blockers if row.installation_id == snapshot.installation_id and row.resolved_at is None}
|
||||
assert snapshot.safe_blocked == len(product_codes)
|
||||
repeated_product = next(row for row in blockers if row.product_code == "P000000")
|
||||
same_product_blockers = [row for row in blockers if row.tenant_id == repeated_product.tenant_id and row.installation_id == repeated_product.installation_id and row.product_code == repeated_product.product_code]
|
||||
assert len(same_product_blockers) >= 2
|
||||
assert all(row.resolved_at is None for row in same_product_blockers)
|
||||
assert all(row.tenant_id == session.query(Installation).filter_by(id=row.installation_id).one().tenant_id for row in blockers)
|
||||
|
||||
failed_jobs = session.query(Job).filter_by(status="FAILED").all()
|
||||
assert failed_jobs and all(job.started_at is not None and job.finished_at is not None and job.finished_at >= job.started_at for job in failed_jobs)
|
||||
linked_events = session.query(AgentEvent).filter(AgentEvent.job_id.is_not(None), AgentEvent.blocker_id.is_not(None)).all()
|
||||
assert linked_events
|
||||
for event in linked_events:
|
||||
job = session.get(Job, event.job_id)
|
||||
blocker = session.get(BlockedProduct, event.blocker_id)
|
||||
installation = session.query(Installation).filter_by(id=blocker.installation_id).one()
|
||||
assert event.installation_id == installation.id == session.query(Installation).filter_by(agent_id=job.agent_id).one().id
|
||||
assert event.tenant_id == blocker.tenant_id == installation.tenant_id
|
||||
assert event.product_code == blocker.product_code
|
||||
assert all("password" not in event.message.lower() and "token" not in event.message.lower() for event in session.query(AgentEvent).all())
|
||||
|
||||
Reference in New Issue
Block a user