Skip to content

Commit e5c6758

Browse files
committed
🐛(backend) api status not found messages
DRF verson 3.15 adds more descriptive not found messages. encode/django-rest-framework#8051
1 parent 1c667e5 commit e5c6758

15 files changed

+82
-26
lines changed

src/backend/joanie/tests/core/api/order/test_read_detail.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,6 @@ def test_api_order_read_detail_authenticated_not_owner(self):
164164
)
165165
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
166166

167-
self.assertDictEqual(response.json(), {"detail": "Not found."})
167+
self.assertDictEqual(
168+
response.json(), {"detail": "No Order matches the given query."}
169+
)

src/backend/joanie/tests/core/api/order/test_submit_for_signature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def test_api_order_submit_for_signature_user_is_not_owner_of_the_order_to_be_sub
7171
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
7272

7373
content = response.json()
74-
self.assertEqual(content["detail"], "Not found.")
74+
self.assertEqual(content["detail"], "No Order matches the given query.")
7575

7676
def test_api_order_submit_for_signature_authenticated_but_order_is_not_validate(
7777
self,

src/backend/joanie/tests/core/api/organizations/test_api_organizations_contract.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,11 @@ def test_api_organizations_contracts_retrieve_with_accesses_and_canceled_order(
621621
HTTP_AUTHORIZATION=f"Bearer {token}",
622622
)
623623

624-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
624+
self.assertContains(
625+
response,
626+
"No Contract matches the given query.",
627+
status_code=HTTPStatus.NOT_FOUND,
628+
)
625629

626630
def test_api_organizations_contracts_retrieve_with_accesses_and_organization_code(
627631
self,

src/backend/joanie/tests/core/api/organizations/test_retrieve.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def test_api_organization_retrieve_authenticated_no_access(self):
4444
)
4545

4646
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
47-
self.assertEqual(response.json(), {"detail": "Not found."})
47+
self.assertEqual(
48+
response.json(), {"detail": "No Organization matches the given query."}
49+
)
4850

4951
@mock.patch.object(
5052
fields.ThumbnailDetailField,

src/backend/joanie/tests/core/test_api_admin_course_access.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ def test_admin_api_course_accesses_request_create_with_unknown_course_id(self):
151151
},
152152
)
153153

154-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
154+
self.assertContains(
155+
response,
156+
"No Course matches the given query.",
157+
status_code=HTTPStatus.NOT_FOUND,
158+
)
155159

156160
def test_admin_api_course_accesses_request_create_with_invalid_role(self):
157161
"""
@@ -231,7 +235,11 @@ def test_admin_api_course_accesses_request_update_with_unknown_course_id(self):
231235
},
232236
)
233237

234-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
238+
self.assertContains(
239+
response,
240+
"No CourseAccess matches the given query.",
241+
status_code=HTTPStatus.NOT_FOUND,
242+
)
235243

236244
def test_admin_api_course_accesses_request_update_with_partial_payload(self):
237245
"""

src/backend/joanie/tests/core/test_api_admin_organization_access.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ def test_admin_api_organization_accesses_request_create_with_unknown_course_id(
161161
},
162162
)
163163

164-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
164+
self.assertContains(
165+
response,
166+
"No Organization matches the given query.",
167+
status_code=HTTPStatus.NOT_FOUND,
168+
)
165169

166170
def test_admin_api_organization_accesses_request_create_with_invalid_role(self):
167171
"""
@@ -243,7 +247,11 @@ def test_admin_api_organization_accesses_request_update_with_unknown_course_id(
243247
},
244248
)
245249

246-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
250+
self.assertContains(
251+
response,
252+
"No OrganizationAccess matches the given query.",
253+
status_code=HTTPStatus.NOT_FOUND,
254+
)
247255

248256
def test_admin_api_organization_accesses_request_update_with_partial_payload(self):
249257
"""

src/backend/joanie/tests/core/test_api_admin_organization_addresses.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ def test_admin_api_organization_addresses_request_update_with_unknown_address_id
233233
},
234234
)
235235

236-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
236+
self.assertContains(
237+
response,
238+
"No Address matches the given query.",
239+
status_code=HTTPStatus.NOT_FOUND,
240+
)
237241

238242
def test_admin_api_organization_addresses_request_update_with_partial_payload(self):
239243
"""
@@ -255,7 +259,10 @@ def test_admin_api_organization_addresses_request_update_with_partial_payload(se
255259
)
256260

257261
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
258-
self.assertEqual(response.json(), {"detail": "Not found."})
262+
self.assertEqual(
263+
response.json(),
264+
{"detail": "No OrganizationAccess matches the given query."},
265+
)
259266

260267
def test_admin_api_organization_addresses_request_update_with_fake_organization_id(
261268
self,

src/backend/joanie/tests/core/test_api_certificate.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ def test_api_certificate_read_authenticated_from_an_order(self, _mock_thumbnail)
446446
)
447447

448448
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
449-
self.assertDictEqual(response.json(), {"detail": "Not found."})
449+
self.assertDictEqual(
450+
response.json(), {"detail": "No Certificate matches the given query."}
451+
)
450452

451453
# - Try to retrieve an owned certificate should return the certificate id
452454
response = self.client.get(
@@ -535,7 +537,9 @@ def test_api_certificate_read_authenticated_from_an_enrollment(
535537
)
536538

537539
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
538-
self.assertDictEqual(response.json(), {"detail": "Not found."})
540+
self.assertDictEqual(
541+
response.json(), {"detail": "No Certificate matches the given query."}
542+
)
539543

540544
# - Try to retrieve an owned certificate should return the certificate id
541545
response = self.client.get(

src/backend/joanie/tests/core/test_api_contract.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,11 @@ def test_api_contracts_retrieve_with_owner_and_canceled_order(self):
815815
HTTP_AUTHORIZATION=f"Bearer {token}",
816816
)
817817

818-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
818+
self.assertContains(
819+
response,
820+
"No Contract matches the given query.",
821+
status_code=HTTPStatus.NOT_FOUND,
822+
)
819823

820824
def test_api_contracts_create_anonymous(self):
821825
"""Anonymous user cannot create a contract."""
@@ -1015,7 +1019,11 @@ def test_api_contract_download_authenticated_with_not_validate_order(self):
10151019
HTTP_AUTHORIZATION=f"Bearer {token}",
10161020
)
10171021

1018-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
1022+
self.assertContains(
1023+
response,
1024+
"No Contract matches the given query.",
1025+
status_code=HTTPStatus.NOT_FOUND,
1026+
)
10191027

10201028
def test_api_contract_download_authenticated_cannot_create(self):
10211029
"""
@@ -1128,7 +1136,11 @@ def test_api_contract_download_authenticated_should_fail_if_owner_is_not_the_act
11281136
HTTP_AUTHORIZATION=f"Bearer {token}",
11291137
)
11301138

1131-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
1139+
self.assertContains(
1140+
response,
1141+
"No Contract matches the given query.",
1142+
status_code=HTTPStatus.NOT_FOUND,
1143+
)
11321144

11331145
def test_api_contract_download_authenticated_should_fail_if_contract_is_not_signed(
11341146
self,

src/backend/joanie/tests/core/test_api_course.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,9 @@ def test_api_course_get_authenticated_no_access(self):
259259
)
260260

261261
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
262-
self.assertDictEqual(response.json(), {"detail": "Not found."})
262+
self.assertDictEqual(
263+
response.json(), {"detail": "No Course matches the given query."}
264+
)
263265

264266
@mock.patch.object(
265267
fields.ThumbnailDetailField,

src/backend/joanie/tests/core/test_api_course_product_relations.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,9 @@ def test_api_course_product_relation_read_detail_no_organization(self):
542542
response = self.client.get(
543543
f"/api/v1.0/courses/{relation.course.id}/products/{relation.product.id}/",
544544
)
545-
546545
self.assertContains(
547546
response,
548-
"Not found.",
547+
"No CourseProductRelation matches the given query.",
549548
status_code=HTTPStatus.NOT_FOUND,
550549
)
551550

@@ -565,7 +564,7 @@ def test_api_course_product_relation_read_detail_no_organization(self):
565564

566565
self.assertContains(
567566
response,
568-
"Not found.",
567+
"No CourseProductRelation matches the given query.",
569568
status_code=HTTPStatus.NOT_FOUND,
570569
)
571570

@@ -576,7 +575,7 @@ def test_api_course_product_relation_read_detail_no_organization(self):
576575

577576
self.assertContains(
578577
response,
579-
"Not found.",
578+
"No CourseProductRelation matches the given query.",
580579
status_code=HTTPStatus.NOT_FOUND,
581580
)
582581

src/backend/joanie/tests/core/test_api_course_run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def test_api_course_run_read_detail_not_listed_anonymous(self):
220220

221221
self.assertContains(
222222
response,
223-
"Not found.",
223+
"No CourseRun matches the given query.",
224224
status_code=HTTPStatus.NOT_FOUND,
225225
)
226226

@@ -239,7 +239,7 @@ def test_api_course_run_read_detail_not_listed_authenticated(self):
239239

240240
self.assertContains(
241241
response,
242-
"Not found.",
242+
"No CourseRun matches the given query.",
243243
status_code=HTTPStatus.NOT_FOUND,
244244
)
245245

src/backend/joanie/tests/core/test_api_course_wishes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_api_course_wish_unknown_course(self):
8585

8686
self.assertContains(
8787
response,
88-
"Not found.",
88+
"No Course matches the given query.",
8989
status_code=HTTPStatus.NOT_FOUND,
9090
)
9191

src/backend/joanie/tests/core/test_api_courses_contract.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,11 @@ def test_api_courses_contracts_retrieve_with_accesses_and_canceled_order(self):
583583
HTTP_AUTHORIZATION=f"Bearer {token}",
584584
)
585585

586-
self.assertContains(response, "Not found.", status_code=HTTPStatus.NOT_FOUND)
586+
self.assertContains(
587+
response,
588+
"No Contract matches the given query.",
589+
status_code=HTTPStatus.NOT_FOUND,
590+
)
587591

588592
def test_api_courses_contracts_retrieve_with_accesses_and_course_code(self):
589593
"""

src/backend/joanie/tests/core/test_api_enrollment.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,9 @@ def test_api_enrollment_read_detail_authenticated_not_owner(self, _mock_set):
796796
)
797797
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
798798

799-
self.assertDictEqual(response.json(), {"detail": "Not found."})
799+
self.assertDictEqual(
800+
response.json(), {"detail": "No Enrollment matches the given query."}
801+
)
800802

801803
def test_api_enrollment_create_anonymous(self):
802804
"""Anonymous users should not be able to create an enrollment."""
@@ -1581,7 +1583,9 @@ def test_api_enrollment_update_detail_state_not_owner(self, _mock_set):
15811583
)
15821584
self.assertEqual(response.status_code, HTTPStatus.NOT_FOUND)
15831585

1584-
self.assertDictEqual(response.json(), {"detail": "Not found."})
1586+
self.assertDictEqual(
1587+
response.json(), {"detail": "No Enrollment matches the given query."}
1588+
)
15851589

15861590
@mock.patch.object(OpenEdXLMSBackend, "set_enrollment", return_value=True)
15871591
@mock.patch.object(

0 commit comments

Comments
 (0)