From 50c872c47c9064a020f80dd2c572b246278e48c9 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Mon, 23 May 2022 14:50:58 -0400 Subject: [PATCH] Clean up tests --- netbox/dcim/forms/connections.py | 2 +- netbox/dcim/graphql/types.py | 8 ++++++++ netbox/dcim/tests/test_models.py | 25 ------------------------- netbox/dcim/tests/test_views.py | 7 +++---- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/netbox/dcim/forms/connections.py b/netbox/dcim/forms/connections.py index 8b8b6e209..d39288bd5 100644 --- a/netbox/dcim/forms/connections.py +++ b/netbox/dcim/forms/connections.py @@ -150,7 +150,7 @@ def get_cable_form(a_type, b_type): # TODO: Temporary hack to work around list handling limitations with utils.normalize_querydict() for field_name in ('a_terminations', 'b_terminations'): - if field_name in kwargs['initial'] and type(kwargs['initial'][field_name]) is not list: + if field_name in kwargs.get('initial', {}) and type(kwargs['initial'][field_name]) is not list: kwargs['initial'][field_name] = [kwargs['initial'][field_name]] super().__init__(*args, **kwargs) diff --git a/netbox/dcim/graphql/types.py b/netbox/dcim/graphql/types.py index d25a6bba6..824e41fc9 100644 --- a/netbox/dcim/graphql/types.py +++ b/netbox/dcim/graphql/types.py @@ -99,6 +99,14 @@ class CableType(NetBoxObjectType): return self.length_unit or None +class CableTerminationType(NetBoxObjectType): + + class Meta: + model = models.CableTermination + fields = '__all__' + filterset_class = filtersets.CableTerminationFilterSet + + class ConsolePortType(ComponentObjectType): class Meta: diff --git a/netbox/dcim/tests/test_models.py b/netbox/dcim/tests/test_models.py index d070efad9..16b8e1c48 100644 --- a/netbox/dcim/tests/test_models.py +++ b/netbox/dcim/tests/test_models.py @@ -521,14 +521,6 @@ class CableTestCase(TestCase): self.assertIsNone(interface2.cable) self.assertIsNone(interface2._link_peer) - def test_cabletermination_deletion(self): - """ - When a CableTermination object is deleted, its attached Cable (if any) must also be deleted. - """ - self.interface1.delete() - cable = Cable.objects.filter(pk=self.cable.pk).first() - self.assertIsNone(cable) - def test_cable_validates_compatible_types(self): """ The clean method should have a check to ensure only compatible port types can be connected by a cable @@ -538,14 +530,6 @@ class CableTestCase(TestCase): with self.assertRaises(ValidationError): cable.clean() - def test_cable_cannot_have_the_same_terminination_on_both_ends(self): - """ - A cable cannot be made with the same A and B side terminations - """ - cable = Cable(a_terminations=[self.interface1], b_terminations=[self.interface1]) - with self.assertRaises(ValidationError): - cable.clean() - def test_cable_front_port_cannot_connect_to_corresponding_rear_port(self): """ A cable cannot connect a front port to its corresponding rear port @@ -554,15 +538,6 @@ class CableTestCase(TestCase): with self.assertRaises(ValidationError): cable.clean() - def test_cable_cannot_terminate_to_an_existing_connection(self): - """ - Either side of a cable cannot be terminated when that side already has a connection - """ - # Try to create a cable with the same interface terminations - cable = Cable(a_terminations=[self.interface2], b_terminations=[self.interface1]) - with self.assertRaises(ValidationError): - cable.clean() - def test_cable_cannot_terminate_to_a_provider_network_circuittermination(self): """ Neither side of a cable can be terminated to a CircuitTermination which is attached to a ProviderNetwork diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index 389e23457..ac9bcbdc3 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -2631,11 +2631,10 @@ class CableTestCase( interface_ct = ContentType.objects.get_for_model(Interface) cls.form_data = { + # TODO: Revisit this limitation # Changing terminations not supported when editing an existing Cable - 'termination_a_type': interface_ct.pk, - 'termination_a_id': interfaces[0].pk, - 'termination_b_type': interface_ct.pk, - 'termination_b_id': interfaces[3].pk, + 'a_terminations': interfaces[0].pk, + 'b_terminations': interfaces[3].pk, 'type': CableTypeChoices.TYPE_CAT6, 'status': LinkStatusChoices.STATUS_PLANNED, 'label': 'Label',