Spaces:
Paused
Paused
File size: 2,105 Bytes
b7980f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_auth_login_customer(client: AsyncClient):
"""Test standard customer login."""
response = await client.post(
"/api/v1/auth/login",
data={"username": "customer@a.com", "password": "password123"}
)
assert response.status_code == 200
assert "access_token" in response.json()
@pytest.mark.asyncio
async def test_auth_login_staff_with_portal(client: AsyncClient):
"""Test staff login specifically with the X-Nexus-Portal header."""
response = await client.post(
"/api/v1/auth/login",
data={"username": "admin@a.com", "password": "password123"},
headers={"X-Nexus-Portal": "internal"}
)
assert response.status_code == 200
assert "access_token" in response.json()
@pytest.mark.asyncio
async def test_ticket_lifecycle(client: AsyncClient, token_a: str):
"""Test creating and listing a ticket in Workspace A."""
headers = {"Authorization": f"Bearer {token_a}"}
# 1. Create
payload = {
"title": "Automated Test Ticket",
"description": "Functional Test",
"priority": "P2",
"category": "Setup"
}
response = await client.post("/api/v1/tickets/", json=payload, headers=headers)
assert response.status_code == 201
ticket_id = response.json()["id"]
# 2. List
list_response = await client.get("/api/v1/tickets/", headers=headers)
assert list_response.status_code == 200
assert any(t["id"] == ticket_id for t in list_response.json())
@pytest.mark.asyncio
async def test_dashboard_stats_isolation_default(client: AsyncClient, admin_token_a: str):
"""Test that dashboard stats are restricted to the admin's workspace."""
headers = {
"Authorization": f"Bearer {admin_token_a}",
"X-Nexus-Portal": "internal"
}
response = await client.get("/api/v1/dashboard/stats", headers=headers)
assert response.status_code == 200
data = response.json()
assert "total_tickets" in data
# Verifies that it didn't crash or return global leak.
|