282 lines
8.9 KiB
Python
282 lines
8.9 KiB
Python
"""Test reference data endpoints."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
|
|
|
|
class TestRoles:
|
|
"""Test role endpoints."""
|
|
|
|
def test_get_roles(self, client: TestClient, auth_headers: dict):
|
|
"""Test getting roles list."""
|
|
response = client.get("/api/v1/reference/roles", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert isinstance(data, list)
|
|
|
|
def test_create_role(self, client: TestClient, auth_headers: dict):
|
|
"""Test creating a new role."""
|
|
response = client.post(
|
|
"/api/v1/reference/roles",
|
|
json={
|
|
"name": "test_role",
|
|
"description": "Test role description"
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "test_role"
|
|
assert data["description"] == "Test role description"
|
|
|
|
def test_create_duplicate_role(self, client: TestClient, auth_headers: dict, sample_role):
|
|
"""Test creating role with existing name."""
|
|
response = client.post(
|
|
"/api/v1/reference/roles",
|
|
json={
|
|
"name": sample_role.name,
|
|
"description": "Duplicate role"
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 409
|
|
|
|
def test_update_role(self, client: TestClient, auth_headers: dict, sample_role):
|
|
"""Test updating a role."""
|
|
response = client.put(
|
|
f"/api/v1/reference/roles/{sample_role.id}",
|
|
json={
|
|
"name": "updated_role",
|
|
"description": "Updated description"
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "updated_role"
|
|
|
|
def test_delete_role(self, client: TestClient, auth_headers: dict, sample_role):
|
|
"""Test deleting a role."""
|
|
response = client.delete(
|
|
f"/api/v1/reference/roles/{sample_role.id}",
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 204
|
|
|
|
|
|
class TestStatuses:
|
|
"""Test status endpoints."""
|
|
|
|
def test_get_statuses(self, client: TestClient, auth_headers: dict):
|
|
"""Test getting statuses list."""
|
|
response = client.get("/api/v1/reference/statuses", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert isinstance(data, list)
|
|
|
|
def test_create_status(self, client: TestClient, auth_headers: dict):
|
|
"""Test creating a new status."""
|
|
response = client.post(
|
|
"/api/v1/reference/statuses",
|
|
json={
|
|
"name": "New Status",
|
|
"is_final": False
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "New Status"
|
|
assert data["is_final"] == False
|
|
|
|
def test_create_duplicate_status(self, client: TestClient, auth_headers: dict, sample_status):
|
|
"""Test creating status with existing name."""
|
|
response = client.post(
|
|
"/api/v1/reference/statuses",
|
|
json={
|
|
"name": sample_status.name,
|
|
"is_final": False
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 409
|
|
|
|
def test_update_status(self, client: TestClient, auth_headers: dict, sample_status):
|
|
"""Test updating a status."""
|
|
response = client.put(
|
|
f"/api/v1/reference/statuses/{sample_status.id}",
|
|
json={
|
|
"name": "Updated Status",
|
|
"is_final": True
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Updated Status"
|
|
assert data["is_final"] == True
|
|
|
|
def test_delete_status(self, client: TestClient, auth_headers: dict, sample_status):
|
|
"""Test deleting a status."""
|
|
response = client.delete(
|
|
f"/api/v1/reference/statuses/{sample_status.id}",
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 204
|
|
|
|
|
|
class TestPriorities:
|
|
"""Test priority endpoints."""
|
|
|
|
def test_get_priorities(self, client: TestClient, auth_headers: dict):
|
|
"""Test getting priorities list."""
|
|
response = client.get("/api/v1/reference/priorities", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert isinstance(data, list)
|
|
|
|
def test_create_priority(self, client: TestClient, auth_headers: dict):
|
|
"""Test creating a new priority."""
|
|
response = client.post(
|
|
"/api/v1/reference/priorities",
|
|
json={
|
|
"name": "Critical",
|
|
"level": 4,
|
|
"default_response_time_minutes": 30
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "Critical"
|
|
assert data["level"] == 4
|
|
|
|
def test_create_duplicate_priority(self, client: TestClient, auth_headers: dict, sample_priority):
|
|
"""Test creating priority with existing name."""
|
|
response = client.post(
|
|
"/api/v1/reference/priorities",
|
|
json={
|
|
"name": sample_priority.name,
|
|
"level": 5
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 409
|
|
|
|
def test_update_priority(self, client: TestClient, auth_headers: dict, sample_priority):
|
|
"""Test updating a priority."""
|
|
response = client.put(
|
|
f"/api/v1/reference/priorities/{sample_priority.id}",
|
|
json={
|
|
"name": "High",
|
|
"level": 3,
|
|
"default_response_time_minutes": 45
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "High"
|
|
assert data["level"] == 3
|
|
|
|
def test_delete_priority(self, client: TestClient, auth_headers: dict, sample_priority):
|
|
"""Test deleting a priority."""
|
|
response = client.delete(
|
|
f"/api/v1/reference/priorities/{sample_priority.id}",
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 204
|
|
|
|
|
|
class TestCategories:
|
|
"""Test category endpoints."""
|
|
|
|
def test_get_categories(self, client: TestClient, auth_headers: dict):
|
|
"""Test getting categories list."""
|
|
response = client.get("/api/v1/reference/categories", headers=auth_headers)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert isinstance(data, list)
|
|
|
|
def test_create_category(self, client: TestClient, auth_headers: dict):
|
|
"""Test creating a new category."""
|
|
response = client.post(
|
|
"/api/v1/reference/categories",
|
|
json={
|
|
"name": "Software"
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "Software"
|
|
|
|
def test_create_subcategory(self, client: TestClient, auth_headers: dict, sample_category):
|
|
"""Test creating a subcategory."""
|
|
response = client.post(
|
|
"/api/v1/reference/categories",
|
|
json={
|
|
"name": "Laptops",
|
|
"parent_id": sample_category.id
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["name"] == "Laptops"
|
|
assert data["parent_id"] == sample_category.id
|
|
|
|
def test_create_duplicate_category(self, client: TestClient, auth_headers: dict, sample_category):
|
|
"""Test creating category with existing name."""
|
|
response = client.post(
|
|
"/api/v1/reference/categories",
|
|
json={
|
|
"name": sample_category.name
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 409
|
|
|
|
def test_update_category(self, client: TestClient, auth_headers: dict, sample_category):
|
|
"""Test updating a category."""
|
|
response = client.put(
|
|
f"/api/v1/reference/categories/{sample_category.id}",
|
|
json={
|
|
"name": "Updated Category"
|
|
},
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["name"] == "Updated Category"
|
|
|
|
def test_delete_category(self, client: TestClient, auth_headers: dict, sample_category):
|
|
"""Test deleting a category."""
|
|
response = client.delete(
|
|
f"/api/v1/reference/categories/{sample_category.id}",
|
|
headers=auth_headers
|
|
)
|
|
|
|
assert response.status_code == 204
|