mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-02 09:02:18 +00:00
Test(beta): use documents factories for taxonomy hint test fixtures
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
committed by
Trenton Holmes
co-authored by
Claude Opus 4.8
parent
c130f0a7c5
commit
4f05ebf14e
@@ -1,5 +1,4 @@
|
||||
import difflib
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -10,6 +9,7 @@ from documents.models import Correspondent
|
||||
from documents.models import DocumentType
|
||||
from documents.models import StoragePath
|
||||
from documents.models import Tag
|
||||
from documents.tests.factories import TagFactory
|
||||
from paperless_ai.matching import extract_unmatched_names
|
||||
from paperless_ai.matching import match_correspondents_by_name
|
||||
from paperless_ai.matching import match_document_types_by_name
|
||||
@@ -97,7 +97,7 @@ class TestHintedMatching:
|
||||
) -> None:
|
||||
mocker.patch(
|
||||
"paperless_ai.matching.get_objects_for_user_owner_aware",
|
||||
return_value=[SimpleNamespace(name="Bloodwork")],
|
||||
return_value=[TagFactory.build(name="Bloodwork")],
|
||||
)
|
||||
spy = mocker.spy(difflib, "get_close_matches")
|
||||
|
||||
@@ -116,7 +116,7 @@ class TestHintedMatching:
|
||||
) -> None:
|
||||
mocker.patch(
|
||||
"paperless_ai.matching.get_objects_for_user_owner_aware",
|
||||
return_value=[SimpleNamespace(name="Bloodwork")],
|
||||
return_value=[TagFactory.build(name="Bloodwork")],
|
||||
)
|
||||
|
||||
# "Bloodwrok" is a typo not in hints -> fuzzy still maps it to Bloodwork.
|
||||
@@ -134,7 +134,7 @@ class TestHintedMatching:
|
||||
) -> None:
|
||||
mocker.patch(
|
||||
"paperless_ai.matching.get_objects_for_user_owner_aware",
|
||||
return_value=[SimpleNamespace(name="Bloodwork")],
|
||||
return_value=[TagFactory.build(name="Bloodwork")],
|
||||
)
|
||||
spy = mocker.spy(difflib, "get_close_matches")
|
||||
|
||||
@@ -154,7 +154,7 @@ class TestHintedMatching:
|
||||
# A hint with no exact object must not fall through to fuzzy.
|
||||
mocker.patch(
|
||||
"paperless_ai.matching.get_objects_for_user_owner_aware",
|
||||
return_value=[SimpleNamespace(name="Bloodwork")],
|
||||
return_value=[TagFactory.build(name="Bloodwork")],
|
||||
)
|
||||
|
||||
result = match_tags_by_name(
|
||||
@@ -171,7 +171,7 @@ class TestHintedMatching:
|
||||
) -> None:
|
||||
mocker.patch(
|
||||
"paperless_ai.matching.get_objects_for_user_owner_aware",
|
||||
return_value=[SimpleNamespace(name="Test Tag 1")],
|
||||
return_value=[TagFactory.build(name="Test Tag 1")],
|
||||
)
|
||||
|
||||
result = match_tags_by_name(["Test Tag 1", "Nonexistent"], user=None)
|
||||
|
||||
@@ -2,6 +2,7 @@ from types import SimpleNamespace
|
||||
|
||||
import pytest_mock
|
||||
|
||||
from documents.tests.factories import DocumentFactory
|
||||
from paperless_ai.taxonomy import TaxonomyHints
|
||||
from paperless_ai.taxonomy import build_taxonomy_hints_from_nodes
|
||||
from paperless_ai.taxonomy import format_hints_for_prompt
|
||||
@@ -143,7 +144,7 @@ class TestGetTaxonomyHintsForDocument:
|
||||
)
|
||||
retrieve = mocker.patch("paperless_ai.taxonomy.retrieve_similar_nodes")
|
||||
|
||||
result = get_taxonomy_hints_for_document(SimpleNamespace(), user=None)
|
||||
result = get_taxonomy_hints_for_document(DocumentFactory.build(), user=None)
|
||||
|
||||
assert result is None
|
||||
retrieve.assert_not_called()
|
||||
@@ -166,7 +167,7 @@ class TestGetTaxonomyHintsForDocument:
|
||||
"paperless_ai.taxonomy.retrieve_similar_nodes",
|
||||
return_value=[],
|
||||
)
|
||||
document = SimpleNamespace()
|
||||
document = DocumentFactory.build()
|
||||
user = mocker.MagicMock()
|
||||
|
||||
get_taxonomy_hints_for_document(document, user=user)
|
||||
@@ -189,7 +190,7 @@ class TestGetTaxonomyHintsForDocument:
|
||||
return_value=[make_node(tags=["Taxes"], document_type="Invoice")],
|
||||
)
|
||||
|
||||
result = get_taxonomy_hints_for_document(SimpleNamespace(), user=None)
|
||||
result = get_taxonomy_hints_for_document(DocumentFactory.build(), user=None)
|
||||
|
||||
assert result == {
|
||||
"tags": ["Taxes"],
|
||||
@@ -211,7 +212,7 @@ class TestGetTaxonomyHintsForDocument:
|
||||
return_value=[],
|
||||
)
|
||||
|
||||
result = get_taxonomy_hints_for_document(SimpleNamespace(), user=None)
|
||||
result = get_taxonomy_hints_for_document(DocumentFactory.build(), user=None)
|
||||
|
||||
assert result == {
|
||||
"tags": [],
|
||||
|
||||
@@ -6,18 +6,14 @@ from django.contrib.auth.models import User
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from documents.models import Document
|
||||
from documents.tests.factories import DocumentFactory
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestSuggestionsHintWiring:
|
||||
@pytest.fixture
|
||||
def document(self) -> Document:
|
||||
return Document.objects.create(
|
||||
title="Doc",
|
||||
content="content",
|
||||
checksum="abc123",
|
||||
mime_type="application/pdf",
|
||||
)
|
||||
return DocumentFactory() # type: ignore[return-value]
|
||||
|
||||
@pytest.fixture
|
||||
def api_client(self, admin_user: User) -> APIClient:
|
||||
|
||||
Reference in New Issue
Block a user