Files
inventory/backend/tests/test_auth.py
2026-07-21 16:11:09 +05:00

24 lines
798 B
Python

from httpx import AsyncClient
from app.models.user import User
async def test_login_success(client: AsyncClient, admin_user: User) -> None:
res = await client.post(
"/api/v1/auth/token", data={"username": admin_user.username, "password": "adminpass123"}
)
assert res.status_code == 200
assert res.json()["token_type"] == "bearer"
async def test_login_wrong_password(client: AsyncClient, admin_user: User) -> None:
res = await client.post(
"/api/v1/auth/token", data={"username": admin_user.username, "password": "wrong"}
)
assert res.status_code == 401
async def test_mutation_requires_auth(client: AsyncClient) -> None:
res = await client.post("/api/v1/objects", json={"inventory_number": "X", "name": "X"})
assert res.status_code == 401