Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Extended tests for ASN barcode parsing

Peter Kappeltc2880bcf9a6b
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-123.pdf b/src/documents/tests/samples/barcodes/barcode-39-asn-123.pdf
new file mode 100644
index 000000000..2e3dfef24
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-123.pdf differ
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-123.png b/src/documents/tests/samples/barcodes/barcode-39-asn-123.png
new file mode 100644
index 000000000..e0f735960
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-123.png differ
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.pdf b/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.pdf
new file mode 100644
index 000000000..5b1da4c3c
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.pdf differ
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.png b/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.png
new file mode 100644
index 000000000..5712c6920
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-custom-prefix.png differ
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.pdf b/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.pdf
new file mode 100644
index 000000000..d0f3a86c6
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.pdf differ
diff --git a/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.png b/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.png
new file mode 100644
index 000000000..cc7f0d453
Binary files /dev/null and b/src/documents/tests/samples/barcodes/barcode-39-asn-invalid.png differ
diff --git a/src/documents/tests/test_barcodes.py b/src/documents/tests/test_barcodes.py
index cdaffcb3b..15e7efd94 100644
--- a/src/documents/tests/test_barcodes.py
+++ b/src/documents/tests/test_barcodes.py
@@ -110,6 +110,30 @@ class TestBarcode(DirectoriesMixin, TestCase):
img = Image.open(test_file)
self.assertEqual(barcodes.barcode_reader(img), ["CUSTOM BARCODE"])
+ def test_barcode_reader_asn_normal(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-123.png",
+ )
+ img = Image.open(test_file)
+ self.assertEqual(barcodes.barcode_reader(img), ["ASN00123"])
+
+ def test_barcode_reader_asn_invalid(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-invalid.png",
+ )
+ img = Image.open(test_file)
+ self.assertEqual(barcodes.barcode_reader(img), ["ASNXYZXYZ"])
+
+ def test_barcode_reader_asn_customprefix(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-custom-prefix.png",
+ )
+ img = Image.open(test_file)
+ self.assertEqual(barcodes.barcode_reader(img), ["CUSTOM-PREFIX-00123"])
+
def test_get_mime_type(self):
tiff_file = os.path.join(
self.SAMPLE_DIR,
@@ -607,3 +631,57 @@ class TestBarcode(DirectoriesMixin, TestCase):
self.assertEqual(pdf_file, test_file)
self.assertListEqual(separator_page_numbers, [])
+
+ def test_scan_file_for_asn_barcode(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-123.pdf",
+ )
+ pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
+ test_file,
+ )
+ asn = barcodes.get_asn_from_barcodes(parsed_barcodes)
+
+ self.assertEqual(pdf_file, test_file)
+ self.assertEqual(asn, 123)
+
+ def test_scan_file_for_asn_not_existing(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "patch-code-t.pdf",
+ )
+ pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
+ test_file,
+ )
+ asn = barcodes.get_asn_from_barcodes(parsed_barcodes)
+
+ self.assertEqual(pdf_file, test_file)
+ self.assertEqual(asn, None)
+
+ def test_scan_file_for_asn_barcode_invalid(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-invalid.pdf",
+ )
+ pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
+ test_file,
+ )
+
+ asn = barcodes.get_asn_from_barcodes(parsed_barcodes)
+
+ self.assertEqual(pdf_file, test_file)
+ self.assertEqual(asn, None)
+
+ @override_settings(CONSUMER_ASN_BARCODE_PREFIX="CUSTOM-PREFIX-")
+ def test_scan_file_for_asn_custom_prefix(self):
+ test_file = os.path.join(
+ self.BARCODE_SAMPLE_DIR,
+ "barcode-39-asn-custom-prefix.pdf",
+ )
+ pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
+ test_file,
+ )
+ asn = barcodes.get_asn_from_barcodes(parsed_barcodes)
+
+ self.assertEqual(pdf_file, test_file)
+ self.assertEqual(asn, 123)