mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-09-05 02:06:20 +00:00
Feature: auto-clean some invalid pdfs (#7651)
This commit is contained in:
@@ -235,6 +235,8 @@ class FaultyGenericExceptionParser(_BaseTestParser):
|
||||
|
||||
def fake_magic_from_file(file, mime=False):
|
||||
if mime:
|
||||
if file.name.startswith("invalid_pdf"):
|
||||
return "application/octet-stream"
|
||||
if os.path.splitext(file)[1] == ".pdf":
|
||||
return "application/pdf"
|
||||
elif os.path.splitext(file)[1] == ".png":
|
||||
@@ -952,6 +954,27 @@ class TestConsumer(
|
||||
|
||||
sanity_check()
|
||||
|
||||
@mock.patch("documents.consumer.run_subprocess")
|
||||
def test_try_to_clean_invalid_pdf(self, m):
|
||||
shutil.copy(
|
||||
Path(__file__).parent / "samples" / "invalid_pdf.pdf",
|
||||
settings.CONSUMPTION_DIR / "invalid_pdf.pdf",
|
||||
)
|
||||
with self.get_consumer(
|
||||
settings.CONSUMPTION_DIR / "invalid_pdf.pdf",
|
||||
) as consumer:
|
||||
# fails because no qpdf
|
||||
self.assertRaises(ConsumerError, consumer.run)
|
||||
|
||||
m.assert_called_once()
|
||||
|
||||
args, _ = m.call_args
|
||||
|
||||
command = args[0]
|
||||
|
||||
self.assertEqual(command[0], "qpdf")
|
||||
self.assertEqual(command[1], "--replace-input")
|
||||
|
||||
|
||||
@mock.patch("documents.consumer.magic.from_file", fake_magic_from_file)
|
||||
class TestConsumerCreatedDate(DirectoriesMixin, GetConsumerMixin, TestCase):
|
||||
|
Reference in New Issue
Block a user