71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
# #region Test.Maintenance.StartRequestTargeting [C:2] [TYPE Module] [SEMANTICS test,maintenance,schema,targeting,validation]
|
|
# @BRIEF Validation contract for MaintenanceStartRequest targeting: exactly one target required and
|
|
# dashboard targeting demands an explicit environment.
|
|
# @RELATION BINDS_TO -> [Api.Schemas.MaintenanceStartRequest]
|
|
# @TEST_CONTRACT: neither tables nor dashboard_ids -> 422 validation error
|
|
# @TEST_CONTRACT: dashboard_ids without environment_id -> 422
|
|
# @TEST_CONTRACT: dashboard_ids with environment_id is valid and tables may be empty
|
|
# @TEST_CONTRACT: table-driven requests remain valid (backward compatible)
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from src.api.routes.maintenance._schemas import MaintenanceStartRequest
|
|
|
|
|
|
def test_no_target_is_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MaintenanceStartRequest(start_time="2026-01-01T00:00:00+00:00")
|
|
|
|
|
|
def test_blank_tables_without_dashboards_is_rejected():
|
|
with pytest.raises(ValidationError):
|
|
MaintenanceStartRequest(tables=[" "], start_time="2026-01-01T00:00:00+00:00")
|
|
|
|
|
|
def test_dashboard_ids_require_environment():
|
|
with pytest.raises(ValidationError):
|
|
MaintenanceStartRequest(
|
|
dashboard_ids=[1, 2],
|
|
start_time="2026-01-01T00:00:00+00:00",
|
|
)
|
|
|
|
|
|
def test_dashboard_targeting_valid_with_environment():
|
|
request = MaintenanceStartRequest(
|
|
dashboard_ids=[1, 2],
|
|
environment_id="env-1",
|
|
start_time="2026-01-01T00:00:00+00:00",
|
|
banner_template="<div>{message}</div>",
|
|
banner_height=25,
|
|
)
|
|
assert request.dashboard_ids == [1, 2]
|
|
assert request.tables == []
|
|
assert request.banner_height == 25
|
|
|
|
|
|
def test_table_targeting_still_valid():
|
|
request = MaintenanceStartRequest(
|
|
tables=["raw.sales"],
|
|
start_time="2026-01-01T00:00:00+00:00",
|
|
)
|
|
assert request.tables == ["raw.sales"]
|
|
assert request.dashboard_ids is None
|
|
|
|
|
|
def test_banner_height_bounds():
|
|
with pytest.raises(ValidationError):
|
|
MaintenanceStartRequest(
|
|
tables=["raw.sales"],
|
|
start_time="2026-01-01T00:00:00+00:00",
|
|
banner_height=0,
|
|
)
|
|
with pytest.raises(ValidationError):
|
|
MaintenanceStartRequest(
|
|
tables=["raw.sales"],
|
|
start_time="2026-01-01T00:00:00+00:00",
|
|
banner_height=201,
|
|
)
|
|
|
|
|
|
# #endregion Test.Maintenance.StartRequestTargeting
|