From 9b64eebd108b1e27238895353298d97425d1fc88 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Sun, 7 Feb 2021 18:26:03 +0100 Subject: [PATCH 1/2] revert commit --- src/documents/sanity_checker.py | 12 +++------ src/documents/tests/samples/simple.png | Bin 7913 -> 0 bytes src/documents/tests/test_consumer.py | 35 ------------------------- 3 files changed, 4 insertions(+), 43 deletions(-) delete mode 100644 src/documents/tests/samples/simple.png diff --git a/src/documents/sanity_checker.py b/src/documents/sanity_checker.py index b8fd73f98..bc0b689d4 100644 --- a/src/documents/sanity_checker.py +++ b/src/documents/sanity_checker.py @@ -56,8 +56,7 @@ def check_sanity(): messages.append(SanityError( f"Thumbnail of document {doc.pk} does not exist.")) else: - if os.path.normpath(doc.thumbnail_path) in present_files: - present_files.remove(os.path.normpath(doc.thumbnail_path)) + present_files.remove(os.path.normpath(doc.thumbnail_path)) try: with doc.thumbnail_file as f: f.read() @@ -72,8 +71,7 @@ def check_sanity(): messages.append(SanityError( f"Original of document {doc.pk} does not exist.")) else: - if os.path.normpath(doc.source_path) in present_files: - present_files.remove(os.path.normpath(doc.source_path)) + present_files.remove(os.path.normpath(doc.source_path)) try: with doc.source_file as f: checksum = hashlib.md5(f.read()).hexdigest() @@ -94,8 +92,7 @@ def check_sanity(): f"Archived version of document {doc.pk} does not exist." )) else: - if os.path.normpath(doc.archive_path) in present_files: - present_files.remove(os.path.normpath(doc.archive_path)) + present_files.remove(os.path.normpath(doc.archive_path)) try: with doc.archive_file as f: checksum = hashlib.md5(f.read()).hexdigest() @@ -106,8 +103,7 @@ def check_sanity(): else: if not checksum == doc.archive_checksum: messages.append(SanityError( - f"Checksum mismatch of archived document " - f"{doc.pk}. " + f"Checksum mismatch of archive {doc.pk}. " f"Stored: {doc.checksum}, actual: {checksum}." )) diff --git a/src/documents/tests/samples/simple.png b/src/documents/tests/samples/simple.png deleted file mode 100644 index a3a76840103812c371dd78f2e8bc704ea3eec1ba..0000000000000000000000000000000000000000 GIT binary patch literal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;is1AgiYK=2W*jN!SJX@m^Z5(Ob}S_4oN4tq71tnGj<@F4u*( zdaFEo`bGLRoscD$d94}wf#y_s^r!^y+GHMH1<~=n(B_ zdJ(dLfdROl6!u@DXS!l%K-1OwABsY?oT(rdnbRA zj04&rNO7L;X9T{;g1L3}@=}ISgzEbB*8l~4jxT~uzbzzm2?$=V%#0ZJY(D64P0!7} zgdy-^*LyC-I@_{HE5FovS}vsQ-~N6p)U;=~lKze)iEdF1*lD{$V}HZ>m6g{r{s$i* zq2fT76oWs(Q`p=1_%gc@zC}rXPR=0ULx{&=+bI+t7|&4i=@+06xGxSW&WrweIfq+b zwp({hISAMTn#NDdN5v>-h$`|mJeP;b!5MVIdrjeRylBb`7upAN)F3WD^DZGFGw}3e zkg2XKE}E*5l%1Md8Vfs4ntFORXof+Nv;Su|uSDkmvpvB7-uwTZoy{X=g#M$ne+jJV Ruvbl>s;I6|ENAlKe*j2SP+b53 diff --git a/src/documents/tests/test_consumer.py b/src/documents/tests/test_consumer.py index 8ead1ea41..a6f0cc55a 100644 --- a/src/documents/tests/test_consumer.py +++ b/src/documents/tests/test_consumer.py @@ -5,14 +5,12 @@ import tempfile from unittest import mock from unittest.mock import MagicMock -from django.conf import settings from django.test import TestCase, override_settings from .utils import DirectoriesMixin from ..consumer import Consumer, ConsumerError from ..models import FileInfo, Tag, Correspondent, DocumentType, Document from ..parsers import DocumentParser, ParseError -from ..tasks import sanity_check class TestAttributes(TestCase): @@ -183,24 +181,6 @@ class DummyParser(DocumentParser): self.text = "The Text" -class CopyParser(DocumentParser): - - def get_thumbnail(self, document_path, mime_type): - return self.fake_thumb - - def get_optimised_thumbnail(self, document_path, mime_type): - return self.fake_thumb - - def __init__(self, logging_group, progress_callback=None): - super(CopyParser, self).__init__(logging_group, progress_callback) - _, self.fake_thumb = tempfile.mkstemp(suffix=".png", dir=self.tempdir) - - def parse(self, document_path, mime_type, file_name=None): - self.text = "The text" - self.archive_path = os.path.join(self.tempdir, "archive.pdf") - shutil.copy(document_path, self.archive_path) - - class FaultyParser(DocumentParser): def get_thumbnail(self, document_path, mime_type): @@ -223,8 +203,6 @@ def fake_magic_from_file(file, mime=False): if mime: if os.path.splitext(file)[1] == ".pdf": return "application/pdf" - elif os.path.splitext(file)[1] == ".png": - return "image/png" else: return "unknown" else: @@ -538,19 +516,6 @@ class TestConsumer(DirectoriesMixin, TestCase): self._assert_first_last_send_progress(last_status="FAILED") - @mock.patch("documents.parsers.document_consumer_declaration.send") - def test_similar_filenames(self, m): - shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "simple.pdf"), os.path.join(settings.CONSUMPTION_DIR, "simple.pdf")) - shutil.copy(os.path.join(os.path.dirname(__file__), "samples", "simple.png"), os.path.join(settings.CONSUMPTION_DIR, "simple.png")) - m.return_value = [(None, { - "parser": CopyParser, - "mime_types": {"application/pdf": ".pdf", "image/png": ".zip"}, - "weight": 0 - })] - doc1 = self.consumer.try_consume_file(os.path.join(settings.CONSUMPTION_DIR, "simple.png")) - doc2 = self.consumer.try_consume_file(os.path.join(settings.CONSUMPTION_DIR, "simple.pdf")) - - sanity_check() class PreConsumeTestCase(TestCase): From 40106f6fccd85ee7ba1eb24765d9beb3305cf6cd Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Mon, 8 Feb 2021 00:10:52 +0100 Subject: [PATCH 2/2] updated documentation regarding execution of management commands with docker fixes #509 --- docs/administration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/administration.rst b/docs/administration.rst index c54323e6e..03a9610d1 100644 --- a/docs/administration.rst +++ b/docs/administration.rst @@ -180,7 +180,7 @@ tasks on your paperless instance. You can invoke these commands either by .. code:: shell-session $ cd /path/to/paperless - $ docker-compose run --rm webserver + $ docker-compose exec -u paperless webserver python3 manage.py or