mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-12-04 02:08:42 +00:00
Fix: allow blank mail rule action_parameter in the API (#14966)
* Fix: allow blank mail rule action_parameter in the API * Merges tests into existing class and test cases instead
This commit is contained in:
1 parent
fc2c32d2b2
commit
5ee2236be1
2 files changed
+36
No files matched your search
@@ -68,6 +68,7 @@ class MailRuleSerializer(OwnedObjectSerializer):
|
||||
account = AccountField(required=True)
|
||||
action_parameter = serializers.CharField(
|
||||
allow_null=True,
|
||||
allow_blank=True,
|
||||
required=False,
|
||||
default="",
|
||||
)
|
||||
|
||||
@@ -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"], "")
|
||||
Reference in new issue
Block a user