start
This commit is contained in:
23
backend/tests/test_auth.py
Normal file
23
backend/tests/test_auth.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user