diff --git a/src/paperless_mail/tests/test_api_mail_rule_action_parameter.py b/src/paperless_mail/tests/test_api_mail_rule_action_parameter.py deleted file mode 100644 index 0c71f55c8..000000000 --- a/src/paperless_mail/tests/test_api_mail_rule_action_parameter.py +++ /dev/null @@ -1,116 +0,0 @@ -from typing import Final - -import pytest -from rest_framework import status -from rest_framework.test import APIClient - -from paperless_mail.models import MailAccount -from paperless_mail.models import MailRule -from paperless_mail.tests.factories import MailAccountFactory - -ENDPOINT: Final = "/api/mail_rules/" - - -@pytest.mark.django_db -class TestMailRuleActionParameter: - @pytest.fixture - def account(self) -> MailAccount: - return MailAccountFactory.create() - - def test_rule_without_parameter_round_trips( - self, - admin_client: APIClient, - account: MailAccount, - ) -> None: - """ - GIVEN: - - A rule created without an action_parameter - WHEN: - - The returned rule is sent back unchanged with PUT - THEN: - - The update succeeds and the parameter stays blank - """ - created = admin_client.post( - ENDPOINT, - { - "name": "omitted", - "account": account.pk, - "folder": "INBOX", - "action": MailRule.MailAction.FLAG, - }, - format="json", - ) - assert created.status_code == status.HTTP_201_CREATED - assert created.data["action_parameter"] == "" - - updated = admin_client.put( - f"{ENDPOINT}{created.data['id']}/", - created.data, - format="json", - ) - - assert updated.status_code == status.HTTP_200_OK - assert updated.data["action_parameter"] == "" - - def test_create_with_blank_parameter( - self, - admin_client: APIClient, - account: MailAccount, - ) -> None: - """ - GIVEN: - - An action which takes no parameter - WHEN: - - A rule is created with a blank action_parameter - THEN: - - The rule is created - """ - response = admin_client.post( - ENDPOINT, - { - "name": "blank", - "account": account.pk, - "folder": "INBOX", - "action": MailRule.MailAction.FLAG, - "action_parameter": "", - }, - format="json", - ) - - assert response.status_code == status.HTTP_201_CREATED - assert response.data["action_parameter"] == "" - - @pytest.mark.parametrize( - "action", - [ - pytest.param(MailRule.MailAction.TAG, id="tag"), - pytest.param(MailRule.MailAction.MOVE, id="move"), - ], - ) - def test_blank_parameter_rejected_when_required( - self, - admin_client: APIClient, - account: MailAccount, - action: MailRule.MailAction, - ) -> None: - """ - GIVEN: - - An action which requires a parameter - WHEN: - - A rule is created with a blank action_parameter - THEN: - - The request is rejected - """ - response = admin_client.post( - ENDPOINT, - { - "name": "blank", - "account": account.pk, - "folder": "INBOX", - "action": action, - "action_parameter": "", - }, - format="json", - ) - - assert response.status_code == status.HTTP_400_BAD_REQUEST diff --git a/src/paperless_mail/tests/test_mail.py b/src/paperless_mail/tests/test_mail.py index b686e13a1..bbdbb5f21 100644 --- a/src/paperless_mail/tests/test_mail.py +++ b/src/paperless_mail/tests/test_mail.py @@ -2427,3 +2427,38 @@ class TestMailRuleAPI(APITestCase): "action parameter is required", str(response.data["non_field_errors"]), ) + + response = self.client.post( + self.url, + {**data, "action_parameter": ""}, + format="json", + ) + self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) + + def test_mail_rule_blank_action_parameter_round_trips(self) -> None: + """ + GIVEN: + - A rule created without an action_parameter + WHEN: + - The returned rule is sent back unchanged with PUT + THEN: + - The update succeeds and the parameter stays blank + """ + created = self.client.post( + self.url, + { + "name": "Test Rule", + "account": self.account.pk, + "action": MailRule.MailAction.FLAG, + }, + format="json", + ) + self.assertEqual(created.status_code, status.HTTP_201_CREATED) + + updated = self.client.put( + f"{self.url}{created.data['id']}/", + created.data, + format="json", + ) + self.assertEqual(updated.status_code, status.HTTP_200_OK) + self.assertEqual(updated.data["action_parameter"], "")