release: v1.10.0 — модуль команд (teams), team_id на алертах
- Alembic 006: teams, team_label_rules, irm_alerts.team_id - Вебхук: сопоставление команды по правилам лейблов (priority) - API/UI Команды; алерты: JOIN team, фильтр team_id - Тесты test_team_match, test_teams_api; обновлён test_root_ui Made-with: Cursor
This commit is contained in:
@ -9,6 +9,7 @@ def _webhook_mock_pool(mock_conn: AsyncMock) -> MagicMock:
|
||||
tx.__aenter__ = AsyncMock(return_value=None)
|
||||
tx.__aexit__ = AsyncMock(return_value=None)
|
||||
mock_conn.transaction = MagicMock(return_value=tx)
|
||||
mock_conn.fetch = AsyncMock(return_value=[])
|
||||
mock_conn.execute = AsyncMock()
|
||||
mock_cm = AsyncMock()
|
||||
mock_cm.__aenter__ = AsyncMock(return_value=mock_conn)
|
||||
|
||||
@ -34,6 +34,7 @@ def test_rail_lists_all_registered_ui_modules(client: TestClient) -> None:
|
||||
expected = (
|
||||
("grafana-catalog", "Каталог Grafana"),
|
||||
("alerts", "Алерты"),
|
||||
("teams", "Команды"),
|
||||
("incidents", "Инциденты"),
|
||||
("tasks", "Задачи"),
|
||||
("escalations", "Эскалации"),
|
||||
@ -51,6 +52,7 @@ def test_each_module_page_single_active_nav_item(client: TestClient) -> None:
|
||||
for slug in (
|
||||
"grafana-catalog",
|
||||
"alerts",
|
||||
"teams",
|
||||
"incidents",
|
||||
"tasks",
|
||||
"escalations",
|
||||
|
||||
38
tests/test_team_match.py
Normal file
38
tests/test_team_match.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""Сопоставление лейблов с командой (без БД)."""
|
||||
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from onguard24.ingress.team_match import match_team_for_labels
|
||||
|
||||
|
||||
def test_match_returns_none_when_empty() -> None:
|
||||
assert match_team_for_labels({}, []) is None
|
||||
assert match_team_for_labels({"a": "b"}, []) is None
|
||||
|
||||
|
||||
def test_match_first_rule_wins_in_order() -> None:
|
||||
u_infra = uuid4()
|
||||
u_other = uuid4()
|
||||
labels = {"team": "infra", "env": "prod"}
|
||||
rules: list[tuple[UUID, str, str]] = [
|
||||
(u_infra, "team", "infra"),
|
||||
(u_other, "env", "prod"),
|
||||
]
|
||||
assert match_team_for_labels(labels, rules) == u_infra
|
||||
|
||||
|
||||
def test_match_skips_until_value_matches() -> None:
|
||||
u = uuid4()
|
||||
labels = {"x": "1"}
|
||||
rules: list[tuple[UUID, str, str]] = [
|
||||
(uuid4(), "x", "2"),
|
||||
(u, "x", "1"),
|
||||
]
|
||||
assert match_team_for_labels(labels, rules) == u
|
||||
|
||||
|
||||
def test_match_coerces_label_values_to_str() -> None:
|
||||
u = uuid4()
|
||||
labels = {"port": 8080}
|
||||
rules: list[tuple[UUID, str, str]] = [(u, "port", "8080")]
|
||||
assert match_team_for_labels(labels, rules) == u
|
||||
9
tests/test_teams_api.py
Normal file
9
tests/test_teams_api.py
Normal file
@ -0,0 +1,9 @@
|
||||
"""API модуля команд без БД."""
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_teams_list_no_db(client: TestClient) -> None:
|
||||
r = client.get("/api/v1/modules/teams/")
|
||||
assert r.status_code == 200
|
||||
assert r.json() == {"items": [], "database": "disabled"}
|
||||
Reference in New Issue
Block a user