File size: 1,662 Bytes
0e76632 | 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 | """Tests for /usage endpoints."""
import pytest
@pytest.mark.asyncio
async def test_my_usage(client, auth_headers):
resp = await client.get("/api/v1/usage/me", headers=auth_headers)
assert resp.status_code == 200
data = resp.json()
assert "usage" in data
assert "quota" in data
assert data["roll_number"] == "21CS045"
@pytest.mark.asyncio
async def test_my_history(client, auth_headers):
resp = await client.get("/api/v1/usage/me/history", headers=auth_headers)
assert resp.status_code == 200
data = resp.json()
assert "requests" in data
assert "total" in data
@pytest.mark.asyncio
async def test_my_quota(client, auth_headers):
resp = await client.get("/api/v1/usage/me/quota", headers=auth_headers)
assert resp.status_code == 200
data = resp.json()
assert data["role"] == "student"
assert "limits" in data
assert "current" in data
@pytest.mark.asyncio
async def test_admin_all_requires_admin(client, auth_headers):
# Student should get 403
resp = await client.get("/api/v1/usage/admin/all", headers=auth_headers)
assert resp.status_code == 403
@pytest.mark.asyncio
async def test_admin_all_usage(client, admin_headers):
resp = await client.get("/api/v1/usage/admin/all", headers=admin_headers)
assert resp.status_code == 200
data = resp.json()
assert "users" in data
@pytest.mark.asyncio
async def test_admin_models_usage(client, admin_headers):
resp = await client.get("/api/v1/usage/admin/models", headers=admin_headers)
assert resp.status_code == 200
assert "models" in resp.json()
|