Skip to content

Commit 6ae8103

Browse files
committed
[fix] Use uuid path converter in geo URLs
1 parent 3b7ff66 commit 6ae8103

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

openwisp_controller/geo/tests/test_api.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.test import TestCase
88
from django.test.client import BOUNDARY, MULTIPART_CONTENT, encode_multipart
99
from django.urls import reverse
10+
from django.urls.exceptions import NoReverseMatch
1011
from PIL import Image
1112
from rest_framework.authtoken.models import Token
1213
from swapper import load_model
@@ -499,19 +500,21 @@ def test_post_location_list(self):
499500
self.assertEqual(response.status_code, 201)
500501

501502
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"):
509504
location = self._create_location()
510505
path = reverse("geo_api:detail_location", args=[location.pk])
511506
with self.assertNumQueries(3):
512507
response = self.client.get(path)
513508
self.assertEqual(response.status_code, 200)
514509

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+
515518
def test_put_location_detail(self):
516519
l1 = self._create_location()
517520
path = reverse("geo_api:detail_location", args=[l1.pk])

openwisp_controller/geo/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
def get_geo_urls(geo_views):
55
return [
66
path(
7-
"api/v1/controller/device/<str:pk>/coordinates/",
7+
"api/v1/controller/device/<uuid:pk>/coordinates/",
88
geo_views.device_coordinates,
99
name="device_coordinates",
1010
),
1111
path(
12-
"api/v1/controller/device/<str:pk>/location/",
12+
"api/v1/controller/device/<uuid:pk>/location/",
1313
geo_views.device_location,
1414
name="device_location",
1515
),
@@ -19,7 +19,7 @@ def get_geo_urls(geo_views):
1919
name="location_geojson",
2020
),
2121
path(
22-
"api/v1/controller/location/<str:pk>/device/",
22+
"api/v1/controller/location/<uuid:pk>/device/",
2323
geo_views.location_device_list,
2424
name="location_device_list",
2525
),
@@ -29,15 +29,15 @@ def get_geo_urls(geo_views):
2929
name="list_floorplan",
3030
),
3131
path(
32-
"api/v1/controller/floorplan/<str:pk>/",
32+
"api/v1/controller/floorplan/<uuid:pk>/",
3333
geo_views.detail_floorplan,
3434
name="detail_floorplan",
3535
),
3636
path(
3737
"api/v1/controller/location/", geo_views.list_location, name="list_location"
3838
),
3939
path(
40-
"api/v1/controller/location/<str:pk>/",
40+
"api/v1/controller/location/<uuid:pk>/",
4141
geo_views.detail_location,
4242
name="detail_location",
4343
),

0 commit comments

Comments
 (0)