]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Reduces number of warnings from testing from 165 to 128. In doing so, fixes a few... 242/head
authorTrenton Holmes <holmes.trenton@gmail.com>
Tue, 8 Mar 2022 00:13:20 +0000 (16:13 -0800)
committerTrenton Holmes <holmes.trenton@gmail.com>
Fri, 11 Mar 2022 02:12:48 +0000 (18:12 -0800)
src/documents/management/commands/decrypt_documents.py
src/documents/management/commands/document_exporter.py
src/documents/tests/test_admin.py
src/documents/tests/test_api.py
src/documents/tests/test_matchables.py
src/paperless_tesseract/parsers.py

index 38b49b4896133c36fc166d89dc85ed7eaff03051..24b78474a25fafbe66028ef4886f473ed7ce47ba 100644 (file)
@@ -59,8 +59,10 @@ class Command(BaseCommand):
 
             old_paths = [document.source_path, document.thumbnail_path]
 
-            raw_document = GnuPG.decrypted(document.source_file, passphrase)
-            raw_thumb = GnuPG.decrypted(document.thumbnail_file, passphrase)
+            with document.source_file as file_handle:
+                raw_document = GnuPG.decrypted(file_handle, passphrase)
+            with document.thumbnail_file as file_handle:
+                raw_thumb = GnuPG.decrypted(file_handle, passphrase)
 
             document.storage_type = Document.STORAGE_TYPE_UNENCRYPTED
 
index d2b6f8e32916a64914287b70f3826da3461a28a8..ec978fcf16d879d39222940002c2fd8c70f8317c 100644 (file)
@@ -199,19 +199,22 @@ class Command(BaseCommand):
 
                 os.makedirs(os.path.dirname(original_target), exist_ok=True)
                 with open(original_target, "wb") as f:
-                    f.write(GnuPG.decrypted(document.source_file))
-                    os.utime(original_target, times=(t, t))
+                    with document.source_file as out_file:
+                        f.write(GnuPG.decrypted(out_file))
+                        os.utime(original_target, times=(t, t))
 
                 os.makedirs(os.path.dirname(thumbnail_target), exist_ok=True)
                 with open(thumbnail_target, "wb") as f:
-                    f.write(GnuPG.decrypted(document.thumbnail_file))
-                    os.utime(thumbnail_target, times=(t, t))
+                    with document.thumbnail_file as out_file:
+                        f.write(GnuPG.decrypted(out_file))
+                        os.utime(thumbnail_target, times=(t, t))
 
                 if archive_target:
                     os.makedirs(os.path.dirname(archive_target), exist_ok=True)
                     with open(archive_target, "wb") as f:
-                        f.write(GnuPG.decrypted(document.archive_path))
-                        os.utime(archive_target, times=(t, t))
+                        with document.archive_path as out_file:
+                            f.write(GnuPG.decrypted(out_file))
+                            os.utime(archive_target, times=(t, t))
             else:
                 self.check_and_copy(
                     document.source_path, document.checksum, original_target
index 3e292dcfc700aed5a381344695a3c6b360f8fd4d..42e616e297ec2946f32148794b4dc5f4ecce2031 100644 (file)
@@ -61,6 +61,6 @@ class TestDocumentAdmin(DirectoriesMixin, TestCase):
 
     def test_created(self):
         doc = Document.objects.create(
-            title="test", created=timezone.datetime(2020, 4, 12)
+            title="test", created=timezone.make_aware(timezone.datetime(2020, 4, 12))
         )
         self.assertEqual(self.doc_admin.created_(doc), "2020-04-12")
index 8778e313dd91dfffb4392cc555a4497578e5f828..e384f8b39c282ddccea5a594268e7b5c2f9a19d4 100644 (file)
@@ -10,6 +10,7 @@ from unittest import mock
 import pytest
 from django.conf import settings
 from django.contrib.auth.models import User
+from django.utils import timezone
 from django.test import override_settings
 from rest_framework.test import APITestCase
 from whoosh.writing import AsyncWriter
@@ -567,11 +568,15 @@ class TestDocumentApi(DirectoriesMixin, APITestCase):
         d3.tags.add(t)
         d3.tags.add(t2)
         d4 = Document.objects.create(
-            checksum="4", created=datetime.datetime(2020, 7, 13), content="test"
+            checksum="4",
+            created=timezone.datetime(2020, 7, 13),
+            content="test",
         )
         d4.tags.add(t2)
         d5 = Document.objects.create(
-            checksum="5", added=datetime.datetime(2020, 7, 13), content="test"
+            checksum="5",
+            added=timezone.datetime(2020, 7, 13),
+            content="test",
         )
         d6 = Document.objects.create(checksum="6", content="test2")
 
index df47db9baefaf80bfc9de437dc8f1a5572f47737..913dde637aa375d04e2486490407c1625228feb8 100644 (file)
@@ -162,7 +162,7 @@ class TestMatching(TestCase):
     def test_match_regex(self):
 
         self._test_matching(
-            "alpha\w+gamma",
+            r"alpha\w+gamma",
             "MATCH_REGEX",
             (
                 "I have alpha_and_gamma in me",
@@ -181,7 +181,7 @@ class TestMatching(TestCase):
         )
 
     def test_tach_invalid_regex(self):
-        self._test_matching("[[", "MATCH_REGEX", [], ["Don't match this"])
+        self._test_matching("[", "MATCH_REGEX", [], ["Don't match this"])
 
     def test_match_fuzzy(self):
 
index c27b598c87ca0435fa913223b345300fbf3ce623..f79e086da4730d8aee04729c5ef9429d716dd169 100644 (file)
@@ -121,7 +121,7 @@ class RasterisedDocumentParser(DocumentParser):
             # TODO catch all for various issues with PDFminer.six.
             #  If PDFminer fails, fall back to OCR.
             self.log(
-                "warn",
+                "warning",
                 "Error while getting text from PDF document with " "pdfminer.six",
                 exc_info=True,
             )