Skip to content

Commit

Permalink
Merge fd91a6f into bceaef8
Browse files Browse the repository at this point in the history
  • Loading branch information
ks129 committed Feb 20, 2021
2 parents bceaef8 + fd91a6f commit 0a5e1bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
7 changes: 2 additions & 5 deletions pydis_site/apps/api/tests/test_nominations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_accepts_valid_data(self):
self.assertEqual(nomination.reason, data['reason'])
self.assertEqual(nomination.active, True)

def test_returns_400_on_second_active_nomination(self):
def test_returns_201_on_second_active_nomination(self):
url = reverse('bot:nomination-list', host='api')
data = {
'actor': self.user.id,
Expand All @@ -49,10 +49,7 @@ def test_returns_400_on_second_active_nomination(self):
self.assertEqual(response1.status_code, 201)

response2 = self.client.post(url, data=data)
self.assertEqual(response2.status_code, 400)
self.assertEqual(response2.json(), {
'active': ['There can only be one active nomination.']
})
self.assertEqual(response2.status_code, 201)

def test_returns_400_for_missing_user(self):
url = reverse('bot:nomination-list', host='api')
Expand Down
8 changes: 1 addition & 7 deletions pydis_site/apps/api/viewsets/bot/nomination.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
Create a new, active nomination returns the created nominations.
The `user`, `reason` and `actor` fields are required and the `user`
and `actor` need to know by the site. Providing other valid fields
is not allowed and invalid fields are ignored. A `user` is only
allowed one active nomination at a time.
is not allowed and invalid fields are ignored.
#### Request body
>>> {
Expand All @@ -91,7 +90,6 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge
#### Status codes
- 201: returned on success
- 400: returned on failure for one of the following reasons:
- A user already has an active nomination;
- The `user` or `actor` are unknown to the site;
- The request contained a field that cannot be set at creation.
Expand Down Expand Up @@ -162,10 +160,6 @@ def create(self, request: HttpRequest, *args, **kwargs) -> Response:
if field in self.frozen_on_create:
raise ValidationError({field: ['This field cannot be set at creation.']})

user_id = request.data.get("user")
if Nomination.objects.filter(active=True, user__id=user_id).exists():
raise ValidationError({'active': ['There can only be one active nomination.']})

serializer = self.get_serializer(
data=ChainMap(
request.data,
Expand Down

0 comments on commit 0a5e1bd

Please sign in to comment.