mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-24 02:02:23 -04:00
Some obvious fixes
This commit is contained in:
parent
83ca4ef69b
commit
8891d5ca16
@ -176,7 +176,7 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"env_key": "PAPERLESS_TRAIN_TASK_CRON",
|
"env_key": "PAPERLESS_TRAIN_TASK_CRON",
|
||||||
# Default hourly at 5 minutes past the hour
|
# Default hourly at 5 minutes past the hour
|
||||||
"env_default": "5 */1 * * *",
|
"env_default": "5 */1 * * *",
|
||||||
"task": "documents.tasks.train_classifier",
|
"task": "paperless.tasks.train_classifier",
|
||||||
"options": {
|
"options": {
|
||||||
# 1 minute before default schedule sends again
|
# 1 minute before default schedule sends again
|
||||||
"expires": 59.0 * 60.0,
|
"expires": 59.0 * 60.0,
|
||||||
@ -187,7 +187,7 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"env_key": "PAPERLESS_INDEX_TASK_CRON",
|
"env_key": "PAPERLESS_INDEX_TASK_CRON",
|
||||||
# Default daily at midnight
|
# Default daily at midnight
|
||||||
"env_default": "0 0 * * *",
|
"env_default": "0 0 * * *",
|
||||||
"task": "documents.tasks.index_optimize",
|
"task": "paperless.tasks.index_optimize",
|
||||||
"options": {
|
"options": {
|
||||||
# 1 hour before default schedule sends again
|
# 1 hour before default schedule sends again
|
||||||
"expires": 23.0 * 60.0 * 60.0,
|
"expires": 23.0 * 60.0 * 60.0,
|
||||||
@ -198,7 +198,7 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"env_key": "PAPERLESS_SANITY_TASK_CRON",
|
"env_key": "PAPERLESS_SANITY_TASK_CRON",
|
||||||
# Default Sunday at 00:30
|
# Default Sunday at 00:30
|
||||||
"env_default": "30 0 * * sun",
|
"env_default": "30 0 * * sun",
|
||||||
"task": "documents.tasks.sanity_check",
|
"task": "paperless.tasks.sanity_check",
|
||||||
"options": {
|
"options": {
|
||||||
# 1 hour before default schedule sends again
|
# 1 hour before default schedule sends again
|
||||||
"expires": ((7.0 * 24.0) - 1.0) * 60.0 * 60.0,
|
"expires": ((7.0 * 24.0) - 1.0) * 60.0 * 60.0,
|
||||||
@ -209,7 +209,7 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"env_key": "PAPERLESS_EMPTY_TRASH_TASK_CRON",
|
"env_key": "PAPERLESS_EMPTY_TRASH_TASK_CRON",
|
||||||
# Default daily at 01:00
|
# Default daily at 01:00
|
||||||
"env_default": "0 1 * * *",
|
"env_default": "0 1 * * *",
|
||||||
"task": "documents.tasks.empty_trash",
|
"task": "paperless.tasks.empty_trash",
|
||||||
"options": {
|
"options": {
|
||||||
# 1 hour before default schedule sends again
|
# 1 hour before default schedule sends again
|
||||||
"expires": 23.0 * 60.0 * 60.0,
|
"expires": 23.0 * 60.0 * 60.0,
|
||||||
@ -220,7 +220,7 @@ def _parse_beat_schedule() -> dict:
|
|||||||
"env_key": "PAPERLESS_WORKFLOW_SCHEDULED_TASK_CRON",
|
"env_key": "PAPERLESS_WORKFLOW_SCHEDULED_TASK_CRON",
|
||||||
# Default hourly at 5 minutes past the hour
|
# Default hourly at 5 minutes past the hour
|
||||||
"env_default": "5 */1 * * *",
|
"env_default": "5 */1 * * *",
|
||||||
"task": "documents.tasks.check_scheduled_workflows",
|
"task": "paperless.tasks.check_scheduled_workflows",
|
||||||
"options": {
|
"options": {
|
||||||
# 1 minute before default schedule sends again
|
# 1 minute before default schedule sends again
|
||||||
"expires": 59.0 * 60.0,
|
"expires": 59.0 * 60.0,
|
||||||
@ -443,7 +443,7 @@ TEMPLATES = [
|
|||||||
"django.template.context_processors.request",
|
"django.template.context_processors.request",
|
||||||
"django.contrib.auth.context_processors.auth",
|
"django.contrib.auth.context_processors.auth",
|
||||||
"django.contrib.messages.context_processors.messages",
|
"django.contrib.messages.context_processors.messages",
|
||||||
"documents.context_processors.settings",
|
"paperless.context_processors.settings",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1278,7 +1278,7 @@ def before_task_publish_handler(sender=None, headers=None, body=None, **kwargs):
|
|||||||
https://docs.celeryq.dev/en/stable/internals/protocol.html#version-2
|
https://docs.celeryq.dev/en/stable/internals/protocol.html#version-2
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if "task" not in headers or headers["task"] != "documents.tasks.consume_file":
|
if "task" not in headers or headers["task"] != "paperless.tasks.consume_file":
|
||||||
# Assumption: this is only ever a v2 message
|
# Assumption: this is only ever a v2 message
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.user = user
|
self.user = user
|
||||||
self.client.force_authenticate(user=user)
|
self.client.force_authenticate(user=user)
|
||||||
|
|
||||||
patcher = mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
patcher = mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
self.async_task = patcher.start()
|
self.async_task = patcher.start()
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
self.c1 = Correspondent.objects.create(name="c1")
|
self.c1 = Correspondent.objects.create(name="c1")
|
||||||
@ -61,7 +61,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
m.return_value = return_value
|
m.return_value = return_value
|
||||||
m.__name__ = method_name
|
m.__name__ = method_name
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_set_correspondent(self, bulk_update_task_mock):
|
def test_api_set_correspondent(self, bulk_update_task_mock):
|
||||||
self.assertNotEqual(self.doc1.correspondent, self.c1)
|
self.assertNotEqual(self.doc1.correspondent, self.c1)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@ -80,7 +80,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(self.doc1.correspondent, self.c1)
|
self.assertEqual(self.doc1.correspondent, self.c1)
|
||||||
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_unset_correspondent(self, bulk_update_task_mock):
|
def test_api_unset_correspondent(self, bulk_update_task_mock):
|
||||||
self.doc1.correspondent = self.c1
|
self.doc1.correspondent = self.c1
|
||||||
self.doc1.save()
|
self.doc1.save()
|
||||||
@ -102,7 +102,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.doc1.refresh_from_db()
|
self.doc1.refresh_from_db()
|
||||||
self.assertIsNone(self.doc1.correspondent)
|
self.assertIsNone(self.doc1.correspondent)
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_set_type(self, bulk_update_task_mock):
|
def test_api_set_type(self, bulk_update_task_mock):
|
||||||
self.assertNotEqual(self.doc1.document_type, self.dt1)
|
self.assertNotEqual(self.doc1.document_type, self.dt1)
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@ -121,7 +121,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(self.doc1.document_type, self.dt1)
|
self.assertEqual(self.doc1.document_type, self.dt1)
|
||||||
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_unset_type(self, bulk_update_task_mock):
|
def test_api_unset_type(self, bulk_update_task_mock):
|
||||||
self.doc1.document_type = self.dt1
|
self.doc1.document_type = self.dt1
|
||||||
self.doc1.save()
|
self.doc1.save()
|
||||||
@ -142,7 +142,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
self.assertIsNone(self.doc1.document_type)
|
self.assertIsNone(self.doc1.document_type)
|
||||||
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_add_tag(self, bulk_update_task_mock):
|
def test_api_add_tag(self, bulk_update_task_mock):
|
||||||
self.assertFalse(self.doc1.tags.filter(pk=self.t1.pk).exists())
|
self.assertFalse(self.doc1.tags.filter(pk=self.t1.pk).exists())
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class TestBulkEditAPI(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
bulk_update_task_mock.assert_called_once_with(document_ids=[self.doc1.pk])
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_remove_tag(self, bulk_update_task_mock):
|
def test_api_remove_tag(self, bulk_update_task_mock):
|
||||||
self.doc1.tags.add(self.t1)
|
self.doc1.tags.add(self.t1)
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ class TestApiStoragePaths(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
self.assertEqual(StoragePath.objects.count(), 2)
|
self.assertEqual(StoragePath.objects.count(), 2)
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_update_storage_path(self, bulk_update_mock):
|
def test_api_update_storage_path(self, bulk_update_mock):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -277,7 +277,7 @@ class TestApiStoragePaths(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertCountEqual([document.pk], args[0])
|
self.assertCountEqual([document.pk], args[0])
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
def test_api_delete_storage_path(self, bulk_update_mock):
|
def test_api_delete_storage_path(self, bulk_update_mock):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
@ -1160,7 +1160,7 @@ class TestDocumentSearchApi(DirectoriesMixin, APITestCase):
|
|||||||
[d3.id, d2.id, d1.id],
|
[d3.id, d2.id, d1.id],
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.bulk_update_documents")
|
@mock.patch("paperless.bulk_edit.bulk_update_documents")
|
||||||
def test_global_search(self, m):
|
def test_global_search(self, m):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
@ -348,7 +348,7 @@ class TestTasks(DirectoriesMixin, APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
|
self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
mock_train_classifier.assert_called_once_with(scheduled=False)
|
mock_train_classifier.assert_called_once_with(scheduled=False)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.sanity_check")
|
@mock.patch("paperless.tasks.sanity_check")
|
||||||
def test_run_task_requires_superuser(self, mock_check_sanity):
|
def test_run_task_requires_superuser(self, mock_check_sanity):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
|
@ -575,7 +575,7 @@ class TestBarcodeNewConsume(
|
|||||||
|
|
||||||
overrides = DocumentMetadataOverrides(tag_ids=[1, 2, 9])
|
overrides = DocumentMetadataOverrides(tag_ids=[1, 2, 9])
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -711,7 +711,7 @@ class TestAsnBarcode(DirectoriesMixin, SampleDirMixin, GetReaderPluginMixin, Tes
|
|||||||
dst = settings.SCRATCH_DIR / "barcode-39-asn-123.pdf"
|
dst = settings.SCRATCH_DIR / "barcode-39-asn-123.pdf"
|
||||||
shutil.copy(test_file, dst)
|
shutil.copy(test_file, dst)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
source=DocumentSource.ConsumeFolder,
|
source=DocumentSource.ConsumeFolder,
|
||||||
|
@ -30,7 +30,7 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
|||||||
self.group1 = Group.objects.create(name="group1")
|
self.group1 = Group.objects.create(name="group1")
|
||||||
self.group2 = Group.objects.create(name="group2")
|
self.group2 = Group.objects.create(name="group2")
|
||||||
|
|
||||||
patcher = mock.patch("documents.bulk_edit.bulk_update_documents.delay")
|
patcher = mock.patch("paperless.bulk_edit.bulk_update_documents.delay")
|
||||||
self.async_task = patcher.start()
|
self.async_task = patcher.start()
|
||||||
self.addCleanup(patcher.stop)
|
self.addCleanup(patcher.stop)
|
||||||
self.c1 = Correspondent.objects.create(name="c1")
|
self.c1 = Correspondent.objects.create(name="c1")
|
||||||
@ -345,7 +345,7 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
|||||||
[self.doc3.id, self.doc4.id, self.doc5.id],
|
[self.doc3.id, self.doc4.id, self.doc5.id],
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.bulk_update_documents.delay")
|
@mock.patch("paperless.tasks.bulk_update_documents.delay")
|
||||||
def test_set_permissions(self, m):
|
def test_set_permissions(self, m):
|
||||||
doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id]
|
doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id]
|
||||||
|
|
||||||
@ -384,7 +384,7 @@ class TestBulkEdit(DirectoriesMixin, TestCase):
|
|||||||
)
|
)
|
||||||
self.assertEqual(groups_with_perms.count(), 1)
|
self.assertEqual(groups_with_perms.count(), 1)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.bulk_update_documents.delay")
|
@mock.patch("paperless.tasks.bulk_update_documents.delay")
|
||||||
def test_set_permissions_merge(self, m):
|
def test_set_permissions_merge(self, m):
|
||||||
doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id]
|
doc_ids = [self.doc1.id, self.doc2.id, self.doc3.id]
|
||||||
|
|
||||||
@ -532,7 +532,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
self.img_doc.archive_filename = img_doc_archive
|
self.img_doc.archive_filename = img_doc_archive
|
||||||
self.img_doc.save()
|
self.img_doc.save()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.consume_file.s")
|
@mock.patch("paperless.tasks.consume_file.s")
|
||||||
def test_merge(self, mock_consume_file):
|
def test_merge(self, mock_consume_file):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -572,9 +572,9 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
self.assertEqual(result, "OK")
|
self.assertEqual(result, "OK")
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.delete.si")
|
@mock.patch("paperless.bulk_edit.delete.si")
|
||||||
@mock.patch("documents.tasks.consume_file.s")
|
@mock.patch("paperless.tasks.consume_file.s")
|
||||||
@mock.patch("documents.bulk_edit.chain")
|
@mock.patch("paperless.bulk_edit.chain")
|
||||||
def test_merge_and_delete_originals(
|
def test_merge_and_delete_originals(
|
||||||
self,
|
self,
|
||||||
mock_chain,
|
mock_chain,
|
||||||
@ -616,7 +616,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
doc_ids,
|
doc_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.consume_file.s")
|
@mock.patch("paperless.tasks.consume_file.s")
|
||||||
def test_merge_with_archive_fallback(self, mock_consume_file):
|
def test_merge_with_archive_fallback(self, mock_consume_file):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -642,7 +642,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
expected_filename,
|
expected_filename,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.consume_file.delay")
|
@mock.patch("paperless.tasks.consume_file.delay")
|
||||||
@mock.patch("pikepdf.open")
|
@mock.patch("pikepdf.open")
|
||||||
def test_merge_with_errors(self, mock_open_pdf, mock_consume_file):
|
def test_merge_with_errors(self, mock_open_pdf, mock_consume_file):
|
||||||
"""
|
"""
|
||||||
@ -667,7 +667,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
mock_consume_file.assert_not_called()
|
mock_consume_file.assert_not_called()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.consume_file.s")
|
@mock.patch("paperless.tasks.consume_file.s")
|
||||||
def test_split(self, mock_consume_file):
|
def test_split(self, mock_consume_file):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -687,9 +687,9 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
self.assertEqual(result, "OK")
|
self.assertEqual(result, "OK")
|
||||||
|
|
||||||
@mock.patch("documents.bulk_edit.delete.si")
|
@mock.patch("paperless.bulk_edit.delete.si")
|
||||||
@mock.patch("documents.tasks.consume_file.s")
|
@mock.patch("paperless.tasks.consume_file.s")
|
||||||
@mock.patch("documents.bulk_edit.chord")
|
@mock.patch("paperless.bulk_edit.chord")
|
||||||
def test_split_and_delete_originals(
|
def test_split_and_delete_originals(
|
||||||
self,
|
self,
|
||||||
mock_chord,
|
mock_chord,
|
||||||
@ -725,7 +725,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
doc_ids,
|
doc_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.consume_file.delay")
|
@mock.patch("paperless.tasks.consume_file.delay")
|
||||||
@mock.patch("pikepdf.Pdf.save")
|
@mock.patch("pikepdf.Pdf.save")
|
||||||
def test_split_with_errors(self, mock_save_pdf, mock_consume_file):
|
def test_split_with_errors(self, mock_save_pdf, mock_consume_file):
|
||||||
"""
|
"""
|
||||||
@ -749,8 +749,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
mock_consume_file.assert_not_called()
|
mock_consume_file.assert_not_called()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.bulk_update_documents.si")
|
@mock.patch("paperless.tasks.bulk_update_documents.si")
|
||||||
@mock.patch("documents.tasks.update_document_content_maybe_archive_file.s")
|
@mock.patch("paperless.tasks.update_document_content_maybe_archive_file.s")
|
||||||
@mock.patch("celery.chord.delay")
|
@mock.patch("celery.chord.delay")
|
||||||
def test_rotate(self, mock_chord, mock_update_document, mock_update_documents):
|
def test_rotate(self, mock_chord, mock_update_document, mock_update_documents):
|
||||||
"""
|
"""
|
||||||
@ -768,8 +768,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
mock_chord.assert_called_once()
|
mock_chord.assert_called_once()
|
||||||
self.assertEqual(result, "OK")
|
self.assertEqual(result, "OK")
|
||||||
|
|
||||||
@mock.patch("documents.tasks.bulk_update_documents.si")
|
@mock.patch("paperless.tasks.bulk_update_documents.si")
|
||||||
@mock.patch("documents.tasks.update_document_content_maybe_archive_file.s")
|
@mock.patch("paperless.tasks.update_document_content_maybe_archive_file.s")
|
||||||
@mock.patch("pikepdf.Pdf.save")
|
@mock.patch("pikepdf.Pdf.save")
|
||||||
def test_rotate_with_error(
|
def test_rotate_with_error(
|
||||||
self,
|
self,
|
||||||
@ -796,8 +796,8 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
self.assertIn(expected_str, error_str)
|
self.assertIn(expected_str, error_str)
|
||||||
mock_update_archive_file.assert_not_called()
|
mock_update_archive_file.assert_not_called()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.bulk_update_documents.si")
|
@mock.patch("paperless.tasks.bulk_update_documents.si")
|
||||||
@mock.patch("documents.tasks.update_document_content_maybe_archive_file.s")
|
@mock.patch("paperless.tasks.update_document_content_maybe_archive_file.s")
|
||||||
@mock.patch("celery.chord.delay")
|
@mock.patch("celery.chord.delay")
|
||||||
def test_rotate_non_pdf(
|
def test_rotate_non_pdf(
|
||||||
self,
|
self,
|
||||||
@ -823,7 +823,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
mock_chord.assert_called_once()
|
mock_chord.assert_called_once()
|
||||||
self.assertEqual(result, "OK")
|
self.assertEqual(result, "OK")
|
||||||
|
|
||||||
@mock.patch("documents.tasks.update_document_content_maybe_archive_file.delay")
|
@mock.patch("paperless.tasks.update_document_content_maybe_archive_file.delay")
|
||||||
@mock.patch("pikepdf.Pdf.save")
|
@mock.patch("pikepdf.Pdf.save")
|
||||||
def test_delete_pages(self, mock_pdf_save, mock_update_archive_file):
|
def test_delete_pages(self, mock_pdf_save, mock_update_archive_file):
|
||||||
"""
|
"""
|
||||||
@ -848,7 +848,7 @@ class TestPDFActions(DirectoriesMixin, TestCase):
|
|||||||
self.doc2.refresh_from_db()
|
self.doc2.refresh_from_db()
|
||||||
self.assertEqual(self.doc2.page_count, expected_page_count)
|
self.assertEqual(self.doc2.page_count, expected_page_count)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.update_document_content_maybe_archive_file.delay")
|
@mock.patch("paperless.tasks.update_document_content_maybe_archive_file.delay")
|
||||||
@mock.patch("pikepdf.Pdf.save")
|
@mock.patch("pikepdf.Pdf.save")
|
||||||
def test_delete_pages_with_error(self, mock_pdf_save, mock_update_archive_file):
|
def test_delete_pages_with_error(self, mock_pdf_save, mock_update_archive_file):
|
||||||
"""
|
"""
|
||||||
|
@ -8,7 +8,6 @@ from django.core.checks import Warning
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from documents.tests.factories import DocumentFactory
|
|
||||||
from paperless.checks import audit_log_check
|
from paperless.checks import audit_log_check
|
||||||
from paperless.checks import binaries_check
|
from paperless.checks import binaries_check
|
||||||
from paperless.checks import changed_password_check
|
from paperless.checks import changed_password_check
|
||||||
@ -18,6 +17,7 @@ from paperless.checks import parser_check
|
|||||||
from paperless.checks import paths_check
|
from paperless.checks import paths_check
|
||||||
from paperless.checks import settings_values_check
|
from paperless.checks import settings_values_check
|
||||||
from paperless.models import Document
|
from paperless.models import Document
|
||||||
|
from paperless.tests.factories import DocumentFactory
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
from paperless.tests.utils import FileSystemAssertsMixin
|
from paperless.tests.utils import FileSystemAssertsMixin
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ class TestDoubleSided(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"documents.tasks.ProgressManager",
|
"paperless.tasks.ProgressManager",
|
||||||
DummyProgressManager,
|
DummyProgressManager,
|
||||||
):
|
):
|
||||||
msg = tasks.consume_file(
|
msg = tasks.consume_file(
|
||||||
|
@ -113,7 +113,7 @@ class TestDecryptDocuments(FileSystemAssertsMixin, TestCase):
|
|||||||
PASSPHRASE="test",
|
PASSPHRASE="test",
|
||||||
FILENAME_FORMAT=None,
|
FILENAME_FORMAT=None,
|
||||||
)
|
)
|
||||||
@mock.patch("documents.management.commands.decrypt_documents.input")
|
@mock.patch("paperless.management.commands.decrypt_documents.input")
|
||||||
def test_decrypt(self, m):
|
def test_decrypt(self, m):
|
||||||
media_dir = tempfile.mkdtemp()
|
media_dir = tempfile.mkdtemp()
|
||||||
originals_dir = Path(media_dir) / "documents" / "originals"
|
originals_dir = Path(media_dir) / "documents" / "originals"
|
||||||
@ -173,12 +173,12 @@ class TestDecryptDocuments(FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestMakeIndex(TestCase):
|
class TestMakeIndex(TestCase):
|
||||||
@mock.patch("documents.management.commands.document_index.index_reindex")
|
@mock.patch("paperless.management.commands.document_index.index_reindex")
|
||||||
def test_reindex(self, m):
|
def test_reindex(self, m):
|
||||||
call_command("document_index", "reindex")
|
call_command("document_index", "reindex")
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_index.index_optimize")
|
@mock.patch("paperless.management.commands.document_index.index_optimize")
|
||||||
def test_optimize(self, m):
|
def test_optimize(self, m):
|
||||||
call_command("document_index", "optimize")
|
call_command("document_index", "optimize")
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
@ -210,7 +210,7 @@ class TestRenamer(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
class TestCreateClassifier(TestCase):
|
class TestCreateClassifier(TestCase):
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
"documents.management.commands.document_create_classifier.train_classifier",
|
"paperless.management.commands.document_create_classifier.train_classifier",
|
||||||
)
|
)
|
||||||
def test_create_classifier(self, m):
|
def test_create_classifier(self, m):
|
||||||
call_command("document_create_classifier")
|
call_command("document_create_classifier")
|
||||||
|
@ -12,9 +12,9 @@ from django.core.management import call_command
|
|||||||
from django.test import TransactionTestCase
|
from django.test import TransactionTestCase
|
||||||
from django.test import override_settings
|
from django.test import override_settings
|
||||||
|
|
||||||
from documents.management.commands import document_consumer
|
|
||||||
from paperless.consumer import ConsumerError
|
from paperless.consumer import ConsumerError
|
||||||
from paperless.data_models import ConsumableDocument
|
from paperless.data_models import ConsumableDocument
|
||||||
|
from paperless.management.commands import document_consumer
|
||||||
from paperless.models import Tag
|
from paperless.models import Tag
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
from paperless.tests.utils import DocumentConsumeDelayMixin
|
from paperless.tests.utils import DocumentConsumeDelayMixin
|
||||||
@ -148,7 +148,7 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
|
|||||||
|
|
||||||
self.assertEqual(input_doc.original_file, f)
|
self.assertEqual(input_doc.original_file, f)
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_consumer.logger.error")
|
@mock.patch("paperless.management.commands.document_consumer.logger.error")
|
||||||
def test_slow_write_pdf(self, error_logger):
|
def test_slow_write_pdf(self, error_logger):
|
||||||
self.consume_file_mock.side_effect = self.bogus_task
|
self.consume_file_mock.side_effect = self.bogus_task
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
|
|||||||
|
|
||||||
self.assertEqual(input_doc.original_file, fname)
|
self.assertEqual(input_doc.original_file, fname)
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_consumer.logger.error")
|
@mock.patch("paperless.management.commands.document_consumer.logger.error")
|
||||||
def test_slow_write_and_move(self, error_logger):
|
def test_slow_write_and_move(self, error_logger):
|
||||||
self.consume_file_mock.side_effect = self.bogus_task
|
self.consume_file_mock.side_effect = self.bogus_task
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
|
|||||||
|
|
||||||
error_logger.assert_not_called()
|
error_logger.assert_not_called()
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_consumer.logger.error")
|
@mock.patch("paperless.management.commands.document_consumer.logger.error")
|
||||||
def test_slow_write_incomplete(self, error_logger):
|
def test_slow_write_incomplete(self, error_logger):
|
||||||
self.consume_file_mock.side_effect = self.bogus_task
|
self.consume_file_mock.side_effect = self.bogus_task
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
|
|||||||
f'_is_ignored("{filepath}") != {expected_ignored_result}',
|
f'_is_ignored("{filepath}") != {expected_ignored_result}',
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_consumer.open")
|
@mock.patch("paperless.management.commands.document_consumer.open")
|
||||||
def test_consume_file_busy(self, open_mock):
|
def test_consume_file_busy(self, open_mock):
|
||||||
# Calling this mock always raises this
|
# Calling this mock always raises this
|
||||||
open_mock.side_effect = OSError
|
open_mock.side_effect = OSError
|
||||||
|
@ -24,8 +24,8 @@ from guardian.models import GroupObjectPermission
|
|||||||
from guardian.models import UserObjectPermission
|
from guardian.models import UserObjectPermission
|
||||||
from guardian.shortcuts import assign_perm
|
from guardian.shortcuts import assign_perm
|
||||||
|
|
||||||
from documents.management.commands import document_exporter
|
|
||||||
from documents.settings import EXPORTER_FILE_NAME
|
from documents.settings import EXPORTER_FILE_NAME
|
||||||
|
from paperless.management.commands import document_exporter
|
||||||
from paperless.models import Correspondent
|
from paperless.models import Correspondent
|
||||||
from paperless.models import CustomField
|
from paperless.models import CustomField
|
||||||
from paperless.models import CustomFieldInstance
|
from paperless.models import CustomFieldInstance
|
||||||
@ -321,7 +321,7 @@ class TestExportImport(
|
|||||||
st_mtime_1 = os.stat(os.path.join(self.target, "manifest.json")).st_mtime
|
st_mtime_1 = os.stat(os.path.join(self.target, "manifest.json")).st_mtime
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"documents.management.commands.document_exporter.copy_file_with_basic_stats",
|
"paperless.management.commands.document_exporter.copy_file_with_basic_stats",
|
||||||
) as m:
|
) as m:
|
||||||
self._do_export()
|
self._do_export()
|
||||||
m.assert_not_called()
|
m.assert_not_called()
|
||||||
@ -332,7 +332,7 @@ class TestExportImport(
|
|||||||
Path(self.d1.source_path).touch()
|
Path(self.d1.source_path).touch()
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"documents.management.commands.document_exporter.copy_file_with_basic_stats",
|
"paperless.management.commands.document_exporter.copy_file_with_basic_stats",
|
||||||
) as m:
|
) as m:
|
||||||
self._do_export()
|
self._do_export()
|
||||||
self.assertEqual(m.call_count, 1)
|
self.assertEqual(m.call_count, 1)
|
||||||
@ -359,7 +359,7 @@ class TestExportImport(
|
|||||||
self.assertIsFile(os.path.join(self.target, "manifest.json"))
|
self.assertIsFile(os.path.join(self.target, "manifest.json"))
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"documents.management.commands.document_exporter.copy_file_with_basic_stats",
|
"paperless.management.commands.document_exporter.copy_file_with_basic_stats",
|
||||||
) as m:
|
) as m:
|
||||||
self._do_export()
|
self._do_export()
|
||||||
m.assert_not_called()
|
m.assert_not_called()
|
||||||
@ -370,7 +370,7 @@ class TestExportImport(
|
|||||||
self.d2.save()
|
self.d2.save()
|
||||||
|
|
||||||
with mock.patch(
|
with mock.patch(
|
||||||
"documents.management.commands.document_exporter.copy_file_with_basic_stats",
|
"paperless.management.commands.document_exporter.copy_file_with_basic_stats",
|
||||||
) as m:
|
) as m:
|
||||||
self._do_export(compare_checksums=True)
|
self._do_export(compare_checksums=True)
|
||||||
self.assertEqual(m.call_count, 1)
|
self.assertEqual(m.call_count, 1)
|
||||||
|
@ -8,9 +8,9 @@ from django.core.management import call_command
|
|||||||
from django.core.management.base import CommandError
|
from django.core.management.base import CommandError
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from documents.management.commands.document_importer import Command
|
|
||||||
from documents.settings import EXPORTER_ARCHIVE_NAME
|
from documents.settings import EXPORTER_ARCHIVE_NAME
|
||||||
from documents.settings import EXPORTER_FILE_NAME
|
from documents.settings import EXPORTER_FILE_NAME
|
||||||
|
from paperless.management.commands.document_importer import Command
|
||||||
from paperless.models import Document
|
from paperless.models import Document
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
from paperless.tests.utils import FileSystemAssertsMixin
|
from paperless.tests.utils import FileSystemAssertsMixin
|
||||||
|
@ -5,7 +5,7 @@ from unittest import mock
|
|||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from documents.management.commands.document_thumbnails import _process_document
|
from paperless.management.commands.document_thumbnails import _process_document
|
||||||
from paperless.models import Document
|
from paperless.models import Document
|
||||||
from paperless.parsers import get_default_thumbnail
|
from paperless.parsers import get_default_thumbnail
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
@ -67,7 +67,7 @@ class TestMakeThumbnails(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
self.assertIsFile(get_default_thumbnail())
|
self.assertIsFile(get_default_thumbnail())
|
||||||
self.assertIsFile(self.d3.thumbnail_path)
|
self.assertIsFile(self.d3.thumbnail_path)
|
||||||
|
|
||||||
@mock.patch("documents.management.commands.document_thumbnails.shutil.move")
|
@mock.patch("paperless.management.commands.document_thumbnails.shutil.move")
|
||||||
def test_process_document_invalid_mime_type(self, m: mock.Mock):
|
def test_process_document_invalid_mime_type(self, m: mock.Mock):
|
||||||
self.d1.mime_type = "asdasdasd"
|
self.d1.mime_type = "asdasdasd"
|
||||||
self.d1.save()
|
self.d1.save()
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from documents.tests.factories import CorrespondentFactory
|
|
||||||
from documents.tests.factories import DocumentFactory
|
|
||||||
from paperless.models import Correspondent
|
from paperless.models import Correspondent
|
||||||
from paperless.models import Document
|
from paperless.models import Document
|
||||||
|
from paperless.tests.factories import CorrespondentFactory
|
||||||
|
from paperless.tests.factories import DocumentFactory
|
||||||
|
|
||||||
|
|
||||||
class CorrespondentTestCase(TestCase):
|
class CorrespondentTestCase(TestCase):
|
||||||
|
@ -178,27 +178,27 @@ class TestCeleryScheduleParsing(TestCase):
|
|||||||
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Train the classifier": {
|
"Train the classifier": {
|
||||||
"task": "documents.tasks.train_classifier",
|
"task": "paperless.tasks.train_classifier",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Optimize the index": {
|
"Optimize the index": {
|
||||||
"task": "documents.tasks.index_optimize",
|
"task": "paperless.tasks.index_optimize",
|
||||||
"schedule": crontab(minute=0, hour=0),
|
"schedule": crontab(minute=0, hour=0),
|
||||||
"options": {"expires": self.INDEX_EXPIRE_TIME},
|
"options": {"expires": self.INDEX_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Perform sanity check": {
|
"Perform sanity check": {
|
||||||
"task": "documents.tasks.sanity_check",
|
"task": "paperless.tasks.sanity_check",
|
||||||
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
||||||
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Empty trash": {
|
"Empty trash": {
|
||||||
"task": "documents.tasks.empty_trash",
|
"task": "paperless.tasks.empty_trash",
|
||||||
"schedule": crontab(minute=0, hour="1"),
|
"schedule": crontab(minute=0, hour="1"),
|
||||||
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Check and run scheduled workflows": {
|
"Check and run scheduled workflows": {
|
||||||
"task": "documents.tasks.check_scheduled_workflows",
|
"task": "paperless.tasks.check_scheduled_workflows",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
@ -230,27 +230,27 @@ class TestCeleryScheduleParsing(TestCase):
|
|||||||
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Train the classifier": {
|
"Train the classifier": {
|
||||||
"task": "documents.tasks.train_classifier",
|
"task": "paperless.tasks.train_classifier",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Optimize the index": {
|
"Optimize the index": {
|
||||||
"task": "documents.tasks.index_optimize",
|
"task": "paperless.tasks.index_optimize",
|
||||||
"schedule": crontab(minute=0, hour=0),
|
"schedule": crontab(minute=0, hour=0),
|
||||||
"options": {"expires": self.INDEX_EXPIRE_TIME},
|
"options": {"expires": self.INDEX_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Perform sanity check": {
|
"Perform sanity check": {
|
||||||
"task": "documents.tasks.sanity_check",
|
"task": "paperless.tasks.sanity_check",
|
||||||
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
||||||
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Empty trash": {
|
"Empty trash": {
|
||||||
"task": "documents.tasks.empty_trash",
|
"task": "paperless.tasks.empty_trash",
|
||||||
"schedule": crontab(minute=0, hour="1"),
|
"schedule": crontab(minute=0, hour="1"),
|
||||||
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Check and run scheduled workflows": {
|
"Check and run scheduled workflows": {
|
||||||
"task": "documents.tasks.check_scheduled_workflows",
|
"task": "paperless.tasks.check_scheduled_workflows",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
@ -279,22 +279,22 @@ class TestCeleryScheduleParsing(TestCase):
|
|||||||
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
"options": {"expires": self.MAIL_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Train the classifier": {
|
"Train the classifier": {
|
||||||
"task": "documents.tasks.train_classifier",
|
"task": "paperless.tasks.train_classifier",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
"options": {"expires": self.CLASSIFIER_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Perform sanity check": {
|
"Perform sanity check": {
|
||||||
"task": "documents.tasks.sanity_check",
|
"task": "paperless.tasks.sanity_check",
|
||||||
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
"schedule": crontab(minute=30, hour=0, day_of_week="sun"),
|
||||||
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
"options": {"expires": self.SANITY_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Empty trash": {
|
"Empty trash": {
|
||||||
"task": "documents.tasks.empty_trash",
|
"task": "paperless.tasks.empty_trash",
|
||||||
"schedule": crontab(minute=0, hour="1"),
|
"schedule": crontab(minute=0, hour="1"),
|
||||||
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
"options": {"expires": self.EMPTY_TRASH_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
"Check and run scheduled workflows": {
|
"Check and run scheduled workflows": {
|
||||||
"task": "documents.tasks.check_scheduled_workflows",
|
"task": "paperless.tasks.check_scheduled_workflows",
|
||||||
"schedule": crontab(minute="5", hour="*/1"),
|
"schedule": crontab(minute="5", hour="*/1"),
|
||||||
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
"options": {"expires": self.RUN_SCHEDULED_WORKFLOWS_EXPIRE_TIME},
|
||||||
},
|
},
|
||||||
|
@ -4,7 +4,6 @@ from unittest import mock
|
|||||||
import celery
|
import celery
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from documents.tests.test_consumer import fake_magic_from_file
|
|
||||||
from paperless.data_models import ConsumableDocument
|
from paperless.data_models import ConsumableDocument
|
||||||
from paperless.data_models import DocumentMetadataOverrides
|
from paperless.data_models import DocumentMetadataOverrides
|
||||||
from paperless.data_models import DocumentSource
|
from paperless.data_models import DocumentSource
|
||||||
@ -13,6 +12,7 @@ from paperless.signals.handlers import before_task_publish_handler
|
|||||||
from paperless.signals.handlers import task_failure_handler
|
from paperless.signals.handlers import task_failure_handler
|
||||||
from paperless.signals.handlers import task_postrun_handler
|
from paperless.signals.handlers import task_postrun_handler
|
||||||
from paperless.signals.handlers import task_prerun_handler
|
from paperless.signals.handlers import task_prerun_handler
|
||||||
|
from paperless.tests.test_consumer import fake_magic_from_file
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
|
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
|
|||||||
"""
|
"""
|
||||||
headers = {
|
headers = {
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"task": "documents.tasks.consume_file",
|
"task": "paperless.tasks.consume_file",
|
||||||
}
|
}
|
||||||
body = (
|
body = (
|
||||||
# args
|
# args
|
||||||
@ -84,7 +84,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"task": "documents.tasks.consume_file",
|
"task": "paperless.tasks.consume_file",
|
||||||
}
|
}
|
||||||
body = (
|
body = (
|
||||||
# args
|
# args
|
||||||
@ -123,7 +123,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
|
|||||||
"""
|
"""
|
||||||
headers = {
|
headers = {
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"task": "documents.tasks.consume_file",
|
"task": "paperless.tasks.consume_file",
|
||||||
}
|
}
|
||||||
body = (
|
body = (
|
||||||
# args
|
# args
|
||||||
@ -165,7 +165,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase):
|
|||||||
"""
|
"""
|
||||||
headers = {
|
headers = {
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"task": "documents.tasks.consume_file",
|
"task": "paperless.tasks.consume_file",
|
||||||
}
|
}
|
||||||
body = (
|
body = (
|
||||||
# args
|
# args
|
||||||
|
@ -7,7 +7,6 @@ from django.conf import settings
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from documents.tests.test_classifier import dummy_preprocess
|
|
||||||
from paperless import tasks
|
from paperless import tasks
|
||||||
from paperless.models import Correspondent
|
from paperless.models import Correspondent
|
||||||
from paperless.models import Document
|
from paperless.models import Document
|
||||||
@ -15,6 +14,7 @@ from paperless.models import DocumentType
|
|||||||
from paperless.models import Tag
|
from paperless.models import Tag
|
||||||
from paperless.sanity_checker import SanityCheckFailedException
|
from paperless.sanity_checker import SanityCheckFailedException
|
||||||
from paperless.sanity_checker import SanityCheckMessages
|
from paperless.sanity_checker import SanityCheckMessages
|
||||||
|
from paperless.tests.test_classifier import dummy_preprocess
|
||||||
from paperless.tests.utils import DirectoriesMixin
|
from paperless.tests.utils import DirectoriesMixin
|
||||||
from paperless.tests.utils import FileSystemAssertsMixin
|
from paperless.tests.utils import FileSystemAssertsMixin
|
||||||
|
|
||||||
@ -46,12 +46,12 @@ class TestIndexReindex(DirectoriesMixin, TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestClassifier(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
class TestClassifier(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||||
@mock.patch("documents.tasks.load_classifier")
|
@mock.patch("paperless.tasks.load_classifier")
|
||||||
def test_train_classifier_no_auto_matching(self, load_classifier):
|
def test_train_classifier_no_auto_matching(self, load_classifier):
|
||||||
tasks.train_classifier()
|
tasks.train_classifier()
|
||||||
load_classifier.assert_not_called()
|
load_classifier.assert_not_called()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.load_classifier")
|
@mock.patch("paperless.tasks.load_classifier")
|
||||||
def test_train_classifier_with_auto_tag(self, load_classifier):
|
def test_train_classifier_with_auto_tag(self, load_classifier):
|
||||||
load_classifier.return_value = None
|
load_classifier.return_value = None
|
||||||
Tag.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
Tag.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
||||||
@ -59,7 +59,7 @@ class TestClassifier(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
load_classifier.assert_called_once()
|
load_classifier.assert_called_once()
|
||||||
self.assertIsNotFile(settings.MODEL_FILE)
|
self.assertIsNotFile(settings.MODEL_FILE)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.load_classifier")
|
@mock.patch("paperless.tasks.load_classifier")
|
||||||
def test_train_classifier_with_auto_type(self, load_classifier):
|
def test_train_classifier_with_auto_type(self, load_classifier):
|
||||||
load_classifier.return_value = None
|
load_classifier.return_value = None
|
||||||
DocumentType.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
DocumentType.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
||||||
@ -67,7 +67,7 @@ class TestClassifier(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
load_classifier.assert_called_once()
|
load_classifier.assert_called_once()
|
||||||
self.assertIsNotFile(settings.MODEL_FILE)
|
self.assertIsNotFile(settings.MODEL_FILE)
|
||||||
|
|
||||||
@mock.patch("documents.tasks.load_classifier")
|
@mock.patch("paperless.tasks.load_classifier")
|
||||||
def test_train_classifier_with_auto_correspondent(self, load_classifier):
|
def test_train_classifier_with_auto_correspondent(self, load_classifier):
|
||||||
load_classifier.return_value = None
|
load_classifier.return_value = None
|
||||||
Correspondent.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
Correspondent.objects.create(matching_algorithm=Tag.MATCH_AUTO, name="test")
|
||||||
@ -103,13 +103,13 @@ class TestClassifier(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class TestSanityCheck(DirectoriesMixin, TestCase):
|
class TestSanityCheck(DirectoriesMixin, TestCase):
|
||||||
@mock.patch("documents.tasks.sanity_checker.check_sanity")
|
@mock.patch("paperless.tasks.sanity_checker.check_sanity")
|
||||||
def test_sanity_check_success(self, m):
|
def test_sanity_check_success(self, m):
|
||||||
m.return_value = SanityCheckMessages()
|
m.return_value = SanityCheckMessages()
|
||||||
self.assertEqual(tasks.sanity_check(), "No issues detected.")
|
self.assertEqual(tasks.sanity_check(), "No issues detected.")
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.sanity_checker.check_sanity")
|
@mock.patch("paperless.tasks.sanity_checker.check_sanity")
|
||||||
def test_sanity_check_error(self, m):
|
def test_sanity_check_error(self, m):
|
||||||
messages = SanityCheckMessages()
|
messages = SanityCheckMessages()
|
||||||
messages.error(None, "Some error")
|
messages.error(None, "Some error")
|
||||||
@ -117,7 +117,7 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
|
|||||||
self.assertRaises(SanityCheckFailedException, tasks.sanity_check)
|
self.assertRaises(SanityCheckFailedException, tasks.sanity_check)
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.sanity_checker.check_sanity")
|
@mock.patch("paperless.tasks.sanity_checker.check_sanity")
|
||||||
def test_sanity_check_error_no_raise(self, m):
|
def test_sanity_check_error_no_raise(self, m):
|
||||||
messages = SanityCheckMessages()
|
messages = SanityCheckMessages()
|
||||||
messages.error(None, "Some error")
|
messages.error(None, "Some error")
|
||||||
@ -130,7 +130,7 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
|
|||||||
)
|
)
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.sanity_checker.check_sanity")
|
@mock.patch("paperless.tasks.sanity_checker.check_sanity")
|
||||||
def test_sanity_check_warning(self, m):
|
def test_sanity_check_warning(self, m):
|
||||||
messages = SanityCheckMessages()
|
messages = SanityCheckMessages()
|
||||||
messages.warning(None, "Some warning")
|
messages.warning(None, "Some warning")
|
||||||
@ -141,7 +141,7 @@ class TestSanityCheck(DirectoriesMixin, TestCase):
|
|||||||
)
|
)
|
||||||
m.assert_called_once()
|
m.assert_called_once()
|
||||||
|
|
||||||
@mock.patch("documents.tasks.sanity_checker.check_sanity")
|
@mock.patch("paperless.tasks.sanity_checker.check_sanity")
|
||||||
def test_sanity_check_info(self, m):
|
def test_sanity_check_info(self, m):
|
||||||
messages = SanityCheckMessages()
|
messages = SanityCheckMessages()
|
||||||
messages.info(None, "Some info")
|
messages.info(None, "Some info")
|
||||||
|
@ -154,7 +154,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -265,7 +265,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -383,7 +383,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -451,7 +451,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -503,7 +503,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -577,7 +577,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -661,7 +661,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -746,7 +746,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -864,7 +864,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -1875,7 +1875,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -1998,7 +1998,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
with self.assertLogs("paperless.matching", level="INFO") as cm:
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -2369,7 +2369,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO"):
|
with self.assertLogs("paperless.matching", level="INFO"):
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
@ -2690,7 +2690,7 @@ class TestWorkflows(
|
|||||||
self.dirs.scratch_dir / "simple.pdf",
|
self.dirs.scratch_dir / "simple.pdf",
|
||||||
)
|
)
|
||||||
|
|
||||||
with mock.patch("documents.tasks.ProgressManager", DummyProgressManager):
|
with mock.patch("paperless.tasks.ProgressManager", DummyProgressManager):
|
||||||
with self.assertLogs("paperless.matching", level="INFO"):
|
with self.assertLogs("paperless.matching", level="INFO"):
|
||||||
tasks.consume_file(
|
tasks.consume_file(
|
||||||
ConsumableDocument(
|
ConsumableDocument(
|
||||||
|
@ -230,7 +230,7 @@ class DocumentConsumeDelayMixin:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.consume_file_patcher = mock.patch("documents.tasks.consume_file.delay")
|
self.consume_file_patcher = mock.patch("paperless.tasks.consume_file.delay")
|
||||||
self.consume_file_mock = self.consume_file_patcher.start()
|
self.consume_file_mock = self.consume_file_patcher.start()
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ class DummyProgressManager:
|
|||||||
connect to Redis. Payloads are stored for test assertions if needed.
|
connect to Redis. Payloads are stored for test assertions if needed.
|
||||||
|
|
||||||
Use it with
|
Use it with
|
||||||
mock.patch("documents.tasks.ProgressManager", DummyProgressManager)
|
mock.patch("paperless.tasks.ProgressManager", DummyProgressManager)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, filename: str, task_id: str | None = None) -> None:
|
def __init__(self, filename: str, task_id: str | None = None) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user