TT-003: complete request-module integration into modular platform

- integrated request-module into module registry
- moved backend into modules/request-module
- added manifest.json and module.py
- implemented dynamic router mounting
- implemented dynamic static mounting
- removed direct dependencies from platform core
- verified startup with request-module
- verified startup without request-module
- added implementation_report_003.md
This commit is contained in:
2026-08-06 16:31:27 +03:00
parent c97e6a42f7
commit 6c86f0f571
180 changed files with 204885 additions and 25 deletions
@@ -0,0 +1 @@
"""Test API package."""
@@ -0,0 +1,95 @@
"""Test auth endpoints."""
import pytest
from fastapi.testclient import TestClient
from app.main import app
class TestAuth:
"""Test authentication endpoints."""
def test_register_user(self, client: TestClient):
"""Test user registration."""
response = client.post(
"/api/v1/auth/register",
json={
"email": "newuser@example.com",
"password": "password123",
"first_name": "John",
"last_name": "Doe"
}
)
assert response.status_code == 201
data = response.json()
assert data["email"] == "newuser@example.com"
assert data["first_name"] == "John"
def test_register_duplicate_user(self, client: TestClient, sample_user):
"""Test registering with existing email."""
response = client.post(
"/api/v1/auth/register",
json={
"email": sample_user.email,
"password": "password123",
"first_name": "Jane",
"last_name": "Smith"
}
)
assert response.status_code == 409
def test_login_success(self, client: TestClient, sample_user):
"""Test successful login."""
response = client.post(
"/api/v1/auth/login",
json={
"email": sample_user.email,
"password": "password123"
}
)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert data["token_type"] == "bearer"
assert data["user"]["email"] == sample_user.email
def test_login_invalid_credentials(self, client: TestClient):
"""Test login with invalid credentials."""
response = client.post(
"/api/v1/auth/login",
json={
"email": "nonexistent@example.com",
"password": "wrongpassword"
}
)
assert response.status_code == 401
def test_login_wrong_password(self, client: TestClient, sample_user):
"""Test login with wrong password."""
response = client.post(
"/api/v1/auth/login",
json={
"email": sample_user.email,
"password": "wrongpassword"
}
)
assert response.status_code == 401
def test_get_current_user(self, client: TestClient, sample_user, auth_headers):
"""Test getting current user."""
response = client.get("/api/v1/auth/me", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert data["id"] == sample_user.id
assert data["email"] == sample_user.email
def test_get_current_user_unauthorized(self, client: TestClient):
"""Test getting current user without auth."""
response = client.get("/api/v1/auth/me")
assert response.status_code == 403
@@ -0,0 +1,281 @@
"""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
@@ -0,0 +1,104 @@
"""Test ticket endpoints."""
import pytest
from fastapi.testclient import TestClient
from app.main import app
class TestTickets:
"""Test ticket endpoints."""
def test_create_ticket(self, client: TestClient, auth_headers: dict, sample_user, sample_category, sample_priority, sample_status):
"""Test creating a new ticket."""
response = client.post(
"/api/v1/tickets",
json={
"subject": "Test Ticket",
"description": "This is a test ticket",
"category_id": sample_category.id,
"priority_id": sample_priority.id,
"status_id": sample_status.id
},
headers=auth_headers
)
assert response.status_code == 201
data = response.json()
assert data["subject"] == "Test Ticket"
assert data["opened_by"] == sample_user.id
def test_get_tickets(self, client: TestClient, auth_headers: dict):
"""Test getting tickets list."""
response = client.get("/api/v1/tickets", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "tickets" in data
assert "total" in data
assert "page" in data
def test_get_ticket_by_id(self, client: TestClient, auth_headers: dict, sample_ticket):
"""Test getting ticket by ID."""
response = client.get(f"/api/v1/tickets/{sample_ticket.id}", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert data["id"] == sample_ticket.id
assert data["subject"] == sample_ticket.subject
def test_update_ticket(self, client: TestClient, auth_headers: dict, sample_ticket):
"""Test updating a ticket."""
response = client.put(
f"/api/v1/tickets/{sample_ticket.id}",
json={
"subject": "Updated Ticket",
"description": "Updated description"
},
headers=auth_headers
)
assert response.status_code == 200
data = response.json()
assert data["subject"] == "Updated Ticket"
def test_delete_ticket(self, client: TestClient, auth_headers: dict, sample_ticket):
"""Test deleting a ticket."""
response = client.delete(
f"/api/v1/tickets/{sample_ticket.id}",
headers=auth_headers
)
assert response.status_code == 204
# Verify ticket is deleted
get_response = client.get(f"/api/v1/tickets/{sample_ticket.id}", headers=auth_headers)
assert get_response.status_code == 404
def test_create_ticket_unauthorized(self, client: TestClient):
"""Test creating ticket without auth."""
response = client.post(
"/api/v1/tickets",
json={
"subject": "Test Ticket",
"description": "This is a test ticket",
"category_id": 1,
"priority_id": 1,
"status_id": 1
}
)
assert response.status_code == 403
def test_get_ticket_not_found(self, client: TestClient, auth_headers: dict):
"""Test getting non-existent ticket."""
response = client.get("/api/v1/tickets/99999", headers=auth_headers)
assert response.status_code == 404
def test_get_ticket_comments(self, client: TestClient, auth_headers: dict, sample_ticket):
"""Test getting ticket comments."""
response = client.get(f"/api/v1/tickets/{sample_ticket.id}/comments", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
@@ -0,0 +1,27 @@
"""Test user endpoints."""
import pytest
from fastapi.testclient import TestClient
from app.main import app
class TestUsers:
"""Test user endpoints."""
def test_get_users(self, client: TestClient, auth_headers: dict):
"""Test getting users list."""
response = client.get("/api/v1/users/", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "users" in data
assert "total" in data
def test_get_me(self, client: TestClient, auth_headers: dict):
"""Test getting current user."""
response = client.get("/api/v1/users/me", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert "id" in data
assert "email" in data