mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Все подряд
This commit is contained in:
47
backend/tests/test_auth.py
Normal file
47
backend/tests/test_auth.py
Normal file
@@ -0,0 +1,47 @@
|
||||
"""Authentication endpoint tests"""
|
||||
import pytest
|
||||
from app.crud import employees
|
||||
from app.models.employee import EmployeeCreate
|
||||
|
||||
def test_login_success(client, test_db, test_employee):
|
||||
"""Test successful login"""
|
||||
# Create test employee
|
||||
employee_data = EmployeeCreate(**test_employee)
|
||||
employees.create_employee(test_db, employee_data)
|
||||
|
||||
# Attempt login
|
||||
response = client.post(
|
||||
"/api/auth/login",
|
||||
json={
|
||||
"lastName": test_employee["last_name"],
|
||||
"password": test_employee["password"]
|
||||
}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["lastName"] == test_employee["last_name"]
|
||||
assert "password" not in data
|
||||
|
||||
def test_login_invalid_credentials(client):
|
||||
"""Test login with invalid credentials"""
|
||||
response = client.post(
|
||||
"/api/auth/login",
|
||||
json={
|
||||
"lastName": "NonExistent",
|
||||
"password": "wrongpass"
|
||||
}
|
||||
)
|
||||
|
||||
assert response.status_code == 401
|
||||
assert response.json()["detail"] == "Неверные учетные данные"
|
||||
|
||||
def test_login_missing_fields(client):
|
||||
"""Test login with missing fields"""
|
||||
response = client.post(
|
||||
"/api/auth/login",
|
||||
json={"lastName": "Test"}
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert "Необходимо указать" in response.json()["detail"]
|
||||
Reference in New Issue
Block a user