modified: netbox_services/engine/__init__.py

modified:   netbox_services/engine/allocators.py
modified:   netbox_services/engine/context.py
new file:   netbox_services/engine/mappers.py
modified:   netbox_services/engine/resolver.py
new file:   netbox_services/engine/templating.py
modified:   netbox_services/forms.py
modified:   netbox_services/models.py
modified:   netbox_services/tests/test_allocators.py
new file:   netbox_services/tests/test_mappers.py
modified:   netbox_services/tests/test_resolver.py
new file:   netbox_services/tests/test_templating.py
Simplify layout to template and service instances
This commit is contained in:
sven committed 2026-08-17 15:12:42 +02:00
1 parent 4ff9eac274
commit b1c9c7a40b
12 files changed
+1133 -33

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
"""Tests for the central link mapper."""
from netbox_services.engine.mappers import map_link, register_link, _LINK_MAP
class TestMapLink:
def test_interface_to_device(self):
from dcim.models import Device, Interface
assert map_link(Interface, Device) == "device"
def test_ipaddress_to_interface(self):
from dcim.models import Interface
from ipam.models import IPAddress
assert map_link(IPAddress, Interface) == "assigned_object"
def test_ipaddress_to_vminterface(self):
from ipam.models import IPAddress
from virtualization.models import VMInterface
assert map_link(IPAddress, VMInterface) == "assigned_object"
def test_interface_to_module(self):
from dcim.models import Interface, Module
assert map_link(Interface, Module) == "module"
def test_device_to_site(self):
from dcim.models import Device, Site
assert map_link(Device, Site) == "site"
def test_device_to_rack(self):
from dcim.models import Device, Rack
assert map_link(Device, Rack) == "rack"
def test_prefix_to_site_scope(self):
from dcim.models import Site
from ipam.models import Prefix
assert map_link(Prefix, Site) == "scope"
def test_vlan_to_vlangroup(self):
from ipam.models import VLAN, VLANGroup
assert map_link(VLAN, VLANGroup) == "group"
def test_interface_self_referential(self):
from dcim.models import Interface
assert map_link(Interface, Interface) == "parent"
def test_vminterface_to_virtualmachine(self):
from virtualization.models import VMInterface, VirtualMachine
assert map_link(VMInterface, VirtualMachine) == "virtual_machine"
def test_poweroutlet_to_powerport(self):
from dcim.models import PowerOutlet, PowerPort
assert map_link(PowerOutlet, PowerPort) == "power_port"
def test_frontport_to_rearport(self):
from dcim.models import FrontPort, RearPort
assert map_link(FrontPort, RearPort) == "rear_port"
def test_unmapped_returns_none(self):
from dcim.models import Device, Rack
from ipam.models import IPAddress
assert map_link(IPAddress, Device) is None
assert map_link(Device, Device) is None
assert map_link(Rack, Device) is None
class TestRegisterLink:
def test_register_new_link(self):
from dcim.models import Device, Rack
assert map_link(Rack, Device) is None
register_link("dcim.rack", "dcim.device", "device")
assert map_link(Rack, Device) == "device"
# cleanup
del _LINK_MAP[("dcim.rack", "dcim.device")]
assert map_link(Rack, Device) is None
def test_override_existing_link(self):
from dcim.models import Interface
original = map_link(Interface, Interface)
register_link("dcim.interface", "dcim.interface", "lag")
assert map_link(Interface, Interface) == "lag"
# restore
register_link("dcim.interface", "dcim.interface", original)