mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
fixes #61
This commit is contained in:
parent
dddd6f5503
commit
6992ac6aa9
@ -9,6 +9,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.db import models, DatabaseError
|
from django.db import models, DatabaseError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from rest_framework.reverse import reverse
|
||||||
|
|
||||||
from .. import index, matching
|
from .. import index, matching
|
||||||
from ..file_handling import delete_empty_directories, generate_filename, \
|
from ..file_handling import delete_empty_directories, generate_filename, \
|
||||||
@ -157,10 +158,10 @@ def run_post_consume_script(sender, document, **kwargs):
|
|||||||
settings.POST_CONSUME_SCRIPT,
|
settings.POST_CONSUME_SCRIPT,
|
||||||
str(document.pk),
|
str(document.pk),
|
||||||
document.file_name,
|
document.file_name,
|
||||||
document.source_path,
|
os.path.normpath(document.source_path),
|
||||||
document.thumbnail_path,
|
os.path.normpath(document.thumbnail_path),
|
||||||
None,
|
reverse("document-download", kwargs={"pk": document.pk}),
|
||||||
None,
|
reverse("document-thumb", kwargs={"pk": document.pk}),
|
||||||
str(document.correspondent),
|
str(document.correspondent),
|
||||||
str(",".join(document.tags.all().values_list("slug", flat=True)))
|
str(",".join(document.tags.all().values_list("slug", flat=True)))
|
||||||
)).wait()
|
)).wait()
|
||||||
|
57
src/documents/tests/test_post_consume_handlers.py
Normal file
57
src/documents/tests/test_post_consume_handlers.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
from unittest import mock
|
||||||
|
|
||||||
|
from django.test import TestCase, override_settings
|
||||||
|
|
||||||
|
from documents.models import Document, Tag, Correspondent
|
||||||
|
from documents.signals.handlers import run_post_consume_script
|
||||||
|
|
||||||
|
|
||||||
|
class PostConsumeTestCase(TestCase):
|
||||||
|
|
||||||
|
@mock.patch("documents.signals.handlers.Popen")
|
||||||
|
@override_settings(POST_CONSUME_SCRIPT=None)
|
||||||
|
def test_no_post_consume_script(self, m):
|
||||||
|
doc = Document.objects.create(title="Test", mime_type="application/pdf")
|
||||||
|
tag1 = Tag.objects.create(name="a")
|
||||||
|
tag2 = Tag.objects.create(name="b")
|
||||||
|
doc.tags.add(tag1)
|
||||||
|
doc.tags.add(tag2)
|
||||||
|
|
||||||
|
run_post_consume_script(None, doc)
|
||||||
|
|
||||||
|
m.assert_not_called()
|
||||||
|
|
||||||
|
@mock.patch("documents.signals.handlers.Popen")
|
||||||
|
@override_settings(POST_CONSUME_SCRIPT="script")
|
||||||
|
def test_post_consume_script_simple(self, m):
|
||||||
|
doc = Document.objects.create(title="Test", mime_type="application/pdf")
|
||||||
|
|
||||||
|
run_post_consume_script(None, doc)
|
||||||
|
|
||||||
|
m.assert_called_once()
|
||||||
|
|
||||||
|
@mock.patch("documents.signals.handlers.Popen")
|
||||||
|
@override_settings(POST_CONSUME_SCRIPT="script")
|
||||||
|
def test_post_consume_script_simple(self, m):
|
||||||
|
c = Correspondent.objects.create(name="my_bank")
|
||||||
|
doc = Document.objects.create(title="Test", mime_type="application/pdf", correspondent=c)
|
||||||
|
tag1 = Tag.objects.create(name="a")
|
||||||
|
tag2 = Tag.objects.create(name="b")
|
||||||
|
doc.tags.add(tag1)
|
||||||
|
doc.tags.add(tag2)
|
||||||
|
|
||||||
|
run_post_consume_script(None, doc)
|
||||||
|
|
||||||
|
m.assert_called_once()
|
||||||
|
|
||||||
|
args, kwargs = m.call_args
|
||||||
|
|
||||||
|
command = args[0]
|
||||||
|
|
||||||
|
self.assertEqual(command[0], "script")
|
||||||
|
self.assertEqual(command[1], str(doc.pk))
|
||||||
|
self.assertEqual(command[5], f"/api/documents/{doc.pk}/download/")
|
||||||
|
self.assertEqual(command[6], f"/api/documents/{doc.pk}/thumb/")
|
||||||
|
self.assertEqual(command[7], "my_bank")
|
||||||
|
# TODO: tags are unordered by default.
|
||||||
|
self.assertEqual(command[8], "a,b")
|
Loading…
x
Reference in New Issue
Block a user