Files
aoc/backend/tests/test_event_model.py
Tomas Kracmar 9271b4e461
Some checks failed
CI / lint-and-test (push) Has been cancelled
feat: implement Phase 2 stabilization
- Cache Graph API tokens with expiry-aware reuse in graph/auth.py
- Add tenacity-based retry/backoff wrapper (utils/http.py) and apply to all Graph/source API calls
- Add Pydantic request/response models (models/api.py) and FastAPI query constraints
- Add unit tests for event_model, auth and integration tests for API endpoints
- Configure ruff linter/formatter in pyproject.toml
- Add GitHub Actions CI pipeline (.github/workflows/ci.yml)
- Add requirements-dev.txt with pytest, mongomock, httpx, ruff
- Clean up typing imports and fix ruff linting across codebase
2026-04-14 12:02:28 +02:00

64 lines
2.1 KiB
Python

from models.event_model import _make_dedupe_key, normalize_event
def test_make_dedupe_key_prefers_id_and_category():
e = {"id": "evt-123", "category": "Directory"}
assert _make_dedupe_key(e) == "evt-123|Directory"
def test_make_dedupe_key_fallback_without_id():
e = {
"activityDateTime": "2024-01-01T00:00:00Z",
"category": "Exchange",
"activityDisplayName": "Update setting",
}
key = _make_dedupe_key(e)
assert "2024-01-01T00:00:00Z|Exchange|Update setting" in key
def test_normalize_event_basic():
e = {
"id": "abc",
"activityDateTime": "2024-01-15T10:30:00Z",
"category": "UserManagement",
"activityDisplayName": "Add user",
"result": "success",
"initiatedBy": {
"user": {
"id": "u1",
"displayName": "Alice",
"userPrincipalName": "alice@example.com",
}
},
"targetResources": [
{"id": "t1", "displayName": "Bob", "type": "User"}
],
}
out = normalize_event(e)
assert out["id"] == "abc"
assert out["timestamp"] == "2024-01-15T10:30:00Z"
assert out["service"] == "UserManagement"
assert out["operation"] == "Add user"
assert out["result"] == "success"
assert out["actor_display"] == "Alice (alice@example.com)"
assert out["target_displays"] == ["Bob"]
assert out["dedupe_key"] == "abc|UserManagement"
assert "raw_text" in out
def test_normalize_event_with_resolved_actor():
e = {
"id": "def",
"activityDateTime": "2024-01-15T11:00:00Z",
"category": "ApplicationManagement",
"activityDisplayName": "Add app",
"result": "success",
"initiatedBy": {"servicePrincipal": {"id": "sp1"}},
"targetResources": [],
"_resolvedActor": {"id": "sp1", "type": "servicePrincipal", "name": "MyApp"},
"_resolvedActorOwners": ["Owner1"],
}
out = normalize_event(e)
assert out["actor_display"] == "MyApp (owners: Owner1)"
assert out["display_category"] == "Application"