|
7 | 7 | from django.test import TestCase
|
8 | 8 | from django.test.client import BOUNDARY, MULTIPART_CONTENT, encode_multipart
|
9 | 9 | from django.urls import reverse
|
| 10 | +from django.urls.exceptions import NoReverseMatch |
10 | 11 | from PIL import Image
|
11 | 12 | from rest_framework.authtoken.models import Token
|
12 | 13 | from swapper import load_model
|
@@ -499,19 +500,21 @@ def test_post_location_list(self):
|
499 | 500 | self.assertEqual(response.status_code, 201)
|
500 | 501 |
|
501 | 502 | def test_get_location_detail(self):
|
502 |
| - with self.subTest("Test with invalid pk"): |
503 |
| - path = reverse("geo_api:detail_location", args=["wrong-pk"]) |
504 |
| - with self.assertNumQueries(1): |
505 |
| - response = self.client.get(path) |
506 |
| - self.assertEqual(response.status_code, 404) |
507 |
| - |
508 |
| - with self.subTest("Test with correct pk"): |
| 503 | + with self.subTest("Test standard behavior"): |
509 | 504 | location = self._create_location()
|
510 | 505 | path = reverse("geo_api:detail_location", args=[location.pk])
|
511 | 506 | with self.assertNumQueries(3):
|
512 | 507 | response = self.client.get(path)
|
513 | 508 | self.assertEqual(response.status_code, 200)
|
514 | 509 |
|
| 510 | + with self.subTest("Test with invalid pk"): |
| 511 | + try: |
| 512 | + reverse("geo_api:detail_location", args=["wrong-pk"]) |
| 513 | + except NoReverseMatch as e: |
| 514 | + self.assertIn("wrong-pk", str(e)) |
| 515 | + else: |
| 516 | + self.fail("NoReverseMatch not raised as expected") |
| 517 | + |
515 | 518 | def test_put_location_detail(self):
|
516 | 519 | l1 = self._create_location()
|
517 | 520 | path = reverse("geo_api:detail_location", args=[l1.pk])
|
|
0 commit comments