A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
Adds given/when/then commenting and adds an end to end test to verify the read ASN is provided to the consumer
Trenton H299a69a2de6d
diff --git a/src/documents/tests/test_barcodes.py b/src/documents/tests/test_barcodes.pyindex dba4afc99..b2d0824ed 100644--- a/src/documents/tests/test_barcodes.py+++ b/src/documents/tests/test_barcodes.py@@ -111,6 +111,15 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertEqual(barcodes.barcode_reader(img), ["CUSTOM BARCODE"])def test_barcode_reader_asn_normal(self):+ """+ GIVEN:+ - Image containing standard ASNxxxxx barcode+ WHEN:+ - Image is scanned for barcodes+ THEN:+ - The barcode is located+ - The barcode value is correct+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-123.png",@@ -119,6 +128,16 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertEqual(barcodes.barcode_reader(img), ["ASN00123"])def test_barcode_reader_asn_invalid(self):+ """+ GIVEN:+ - Image containing invalid ASNxxxxx barcode+ - The number portion of the ASN is not a number+ WHEN:+ - Image is scanned for barcodes+ THEN:+ - The barcode is located+ - The barcode value is correct+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-invalid.png",@@ -126,7 +145,16 @@ class TestBarcode(DirectoriesMixin, TestCase):img = Image.open(test_file)self.assertEqual(barcodes.barcode_reader(img), ["ASNXYZXYZ"])- def test_barcode_reader_asn_customprefix(self):+ def test_barcode_reader_asn_custom_prefix(self):+ """+ GIVEN:+ - Image containing custom prefix barcode+ WHEN:+ - Image is scanned for barcodes+ THEN:+ - The barcode is located+ - The barcode value is correct+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-custom-prefix.png",@@ -619,7 +647,7 @@ class TestBarcode(DirectoriesMixin, TestCase):WHEN:- File is scanned for barcodeTHEN:- - Scanning handle the exception without exception+ - Scanning handles the exception without exception"""test_file = os.path.join(self.SAMPLE_DIR, "password-is-test.pdf")doc_barcode_info = barcodes.scan_file_for_barcodes(@@ -633,6 +661,16 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertListEqual(separator_page_numbers, [])def test_scan_file_for_asn_barcode(self):+ """+ GIVEN:+ - PDF containing an ASN barcode+ - The ASN value is 123+ WHEN:+ - File is scanned for barcodes+ THEN:+ - The ASN is located+ - The ASN integer value is correct+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-123.pdf",@@ -646,6 +684,14 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertEqual(asn, 123)def test_scan_file_for_asn_not_existing(self):+ """+ GIVEN:+ - PDF without an ASN barcode+ WHEN:+ - File is scanned for barcodes+ THEN:+ - No ASN is retrieved from the document+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"patch-code-t.pdf",@@ -659,6 +705,16 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertEqual(asn, None)def test_scan_file_for_asn_barcode_invalid(self):+ """+ GIVEN:+ - PDF containing an ASN barcode+ - The ASN value is XYZXYZ+ WHEN:+ - File is scanned for barcodes+ THEN:+ - The ASN is located+ - The ASN value is not used+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-invalid.pdf",@@ -674,6 +730,16 @@ class TestBarcode(DirectoriesMixin, TestCase):@override_settings(CONSUMER_ASN_BARCODE_PREFIX="CUSTOM-PREFIX-")def test_scan_file_for_asn_custom_prefix(self):+ """+ GIVEN:+ - PDF containing an ASN barcode with custom prefix+ - The ASN value is 123+ WHEN:+ - File is scanned for barcodes+ THEN:+ - The ASN is located+ - The ASN integer value is correct+ """test_file = os.path.join(self.BARCODE_SAMPLE_DIR,"barcode-39-asn-custom-prefix.pdf",@@ -685,3 +751,31 @@ class TestBarcode(DirectoriesMixin, TestCase):self.assertEqual(doc_barcode_info.pdf_path, test_file)self.assertEqual(asn, 123)++ @override_settings(CONSUMER_ENABLE_ASN_BARCODE=True)+ def test_consume_barcode_file_asn_assignment(self):+ """+ GIVEN:+ - PDF containing an ASN barcode+ - The ASN value is 123+ WHEN:+ - File is scanned for barcodes+ THEN:+ - The ASN is located+ - The ASN integer value is correct+ - The ASN is provided as the override value to the consumer+ """+ test_file = os.path.join(+ self.BARCODE_SAMPLE_DIR,+ "barcode-39-asn-123.pdf",+ )++ dst = os.path.join(settings.SCRATCH_DIR, "barcode-39-asn-123.pdf")+ shutil.copy(test_file, dst)++ with mock.patch("documents.consumer.Consumer.try_consume_file") as mocked_call:+ tasks.consume_file(dst)++ args, kwargs = mocked_call.call_args++ self.assertEqual(kwargs["override_asn"], 123)