feat: add maintenance tree_type with db migration and tests
- Expand ck_trees_tree_type CHECK constraint to include 'maintenance' - Add 'maintenance' to TreeType Literal in schemas - Treat maintenance trees as procedural in can_publish_tree validation - Alembic migration 0f1ca2af3647 drops and recreates the constraint - Two integration tests: create and filter by tree_type=maintenance Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
52
backend/tests/test_maintenance_tree_type.py
Normal file
52
backend/tests/test_maintenance_tree_type.py
Normal file
@@ -0,0 +1,52 @@
|
||||
"""Tests for maintenance tree type."""
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_maintenance_tree(client: AsyncClient, auth_headers: dict):
|
||||
"""Maintenance tree type is accepted by the API."""
|
||||
resp = await client.post(
|
||||
"/api/v1/trees",
|
||||
json={
|
||||
"name": "Update FSLogix",
|
||||
"description": "Monthly FSLogix update procedure",
|
||||
"tree_type": "maintenance",
|
||||
"tree_structure": {
|
||||
"steps": [
|
||||
{"id": "step-1", "type": "procedure_step", "title": "Download installer",
|
||||
"description": "Get latest FSLogix from Microsoft", "content_type": "action"},
|
||||
{"id": "step-end", "type": "procedure_end", "title": "Complete"},
|
||||
]
|
||||
},
|
||||
},
|
||||
headers=auth_headers,
|
||||
)
|
||||
assert resp.status_code == 201, resp.text
|
||||
data = resp.json()
|
||||
assert data["tree_type"] == "maintenance"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_maintenance_trees_filter(client: AsyncClient, auth_headers: dict):
|
||||
"""Filtering by tree_type=maintenance returns only maintenance trees."""
|
||||
await client.post(
|
||||
"/api/v1/trees",
|
||||
json={
|
||||
"name": "Maintenance Only",
|
||||
"tree_type": "maintenance",
|
||||
"tree_structure": {
|
||||
"steps": [
|
||||
{"id": "s1", "type": "procedure_step", "title": "Step",
|
||||
"description": "Do it", "content_type": "action"},
|
||||
{"id": "end", "type": "procedure_end", "title": "Done"},
|
||||
]
|
||||
},
|
||||
},
|
||||
headers=auth_headers,
|
||||
)
|
||||
resp = await client.get("/api/v1/trees?tree_type=maintenance", headers=auth_headers)
|
||||
assert resp.status_code == 200
|
||||
trees = resp.json()
|
||||
assert all(t["tree_type"] == "maintenance" for t in trees)
|
||||
assert len(trees) >= 1
|
||||
Reference in New Issue
Block a user