generating openapi from backend and adding ci pipeline
This commit is contained in:
30
backend/tests/test_auth.py
Normal file
30
backend/tests/test_auth.py
Normal file
@ -0,0 +1,30 @@
|
||||
# tests/test_auth.py
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_login_success():
|
||||
response = client.post("/auth/token/login", data={"username": "testuser", "password": "testpass"})
|
||||
assert response.status_code == 200
|
||||
assert "access_token" in response.json()
|
||||
|
||||
|
||||
def test_login_failure():
|
||||
response = client.post("/auth/token/login", data={"username": "wrong", "password": "wrongpass"})
|
||||
assert response.status_code == 401
|
||||
assert response.json() == {"detail": "Incorrect username or password"}
|
||||
|
||||
|
||||
def test_protected_route():
|
||||
# Step 1: Login
|
||||
response = client.post("/auth/token/login", data={"username": "testuser", "password": "testpass"})
|
||||
token = response.json()["access_token"]
|
||||
|
||||
# Step 2: Access protected route
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = client.get("/auth/protected-route", headers=headers)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"username": "testuser", "pgroups": [20000, 20001, 20003]}
|
Reference in New Issue
Block a user