Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for DRF 3.15 regression #1279

Merged
merged 2 commits into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 46 additions & 1 deletion pydis_site/apps/api/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.models import Model
from django.urls import reverse

from pydis_site.apps.api.models.bot.filters import Filter, FilterList
from pydis_site.apps.api.models.bot.filters import Filter, FilterList, FilterListType
from pydis_site.apps.api.tests.base import AuthenticatedAPITestCase


Expand Down Expand Up @@ -350,3 +350,48 @@ def test_filter_unique_constraint(self) -> None:

response = self.client.post(test_filter.url(), data=clean_test_json(test_filter.object))
self.assertEqual(response.status_code, 400)


class FilterCreationMissingOptionalFieldsTestCase(AuthenticatedAPITestCase):
@classmethod
def setUpTestData(cls):
cls.filter_list = FilterList.objects.create(
name="Ingsoc",
list_type=FilterListType.ALLOW,
dm_content="But if thought corrupts language, language can also corrupt thought.",
dm_embed="",
infraction_type="timeout",
infraction_duration=timedelta(days=80 * 365),
infraction_reason="Thoughtcrime",
infraction_channel=1,
guild_pings=["@BigBrother"],
filter_dm=False,
dm_pings=["@BigBrother"],
remove_context=True,
bypass_roles=[],
enabled=True,
send_alert=True,
enabled_channels=[],
disabled_channels=[],
enabled_categories=[],
disabled_categories=[],
)

def test_creation_missing_optional_fields(self) -> None:
data = {
"filter_list": self.filter_list.id,
"content": "1234567",
"description": "Guild \"Python\" - Phishing",
"additional_settings": {},
"guild_pings": [],
"infraction_type": "BAN",
"infraction_channel": 1,
"infraction_duration": 345600.0,
"infraction_reason": (
"The creatures outside looked from pig to man, and from man to pig, "
"and from pig to man again; but already it was impossible to say which was which"
)
}
endpoint = reverse('api:bot:filter-list')
response = self.client.post(endpoint, data=data)
self.assertEqual(response.status_code, 201)