semantics
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# [DEF:TestDashboardsApi:Module]
|
||||
# @RELATION: VERIFIES ->[src.api.routes.dashboards]
|
||||
# #region TestDashboardsApi [C:2] [TYPE Module]
|
||||
# @RELATION BINDS_TO ->[DashboardsApi]
|
||||
# @PURPOSE: Comprehensive contract-driven tests for Dashboard Hub API
|
||||
# @LAYER: Domain (Tests)
|
||||
# @LAYER Tests
|
||||
# @SEMANTICS: tests, dashboards, api, contract, remediation
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
@@ -74,8 +74,8 @@ client = TestClient(app)
|
||||
# --- 1. get_dashboards tests ---
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_success(mock_deps):
|
||||
"""Uses @TEST_FIXTURE: dashboard_list_happy data."""
|
||||
mock_env = MagicMock()
|
||||
@@ -113,11 +113,11 @@ def test_get_dashboards_success(mock_deps):
|
||||
DashboardsResponse(**data)
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboards_success:Function]
|
||||
# #endregion test_get_dashboards_success
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_with_search:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_with_search [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_with_search(mock_deps):
|
||||
mock_env = MagicMock()
|
||||
mock_env.id = "prod"
|
||||
@@ -137,11 +137,11 @@ def test_get_dashboards_with_search(mock_deps):
|
||||
assert data["dashboards"][0]["title"] == "Sales Report"
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboards_with_search:Function]
|
||||
# #endregion test_get_dashboards_with_search
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_empty:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_empty [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_empty(mock_deps):
|
||||
"""@TEST_EDGE: empty_dashboards -> {env_id: 'empty_env', expected_total: 0}"""
|
||||
mock_env = MagicMock()
|
||||
@@ -159,11 +159,11 @@ def test_get_dashboards_empty(mock_deps):
|
||||
DashboardsResponse(**data)
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboards_empty:Function]
|
||||
# #endregion test_get_dashboards_empty
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_superset_failure:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_superset_failure [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_superset_failure(mock_deps):
|
||||
"""@TEST_EDGE: external_superset_failure -> {env_id: 'bad_conn', status: 503}"""
|
||||
mock_env = MagicMock()
|
||||
@@ -179,11 +179,11 @@ def test_get_dashboards_superset_failure(mock_deps):
|
||||
assert "Failed to fetch dashboards" in response.json()["detail"]
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboards_superset_failure:Function]
|
||||
# #endregion test_get_dashboards_superset_failure
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_env_not_found(mock_deps):
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
response = client.get("/api/dashboards?env_id=nonexistent")
|
||||
@@ -191,11 +191,11 @@ def test_get_dashboards_env_not_found(mock_deps):
|
||||
assert "Environment not found" in response.json()["detail"]
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboards_env_not_found:Function]
|
||||
# #endregion test_get_dashboards_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_get_dashboards_invalid_pagination:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboards_invalid_pagination [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboards_invalid_pagination(mock_deps):
|
||||
mock_env = MagicMock()
|
||||
mock_env.id = "prod"
|
||||
@@ -214,11 +214,11 @@ def test_get_dashboards_invalid_pagination(mock_deps):
|
||||
|
||||
# --- 2. get_database_mappings tests ---
|
||||
|
||||
# [/DEF:test_get_dashboards_invalid_pagination:Function]
|
||||
# #endregion test_get_dashboards_invalid_pagination
|
||||
|
||||
|
||||
# [DEF:test_get_database_mappings_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_database_mappings_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_database_mappings_success(mock_deps):
|
||||
mock_s = MagicMock()
|
||||
mock_s.id = "s"
|
||||
@@ -237,11 +237,11 @@ def test_get_database_mappings_success(mock_deps):
|
||||
DatabaseMappingsResponse(**data)
|
||||
|
||||
|
||||
# [/DEF:test_get_database_mappings_success:Function]
|
||||
# #endregion test_get_database_mappings_success
|
||||
|
||||
|
||||
# [DEF:test_get_database_mappings_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_database_mappings_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_database_mappings_env_not_found(mock_deps):
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
response = client.get(
|
||||
@@ -252,11 +252,11 @@ def test_get_database_mappings_env_not_found(mock_deps):
|
||||
|
||||
# --- 3. get_dashboard_detail tests ---
|
||||
|
||||
# [/DEF:test_get_database_mappings_env_not_found:Function]
|
||||
# #endregion test_get_database_mappings_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_detail_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_detail_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_detail_success(mock_deps):
|
||||
with patch("src.api.routes.dashboards.SupersetClient") as mock_client_cls:
|
||||
mock_env = MagicMock()
|
||||
@@ -282,11 +282,11 @@ def test_get_dashboard_detail_success(mock_deps):
|
||||
DashboardDetailResponse(**data)
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboard_detail_success:Function]
|
||||
# #endregion test_get_dashboard_detail_success
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_detail_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_detail_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_detail_env_not_found(mock_deps):
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
response = client.get("/api/dashboards/42?env_id=missing")
|
||||
@@ -295,11 +295,11 @@ def test_get_dashboard_detail_env_not_found(mock_deps):
|
||||
|
||||
# --- 4. get_dashboard_tasks_history tests ---
|
||||
|
||||
# [/DEF:test_get_dashboard_detail_env_not_found:Function]
|
||||
# #endregion test_get_dashboard_detail_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_tasks_history_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_tasks_history_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_tasks_history_success(mock_deps):
|
||||
now = datetime.now(UTC)
|
||||
task1 = MagicMock(
|
||||
@@ -321,11 +321,11 @@ def test_get_dashboard_tasks_history_success(mock_deps):
|
||||
DashboardTaskHistoryResponse(**data)
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboard_tasks_history_success:Function]
|
||||
# #endregion test_get_dashboard_tasks_history_success
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_tasks_history_sorting:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_tasks_history_sorting [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_tasks_history_sorting(mock_deps):
|
||||
"""@POST: Response contains sorted task history (newest first)."""
|
||||
from datetime import timedelta
|
||||
@@ -367,11 +367,11 @@ def test_get_dashboard_tasks_history_sorting(mock_deps):
|
||||
|
||||
# --- 5. get_dashboard_thumbnail tests ---
|
||||
|
||||
# [/DEF:test_get_dashboard_tasks_history_sorting:Function]
|
||||
# #endregion test_get_dashboard_tasks_history_sorting
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_thumbnail_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_thumbnail_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_thumbnail_success(mock_deps):
|
||||
with patch("src.api.routes.dashboards.SupersetClient") as mock_client_cls:
|
||||
mock_env = MagicMock()
|
||||
@@ -393,22 +393,22 @@ def test_get_dashboard_thumbnail_success(mock_deps):
|
||||
assert response.content == b"img"
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboard_thumbnail_success:Function]
|
||||
# #endregion test_get_dashboard_thumbnail_success
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_thumbnail_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_thumbnail_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_thumbnail_env_not_found(mock_deps):
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
response = client.get("/api/dashboards/42/thumbnail?env_id=missing")
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
# [/DEF:test_get_dashboard_thumbnail_env_not_found:Function]
|
||||
# #endregion test_get_dashboard_thumbnail_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_get_dashboard_thumbnail_202:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_get_dashboard_thumbnail_202 [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_get_dashboard_thumbnail_202(mock_deps):
|
||||
"""@POST: Returns 202 when thumbnail is being prepared by Superset."""
|
||||
with patch("src.api.routes.dashboards.SupersetClient") as mock_client_cls:
|
||||
@@ -435,11 +435,11 @@ def test_get_dashboard_thumbnail_202(mock_deps):
|
||||
|
||||
# --- 6. migrate_dashboards tests ---
|
||||
|
||||
# [/DEF:test_get_dashboard_thumbnail_202:Function]
|
||||
# #endregion test_get_dashboard_thumbnail_202
|
||||
|
||||
|
||||
# [DEF:test_migrate_dashboards_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_migrate_dashboards_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_migrate_dashboards_success(mock_deps):
|
||||
mock_s = MagicMock()
|
||||
mock_s.id = "s"
|
||||
@@ -456,11 +456,11 @@ def test_migrate_dashboards_success(mock_deps):
|
||||
assert response.json()["task_id"] == "task-123"
|
||||
|
||||
|
||||
# [/DEF:test_migrate_dashboards_success:Function]
|
||||
# #endregion test_migrate_dashboards_success
|
||||
|
||||
|
||||
# [DEF:test_migrate_dashboards_pre_checks:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_migrate_dashboards_pre_checks [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_migrate_dashboards_pre_checks(mock_deps):
|
||||
# Missing IDs
|
||||
response = client.post(
|
||||
@@ -471,11 +471,11 @@ def test_migrate_dashboards_pre_checks(mock_deps):
|
||||
assert "At least one dashboard ID must be provided" in response.json()["detail"]
|
||||
|
||||
|
||||
# [/DEF:test_migrate_dashboards_pre_checks:Function]
|
||||
# #endregion test_migrate_dashboards_pre_checks
|
||||
|
||||
|
||||
# [DEF:test_migrate_dashboards_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_migrate_dashboards_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_migrate_dashboards_env_not_found(mock_deps):
|
||||
"""@PRE: source_env_id and target_env_id are valid environment IDs."""
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
@@ -489,11 +489,11 @@ def test_migrate_dashboards_env_not_found(mock_deps):
|
||||
|
||||
# --- 7. backup_dashboards tests ---
|
||||
|
||||
# [/DEF:test_migrate_dashboards_env_not_found:Function]
|
||||
# #endregion test_migrate_dashboards_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_backup_dashboards_success:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_backup_dashboards_success [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_backup_dashboards_success(mock_deps):
|
||||
mock_env = MagicMock()
|
||||
mock_env.id = "prod"
|
||||
@@ -507,11 +507,11 @@ def test_backup_dashboards_success(mock_deps):
|
||||
assert response.json()["task_id"] == "backup-123"
|
||||
|
||||
|
||||
# [/DEF:test_backup_dashboards_success:Function]
|
||||
# #endregion test_backup_dashboards_success
|
||||
|
||||
|
||||
# [DEF:test_backup_dashboards_pre_checks:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_backup_dashboards_pre_checks [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_backup_dashboards_pre_checks(mock_deps):
|
||||
response = client.post(
|
||||
"/api/dashboards/backup", json={"env_id": "prod", "dashboard_ids": []}
|
||||
@@ -519,11 +519,11 @@ def test_backup_dashboards_pre_checks(mock_deps):
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
# [/DEF:test_backup_dashboards_pre_checks:Function]
|
||||
# #endregion test_backup_dashboards_pre_checks
|
||||
|
||||
|
||||
# [DEF:test_backup_dashboards_env_not_found:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_backup_dashboards_env_not_found [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_backup_dashboards_env_not_found(mock_deps):
|
||||
"""@PRE: env_id is a valid environment ID."""
|
||||
mock_deps["config"].get_environments.return_value = []
|
||||
@@ -534,11 +534,11 @@ def test_backup_dashboards_env_not_found(mock_deps):
|
||||
assert "Environment not found" in response.json()["detail"]
|
||||
|
||||
|
||||
# [/DEF:test_backup_dashboards_env_not_found:Function]
|
||||
# #endregion test_backup_dashboards_env_not_found
|
||||
|
||||
|
||||
# [DEF:test_backup_dashboards_with_schedule:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_backup_dashboards_with_schedule [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_backup_dashboards_with_schedule(mock_deps):
|
||||
"""@POST: If schedule is provided, a scheduled task is created."""
|
||||
mock_env = MagicMock()
|
||||
@@ -560,13 +560,13 @@ def test_backup_dashboards_with_schedule(mock_deps):
|
||||
|
||||
|
||||
# --- 8. Internal logic: _task_matches_dashboard ---
|
||||
# [/DEF:test_backup_dashboards_with_schedule:Function]
|
||||
# #endregion test_backup_dashboards_with_schedule
|
||||
|
||||
from src.api.routes.dashboards._projection import _task_matches_dashboard
|
||||
|
||||
|
||||
# [DEF:test_task_matches_dashboard_logic:Function]
|
||||
# @RELATION: BINDS_TO ->[TestDashboardsApi]
|
||||
# #region test_task_matches_dashboard_logic [C:2] [TYPE Function]
|
||||
# @RELATION BINDS_TO ->[TestDashboardsApi]
|
||||
def test_task_matches_dashboard_logic():
|
||||
task = MagicMock(
|
||||
plugin_id="superset-backup", params={"dashboards": [42], "env": "prod"}
|
||||
@@ -583,5 +583,5 @@ def test_task_matches_dashboard_logic():
|
||||
assert _task_matches_dashboard(llm_task, 42, None) is True
|
||||
|
||||
|
||||
# [/DEF:test_task_matches_dashboard_logic:Function]
|
||||
# [/DEF:TestDashboardsApi:Module]
|
||||
# #endregion test_task_matches_dashboard_logic
|
||||
# #endregion TestDashboardsApi
|
||||
|
||||
Reference in New Issue
Block a user