Files
opsxsql/backend/tests/test_dashboard.py
T
loganandClaude Opus 4.7 c0c731acfc feat: TDD Phase 1 — 44 backend API tests passing
Test infrastructure:
- conftest.py with SQLite in-memory DB, isolated per-test cleanup
- pytest.ini with asyncio auto mode
- Fixtures: admin/dba/developer/guest/disabled users, tokens, test instance

Test coverage (44 tests):
- test_auth: login/logout/me/token expiry (8 tests)
- test_users: CRUD + role permissions (8 tests)
- test_instances: CRUD + connection test mock (8 tests)
- test_tickets: CRUD + review/execute workflow + pagination (11 tests)
- test_query: select/drop/delete rejection + guest deny (4 tests)
- test_dashboard: stats + auth check (2 tests)

Backend fix:
- query endpoint now catches ValueError from QueryService → 400 instead of 500

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-22 11:34:47 +08:00

18 lines
605 B
Python

from httpx import AsyncClient
from tests.conftest import auth_header
class TestDashboard:
async def test_get_stats(self, client: AsyncClient, admin_token):
resp = await client.get("/api/v1/dashboard/stats", headers=auth_header(admin_token))
assert resp.status_code == 200
data = resp.json()
assert "ticket_total" in data
assert "instance_total" in data
assert "user_total" in data
async def test_unauthenticated(self, client: AsyncClient):
resp = await client.get("/api/v1/dashboard/stats")
assert resp.status_code in (401, 403)