From cdf7aa1ea59b0ba818d5f4247ca5199ae2a32839 Mon Sep 17 00:00:00 2001 From: Brian Tiemann Date: Tue, 19 Nov 2024 10:30:32 -0500 Subject: [PATCH] Test from_origin directly --- netbox/dcim/models/cables.py | 3 +-- netbox/dcim/tests/test_cablepaths.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/netbox/dcim/models/cables.py b/netbox/dcim/models/cables.py index 745a146f2..f6c791819 100644 --- a/netbox/dcim/models/cables.py +++ b/netbox/dcim/models/cables.py @@ -596,8 +596,7 @@ class CablePath(models.Model): if cable not in cables: cables.append(cable) path.append(cables) - print(len(path), max_length) - if len(path) > max_length: + if len(path) >= max_length: logger.warning('Infinite loop detected while updating cable path trace') break diff --git a/netbox/dcim/tests/test_cablepaths.py b/netbox/dcim/tests/test_cablepaths.py index d04bfb80d..d4b9daae6 100644 --- a/netbox/dcim/tests/test_cablepaths.py +++ b/netbox/dcim/tests/test_cablepaths.py @@ -6,6 +6,7 @@ from dcim.choices import LinkStatusChoices from dcim.models import * from dcim.svg import CableTraceSVG from dcim.utils import object_to_path_node +from dcim.choices import CableEndChoices class CablePathTestCase(TestCase): @@ -2380,5 +2381,15 @@ class CablePathTestCase(TestCase): CableTermination.objects.create(cable=cable_2, cable_end='A', termination_type=ct_frontport, termination_id=front_port_2.id) CableTermination.objects.create(cable=cable_2, cable_end='B', termination_type=ct_rearport, termination_id=rear_splice.id) - cable_1._terminations_modified = True - cable_1.save() + cable_1.save(max_length=50) + a_terminations = [] + b_terminations = [] + for t in cable_1.terminations.all(): + if t.cable_end == CableEndChoices.SIDE_A: + a_terminations.append(t.termination) + else: + b_terminations.append(t.termination) + cp = CablePath.from_origin(a_terminations, max_length=50) + self.assertEqual(len(cp.path), 50) + cp = CablePath.from_origin(b_terminations, max_length=10) + self.assertEqual(len(cp.path), 3)