mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Все подряд
This commit is contained in:
68
backend/tests/test_employees.py
Normal file
68
backend/tests/test_employees.py
Normal file
@@ -0,0 +1,68 @@
|
||||
"""Employee management endpoint tests"""
|
||||
import pytest
|
||||
from app.models.employee import EmployeeCreate
|
||||
|
||||
def test_create_employee(client, test_employee):
|
||||
"""Test employee creation"""
|
||||
response = client.post(
|
||||
"/api/employees",
|
||||
json={
|
||||
"first_name": test_employee["first_name"],
|
||||
"last_name": test_employee["last_name"],
|
||||
"department": test_employee["department"],
|
||||
"office": test_employee["office"],
|
||||
"password": test_employee["password"]
|
||||
}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["firstName"] == test_employee["first_name"]
|
||||
assert data["lastName"] == test_employee["last_name"]
|
||||
assert "password" not in data
|
||||
|
||||
def test_create_employee_duplicate(client, test_employee):
|
||||
"""Test creating duplicate employee"""
|
||||
# Create first employee
|
||||
client.post(
|
||||
"/api/employees",
|
||||
json={
|
||||
"first_name": test_employee["first_name"],
|
||||
"last_name": test_employee["last_name"],
|
||||
"department": test_employee["department"],
|
||||
"office": test_employee["office"],
|
||||
"password": test_employee["password"]
|
||||
}
|
||||
)
|
||||
|
||||
# Try to create duplicate
|
||||
response = client.post(
|
||||
"/api/employees",
|
||||
json={
|
||||
"first_name": test_employee["first_name"],
|
||||
"last_name": test_employee["last_name"],
|
||||
"department": test_employee["department"],
|
||||
"office": test_employee["office"],
|
||||
"password": test_employee["password"]
|
||||
}
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
assert "уже существует" in response.json()["detail"]
|
||||
|
||||
def test_create_employee_invalid_data(client):
|
||||
"""Test creating employee with invalid data"""
|
||||
invalid_employee = {
|
||||
"first_name": "", # Empty name
|
||||
"last_name": "Test",
|
||||
"department": "invalid", # Invalid department
|
||||
"office": "101",
|
||||
"password": "test"
|
||||
}
|
||||
|
||||
response = client.post(
|
||||
"/api/employees",
|
||||
json=invalid_employee
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
Reference in New Issue
Block a user