Skip to content

Commit 70c1c7b

Browse files
committed
[Test] Test for DeviceLocationView 500 error Fixes #1110
This test confirms the API correctly returns a 404 Not Found instead of crashing with a 500 FieldError. Fixes #1110
1 parent 41d899c commit 70c1c7b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

openwisp_controller/geo/tests/test_api.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.urls import reverse
1010
from django.urls.exceptions import NoReverseMatch
1111
from PIL import Image
12+
from rest_framework import status
1213
from rest_framework.authtoken.models import Token
1314
from swapper import load_model
1415

@@ -1036,3 +1037,20 @@ def test_deactivated_device(self):
10361037
with self.subTest("Test deleting DeviceLocation"):
10371038
response = self.client.delete(url)
10381039
self.assertEqual(response.status_code, 403)
1040+
1041+
def test_device_location_view_parent_permission(self):
1042+
org1 = self._create_org(name="Org One")
1043+
device1 = self._create_device(organization=org1)
1044+
org2 = self._create_org(name="Org Two")
1045+
manager_org2 = self._create_administrator(
1046+
organizations=[org2],
1047+
username="manager_org2",
1048+
password="test_password",
1049+
is_superuser=False,
1050+
is_staff=True,
1051+
)
1052+
self.client.force_login(manager_org2)
1053+
url = reverse("geo_api:device_location", args=[device1.pk])
1054+
response = self.client.get(url)
1055+
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
1056+
self.client.logout()

0 commit comments

Comments
 (0)