From 58ca48987baaadd0226a20680b3fe75a8bf9b6bc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 18 Sep 2023 10:38:49 -0400 Subject: [PATCH 1/2] Clean up tests --- netbox/dcim/tests/test_cablepaths.py | 30 ++++++++++------------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/netbox/dcim/tests/test_cablepaths.py b/netbox/dcim/tests/test_cablepaths.py index 73093be6d..783642ce1 100644 --- a/netbox/dcim/tests/test_cablepaths.py +++ b/netbox/dcim/tests/test_cablepaths.py @@ -40,7 +40,6 @@ class CablePathTestCase(TestCase): Return a given cable path :param nodes: Iterable of steps, with each step being either a single node or a list of nodes - :param is_active: Boolean indicating whether the end-to-end path is complete and active (optional) :return: The matching CablePath (if any) """ @@ -54,31 +53,24 @@ class CablePathTestCase(TestCase): def assertPathExists(self, nodes, **kwargs): """ - Assert that a CablePath from origin to destination with a specific intermediate path exists. + Assert that a CablePath from origin to destination with a specific intermediate path exists. Returns the + first matching CablePath, if found. :param nodes: Iterable of steps, with each step being either a single node or a list of nodes - :param is_active: Boolean indicating whether the end-to-end path is complete and active (optional) - - :return: The matching CablePath (if any) """ cablepath = self._get_cablepath(nodes, **kwargs) self.assertIsNotNone(cablepath, msg='CablePath not found') return cablepath - def assertPathNotExists(self, nodes, **kwargs): + def assertPathDoesNotExist(self, nodes, **kwargs): """ - Assert that a CablePath from origin to destination with a specific intermediate path exists. + Assert that a specific CablePath does *not* exist. :param nodes: Iterable of steps, with each step being either a single node or a list of nodes - :param is_active: Boolean indicating whether the end-to-end path is complete and active (optional) - - :return: The matching CablePath (if any) """ cablepath = self._get_cablepath(nodes, **kwargs) - self.assertIsNone(cablepath, msg='CablePath not found') - - return cablepath + self.assertIsNone(cablepath, msg='Unexpected CablePath found') def assertPathIsSet(self, origin, cablepath, msg=None): """ @@ -2044,8 +2036,8 @@ class CablePathTestCase(TestCase): def test_401_non_symmetric_paths(self): """ - [IF1] --C1-- [FP1] [RP1] --C2-- [RP2] [FP2] --C3-- -------------------------------------- [IF2] - [IF2] --C5-- [FP3] [RP3] --C4-- [RP4] [FP4] --C6-- [FP5] [RP5] --C7-- [RP6] [FP6] --C3---/ + [IF1] --C1-- [FP1] [RP1] --C2-- [RP2] [FP2] -------------------------------------------C3-- [IF2] + [IF2] --C5-- [FP3] [RP3] --C4-- [RP4] [FP4] --C6-- [FP5] [RP5] --C7-- [RP6] [FP6] --/ """ interface1 = Interface.objects.create(device=self.device, name='Interface 1') interface2 = Interface.objects.create(device=self.device, name='Interface 2') @@ -2165,7 +2157,7 @@ class CablePathTestCase(TestCase): def test_402_exclude_midspan_devices(self): """ [IF1] --C1-- [FP1] [RP1] --C2-- [RP2] [FP2] --C3-- [IF2] - [FP3] [RP3] --C4-- [RP4] [FP4] / + [FP3] [RP3] --C4-- [RP4] [FP4] """ device = Device.objects.create( site=self.site, @@ -2216,7 +2208,7 @@ class CablePathTestCase(TestCase): cable1.save() except AssertionError: pass - self.assertPathNotExists( + self.assertPathDoesNotExist( ( interface1, cable1, (frontport1, frontport3), (rearport1, rearport3), (cable2, cable4), (rearport2, rearport4), (frontport2, frontport4) @@ -2236,7 +2228,7 @@ class CablePathTestCase(TestCase): cable3.save() except AssertionError: pass - self.assertPathNotExists( + self.assertPathDoesNotExist( ( interface2, cable3, (frontport2, frontport4), (rearport2, rearport4), (cable2, cable4), (rearport1, rearport3), (frontport1, frontport2), cable1, interface1 @@ -2244,7 +2236,7 @@ class CablePathTestCase(TestCase): is_complete=True, is_active=True ) - self.assertPathNotExists( + self.assertPathDoesNotExist( ( interface1, cable1, (frontport1, frontport3), (rearport1, rearport3), (cable2, cable4), (rearport2, rearport4), (frontport2, frontport4), cable3, interface2 From fc8b5e17e4e554b55a09d02857462df0d19e41bc Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 18 Sep 2023 10:58:42 -0400 Subject: [PATCH 2/2] Remove unused objects from tests --- netbox/dcim/tests/test_cablepaths.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/netbox/dcim/tests/test_cablepaths.py b/netbox/dcim/tests/test_cablepaths.py index 783642ce1..eb284fde5 100644 --- a/netbox/dcim/tests/test_cablepaths.py +++ b/netbox/dcim/tests/test_cablepaths.py @@ -25,7 +25,6 @@ class CablePathTestCase(TestCase): manufacturer = Manufacturer.objects.create(name='Generic', slug='generic') device_type = DeviceType.objects.create(manufacturer=manufacturer, model='Test Device') - module_type = ModuleType.objects.create(manufacturer=manufacturer, model='Test Module') role = DeviceRole.objects.create(name='Device Role', slug='device-role') cls.device = Device.objects.create(site=cls.site, device_type=device_type, role=role, name='Test Device') @@ -1790,11 +1789,6 @@ class CablePathTestCase(TestCase): [IF1] --C1-- [FP1] [RP1] --C2-- [RP2] [FP2] --C3-- [IF2] [IF2] --C5-- [FP3] [RP3] --C4-- [RP4] [FP4] """ - module_type = ModuleType.objects.get(model='Test Module') - module_bay1 = ModuleBay.objects.create(device=self.device, name='Module Bay 1', position='1') - module_bay2 = ModuleBay.objects.create(device=self.device, name='Module Bay 2', position='2') - module_bay3 = ModuleBay.objects.create(device=self.device, name='Module Bay 3', position='3') - module_bay4 = ModuleBay.objects.create(device=self.device, name='Module Bay 4', position='4') interface1 = Interface.objects.create(device=self.device, name='Interface 1') interface2 = Interface.objects.create(device=self.device, name='Interface 2') interface3 = Interface.objects.create(device=self.device, name='Interface 3')