mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-16 11:36:39 +01:00
Merge pull request #4037 from andreheuer/dev
Enhancement: add task id to pre/post consume script as env
This commit is contained in:
commit
714995877a
4 changed files with 39 additions and 19 deletions
|
|
@ -4,6 +4,7 @@ import re
|
|||
import shutil
|
||||
import stat
|
||||
import tempfile
|
||||
import uuid
|
||||
from unittest import mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
|
@ -862,6 +863,7 @@ class PreConsumeTestCase(TestCase):
|
|||
c = Consumer()
|
||||
c.original_path = "path-to-file"
|
||||
c.path = "/tmp/somewhere/path-to-file"
|
||||
c.task_id = str(uuid.uuid4())
|
||||
c.run_pre_consume_script()
|
||||
|
||||
m.assert_called_once()
|
||||
|
|
@ -877,6 +879,7 @@ class PreConsumeTestCase(TestCase):
|
|||
subset = {
|
||||
"DOCUMENT_SOURCE_PATH": c.original_path,
|
||||
"DOCUMENT_WORKING_PATH": c.path,
|
||||
"TASK_ID": c.task_id,
|
||||
}
|
||||
self.assertDictEqual(environment, {**environment, **subset})
|
||||
|
||||
|
|
@ -937,7 +940,10 @@ class PreConsumeTestCase(TestCase):
|
|||
with override_settings(PRE_CONSUME_SCRIPT=script.name):
|
||||
c = Consumer()
|
||||
c.path = "path-to-file"
|
||||
self.assertRaises(ConsumerError, c.run_pre_consume_script)
|
||||
self.assertRaises(
|
||||
ConsumerError,
|
||||
c.run_pre_consume_script,
|
||||
)
|
||||
|
||||
|
||||
class PostConsumeTestCase(TestCase):
|
||||
|
|
@ -968,7 +974,11 @@ class PostConsumeTestCase(TestCase):
|
|||
doc = Document.objects.create(title="Test", mime_type="application/pdf")
|
||||
c = Consumer()
|
||||
c.filename = "somefile.pdf"
|
||||
self.assertRaises(ConsumerError, c.run_post_consume_script, doc)
|
||||
self.assertRaises(
|
||||
ConsumerError,
|
||||
c.run_post_consume_script,
|
||||
doc,
|
||||
)
|
||||
|
||||
@mock.patch("documents.consumer.run")
|
||||
def test_post_consume_script_simple(self, m):
|
||||
|
|
@ -995,7 +1005,9 @@ class PostConsumeTestCase(TestCase):
|
|||
doc.tags.add(tag1)
|
||||
doc.tags.add(tag2)
|
||||
|
||||
Consumer().run_post_consume_script(doc)
|
||||
consumer = Consumer()
|
||||
consumer.task_id = str(uuid.uuid4())
|
||||
consumer.run_post_consume_script(doc)
|
||||
|
||||
m.assert_called_once()
|
||||
|
||||
|
|
@ -1017,6 +1029,7 @@ class PostConsumeTestCase(TestCase):
|
|||
"DOCUMENT_THUMBNAIL_URL": f"/api/documents/{doc.pk}/thumb/",
|
||||
"DOCUMENT_CORRESPONDENT": "my_bank",
|
||||
"DOCUMENT_TAGS": "a,b",
|
||||
"TASK_ID": consumer.task_id,
|
||||
}
|
||||
|
||||
self.assertDictEqual(environment, {**environment, **subset})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue