Spaces:
Paused

miracle / tests /test_escalations.py
dushyantsingh0
backend stabilization
4405ca9
Raw History Blame Contribute Delete
1.9 kB
import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_create_escalation_rule_invalid_workspace(client: AsyncClient, admin_token_a: str):
"""
Test that creating an escalation rule with a non-existent workspace_id
returns a 404 instead of a 500 IntegrityError.
"""
headers = {
"Authorization": f"Bearer {admin_token_a}",
"X-Nexus-Portal": "internal"
}
# Common placeholder UUID that doesn't exist in seeded test DB
invalid_ws_id = "3fa85f64-5717-4562-b3fc-2c963f66afa6"
payload = {
"name": "Invalid Workspace Rule",
"priority_level": "P1",
"threshold_minutes": 30,
"is_active": True,
"workspace_id": invalid_ws_id
}
response = await client.post("/api/v1/escalations/rules", json=payload, headers=headers)
# Before fix, this returns 500 due to IntegrityError
# After fix, it should return 404 or 400
assert response.status_code == 404
assert "Workspace not found" in response.json()["detail"]
@pytest.mark.asyncio
async def test_create_escalation_rule_success(client: AsyncClient, admin_token_a: str, workspace_b_id: str):
"""
Test that creating an escalation rule with a valid workspace_id (Workspace B)
by an Admin works correctly.
"""
headers = {
"Authorization": f"Bearer {admin_token_a}",
"X-Nexus-Portal": "internal"
}
payload = {
"name": "Valid Workspace B Rule",
"priority_level": "P2",
"threshold_minutes": 60,
"is_active": True,
"workspace_id": workspace_b_id
}
response = await client.post("/api/v1/escalations/rules", json=payload, headers=headers)
assert response.status_code == 201
data = response.json()
assert data["name"] == "Valid Workspace B Rule"
assert data["workspace_id"] == workspace_b_id