mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-30 18:27:45 -05:00
Configures ruff as the one stop linter and resolves warnings it raised
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from factory import Faker
|
||||
from factory.django import DjangoModelFactory
|
||||
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
|
||||
|
||||
class CorrespondentFactory(DjangoModelFactory):
|
||||
|
@@ -17,7 +17,7 @@ import celery
|
||||
try:
|
||||
import zoneinfo
|
||||
except ImportError:
|
||||
import backports.zoneinfo as zoneinfo
|
||||
from backports import zoneinfo
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
@@ -110,9 +110,9 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
def test_document_fields(self):
|
||||
c = Correspondent.objects.create(name="c", pk=41)
|
||||
dt = DocumentType.objects.create(name="dt", pk=63)
|
||||
tag = Tag.objects.create(name="t", pk=85)
|
||||
Tag.objects.create(name="t", pk=85)
|
||||
storage_path = StoragePath.objects.create(name="sp", pk=77, path="p")
|
||||
doc = Document.objects.create(
|
||||
Document.objects.create(
|
||||
title="WOW",
|
||||
content="the content",
|
||||
correspondent=c,
|
||||
@@ -877,7 +877,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
added=timezone.make_aware(datetime.datetime(2020, 7, 13)),
|
||||
content="test",
|
||||
)
|
||||
d6 = Document.objects.create(checksum="6", content="test2")
|
||||
Document.objects.create(checksum="6", content="test2")
|
||||
d7 = Document.objects.create(checksum="7", storage_path=sp, content="test")
|
||||
|
||||
with AsyncWriter(index.open_index()) as writer:
|
||||
@@ -1046,13 +1046,13 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
mime_type="application/pdf",
|
||||
content="abc",
|
||||
)
|
||||
doc2 = Document.objects.create(
|
||||
Document.objects.create(
|
||||
title="none2",
|
||||
checksum="B",
|
||||
mime_type="application/pdf",
|
||||
content="123",
|
||||
)
|
||||
doc3 = Document.objects.create(
|
||||
Document.objects.create(
|
||||
title="none3",
|
||||
checksum="C",
|
||||
mime_type="text/plain",
|
||||
@@ -1546,14 +1546,14 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
show_on_dashboard=False,
|
||||
show_in_sidebar=False,
|
||||
)
|
||||
v2 = SavedView.objects.create(
|
||||
SavedView.objects.create(
|
||||
owner=u2,
|
||||
name="test2",
|
||||
sort_field="",
|
||||
show_on_dashboard=False,
|
||||
show_in_sidebar=False,
|
||||
)
|
||||
v3 = SavedView.objects.create(
|
||||
SavedView.objects.create(
|
||||
owner=u2,
|
||||
name="test3",
|
||||
sort_field="",
|
||||
@@ -1594,7 +1594,7 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
||||
|
||||
def test_create_update_patch(self):
|
||||
|
||||
u1 = User.objects.create_user("user1")
|
||||
User.objects.create_user("user1")
|
||||
|
||||
view = {
|
||||
"name": "test",
|
||||
@@ -3020,7 +3020,7 @@ class TestBulkDownload(DirectoriesMixin, APITestCase):
|
||||
self.assertEqual(f.read(), zipf.read("2021-01-01 document A_01.pdf"))
|
||||
|
||||
def test_compression(self):
|
||||
response = self.client.post(
|
||||
self.client.post(
|
||||
self.ENDPOINT,
|
||||
json.dumps(
|
||||
{"documents": [self.doc2.id, self.doc2b.id], "compression": "lzma"},
|
||||
@@ -3271,7 +3271,7 @@ class TestApiAuth(DirectoriesMixin, APITestCase):
|
||||
user = User.objects.create_user(username="test")
|
||||
self.client.force_authenticate(user)
|
||||
|
||||
d = Document.objects.create(title="Test")
|
||||
Document.objects.create(title="Test")
|
||||
|
||||
self.assertEqual(
|
||||
self.client.get("/api/documents/").status_code,
|
||||
@@ -3305,7 +3305,7 @@ class TestApiAuth(DirectoriesMixin, APITestCase):
|
||||
user.user_permissions.add(*Permission.objects.all())
|
||||
self.client.force_authenticate(user)
|
||||
|
||||
d = Document.objects.create(title="Test")
|
||||
Document.objects.create(title="Test")
|
||||
|
||||
self.assertEqual(
|
||||
self.client.get("/api/documents/").status_code,
|
||||
@@ -3696,7 +3696,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
THEN:
|
||||
- No task data is returned
|
||||
"""
|
||||
task1 = PaperlessTask.objects.create(
|
||||
PaperlessTask.objects.create(
|
||||
task_id=str(uuid.uuid4()),
|
||||
task_file_name="task_one.pdf",
|
||||
)
|
||||
@@ -3746,7 +3746,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
THEN:
|
||||
- The returned data includes the task result
|
||||
"""
|
||||
task = PaperlessTask.objects.create(
|
||||
PaperlessTask.objects.create(
|
||||
task_id=str(uuid.uuid4()),
|
||||
task_file_name="task_one.pdf",
|
||||
status=celery.states.SUCCESS,
|
||||
@@ -3772,7 +3772,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
THEN:
|
||||
- The returned result is the exception info
|
||||
"""
|
||||
task = PaperlessTask.objects.create(
|
||||
PaperlessTask.objects.create(
|
||||
task_id=str(uuid.uuid4()),
|
||||
task_file_name="task_one.pdf",
|
||||
status=celery.states.FAILURE,
|
||||
@@ -3801,7 +3801,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
THEN:
|
||||
- Returned data include the filename
|
||||
"""
|
||||
task = PaperlessTask.objects.create(
|
||||
PaperlessTask.objects.create(
|
||||
task_id=str(uuid.uuid4()),
|
||||
task_file_name="test.pdf",
|
||||
task_name="documents.tasks.some_task",
|
||||
@@ -3827,7 +3827,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
||||
THEN:
|
||||
- Returned data include the filename
|
||||
"""
|
||||
task = PaperlessTask.objects.create(
|
||||
PaperlessTask.objects.create(
|
||||
task_id=str(uuid.uuid4()),
|
||||
task_file_name="anothertest.pdf",
|
||||
task_name="documents.tasks.some_task",
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
import platform
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
@@ -11,19 +11,11 @@ from documents import barcodes
|
||||
from documents import tasks
|
||||
from documents.consumer import ConsumerError
|
||||
from documents.data_models import ConsumableDocument
|
||||
from documents.data_models import DocumentMetadataOverrides
|
||||
from documents.data_models import DocumentSource
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
from documents.tests.utils import FileSystemAssertsMixin
|
||||
from PIL import Image
|
||||
|
||||
try:
|
||||
import zxingcpp
|
||||
|
||||
ZXING_AVAILIBLE = True
|
||||
except ImportError:
|
||||
ZXING_AVAILIBLE = False
|
||||
|
||||
|
||||
@override_settings(CONSUMER_BARCODE_SCANNER="PYZBAR")
|
||||
class TestBarcode(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
@@ -459,7 +451,7 @@ class TestBarcode(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
self.assertDictEqual(separator_page_numbers, {})
|
||||
|
||||
@override_settings(CONSUMER_BARCODE_STRING="ADAR-NEXTDOC")
|
||||
def test_scan_file_for_separating_qr_barcodes(self):
|
||||
def test_scan_file_qr_barcodes_was_problem(self):
|
||||
"""
|
||||
GIVEN:
|
||||
- Input PDF with certain QR codes that aren't detected at current size
|
||||
@@ -1068,7 +1060,7 @@ class TestAsnBarcode(DirectoriesMixin, TestCase):
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not ZXING_AVAILIBLE,
|
||||
platform.machine().upper() not in {"AMD64"},
|
||||
reason="No zxingcpp",
|
||||
)
|
||||
@override_settings(CONSUMER_BARCODE_SCANNER="ZXING")
|
||||
@@ -1077,7 +1069,7 @@ class TestBarcodeZxing(TestBarcode):
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
not ZXING_AVAILIBLE,
|
||||
platform.machine().upper() not in {"AMD64"},
|
||||
reason="No zxingcpp",
|
||||
)
|
||||
@override_settings(CONSUMER_BARCODE_SCANNER="ZXING")
|
||||
|
@@ -386,7 +386,6 @@ class TestClassifier(DirectoriesMixin, TestCase):
|
||||
# rebuilding the file and committing that. Not developer friendly
|
||||
# Need to rethink how to pass the load through to a file with a single
|
||||
# old model?
|
||||
pass
|
||||
|
||||
def test_one_correspondent_predict(self):
|
||||
c1 = Correspondent.objects.create(
|
||||
@@ -516,7 +515,7 @@ class TestClassifier(DirectoriesMixin, TestCase):
|
||||
self.assertListEqual(self.classifier.predict_tags(doc1.content), [t1.pk])
|
||||
|
||||
def test_one_tag_predict_unassigned(self):
|
||||
t1 = Tag.objects.create(name="t1", matching_algorithm=Tag.MATCH_AUTO, pk=12)
|
||||
Tag.objects.create(name="t1", matching_algorithm=Tag.MATCH_AUTO, pk=12)
|
||||
|
||||
doc1 = Document.objects.create(
|
||||
title="doc1",
|
||||
@@ -643,7 +642,7 @@ class TestClassifier(DirectoriesMixin, TestCase):
|
||||
self.assertIsNotNone(classifier)
|
||||
|
||||
with mock.patch("documents.classifier.DocumentClassifier.load") as load:
|
||||
classifier2 = load_classifier()
|
||||
load_classifier()
|
||||
load.assert_not_called()
|
||||
|
||||
@mock.patch("documents.classifier.DocumentClassifier.load")
|
||||
|
@@ -12,23 +12,23 @@ from dateutil import tz
|
||||
try:
|
||||
import zoneinfo
|
||||
except ImportError:
|
||||
import backports.zoneinfo as zoneinfo
|
||||
from backports import zoneinfo
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
|
||||
from ..consumer import Consumer
|
||||
from ..consumer import ConsumerError
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from ..models import DocumentType
|
||||
from ..models import FileInfo
|
||||
from ..models import Tag
|
||||
from ..parsers import DocumentParser
|
||||
from ..parsers import ParseError
|
||||
from ..tasks import sanity_check
|
||||
from documents.consumer import Consumer
|
||||
from documents.consumer import ConsumerError
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import FileInfo
|
||||
from documents.models import Tag
|
||||
from documents.parsers import DocumentParser
|
||||
from documents.parsers import ParseError
|
||||
from documents.tasks import sanity_check
|
||||
from .utils import DirectoriesMixin
|
||||
from documents.tests.utils import FileSystemAssertsMixin
|
||||
|
||||
@@ -72,8 +72,8 @@ class TestFieldPermutations(TestCase):
|
||||
"20150102030405Z",
|
||||
"20150102Z",
|
||||
)
|
||||
valid_correspondents = ["timmy", "Dr. McWheelie", "Dash Gor-don", "ο Θερμαστής", ""]
|
||||
valid_titles = ["title", "Title w Spaces", "Title a-dash", "Τίτλος", ""]
|
||||
valid_correspondents = ["timmy", "Dr. McWheelie", "Dash Gor-don", "o Θεpμaoτής", ""]
|
||||
valid_titles = ["title", "Title w Spaces", "Title a-dash", "Tίτλoς", ""]
|
||||
valid_tags = ["tag", "tig,tag", "tag1,tag2,tag-3"]
|
||||
|
||||
def _test_guessed_attributes(
|
||||
@@ -135,9 +135,7 @@ class TestFieldPermutations(TestCase):
|
||||
filename = "tag1,tag2_20190908_180610_0001.pdf"
|
||||
all_patt = re.compile("^.*$")
|
||||
none_patt = re.compile("$a")
|
||||
exact_patt = re.compile("^([a-z0-9,]+)_(\\d{8})_(\\d{6})_([0-9]+)\\.")
|
||||
repl1 = " - \\4 - \\1." # (empty) corrspondent, title and tags
|
||||
repl2 = "\\2Z - " + repl1 # creation date + repl1
|
||||
re.compile("^([a-z0-9,]+)_(\\d{8})_(\\d{6})_([0-9]+)\\.")
|
||||
|
||||
# No transformations configured (= default)
|
||||
info = FileInfo.from_filename(filename)
|
||||
@@ -177,10 +175,6 @@ class TestFieldPermutations(TestCase):
|
||||
|
||||
|
||||
class DummyParser(DocumentParser):
|
||||
def get_thumbnail(self, document_path, mime_type, file_name=None):
|
||||
# not important during tests
|
||||
raise NotImplementedError()
|
||||
|
||||
def __init__(self, logging_group, scratch_dir, archive_path):
|
||||
super().__init__(logging_group, None)
|
||||
_, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=scratch_dir)
|
||||
@@ -197,9 +191,6 @@ class CopyParser(DocumentParser):
|
||||
def get_thumbnail(self, document_path, mime_type, file_name=None):
|
||||
return self.fake_thumb
|
||||
|
||||
def get_thumbnail(self, document_path, mime_type, file_name=None):
|
||||
return self.fake_thumb
|
||||
|
||||
def __init__(self, logging_group, progress_callback=None):
|
||||
super().__init__(logging_group, progress_callback)
|
||||
_, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=self.tempdir)
|
||||
@@ -211,10 +202,6 @@ class CopyParser(DocumentParser):
|
||||
|
||||
|
||||
class FaultyParser(DocumentParser):
|
||||
def get_thumbnail(self, document_path, mime_type, file_name=None):
|
||||
# not important during tests
|
||||
raise NotImplementedError()
|
||||
|
||||
def __init__(self, logging_group, scratch_dir):
|
||||
super().__init__(logging_group)
|
||||
_, self.fake_thumb = tempfile.mkstemp(suffix=".webp", dir=scratch_dir)
|
||||
|
@@ -46,7 +46,7 @@ class TestDate(TestCase):
|
||||
)
|
||||
|
||||
def test_date_format_5(self):
|
||||
text = "lorem ipsum 130218, 2018, 20180213 and lorem 13.02.2018 lorem " "ipsum"
|
||||
text = "lorem ipsum 130218, 2018, 20180213 and lorem 13.02.2018 lorem ipsum"
|
||||
date = parse_date("", text)
|
||||
self.assertEqual(
|
||||
date,
|
||||
@@ -68,7 +68,7 @@ class TestDate(TestCase):
|
||||
self.assertEqual(parse_date("", text), None)
|
||||
|
||||
def test_date_format_7(self):
|
||||
text = "lorem ipsum\n" "März 2019\n" "lorem ipsum"
|
||||
text = "lorem ipsum\nMärz 2019\nlorem ipsum"
|
||||
date = parse_date("", text)
|
||||
self.assertEqual(
|
||||
date,
|
||||
@@ -95,7 +95,7 @@ class TestDate(TestCase):
|
||||
|
||||
@override_settings(SCRATCH_DIR=SCRATCH)
|
||||
def test_date_format_9(self):
|
||||
text = "lorem ipsum\n" "27. Nullmonth 2020\n" "März 2020\n" "lorem ipsum"
|
||||
text = "lorem ipsum\n27. Nullmonth 2020\nMärz 2020\nlorem ipsum"
|
||||
self.assertEqual(
|
||||
parse_date("", text),
|
||||
datetime.datetime(2020, 3, 1, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)),
|
||||
@@ -262,7 +262,7 @@ class TestDate(TestCase):
|
||||
THEN:
|
||||
- Should parse the date non-ignored date from content
|
||||
"""
|
||||
text = "lorem ipsum 110319, 20200117 and lorem 13.02.2018 lorem " "ipsum"
|
||||
text = "lorem ipsum 110319, 20200117 and lorem 13.02.2018 lorem ipsum"
|
||||
self.assertEqual(
|
||||
parse_date("", text),
|
||||
datetime.datetime(2018, 2, 13, 0, 0, tzinfo=tz.gettz(settings.TIME_ZONE)),
|
||||
@@ -283,7 +283,7 @@ class TestDate(TestCase):
|
||||
THEN:
|
||||
- Should parse the date non-ignored date from content
|
||||
"""
|
||||
text = "lorem ipsum 190311, 20200117 and lorem 13.02.2018 lorem " "ipsum"
|
||||
text = "lorem ipsum 190311, 20200117 and lorem 13.02.2018 lorem ipsum"
|
||||
|
||||
self.assertEqual(
|
||||
parse_date("", text),
|
||||
|
@@ -6,14 +6,14 @@ from unittest import mock
|
||||
try:
|
||||
import zoneinfo
|
||||
except ImportError:
|
||||
import backports.zoneinfo as zoneinfo
|
||||
from backports import zoneinfo
|
||||
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
|
||||
|
||||
class TestDocument(TestCase):
|
||||
|
@@ -10,17 +10,16 @@ from django.db import DatabaseError
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
from django.utils import timezone
|
||||
from documents.tests.utils import FileSystemAssertsMixin
|
||||
|
||||
from ..file_handling import create_source_path_directory
|
||||
from ..file_handling import delete_empty_directories
|
||||
from ..file_handling import generate_filename
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from ..models import DocumentType
|
||||
from ..models import StoragePath
|
||||
from .utils import DirectoriesMixin
|
||||
from .utils import FileSystemAssertsMixin
|
||||
from documents.file_handling import create_source_path_directory
|
||||
from documents.file_handling import delete_empty_directories
|
||||
from documents.file_handling import generate_filename
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import StoragePath
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
from documents.tests.utils import FileSystemAssertsMixin
|
||||
|
||||
|
||||
class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
@@ -121,7 +120,7 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
@override_settings(FILENAME_FORMAT="{correspondent}/{correspondent}")
|
||||
def test_file_renaming_database_error(self):
|
||||
|
||||
document1 = Document.objects.create(
|
||||
Document.objects.create(
|
||||
mime_type="application/pdf",
|
||||
storage_type=Document.STORAGE_TYPE_UNENCRYPTED,
|
||||
checksum="AAAAA",
|
||||
@@ -171,7 +170,6 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
Path(document.source_path).touch()
|
||||
|
||||
# Ensure file deletion after delete
|
||||
pk = document.pk
|
||||
document.delete()
|
||||
self.assertIsNotFile(
|
||||
os.path.join(settings.ORIGINALS_DIR, "none", "none.pdf"),
|
||||
@@ -440,7 +438,6 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
# Check proper handling of files
|
||||
self.assertIsDir(os.path.join(settings.ORIGINALS_DIR, "none/none"))
|
||||
|
||||
pk = document.pk
|
||||
document.delete()
|
||||
|
||||
self.assertIsNotFile(
|
||||
@@ -705,7 +702,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
|
||||
def test_move_archive_error(self, m):
|
||||
def fake_rename(src, dst):
|
||||
if "archive" in str(src):
|
||||
raise OSError()
|
||||
raise OSError
|
||||
else:
|
||||
os.remove(src)
|
||||
Path(dst).touch()
|
||||
@@ -756,7 +753,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
|
||||
def test_move_file_error(self, m):
|
||||
def fake_rename(src, dst):
|
||||
if "original" in str(src):
|
||||
raise OSError()
|
||||
raise OSError
|
||||
else:
|
||||
os.remove(src)
|
||||
Path(dst).touch()
|
||||
|
@@ -2,7 +2,7 @@ from django.core.management.base import CommandError
|
||||
from django.test import TestCase
|
||||
from documents.settings import EXPORTER_FILE_NAME
|
||||
|
||||
from ..management.commands.document_importer import Command
|
||||
from documents.management.commands.document_importer import Command
|
||||
|
||||
|
||||
class TestImporter(TestCase):
|
||||
|
@@ -13,7 +13,6 @@ from django.test import override_settings
|
||||
from django.test import TransactionTestCase
|
||||
from documents.consumer import ConsumerError
|
||||
from documents.data_models import ConsumableDocument
|
||||
from documents.data_models import DocumentMetadataOverrides
|
||||
from documents.management.commands import document_consumer
|
||||
from documents.models import Tag
|
||||
from documents.tests.utils import DirectoriesMixin
|
||||
|
@@ -204,7 +204,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
self.assertEqual(element["fields"]["document"], self.d1.id)
|
||||
self.assertEqual(element["fields"]["user"], self.user.id)
|
||||
|
||||
with paperless_environment() as dirs:
|
||||
with paperless_environment():
|
||||
self.assertEqual(Document.objects.count(), 4)
|
||||
Document.objects.all().delete()
|
||||
Correspondent.objects.all().delete()
|
||||
@@ -345,7 +345,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
os.path.join(self.dirs.media_dir, "documents"),
|
||||
)
|
||||
|
||||
m = self._do_export(use_filename_format=True)
|
||||
self._do_export(use_filename_format=True)
|
||||
self.assertIsFile(os.path.join(self.target, "wow1", "c.pdf"))
|
||||
|
||||
self.assertIsFile(os.path.join(self.target, "manifest.json"))
|
||||
@@ -537,7 +537,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
)
|
||||
self.assertFalse(has_archive)
|
||||
|
||||
with paperless_environment() as dirs:
|
||||
with paperless_environment():
|
||||
self.assertEqual(Document.objects.count(), 4)
|
||||
Document.objects.all().delete()
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
@@ -580,7 +580,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
)
|
||||
self.assertFalse(has_thumbnail)
|
||||
|
||||
with paperless_environment() as dirs:
|
||||
with paperless_environment():
|
||||
self.assertEqual(Document.objects.count(), 4)
|
||||
Document.objects.all().delete()
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
@@ -609,7 +609,7 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
has_document = has_document or element["model"] == "documents.document"
|
||||
self.assertFalse(has_document)
|
||||
|
||||
with paperless_environment() as dirs:
|
||||
with paperless_environment():
|
||||
self.assertEqual(Document.objects.count(), 4)
|
||||
Document.objects.all().delete()
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
@@ -631,9 +631,9 @@ class TestExportImport(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||
os.path.join(self.dirs.media_dir, "documents"),
|
||||
)
|
||||
|
||||
manifest = self._do_export(use_folder_prefix=True)
|
||||
self._do_export(use_folder_prefix=True)
|
||||
|
||||
with paperless_environment() as dirs:
|
||||
with paperless_environment():
|
||||
self.assertEqual(Document.objects.count(), 4)
|
||||
Document.objects.all().delete()
|
||||
self.assertEqual(Document.objects.count(), 0)
|
||||
|
@@ -8,12 +8,12 @@ from django.contrib.auth.models import User
|
||||
from django.test import override_settings
|
||||
from django.test import TestCase
|
||||
|
||||
from .. import matching
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from ..models import DocumentType
|
||||
from ..models import Tag
|
||||
from ..signals import document_consumption_finished
|
||||
from documents import matching
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
from documents.models import DocumentType
|
||||
from documents.models import Tag
|
||||
from documents.signals import document_consumption_finished
|
||||
|
||||
|
||||
class _TestMatchingBase(TestCase):
|
||||
|
@@ -310,7 +310,7 @@ class TestMigrateArchiveFilesErrors(DirectoriesMixin, TestMigrations):
|
||||
def test_parser_missing(self):
|
||||
Document = self.apps.get_model("documents", "Document")
|
||||
|
||||
doc1 = make_test_document(
|
||||
make_test_document(
|
||||
Document,
|
||||
"document",
|
||||
"invalid/typesss768",
|
||||
@@ -318,7 +318,7 @@ class TestMigrateArchiveFilesErrors(DirectoriesMixin, TestMigrations):
|
||||
"document.png",
|
||||
simple_pdf,
|
||||
)
|
||||
doc2 = make_test_document(
|
||||
make_test_document(
|
||||
Document,
|
||||
"document",
|
||||
"invalid/typesss768",
|
||||
@@ -462,7 +462,7 @@ class TestMigrateArchiveFilesBackwards(
|
||||
|
||||
Document = apps.get_model("documents", "Document")
|
||||
|
||||
doc_unrelated = make_test_document(
|
||||
make_test_document(
|
||||
Document,
|
||||
"unrelated",
|
||||
"application/pdf",
|
||||
@@ -471,14 +471,14 @@ class TestMigrateArchiveFilesBackwards(
|
||||
simple_pdf2,
|
||||
"unrelated.pdf",
|
||||
)
|
||||
doc_no_archive = make_test_document(
|
||||
make_test_document(
|
||||
Document,
|
||||
"no_archive",
|
||||
"text/plain",
|
||||
simple_txt,
|
||||
"no_archive.txt",
|
||||
)
|
||||
clashB = make_test_document(
|
||||
make_test_document(
|
||||
Document,
|
||||
"clash",
|
||||
"image/jpeg",
|
||||
|
@@ -1,14 +1,14 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from ..models import Correspondent
|
||||
from ..models import Document
|
||||
from documents.models import Correspondent
|
||||
from documents.models import Document
|
||||
from .factories import CorrespondentFactory
|
||||
from .factories import DocumentFactory
|
||||
|
||||
|
||||
class CorrespondentTestCase(TestCase):
|
||||
def test___str__(self):
|
||||
for s in ("test", "οχι", "test with fun_charÅc'\"terß"):
|
||||
for s in ("test", "oχi", "test with fun_charÅc'\"terß"):
|
||||
correspondent = CorrespondentFactory.create(name=s)
|
||||
self.assertEqual(str(correspondent), s)
|
||||
|
||||
|
@@ -94,7 +94,7 @@ class TestParserDiscovery(TestCase):
|
||||
- No parser class is returned
|
||||
"""
|
||||
m.return_value = []
|
||||
with TemporaryDirectory() as tmpdir:
|
||||
with TemporaryDirectory():
|
||||
self.assertIsNone(get_parser_class_for_mime_type("application/pdf"))
|
||||
|
||||
@mock.patch("documents.parsers.document_consumer_declaration.send")
|
||||
|
@@ -149,7 +149,7 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
|
||||
)
|
||||
|
||||
def test_orphaned_file(self):
|
||||
doc = self.make_test_data()
|
||||
self.make_test_data()
|
||||
Path(self.dirs.originals_dir, "orphaned").touch()
|
||||
messages = check_sanity()
|
||||
self.assertTrue(messages.has_warning)
|
||||
|
@@ -4,7 +4,6 @@ from unittest import mock
|
||||
import celery
|
||||
from django.test import TestCase
|
||||
from documents.data_models import ConsumableDocument
|
||||
from documents.data_models import DocumentMetadataOverrides
|
||||
from documents.data_models import DocumentSource
|
||||
from documents.models import PaperlessTask
|
||||
from documents.signals.handlers import before_task_publish_handler
|
||||
|
@@ -47,7 +47,7 @@ class TestViews(TestCase):
|
||||
self.client.cookies.load(
|
||||
{settings.LANGUAGE_COOKIE_NAME: language_given},
|
||||
)
|
||||
elif settings.LANGUAGE_COOKIE_NAME in self.client.cookies.keys():
|
||||
elif settings.LANGUAGE_COOKIE_NAME in self.client.cookies:
|
||||
self.client.cookies.pop(settings.LANGUAGE_COOKIE_NAME)
|
||||
|
||||
response = self.client.get(
|
||||
|
Reference in New Issue
Block a user