Skip to content

Commit

Permalink
Add test for device update
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Jan 30, 2025
1 parent 928acd1 commit cde40dd
Showing 1 changed file with 122 additions and 0 deletions.
122 changes: 122 additions & 0 deletions src/meshapi/tests/test_uisp_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,128 @@ def test_update_device_no_changes(self):

self.assertEqual(change_messages, [])

class TestUISPImportHandlersDontDuplicateHistory(TransactionTestCase):
def setUp(self) -> None:
self.node1 = Node(
network_number=1234,
status=Node.NodeStatus.ACTIVE,
type=Node.NodeType.STANDARD,
latitude=0,
longitude=0,
)
self.node1.save()

self.node2 = Node(
network_number=5678,
status=Node.NodeStatus.ACTIVE,
type=Node.NodeType.STANDARD,
latitude=0,
longitude=0,
)
self.node2.save()

self.building1 = Building(latitude=0, longitude=0, address_truth_sources=[])
self.building1.primary_node = self.node1
self.building1.save()

self.building2 = Building(latitude=0, longitude=0, address_truth_sources=[])
self.building2.primary_node = self.node2
self.building2.save()

self.device1 = Device(
node=self.node1,
status=Device.DeviceStatus.ACTIVE,
name="nycmesh-1234-dev1",
uisp_id="uisp-uuid1",
)
self.device1.save()

self.device2 = Device(
node=self.node2,
status=Device.DeviceStatus.ACTIVE,
name="nycmesh-5678-dev2",
uisp_id="uisp-uuid2",
)
self.device2.save()

self.link1 = Link(
from_device=self.device1,
to_device=self.device2,
status=Link.LinkStatus.ACTIVE,
type=Link.LinkType.FIVE_GHZ,
uisp_id="uisp-uuid1",
)
self.link1.save()




@patch("meshapi.util.uisp_import.sync_handlers.notify_admins_of_changes")
def test_import_and_sync_devices_and_ensure_history_does_not_duplicate(self, mock_notify_admins):

uisp_devices = [
{
"overview": {
"status": "active",
"createdAt": "2018-11-14T15:20:32.004Z",
"lastSeen": "2024-08-12T02:04:35.335Z",
"wirelessMode": "sta-ptmp",
},
"identification": {
"id": "uisp-uuid1",
"name": "nycmesh-1234-dev69", # Gonna change dev1 to dev69
"category": "wireless",
"type": "airMax",
},
},
{
"overview": {
"status": None,
"createdAt": "2018-11-14T15:20:32.004Z",
"lastSeen": "2024-08-12T02:04:35.335Z",
"wirelessMode": "sta-ptmp",
},
"identification": {
"id": "uisp-uuid2",
"name": "nycmesh-5678-dev2",
"category": "wireless",
"type": "airMax",
},
},
{
"overview": {
"status": "active",
"createdAt": "2018-11-14T15:20:32.004Z",
"lastSeen": "2024-08-12T02:04:35.335Z",
"wirelessMode": "sta-ptmp",
},
"identification": {
"id": "uisp-uuid100",
"name": "nycmesh-1234-dev100",
"category": "wireless",
"type": "airMax",
},
},
]

created_device = Device.objects.get(uisp_id="uisp-uuid1")
length_1 = len(created_device.history.all())

import_and_sync_uisp_devices(uisp_devices)

created_device.refresh_from_db()
length_2 = len(created_device.history.all())

# Run it again. Should be a noop
import_and_sync_uisp_devices(uisp_devices)

created_device.refresh_from_db()
length_3 = len(created_device.history.all())

print(length_1)
print(length_2)
print(length_3)


class TestUISPImportHandlers(TransactionTestCase):
def setUp(self):
Expand Down

0 comments on commit cde40dd

Please sign in to comment.