1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Fix database

This commit is contained in:
MoonTestUse1
2025-01-07 05:55:57 +06:00
parent 3b55096e31
commit 4a9aafa810
3 changed files with 43 additions and 35 deletions

View File

@@ -1,18 +1,16 @@
fastapi==0.110.0
uvicorn==0.27.1
sqlalchemy==2.0.27
pydantic==2.5.2
pydantic-settings==2.2.1
python-multipart==0.0.9
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
bcrypt==3.2.2
redis>=4.0.0
python-dotenv==1.0.1
psycopg2-binary==2.9.9
alembic==1.13.1
pytest==8.0.0
httpx==0.26.0
requests>=2.26.0
aiogram==3.4.1
fakeredis>=2.20.0
fastapi>=0.100.0
uvicorn>=0.22.0
sqlalchemy>=2.0.0
psycopg2-binary>=2.9.6
python-jose[cryptography]>=3.3.0
passlib[bcrypt]>=1.7.4
python-multipart>=0.0.6
pydantic>=2.0.0
pydantic-settings>=2.0.0
pytest>=7.4.0
pytest-cov>=4.1.0
pytest-timeout>=2.1.0
pytest-xdist>=3.3.1
httpx>=0.24.1
redis>=4.6.0
python-telegram-bot>=20.4

View File

@@ -3,7 +3,9 @@ import pytest
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
def test_login_success(client: TestClient, test_employee: dict):
from app.models.employee import Employee
def test_login_success(client: TestClient, test_employee: Employee):
"""Test successful login"""
response = client.post(
"/api/auth/login",
@@ -13,10 +15,11 @@ def test_login_success(client: TestClient, test_employee: dict):
}
)
assert response.status_code == 200
assert "access_token" in response.json()
assert response.json()["token_type"] == "bearer"
data = response.json()
assert "access_token" in data
assert data["token_type"] == "bearer"
def test_login_wrong_password(client: TestClient, test_employee: dict):
def test_login_wrong_password(client: TestClient, test_employee: Employee):
"""Test login with wrong password"""
response = client.post(
"/api/auth/login",
@@ -49,10 +52,10 @@ def test_login_invalid_username_format(client: TestClient):
"password": "testpass123"
}
)
assert response.status_code == 401
assert response.json()["detail"] == "Username should be in format: 'First Last'"
assert response.status_code == 400
assert response.json()["detail"] == "Username must be in format: 'First Last'"
def test_admin_login_success(client: TestClient, test_admin: dict):
def test_admin_login_success(client: TestClient, test_admin: Employee):
"""Test successful admin login"""
response = client.post(
"/api/auth/admin/login",
@@ -62,10 +65,11 @@ def test_admin_login_success(client: TestClient, test_admin: dict):
}
)
assert response.status_code == 200
assert "access_token" in response.json()
assert response.json()["token_type"] == "bearer"
data = response.json()
assert "access_token" in data
assert data["token_type"] == "bearer"
def test_admin_login_not_admin(client: TestClient, test_employee: dict):
def test_admin_login_not_admin(client: TestClient, test_employee: Employee):
"""Test admin login with non-admin user"""
response = client.post(
"/api/auth/admin/login",
@@ -74,14 +78,14 @@ def test_admin_login_not_admin(client: TestClient, test_employee: dict):
"password": "testpass123"
}
)
assert response.status_code == 401
assert response.json()["detail"] == "Incorrect username or password"
assert response.status_code == 403
assert response.json()["detail"] == "User is not an admin"
def test_protected_route_with_invalid_token(client: TestClient):
"""Test accessing protected route with invalid token"""
"""Test protected route with invalid token"""
response = client.get(
"/api/employees/me",
headers={"Authorization": "Bearer invalid_token"}
)
assert response.status_code == 401
assert response.json()["detail"] == "Invalid authentication credentials"
assert response.json()["detail"] == "Could not validate credentials"