mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-19 10:19:27 -05:00
Change: Use fnmatch for workflow path matching (#5250)
This commit is contained in:
parent
355a434a07
commit
d623af9c41
@ -296,7 +296,10 @@ def consumable_document_matches_workflow(
|
|||||||
if (
|
if (
|
||||||
trigger.filter_path is not None
|
trigger.filter_path is not None
|
||||||
and len(trigger.filter_path) > 0
|
and len(trigger.filter_path) > 0
|
||||||
and not document.original_file.match(trigger.filter_path)
|
and not fnmatch(
|
||||||
|
document.original_file,
|
||||||
|
trigger.filter_path,
|
||||||
|
)
|
||||||
):
|
):
|
||||||
reason = (
|
reason = (
|
||||||
f"Document path {document.original_file}"
|
f"Document path {document.original_file}"
|
||||||
|
@ -324,6 +324,53 @@ class TestWorkflows(DirectoriesMixin, FileSystemAssertsMixin, APITestCase):
|
|||||||
expected_str = f"Document matched {trigger2} from {w2}"
|
expected_str = f"Document matched {trigger2} from {w2}"
|
||||||
self.assertIn(expected_str, cm.output[1])
|
self.assertIn(expected_str, cm.output[1])
|
||||||
|
|
||||||
|
@mock.patch("documents.consumer.Consumer.try_consume_file")
|
||||||
|
def test_workflow_fnmatch_path(self, m):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- Existing workflow
|
||||||
|
WHEN:
|
||||||
|
- File that matches using fnmatch on path is consumed
|
||||||
|
THEN:
|
||||||
|
- Template overrides are applied
|
||||||
|
- Note: Test was added when path matching changed from pathlib.match to fnmatch
|
||||||
|
"""
|
||||||
|
trigger = WorkflowTrigger.objects.create(
|
||||||
|
type=WorkflowTrigger.WorkflowTriggerType.CONSUMPTION,
|
||||||
|
sources=f"{DocumentSource.ApiUpload},{DocumentSource.ConsumeFolder},{DocumentSource.MailFetch}",
|
||||||
|
filter_path="*sample*",
|
||||||
|
)
|
||||||
|
action = WorkflowAction.objects.create(
|
||||||
|
assign_title="Doc fnmatch title",
|
||||||
|
)
|
||||||
|
action.save()
|
||||||
|
|
||||||
|
w = Workflow.objects.create(
|
||||||
|
name="Workflow 1",
|
||||||
|
order=0,
|
||||||
|
)
|
||||||
|
w.triggers.add(trigger)
|
||||||
|
w.actions.add(action)
|
||||||
|
w.save()
|
||||||
|
|
||||||
|
test_file = self.SAMPLE_DIR / "simple.pdf"
|
||||||
|
|
||||||
|
with mock.patch("documents.tasks.async_to_sync"):
|
||||||
|
with self.assertLogs("paperless.matching", level="DEBUG") as cm:
|
||||||
|
tasks.consume_file(
|
||||||
|
ConsumableDocument(
|
||||||
|
source=DocumentSource.ConsumeFolder,
|
||||||
|
original_file=test_file,
|
||||||
|
),
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
m.assert_called_once()
|
||||||
|
_, overrides = m.call_args
|
||||||
|
self.assertEqual(overrides["override_title"], "Doc fnmatch title")
|
||||||
|
|
||||||
|
expected_str = f"Document matched {trigger} from {w}"
|
||||||
|
self.assertIn(expected_str, cm.output[0])
|
||||||
|
|
||||||
@mock.patch("documents.consumer.Consumer.try_consume_file")
|
@mock.patch("documents.consumer.Consumer.try_consume_file")
|
||||||
def test_workflow_no_match_filename(self, m):
|
def test_workflow_no_match_filename(self, m):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user