mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-11 10:00:48 -05:00
update existing tests to use modified barcode api
This commit is contained in:
parent
31a03b1d30
commit
d8d111f093
@ -167,18 +167,24 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"patch-code-t.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [0])
|
self.assertListEqual(separator_page_numbers, [0])
|
||||||
|
|
||||||
def test_scan_file_for_separating_barcodes_none_present(self):
|
def test_scan_file_for_separating_barcodes_none_present(self):
|
||||||
test_file = os.path.join(self.SAMPLE_DIR, "simple.pdf")
|
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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [])
|
self.assertListEqual(separator_page_numbers, [])
|
||||||
@ -188,9 +194,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"patch-code-t-middle.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [1])
|
self.assertListEqual(separator_page_numbers, [1])
|
||||||
@ -200,9 +209,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"several-patcht-codes.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [2, 5])
|
self.assertListEqual(separator_page_numbers, [2, 5])
|
||||||
@ -212,14 +224,17 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"patch-code-t-middle_reverse.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [1])
|
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:
|
GIVEN:
|
||||||
- A PDF containing an image which cannot be transcoded to a PIL image
|
- 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:
|
with mock.patch("documents.barcodes.barcode_reader") as reader:
|
||||||
reader.return_value = list()
|
reader.return_value = list()
|
||||||
|
|
||||||
_, _ = barcodes.scan_file_for_separating_barcodes(
|
_, _ = barcodes.scan_file_for_barcodes(
|
||||||
str(device_n_pdf.name),
|
str(device_n_pdf.name),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -292,9 +307,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"barcode-fax-image.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [1])
|
self.assertListEqual(separator_page_numbers, [1])
|
||||||
@ -304,9 +322,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"patch-code-t-qr.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [0])
|
self.assertListEqual(separator_page_numbers, [0])
|
||||||
@ -317,9 +338,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"barcode-39-custom.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [0])
|
self.assertListEqual(separator_page_numbers, [0])
|
||||||
@ -330,9 +354,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"barcode-qr-custom.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [0])
|
self.assertListEqual(separator_page_numbers, [0])
|
||||||
@ -343,9 +370,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"barcode-128-custom.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [0])
|
self.assertListEqual(separator_page_numbers, [0])
|
||||||
@ -355,9 +385,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
self.BARCODE_SAMPLE_DIR,
|
self.BARCODE_SAMPLE_DIR,
|
||||||
"barcode-39-custom.pdf",
|
"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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [])
|
self.assertListEqual(separator_page_numbers, [])
|
||||||
@ -450,9 +483,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
)
|
)
|
||||||
tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR)
|
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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(test_file, pdf_file)
|
self.assertEqual(test_file, pdf_file)
|
||||||
self.assertTrue(len(separator_page_numbers) > 0)
|
self.assertTrue(len(separator_page_numbers) > 0)
|
||||||
@ -562,9 +598,12 @@ class TestBarcode(DirectoriesMixin, TestCase):
|
|||||||
- Scanning handle the exception without exception
|
- Scanning handle the exception without exception
|
||||||
"""
|
"""
|
||||||
test_file = os.path.join(self.SAMPLE_DIR, "password-is-test.pdf")
|
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,
|
test_file,
|
||||||
)
|
)
|
||||||
|
separator_page_numbers = barcodes.get_separating_barcodes(
|
||||||
|
parsed_barcodes,
|
||||||
|
)
|
||||||
|
|
||||||
self.assertEqual(pdf_file, test_file)
|
self.assertEqual(pdf_file, test_file)
|
||||||
self.assertListEqual(separator_page_numbers, [])
|
self.assertListEqual(separator_page_numbers, [])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user