45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
from apps.audit.models import OperationAuditLog
|
|
|
|
|
|
def test_list_operation_logs_returns_recent_logs(admin_client, db):
|
|
OperationAuditLog.objects.create(
|
|
module="system",
|
|
action="health_check",
|
|
target_type="system",
|
|
target_id="health",
|
|
result="success",
|
|
request_snapshot={"path": "/api/system/health"},
|
|
)
|
|
|
|
response = admin_client.get("/api/audit/operation-logs")
|
|
|
|
assert response.status_code == 200
|
|
payload = response.json()
|
|
assert len(payload) == 1
|
|
assert payload[0]["module"] == "system"
|
|
assert payload[0]["action"] == "health_check"
|
|
|
|
|
|
def test_list_operation_logs_supports_business_object_filters(admin_client, db):
|
|
OperationAuditLog.objects.create(
|
|
module="tickets",
|
|
action="status_transition",
|
|
target_type="ticket",
|
|
target_id="42",
|
|
result="success",
|
|
)
|
|
OperationAuditLog.objects.create(
|
|
module="agents",
|
|
action="run_started",
|
|
target_type="agent_run",
|
|
target_id="run-1",
|
|
result="success",
|
|
)
|
|
|
|
response = admin_client.get(
|
|
"/api/audit/operation-logs?module=tickets&target_type=ticket&target_id=42"
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
assert [item["target_id"] for item in response.json()] == ["42"]
|