Merges tests into existing class and test cases instead

This commit is contained in:
stumpylog committed 2026-12-03 08:02:15 -08:00
1 parent 4372554414
commit eece30cc4e
2 files changed
+35 -116

No files matched your search

@@ -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
+35
View File
@@ -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"], "")