mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 15:53:57 +00:00
Refactor Omada integration: encapsulate API calls in Omada class, update device management tasks, and enhance device creation tests
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 2m12s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 2m12s
This commit is contained in:
@ -35,11 +35,18 @@ class DeviceAPITestCase(APITestCase):
|
||||
response = self.client.get("/api/devices/")
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
def test_create_device(self):
|
||||
def test_create_device_with_no_vendor_mac(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
data = {"name": "New Device", "mac": "11:22:33:44:55:66"}
|
||||
response = self.client.post("/api/devices/", data)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
def test_create_device_with_vendor_mac(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
data = {"name": "New Device", "mac": "64:16:7F:21:51:A5"}
|
||||
response = self.client.post("/api/devices/", data)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertIn("New Device", response.data["name"])
|
||||
|
||||
def test_create_device_invalid_mac(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
@ -48,6 +55,15 @@ class DeviceAPITestCase(APITestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn("Invalid mac address.", response.data["message"])
|
||||
|
||||
def test_mac_address_already_exists(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
data = {"name": "Existing Device", "mac": self.device.mac}
|
||||
response = self.client.post("/api/devices/", data)
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn(
|
||||
"Device with this mac address already exists.", response.data["message"]
|
||||
)
|
||||
|
||||
def test_update_device(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
data = {"name": "Updated Device"}
|
||||
@ -59,14 +75,14 @@ class DeviceAPITestCase(APITestCase):
|
||||
def test_block_device(self):
|
||||
self.client.credentials(HTTP_AUTHORIZATION=f"Token {self.token}")
|
||||
data = {
|
||||
"blocked": True, # also use Python boolean here, not a string
|
||||
"blocked": True,
|
||||
"reason_for_blocking": "hello",
|
||||
"blocked_by": "ADMIN",
|
||||
}
|
||||
response = self.client.put(
|
||||
f"/api/devices/{self.device.pk}/block/",
|
||||
data,
|
||||
format="json", # ✅ this is crucial!
|
||||
format="json",
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.device.refresh_from_db()
|
||||
|
@ -63,7 +63,6 @@ class DeviceListCreateAPIView(
|
||||
return Response({"message": "MAC address vendor not found."}, status=400)
|
||||
|
||||
mac = re.sub(NORMALIZE_MAC_REGEX, "-", mac).upper()
|
||||
request.data["mac"] = mac
|
||||
|
||||
return super().create(request, *args, **kwargs)
|
||||
|
||||
|
Reference in New Issue
Block a user