Chore: Fix bugs in the test suite (#14244)

* Fix: redirect SHARE_LINK_BUNDLE_DIR to the test temp layout instead of the real media directory

* Fix: include f_to in test_filters subTest labels so each of the 8 cases reports distinctly

* Fix: run the post_consume error-log assertion after the raising call and match the actual paperless_mail logger name

* Fix: rename the blank-password workflow test to match its behavior and add a real wrong-password-fails test

* Fix: use the created social account's actual pk and remove an accidental tuple wrapping the mock provider

* Fix: assert against the created documents' actual pks instead of hardcoded 1 and 2

* Fix: assert test_compression actually produces a valid LZMA-compressed zip

* Fix: clear os.environ when patching PAPERLESS_ADMIN_* vars so a host-set value can't leak into the no-user test

* Fix: restore MIDDLEWARE, AUTHENTICATION_BACKENDS and REST_FRAMEWORK auth classes after each remote-user settings test instead of leaking the mutation into later tests

* Fix: use a guaranteed-nonexistent temp path instead of hardcoded /tmp/foo/bar in test_export_target_not_exists
This commit is contained in:
Trenton H
2026-09-23 19:11:58 +00:00
committed by GitHub
parent 969c2ea0e2
commit b457610ffb
10 changed files with 124 additions and 45 deletions
+57 -3
View File
@@ -4459,18 +4459,18 @@ class TestWorkflows(
)
@mock.patch("documents.bulk_edit.remove_password")
def test_password_removal_action_fails_without_correct_password(
def test_password_removal_action_skips_blank_and_whitespace_passwords(
self,
mock_remove_password,
) -> None:
"""
GIVEN:
- Workflow password removal action
- No correct password provided
- Only blank and whitespace-only passwords configured
WHEN:
- Document updated triggering the workflow
THEN:
- Password removal is attempted for all passwords and fails
- Password removal is not attempted
"""
doc = Document.objects.create(
title="Protected",
@@ -4491,6 +4491,60 @@ class TestWorkflows(
mock_remove_password.assert_not_called()
@mock.patch("documents.bulk_edit.remove_password")
def test_password_removal_action_fails_without_correct_password(
self,
mock_remove_password,
) -> None:
"""
GIVEN:
- Workflow password removal action
- No configured password is correct
WHEN:
- Document updated triggering the workflow
THEN:
- Password removal is attempted for every configured password and fails
"""
doc = Document.objects.create(
title="Protected",
checksum="pw-checksum-3",
)
trigger = WorkflowTrigger.objects.create(
type=WorkflowTrigger.WorkflowTriggerType.DOCUMENT_UPDATED,
)
action = WorkflowAction.objects.create(
type=WorkflowAction.WorkflowActionType.PASSWORD_REMOVAL,
passwords=["wrong", "also-wrong"],
)
workflow = Workflow.objects.create(name="Password workflow wrong passwords")
workflow.triggers.add(trigger)
workflow.actions.add(action)
mock_remove_password.side_effect = ValueError("wrong password")
with self.assertLogs("paperless.workflows.actions", level="ERROR"):
run_workflows(trigger.type, doc)
assert mock_remove_password.call_count == 2
mock_remove_password.assert_has_calls(
[
mock.call(
[doc.id],
password="wrong",
update_document=True,
user=doc.owner,
source_paths_by_id=None,
),
mock.call(
[doc.id],
password="also-wrong",
update_document=True,
user=doc.owner,
source_paths_by_id=None,
),
],
)
@mock.patch("documents.bulk_edit.remove_password")
def test_password_removal_action_skips_without_passwords(
self,