64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from collections import Counter
|
|
|
|
from govoplan_campaign.backend.router import router
|
|
from govoplan_campaign.backend.routes.attachments import router as attachments_router
|
|
from govoplan_campaign.backend.routes.campaigns import router as campaigns_router
|
|
from govoplan_campaign.backend.routes.delivery import router as delivery_router
|
|
from govoplan_campaign.backend.routes.jobs import router as jobs_router
|
|
from govoplan_campaign.backend.routes.reports import router as reports_router
|
|
from govoplan_campaign.backend.routes.sharing import router as sharing_router
|
|
from govoplan_campaign.backend.routes.versions import router as versions_router
|
|
|
|
|
|
def _operation_keys(candidate_router) -> list[tuple[str, str]]:
|
|
return [
|
|
(method, route.path)
|
|
for route in candidate_router.routes
|
|
for method in sorted(route.methods or ())
|
|
]
|
|
|
|
|
|
def test_campaign_router_composes_every_workflow_operation_once() -> None:
|
|
workflow_routers = (
|
|
campaigns_router,
|
|
versions_router,
|
|
jobs_router,
|
|
reports_router,
|
|
sharing_router,
|
|
delivery_router,
|
|
attachments_router,
|
|
)
|
|
expected = [
|
|
operation
|
|
for workflow_router in workflow_routers
|
|
for operation in _operation_keys(workflow_router)
|
|
]
|
|
actual = _operation_keys(router)
|
|
|
|
assert actual == expected
|
|
assert len(actual) == 62
|
|
assert not [operation for operation, count in Counter(actual).items() if count > 1]
|
|
|
|
|
|
def test_key_routes_are_owned_by_their_focused_router() -> None:
|
|
expectations = (
|
|
(campaigns_router, ("GET", "/campaigns/{campaign_id}/workspace")),
|
|
(versions_router, ("POST", "/campaigns/versions/{version_id}/build")),
|
|
(jobs_router, ("GET", "/campaigns/{campaign_id}/jobs")),
|
|
(reports_router, ("GET", "/campaigns/{campaign_id}/report")),
|
|
(sharing_router, ("POST", "/campaigns/{campaign_id}/shares")),
|
|
(delivery_router, ("POST", "/campaigns/{campaign_id}/send-now")),
|
|
(
|
|
attachments_router,
|
|
(
|
|
"POST",
|
|
"/campaigns/{campaign_id}/versions/{version_id}/attachments/preview",
|
|
),
|
|
),
|
|
)
|
|
|
|
for workflow_router, operation in expectations:
|
|
assert operation in _operation_keys(workflow_router)
|