Skip to content

Commit

Permalink
Merge branch 'main' into support-test-keepdb
Browse files Browse the repository at this point in the history
  • Loading branch information
Xithrius committed Mar 30, 2024
2 parents 940d88c + 95c0602 commit 3f5a5e9
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 50 deletions.
20 changes: 4 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pydis_site/apps/api/tests/test_bumped_threads.py
Expand Up @@ -60,4 +60,4 @@ def test_returns_404_for_non_existing_data(self):

response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.json(), {"detail": "Not found."})
self.assertEqual(response.json(), {"detail": "No BumpedThread matches the given query."})
7 changes: 6 additions & 1 deletion pydis_site/apps/api/tests/test_filters.py
Expand Up @@ -211,7 +211,12 @@ def test_fetch_non_existing(self) -> None:

response = self.client.get(f"{sequence.url()}/42")
self.assertEqual(response.status_code, 404)
self.assertDictEqual(response.json(), {'detail': 'Not found.'})
parsed = response.json()
self.assertIn('detail', parsed)
self.assertIn(parsed['detail'], (
"No Filter matches the given query.",
"No FilterList matches the given query."
))

def test_creation(self) -> None:
for name, sequence in get_test_sequences().items():
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/tests/test_infractions.py
Expand Up @@ -559,7 +559,7 @@ def test_returns_400_for_second_active_infraction_of_the_same_type(self):
second_response.json(),
{
'non_field_errors': [
'This user already has an active infraction of this type.'
'The fields user, type must make a unique set.'
]
}
)
Expand Down
4 changes: 2 additions & 2 deletions pydis_site/apps/api/tests/test_nominations.py
Expand Up @@ -379,7 +379,7 @@ def test_returns_404_on_get_unknown_nomination(self):
response = self.client.get(url, data={})
self.assertEqual(response.status_code, 404)
self.assertEqual(response.json(), {
"detail": "Not found."
"detail": "No Nomination matches the given query."
})

def test_returns_404_on_patch_unknown_nomination(self):
Expand All @@ -391,7 +391,7 @@ def test_returns_404_on_patch_unknown_nomination(self):
response = self.client.patch(url, data={})
self.assertEqual(response.status_code, 404)
self.assertEqual(response.json(), {
"detail": "Not found."
"detail": "No Nomination matches the given query."
})

def test_returns_405_on_list_put(self):
Expand Down
2 changes: 1 addition & 1 deletion pydis_site/apps/api/tests/test_roles.py
Expand Up @@ -208,4 +208,4 @@ def test_role_detail_404_all_methods(self):
for method in ('get', 'put', 'patch', 'delete'):
response = getattr(self.client, method)(url)
self.assertEqual(response.status_code, 404)
self.assertJSONEqual(response.content, '{"detail": "Not found."}')
self.assertJSONEqual(response.content, '{"detail": "No Role matches the given query."}')
3 changes: 2 additions & 1 deletion pydis_site/apps/api/urls.py
Expand Up @@ -30,7 +30,8 @@
bot_router = DefaultRouter(trailing_slash=False)
bot_router.register(
'filter/filter_lists',
FilterListViewSet
FilterListViewSet,
basename='filter-filter-lists',
)
bot_router.register(
"aoc-account-links",
Expand Down
26 changes: 0 additions & 26 deletions pydis_site/apps/api/viewsets/bot/infraction.py
@@ -1,6 +1,5 @@
import datetime

from django.db import IntegrityError
from django.db.models import QuerySet
from django.http.request import HttpRequest
from django_filters.rest_framework import DjangoFilterBackend
Expand Down Expand Up @@ -275,28 +274,3 @@ def partial_update_expanded(self, *args, **kwargs) -> Response:
"""
self.serializer_class = ExpandedInfractionSerializer
return self.partial_update(*args, **kwargs)

def create(self, request: HttpRequest, *args, **kwargs) -> Response:
"""
Create an infraction for a target user.
Called by the Django Rest Framework in response to the corresponding HTTP request.
"""
try:
return super().create(request, *args, **kwargs)
except IntegrityError as err:
# We need to use `__cause__` here, as Django reraises the internal
# UniqueViolation emitted by psycopg2 (which contains the attribute
# that we actually need)
#
# _meta is documented and mainly named that way to prevent
# name clashes: https://docs.djangoproject.com/en/dev/ref/models/meta/
if err.__cause__.diag.constraint_name == Infraction._meta.constraints[0].name:
raise ValidationError(
{
'non_field_errors': [
'This user already has an active infraction of this type.',
]
}
)
raise # pragma: no cover - no other constraint to test with
2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -14,7 +14,7 @@ django-environ = "0.11.2"
django-filter = "24.2"
django-prometheus = "2.3.1"
django-simple-bulma = "2.6.0"
djangorestframework = "3.14.0"
djangorestframework = "3.15.1"
gunicorn = "21.2.0"
httpx = "0.27.0"
markdown = "3.6"
Expand Down

0 comments on commit 3f5a5e9

Please sign in to comment.