diff --git a/src/documents/tests/test_api_bulk_edit.py b/src/documents/tests/test_api_bulk_edit.py index 6fd94cda8a..87739963b1 100644 --- a/src/documents/tests/test_api_bulk_edit.py +++ b/src/documents/tests/test_api_bulk_edit.py @@ -2908,7 +2908,7 @@ class TestRunZoneOcrBulkEditAPI: @pytest.fixture def doc1(self) -> Document: - return DocumentFactory(checksum="A", title="A") + return DocumentFactory() def test_run_zone_ocr_documents_endpoint( self, @@ -2951,11 +2951,7 @@ class TestRunZoneOcrBulkEditAPI: THEN: - run_zone_ocr is called with the template """ - template = OcrTemplateFactory( - name="Bills", - source_width=100, - source_height=100, - ) + template = OcrTemplateFactory() response = api_client.post( "/api/documents/run_zone_ocr/", json.dumps({"documents": [doc1.id], "template": template.pk}), @@ -2986,8 +2982,6 @@ class TestRunZoneOcrBulkEditAPI: template = OcrTemplateFactory( name="Private", owner=UserFactory(username="other"), - source_width=100, - source_height=100, ) api_client.force_authenticate(user=user) diff --git a/src/documents/tests/test_api_ocr_templates.py b/src/documents/tests/test_api_ocr_templates.py index afe035e5f2..96a99e231c 100644 --- a/src/documents/tests/test_api_ocr_templates.py +++ b/src/documents/tests/test_api_ocr_templates.py @@ -212,7 +212,6 @@ class TestZoneOcrIndexing: template = OcrTemplateFactory( name="Invoice template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) @@ -220,12 +219,8 @@ class TestZoneOcrIndexing: OcrTemplateZoneFactory( template=template, name="Title", - target=OcrTemplateZone.TargetType.TITLE, page=-1, - x=0, - y=0, width=50, - height=50, ) OcrTemplateZoneFactory( template=template, @@ -233,10 +228,8 @@ class TestZoneOcrIndexing: target=OcrTemplateZone.TargetType.CUSTOM_FIELD, custom_field=field, page=-1, - x=0, y=50, width=50, - height=50, order=1, ) mocker.patch( @@ -452,9 +445,6 @@ class TestOcrTemplatePermissions: return OcrTemplateFactory( name=name, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, owner=owner, ) @@ -491,9 +481,6 @@ class TestOcrTemplatePermissions: template = OcrTemplateFactory( name="Private", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, owner=other, ) grant_object(user, template, "view_ocrtemplate") @@ -620,7 +607,6 @@ class TestOcrTemplatePermissions: name="Shared", owner=admin_user, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) @@ -806,10 +792,7 @@ class TestOcrTemplateValidation: """ template = OcrTemplateFactory( name="Test", - matching_algorithm=MatchingModel.MATCH_ANY, owner=admin_user, - source_width=1000, - source_height=1000, ) response = admin_client.patch( f"{ENDPOINT}{template.pk}/", @@ -834,10 +817,7 @@ class TestOcrTemplateValidation: """ template = OcrTemplateFactory( name="Test", - matching_algorithm=MatchingModel.MATCH_ANY, owner=admin_user, - source_width=1000, - source_height=1000, ) response = admin_client.patch( f"{ENDPOINT}{template.pk}/", @@ -861,17 +841,12 @@ class TestOcrTemplateValidation: """ template = OcrTemplateFactory( name="Test", - matching_algorithm=MatchingModel.MATCH_ANY, owner=admin_user, - source_width=1000, - source_height=1000, ) zone = OcrTemplateZoneFactory( template=template, name="Original", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, - x=0, - y=0, width=10, height=10, ) @@ -981,9 +956,6 @@ class TestOcrTemplateList: template = OcrTemplateFactory( name="Test Template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, ) OcrTemplateZoneFactory( template=template, @@ -993,7 +965,6 @@ class TestOcrTemplateList: x=100, y=100, width=200, - height=50, ) resp = admin_client.get(ENDPOINT) @@ -1036,18 +1007,12 @@ class TestOcrTemplateUpdate: template = OcrTemplateFactory( name="Old Name", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, ) OcrTemplateZoneFactory( template=template, name="Old Zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, custom_field=text_field, - x=0, - y=0, - width=100, height=100, ) @@ -1081,17 +1046,12 @@ class TestOcrTemplateUpdate: """ template = OcrTemplateFactory( name="Original", - matching_algorithm=MatchingModel.MATCH_ANY, owner=admin_user, - source_width=1000, - source_height=1000, ) zone = OcrTemplateZoneFactory( template=template, name="Original zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, - x=0, - y=0, width=10, height=10, ) @@ -1121,17 +1081,12 @@ class TestOcrTemplateUpdate: """ template = OcrTemplateFactory( name="Test", - matching_algorithm=MatchingModel.MATCH_ANY, owner=admin_user, - source_width=1000, - source_height=1000, ) OcrTemplateZoneFactory( template=template, name="Zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, - x=0, - y=0, width=10, height=10, ) @@ -1155,10 +1110,6 @@ class TestOcrTemplateUpdate: template = OcrTemplateFactory( name="Toggle Test", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, - enabled=True, ) resp = admin_client.patch( @@ -1186,18 +1137,12 @@ class TestOcrTemplateUpdate: template = OcrTemplateFactory( name="Patch Test", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, ) OcrTemplateZoneFactory( template=template, name="Existing Zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, custom_field=text_field, - x=0, - y=0, - width=100, height=100, ) @@ -1229,18 +1174,12 @@ class TestOcrTemplateDelete: template = OcrTemplateFactory( name="To Delete", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, ) OcrTemplateZoneFactory( template=template, name="Zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, custom_field=text_field, - x=0, - y=0, - width=100, height=100, ) @@ -1283,9 +1222,6 @@ class TestRunZoneOcr: OcrTemplateFactory( name="Other sender", match="Contoso", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, ) response = admin_client.post(RUN_ZONE_OCR_URL.format(pk=document.pk)) @@ -1325,9 +1261,6 @@ class TestRunZoneOcr: OcrTemplateFactory( name="Disabled template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, enabled=False, ) @@ -1360,10 +1293,7 @@ class TestRunZoneOcr: template = OcrTemplateFactory( name="Manual only", match="Contoso", - matching_algorithm=MatchingModel.MATCH_ANY, enabled=False, - source_width=1000, - source_height=1000, ) response = admin_client.post( @@ -1411,7 +1341,6 @@ class TestRunZoneOcr: template = OcrTemplateFactory( name="Northwind", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) @@ -1523,9 +1452,6 @@ class TestRunZoneOcr: OcrTemplateFactory( name="Template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, ) response = admin_client.post(RUN_ZONE_OCR_URL.format(pk=document.pk)) @@ -1558,17 +1484,10 @@ class TestRunZoneOcr: template = OcrTemplateFactory( name="Template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=1000, - source_height=1000, ) OcrTemplateZoneFactory( template=template, name="Title zone", - target=OcrTemplateZone.TargetType.TITLE, - x=0, - y=0, - width=100, height=100, ) @@ -1611,16 +1530,12 @@ class TestRunZoneOcr: template = OcrTemplateFactory( name="Template", match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) OcrTemplateZoneFactory( template=template, name="Title", - target=OcrTemplateZone.TargetType.TITLE, - x=0, - y=0, width=20, height=20, ) @@ -1667,7 +1582,6 @@ class TestRunZoneOcr: ] template = OcrTemplateFactory( name="Test", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) @@ -1689,8 +1603,6 @@ class TestRunZoneOcr: name=name, target=target, custom_field=field, - x=0, - y=0, width=10, height=10, ) @@ -1738,10 +1650,7 @@ class TestRunZoneOcrPermissions: document = DocumentFactory(content=CONTENT, owner=user) template = OcrTemplateFactory( name="Private", - matching_algorithm=MatchingModel.MATCH_ANY, owner=UserFactory(), - source_width=1000, - source_height=1000, ) rest_api_client.force_authenticate(user=user) @@ -1830,7 +1739,6 @@ class TestRunZoneOcrPermissions: source_width=100, source_height=100, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, ) rest_api_client.force_authenticate(user) @@ -1861,7 +1769,6 @@ class TestRunZoneOcrPermissions: name="Requester's private template", owner=admin_user, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) @@ -1908,16 +1815,12 @@ class TestRunZoneOcrPermissions: name=name, owner=template_owner, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) OcrTemplateZoneFactory( template=template, name=name, - target=OcrTemplateZone.TargetType.TITLE, - x=0, - y=0, width=20, height=20, ) @@ -1966,16 +1869,12 @@ class TestRunZoneOcrPermissions: name=name, owner=template_owner, match="Northwind", - matching_algorithm=MatchingModel.MATCH_ANY, source_width=100, source_height=100, ) OcrTemplateZoneFactory( template=template, name=name, - target=OcrTemplateZone.TargetType.TITLE, - x=0, - y=0, width=20, height=20, ) diff --git a/src/documents/tests/test_bulk_edit.py b/src/documents/tests/test_bulk_edit.py index b88f9a9dc2..45068e4d12 100644 --- a/src/documents/tests/test_bulk_edit.py +++ b/src/documents/tests/test_bulk_edit.py @@ -21,7 +21,6 @@ from documents.models import CustomField from documents.models import CustomFieldInstance from documents.models import Document from documents.models import DocumentType -from documents.models import OcrTemplate from documents.models import StoragePath from documents.models import Tag from documents.pdf_ops import PageSpec @@ -30,6 +29,7 @@ from documents.permissions import set_permissions_for_objects from documents.tasks import extract_zones from paperless_testing.dirs import DirectoriesMixin from paperless_testing.factories import DocumentFactory +from paperless_testing.factories import OcrTemplateFactory from paperless_testing.factories import UserFactory from paperless_testing.permissions import grant_object from paperless_testing.samples import MULTI_PAGE_DIGITAL_PDF @@ -1962,11 +1962,7 @@ class TestBulkEditRunZoneOcr: def test_runs_the_chosen_template(self, mock_task: mock.MagicMock) -> None: doc = DocumentFactory() - template = OcrTemplate.objects.create( - name="Bills", - source_width=100, - source_height=100, - ) + template = OcrTemplateFactory() bulk_edit.run_zone_ocr([doc.id], template=template.pk) @@ -2012,11 +2008,7 @@ class TestBulkEditRunZoneOcr: """ extract = mocker.patch("documents.tasks.run_zone_extraction") doc = DocumentFactory() - template = OcrTemplate.objects.create( - name="Bills", - source_width=100, - source_height=100, - ) + template = OcrTemplateFactory() extract_zones(doc.id, template.pk) diff --git a/src/documents/tests/test_bulk_operations.py b/src/documents/tests/test_bulk_operations.py index 2e90e67161..f4cce74635 100644 --- a/src/documents/tests/test_bulk_operations.py +++ b/src/documents/tests/test_bulk_operations.py @@ -86,7 +86,7 @@ class TestRunZoneOcrBulkOperation: - Extraction does not run in the request """ user, client, doc, _ = bulk_setup - template = OcrTemplateFactory(source_width=100, source_height=100) + template = OcrTemplateFactory() enqueue = mocker.patch("documents.views.execute_bulk_operation.apply_async") extract = mocker.patch("documents.bulk_edit.extract_zones") enqueue.return_value.id = "zone-ocr-task" @@ -127,7 +127,7 @@ class TestRunZoneOcrBulkOperation: - The result reports the operation and document count """ user, _, doc, _ = bulk_setup - template = OcrTemplateFactory(source_width=100, source_height=100) + template = OcrTemplateFactory() extract = mocker.patch("documents.bulk_edit.extract_zones") result = execute_bulk_operation( "run_zone_ocr", @@ -194,11 +194,7 @@ class TestRunZoneOcrBulkOperation: _, client, doc, _ = bulk_setup user = UserFactory() grant_global(user, "change_document") - template = OcrTemplateFactory( - owner=user, - source_width=100, - source_height=100, - ) + template = OcrTemplateFactory(owner=user) client.force_authenticate(user) enqueue = mocker.patch("documents.views.execute_bulk_operation.apply_async") enqueue.return_value.id = "zone-ocr-task" diff --git a/src/documents/tests/test_zone_ocr.py b/src/documents/tests/test_zone_ocr.py index 5a61390794..b54ec8a2c4 100644 --- a/src/documents/tests/test_zone_ocr.py +++ b/src/documents/tests/test_zone_ocr.py @@ -426,8 +426,7 @@ class TestZoneExtraction: def make_template(name: str, **kwargs: Any) -> OcrTemplate: - """Build a saved template, 100x50 by default, using the model default matching.""" - kwargs.setdefault("matching_algorithm", MatchingModel.MATCH_ANY) + """Build a saved template, 100x50 by default.""" kwargs.setdefault("source_width", 100) kwargs.setdefault("source_height", 50) return OcrTemplateFactory(name=name, **kwargs) @@ -444,8 +443,6 @@ def make_zone( template=template, name=name, target=target, - x=0, - y=0, width=20, height=10, **kwargs, @@ -1306,9 +1303,6 @@ class TestTemplateVisibility: OcrTemplateZoneFactory( template=template, name="Title", - target="title", - x=0, - y=0, width=20, height=20, ) @@ -2049,9 +2043,6 @@ class TestRunZoneExtraction: kwargs.setdefault("match", "test") template = OcrTemplateFactory( name=name, - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, **kwargs, ) OcrTemplateZoneFactory( @@ -2059,10 +2050,6 @@ class TestRunZoneExtraction: name="Zone", target=OcrTemplateZone.TargetType.CUSTOM_FIELD, custom_field=custom_field, - x=0, - y=0, - width=100, - height=50, ) return template @@ -2124,10 +2111,6 @@ class TestRunZoneExtraction: OcrTemplateFactory( name="Empty", match="test", - matching_algorithm=MatchingModel.MATCH_ANY, - source_width=2480, - source_height=3508, - enabled=True, ) run_zone_extraction(document, pdf) diff --git a/src/paperless_testing/factories.py b/src/paperless_testing/factories.py index aacfb1e87f..74ac38d334 100644 --- a/src/paperless_testing/factories.py +++ b/src/paperless_testing/factories.py @@ -118,7 +118,7 @@ class OcrTemplateFactory(TypedModelFactory[OcrTemplate]): name = factory.Sequence(lambda n: f"OCR template {n}") match = "" - matching_algorithm = MatchingModel.MATCH_NONE + matching_algorithm = MatchingModel.MATCH_ANY source_width = 1000 source_height = 1000