]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
update existing tests to use modified barcode api
authorPeter Kappelt <kappelt.peter@gmail.com>
Mon, 16 Jan 2023 08:35:32 +0000 (09:35 +0100)
committerTrenton H <797416+stumpylog@users.noreply.github.com>
Tue, 24 Jan 2023 17:43:52 +0000 (09:43 -0800)
src/documents/tests/test_barcodes.py

index 0c4660fed1152d9d534a1a9580030abb969955e4..cdaffcb3bf563f7da78ba759be8f258cc52051be 100644 (file)
@@ -167,18 +167,24 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "patch-code-t.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [0])
 
     def test_scan_file_for_separating_barcodes_none_present(self):
         test_file = os.path.join(self.SAMPLE_DIR, "simple.pdf")
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [])
@@ -188,9 +194,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "patch-code-t-middle.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [1])
@@ -200,9 +209,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "several-patcht-codes.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [2, 5])
@@ -212,14 +224,17 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "patch-code-t-middle_reverse.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [1])
 
-    def test_scan_file_for_separating_barcodes_pillow_transcode_error(self):
+    def test_scan_file_for_barcodes_pillow_transcode_error(self):
         """
         GIVEN:
             - A PDF containing an image which cannot be transcoded to a PIL image
@@ -273,7 +288,7 @@ class TestBarcode(DirectoriesMixin, TestCase):
             with mock.patch("documents.barcodes.barcode_reader") as reader:
                 reader.return_value = list()
 
-                _, _ = barcodes.scan_file_for_separating_barcodes(
+                _, _ = barcodes.scan_file_for_barcodes(
                     str(device_n_pdf.name),
                 )
 
@@ -292,9 +307,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "barcode-fax-image.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [1])
@@ -304,9 +322,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "patch-code-t-qr.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [0])
@@ -317,9 +338,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "barcode-39-custom.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [0])
@@ -330,9 +354,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "barcode-qr-custom.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [0])
@@ -343,9 +370,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "barcode-128-custom.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [0])
@@ -355,9 +385,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             self.BARCODE_SAMPLE_DIR,
             "barcode-39-custom.pdf",
         )
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [])
@@ -450,9 +483,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
         )
         tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR)
 
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(test_file, pdf_file)
         self.assertTrue(len(separator_page_numbers) > 0)
@@ -562,9 +598,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
             - Scanning handle the exception without exception
         """
         test_file = os.path.join(self.SAMPLE_DIR, "password-is-test.pdf")
-        pdf_file, separator_page_numbers = barcodes.scan_file_for_separating_barcodes(
+        pdf_file, parsed_barcodes = barcodes.scan_file_for_barcodes(
             test_file,
         )
+        separator_page_numbers = barcodes.get_separating_barcodes(
+            parsed_barcodes,
+        )
 
         self.assertEqual(pdf_file, test_file)
         self.assertListEqual(separator_page_numbers, [])