Parcourir la source

test(dcim): Add test coverage for Connection list views

Add test cases for Console, Power, and Interface Connection list views.
Include query count baselines and shared mixin for read-only connection
views that filter by complete cable paths.

Fixes #22577
Martin Hauser il y a 1 jour
Parent
commit
0663ea1a47
2 fichiers modifiés avec 107 ajouts et 0 suppressions
  1. 3 0
      netbox/dcim/tests/query_counts.json
  2. 104 0
      netbox/dcim/tests/test_views.py

+ 3 - 0
netbox/dcim/tests/query_counts.json

@@ -4,6 +4,7 @@
   "cablebundle:api_list_objects": 13,
   "cablebundle:list_objects_with_permission": 20,
   "cabletermination:api_list_objects": 16,
+  "consoleconnection:list_objects_with_permission": 29,
   "consoleport:api_list_objects": 14,
   "consoleport:list_objects_with_permission": 21,
   "consoleporttemplate:api_list_objects": 11,
@@ -24,6 +25,7 @@
   "frontporttemplate:api_list_objects": 12,
   "interface:api_list_objects": 23,
   "interface:list_objects_with_permission": 21,
+  "interfaceconnection:list_objects_with_permission": 41,
   "interfacetemplate:api_list_objects": 11,
   "inventoryitem:api_list_objects": 20,
   "inventoryitem:list_objects_with_permission": 23,
@@ -47,6 +49,7 @@
   "moduletypeprofile:list_objects_with_permission": 20,
   "platform:api_list_objects": 13,
   "platform:list_objects_with_permission": 21,
+  "powerconnection:list_objects_with_permission": 29,
   "powerfeed:api_list_objects": 15,
   "powerfeed:list_objects_with_permission": 22,
   "poweroutlet:api_list_objects": 14,

+ 104 - 0
netbox/dcim/tests/test_views.py

@@ -4052,6 +4052,110 @@ class CableTestCase(
         return data
 
 
+#
+# Connections
+#
+
+class ConnectionsListViewTestCaseMixin:
+    """
+    Shared behavior for the read-only connection list views.
+
+    These views list components whose cable paths are complete, but their URL names
+    do not follow the <model>_list pattern assumed by ModelViewTestCase.
+    """
+    url_base = None
+
+    def _get_base_url(self):
+        return self.url_base
+
+    def _get_queryset(self):
+        return self.model.objects.filter(_path__is_complete=True)
+
+
+class ConsoleConnectionsListViewTestCase(
+    ConnectionsListViewTestCaseMixin,
+    ViewTestCases.ListObjectsViewTestCase
+):
+    model = ConsolePort
+    url_base = 'dcim:console_connections_{}'
+    query_count_model_label = 'consoleconnection'
+
+    @classmethod
+    def setUpTestData(cls):
+        device = create_test_device('Device 1')
+        peer_device = create_test_device('Device 2')
+
+        console_ports = ConsolePort.objects.bulk_create((
+            ConsolePort(device=device, name='Console Port 1'),
+            ConsolePort(device=device, name='Console Port 2'),
+            ConsolePort(device=device, name='Console Port 3'),
+        ))
+        console_server_ports = ConsoleServerPort.objects.bulk_create((
+            ConsoleServerPort(device=peer_device, name='Console Server Port 1'),
+            ConsoleServerPort(device=peer_device, name='Console Server Port 2'),
+            ConsoleServerPort(device=peer_device, name='Console Server Port 3'),
+        ))
+
+        for console_port, console_server_port in zip(console_ports, console_server_ports):
+            Cable(a_terminations=[console_port], b_terminations=[console_server_port]).save()
+
+
+class PowerConnectionsListViewTestCase(
+    ConnectionsListViewTestCaseMixin,
+    ViewTestCases.ListObjectsViewTestCase
+):
+    model = PowerPort
+    url_base = 'dcim:power_connections_{}'
+    query_count_model_label = 'powerconnection'
+
+    @classmethod
+    def setUpTestData(cls):
+        device = create_test_device('Device 1')
+        peer_device = create_test_device('Device 2')
+
+        power_ports = PowerPort.objects.bulk_create((
+            PowerPort(device=device, name='Power Port 1'),
+            PowerPort(device=device, name='Power Port 2'),
+            PowerPort(device=device, name='Power Port 3'),
+        ))
+        power_outlets = PowerOutlet.objects.bulk_create((
+            PowerOutlet(device=peer_device, name='Power Outlet 1'),
+            PowerOutlet(device=peer_device, name='Power Outlet 2'),
+            PowerOutlet(device=peer_device, name='Power Outlet 3'),
+        ))
+
+        for power_port, power_outlet in zip(power_ports, power_outlets):
+            Cable(a_terminations=[power_port], b_terminations=[power_outlet]).save()
+
+
+class InterfaceConnectionsListViewTestCase(
+    ConnectionsListViewTestCaseMixin,
+    ViewTestCases.ListObjectsViewTestCase
+):
+    model = Interface
+    url_base = 'dcim:interface_connections_{}'
+    query_count_model_label = 'interfaceconnection'
+
+    @classmethod
+    def setUpTestData(cls):
+        device = create_test_device('Device 1')
+        peer_device = create_test_device('Device 2')
+
+        interfaces = Interface.objects.bulk_create((
+            Interface(device=device, name='Interface 1', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+            Interface(device=device, name='Interface 2', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+            Interface(device=device, name='Interface 3', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+        ))
+        peer_interfaces = Interface.objects.bulk_create((
+            Interface(device=peer_device, name='Interface 1', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+            Interface(device=peer_device, name='Interface 2', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+            Interface(device=peer_device, name='Interface 3', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
+        ))
+
+        for interface, peer_interface in zip(interfaces, peer_interfaces):
+            Cable(a_terminations=[interface], b_terminations=[peer_interface]).save()
+
+
 class VirtualChassisTestCase(ViewTestCases.PrimaryObjectViewTestCase):
     model = VirtualChassis