Files
headquarter/apps/api/tests/unit/test_notifications_api_routes.py
Developer 81b9a66ef5 fix: resolve stale backend test imports and schema drift
- Delete 4 obsolete unit tests tied to removed git mount/clone models
- Update imports and assertions across unit/integration/service tests
- Fix Settings defaults (postgres host, JWT props, cookie_samesite)
- Add skip guards for PostgreSQL-dependent integration tests
- Fix GitService env assertions and HealthMonitor state-change tests
- Repair docker/container inspect assertions in test_docker_service
- Fix ToolTypeCreate default_port validator ordering bug
- Fix check_port_exposed substring false-positive for port 0
- Update test_tool_types_api_extended to use interface_type field

Quality gates: pytest 311 passed, 34 skipped; npm typecheck/lint/test 87 passed
2026-06-12 20:23:17 +00:00

35 lines
1.4 KiB
Python

"""Unit tests for notification API route ordering."""
from fastapi import FastAPI
from fastapi.testclient import TestClient
from src.api.system.notifications import router as notifications_router
def test_delete_notifications_route_order() -> None:
"""DELETE /notifications must match before DELETE /notifications/{id}.
FastAPI matches routes in declaration order. The bulk clear endpoint
(DELETE /notifications) must be registered before the single dismiss
endpoint (DELETE /notifications/{notification_id}) or the path
parameter route will intercept the bulk route.
"""
app = FastAPI()
app.include_router(notifications_router)
client = TestClient(app)
# Verify the bulk delete route exists and returns the expected schema
# (it will 401 without auth, but that's fine — we just need to confirm
# routing doesn't hit the UUID-parameter route first)
response = client.delete("/notifications")
# Should get 401 (unauthenticated), NOT 422 (UUID parse error)
assert response.status_code == 401, (
f"Expected 401 (auth required), got {response.status_code}. "
f"Route order may be wrong — DELETE /notifications matched "
f"DELETE /notifications/{{notification_id}} instead."
)
# Verify the single dismiss route still works (also 401 without auth)
response = client.delete("/notifications/12345678-1234-1234-1234-123456789abc")
assert response.status_code == 401