A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Small improvements to coverage
Trenton H45d8c945e29b
diff --git a/src/documents/consumer.py b/src/documents/consumer.pyindex 7ccc8336a..d6d3513ec 100644--- a/src/documents/consumer.py+++ b/src/documents/consumer.py@@ -69,7 +69,7 @@ class Consumer(LoggingMixin):status,message=None,document_id=None,- ):+ ): # pragma: no coverpayload = {"filename": os.path.basename(self.filename) if self.filename else None,"task_id": self.task_id,@@ -352,7 +352,7 @@ class Consumer(LoggingMixin):self.run_pre_consume_script()- def progress_callback(current_progress, max_progress):+ def progress_callback(current_progress, max_progress): # pragma: no cover# recalculate progress to be within 20 and 80p = int((current_progress / max_progress) * 50 + 20)self._send_progress(p, 100, "WORKING")diff --git a/src/documents/tests/test_barcodes.py b/src/documents/tests/test_barcodes.pyindex 838671256..eda97554d 100644--- a/src/documents/tests/test_barcodes.py+++ b/src/documents/tests/test_barcodes.py@@ -12,6 +12,7 @@ from documents.barcodes import BarcodeReaderfrom documents.consumer import ConsumerErrorfrom documents.data_models import ConsumableDocumentfrom documents.data_models import DocumentSource+from documents.models import Documentfrom documents.tests.utils import DirectoriesMixinfrom documents.tests.utils import FileSystemAssertsMixin@@ -764,7 +765,7 @@ class TestAsnBarcode(DirectoriesMixin, TestCase):self.assertEqual(reader.pdf_file, test_file)self.assertEqual(asn, 123)- def test_scan_file_for_asn_not_existing(self):+ def test_scan_file_for_asn_not_found(self):"""GIVEN:- PDF without an ASN barcode@@ -781,6 +782,49 @@ class TestAsnBarcode(DirectoriesMixin, TestCase):self.assertEqual(reader.pdf_file, test_file)self.assertEqual(asn, None)+ @override_settings(CONSUMER_ENABLE_ASN_BARCODE=True)+ def test_scan_file_for_asn_already_exists(self):+ """+ GIVEN:+ - PDF with an ASN barcode+ - ASN value already exists+ WHEN:+ - File is scanned for barcodes+ THEN:+ - ASN is retrieved from the document+ - Consumption fails+ """++ Document.objects.create(+ title="WOW",+ content="the content",+ archive_serial_number=123,+ checksum="456",+ mime_type="application/pdf",+ )++ test_file = self.BARCODE_SAMPLE_DIR / "barcode-39-asn-123.pdf"++ dst = settings.SCRATCH_DIR / "barcode-39-asn-123.pdf"+ shutil.copy(test_file, dst)++ with mock.patch("documents.consumer.Consumer._send_progress"):+ with self.assertRaises(ConsumerError) as cm, self.assertLogs(+ "paperless.consumer",+ level="ERROR",+ ) as logs_cm:+ tasks.consume_file(+ ConsumableDocument(+ source=DocumentSource.ConsumeFolder,+ original_file=dst,+ ),+ None,+ )+ self.assertIn("Not consuming barcode-39-asn-123.pdf", str(cm.exception))+ error_str = logs_cm.output[0]+ expected_str = "ERROR:paperless.consumer:Not consuming barcode-39-asn-123.pdf: Given ASN already exists!"+ self.assertEqual(expected_str, error_str)+def test_scan_file_for_asn_barcode_invalid(self):"""GIVEN: