Skip to content

Commit a441b93

Browse files
committed
Update tests for DRF 3.16.0
New error messages are returned, and there appears to be an upstream bug which presently requires us to specify all attributes in the update.
1 parent 22948fc commit a441b93

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

pydis_site/apps/api/tests/test_bumped_threads.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,7 @@ def test_returns_404_for_non_existing_data(self):
6060

6161
response = self.client.get(url)
6262
self.assertEqual(response.status_code, 404)
63-
self.assertEqual(response.json(), {"detail": "Not found."})
63+
self.assertEqual(
64+
response.json(),
65+
{"detail": "No BumpedThread matches the given query."},
66+
)

pydis_site/apps/api/tests/test_filters.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,15 @@ def test_fetch_non_existing(self) -> None:
210210
sequence.model.objects.all().delete()
211211

212212
response = self.client.get(f"{sequence.url()}/42")
213+
if "filter-lists" in sequence.url():
214+
kind = "FilterList"
215+
else:
216+
kind = "Filter"
213217
self.assertEqual(response.status_code, 404)
214-
self.assertDictEqual(response.json(), {'detail': 'Not found.'})
218+
self.assertDictEqual(
219+
response.json(),
220+
{'detail': f"No {kind} matches the given query."},
221+
)
215222

216223
def test_creation(self) -> None:
217224
for name, sequence in get_test_sequences().items():

pydis_site/apps/api/tests/test_infractions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def test_partial_update(self):
329329

330330
def test_partial_update_returns_400_for_frozen_field(self):
331331
url = reverse('api:bot:infraction-detail', args=(self.ban_hidden.id,))
332-
data = {'user': 6}
332+
data = {'user': 6, 'active': True}
333333

334334
response = self.client.patch(url, data=data)
335335
self.assertEqual(response.status_code, 400)
@@ -559,7 +559,7 @@ def test_returns_400_for_second_active_infraction_of_the_same_type(self):
559559
second_response.json(),
560560
{
561561
'non_field_errors': [
562-
'This user already has an active infraction of this type.'
562+
'The fields user, type must make a unique set.'
563563
]
564564
}
565565
)
@@ -824,7 +824,7 @@ def test_is_valid_if_active_infraction_with_same_fields_exists(self):
824824
self.create_infraction('ban', active=True)
825825
instance = self.create_infraction('ban', active=False)
826826

827-
data = {'reason': 'hello'}
827+
data = {'reason': 'hello', 'active': True}
828828
serializer = InfractionSerializer(instance, data=data, partial=True)
829829

830830
self.assertTrue(serializer.is_valid(), msg=serializer.errors)

pydis_site/apps/api/tests/test_nominations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def test_returns_404_on_get_unknown_nomination(self):
379379
response = self.client.get(url, data={})
380380
self.assertEqual(response.status_code, 404)
381381
self.assertEqual(response.json(), {
382-
"detail": "Not found."
382+
"detail": "No Nomination matches the given query."
383383
})
384384

385385
def test_returns_404_on_patch_unknown_nomination(self):
@@ -391,7 +391,7 @@ def test_returns_404_on_patch_unknown_nomination(self):
391391
response = self.client.patch(url, data={})
392392
self.assertEqual(response.status_code, 404)
393393
self.assertEqual(response.json(), {
394-
"detail": "Not found."
394+
"detail": "No Nomination matches the given query."
395395
})
396396

397397
def test_returns_405_on_list_put(self):

pydis_site/apps/api/tests/test_roles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,7 @@ def test_role_detail_404_all_methods(self):
208208
for method in ('get', 'put', 'patch', 'delete'):
209209
response = getattr(self.client, method)(url)
210210
self.assertEqual(response.status_code, 404)
211-
self.assertJSONEqual(response.content, '{"detail": "Not found."}')
211+
self.assertJSONEqual(
212+
response.content,
213+
'{"detail": "No Role matches the given query."}',
214+
)

pydis_site/apps/api/tests/test_users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def verify_adding_existing_alt(self, add_on_source: bool) -> None:
746746
response = self.client.post(repeated_url, repeated_data)
747747
self.assertEqual(response.status_code, 400)
748748
self.assertEqual(response.json(), {
749-
'source': ["This relationship has already been established"]
749+
'non_field_errors': ["The fields source, target must make a unique set."]
750750
})
751751

752752
def test_removing_existing_alt_source_from_target(self) -> None:

0 commit comments

Comments
 (0)