mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 21:16:27 -06:00
Test from_origin directly
This commit is contained in:
parent
6a42ca3ff2
commit
cdf7aa1ea5
@ -596,8 +596,7 @@ class CablePath(models.Model):
|
|||||||
if cable not in cables:
|
if cable not in cables:
|
||||||
cables.append(cable)
|
cables.append(cable)
|
||||||
path.append(cables)
|
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')
|
logger.warning('Infinite loop detected while updating cable path trace')
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ from dcim.choices import LinkStatusChoices
|
|||||||
from dcim.models import *
|
from dcim.models import *
|
||||||
from dcim.svg import CableTraceSVG
|
from dcim.svg import CableTraceSVG
|
||||||
from dcim.utils import object_to_path_node
|
from dcim.utils import object_to_path_node
|
||||||
|
from dcim.choices import CableEndChoices
|
||||||
|
|
||||||
|
|
||||||
class CablePathTestCase(TestCase):
|
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='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)
|
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(max_length=50)
|
||||||
cable_1.save()
|
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user