This commit is contained in:
Yaojia Wang
2026-02-01 18:51:54 +01:00
parent 4126196dea
commit a564ac9d70
82 changed files with 13123 additions and 3282 deletions

View File

@@ -45,10 +45,10 @@ class TestDocumentListFilterByCategory:
"""Tests for filtering documents by category."""
@pytest.fixture
def mock_admin_db(self):
"""Create mock AdminDB."""
db = MagicMock()
db.is_valid_admin_token.return_value = True
def mock_document_repo(self):
"""Create mock DocumentRepository."""
repo = MagicMock()
repo.is_valid.return_value = True
# Mock documents with different categories
invoice_doc = MagicMock()
@@ -61,11 +61,11 @@ class TestDocumentListFilterByCategory:
letter_doc.category = "letter"
letter_doc.filename = "letter1.pdf"
db.get_documents.return_value = ([invoice_doc], 1)
db.get_document_categories.return_value = ["invoice", "letter", "receipt"]
return db
repo.get_paginated.return_value = ([invoice_doc], 1)
repo.get_categories.return_value = ["invoice", "letter", "receipt"]
return repo
def test_list_documents_accepts_category_filter(self, mock_admin_db):
def test_list_documents_accepts_category_filter(self, mock_document_repo):
"""Test list documents endpoint accepts category query parameter."""
# The endpoint should accept ?category=invoice parameter
# This test verifies the schema/query parameter exists
@@ -74,9 +74,9 @@ class TestDocumentListFilterByCategory:
# Schema should work with category filter applied
assert DocumentListResponse is not None
def test_get_document_categories_from_db(self, mock_admin_db):
"""Test fetching unique categories from database."""
categories = mock_admin_db.get_document_categories()
def test_get_document_categories_from_repo(self, mock_document_repo):
"""Test fetching unique categories from repository."""
categories = mock_document_repo.get_categories()
assert "invoice" in categories
assert "letter" in categories
assert len(categories) == 3
@@ -122,24 +122,24 @@ class TestDocumentUploadWithCategory:
assert response.category == "invoice"
class TestAdminDBCategoryMethods:
"""Tests for AdminDB category-related methods."""
class TestDocumentRepositoryCategoryMethods:
"""Tests for DocumentRepository category-related methods."""
def test_get_document_categories_method_exists(self):
"""Test AdminDB has get_document_categories method."""
from inference.data.admin_db import AdminDB
def test_get_categories_method_exists(self):
"""Test DocumentRepository has get_categories method."""
from inference.data.repositories import DocumentRepository
db = AdminDB()
assert hasattr(db, "get_document_categories")
repo = DocumentRepository()
assert hasattr(repo, "get_categories")
def test_get_documents_accepts_category_filter(self):
"""Test get_documents_by_token method accepts category parameter."""
from inference.data.admin_db import AdminDB
def test_get_paginated_accepts_category_filter(self):
"""Test get_paginated method accepts category parameter."""
from inference.data.repositories import DocumentRepository
import inspect
db = AdminDB()
repo = DocumentRepository()
# Check the method exists and accepts category parameter
method = getattr(db, "get_documents_by_token", None)
method = getattr(repo, "get_paginated", None)
assert callable(method)
# Check category is in the method signature
@@ -150,12 +150,12 @@ class TestAdminDBCategoryMethods:
class TestUpdateDocumentCategory:
"""Tests for updating document category."""
def test_update_document_category_method_exists(self):
"""Test AdminDB has method to update document category."""
from inference.data.admin_db import AdminDB
def test_update_category_method_exists(self):
"""Test DocumentRepository has method to update document category."""
from inference.data.repositories import DocumentRepository
db = AdminDB()
assert hasattr(db, "update_document_category")
repo = DocumentRepository()
assert hasattr(repo, "update_category")
def test_update_request_schema(self):
"""Test DocumentUpdateRequest can update category."""