feat(dcim): Enhance test data setup with multiple sites

Refactors tests to create multiple sites and assign devices accordingly.
Updates CSV data to include `side_a_site` and `side_b_site` fields for
scenarios involving multiple sites. This improves test coverage and
alignment with real-world use cases.
This commit is contained in:
Martin Hauser 2025-07-21 21:47:18 +02:00
parent 8f7f258612
commit b963cf3dcf
No known key found for this signature in database

View File

@ -3266,17 +3266,21 @@ class CableTestCase(
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
site = Site.objects.create(name='Site 1', slug='site-1') sites = (
Site(name='Site 1', slug='site-1'),
Site(name='Site 2', slug='site-2'),
)
Site.objects.bulk_create(sites)
manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1') manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
devicetype = DeviceType.objects.create(model='Device Type 1', manufacturer=manufacturer) devicetype = DeviceType.objects.create(model='Device Type 1', manufacturer=manufacturer)
role = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1') role = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1')
vc = VirtualChassis.objects.create(name='Virtual Chassis') vc = VirtualChassis.objects.create(name='Virtual Chassis')
devices = ( devices = (
Device(name='Device 1', site=site, device_type=devicetype, role=role), Device(name='Device 1', site=sites[0], device_type=devicetype, role=role),
Device(name='Device 2', site=site, device_type=devicetype, role=role), Device(name='Device 2', site=sites[0], device_type=devicetype, role=role),
Device(name='Device 3', site=site, device_type=devicetype, role=role), Device(name='Device 3', site=sites[0], device_type=devicetype, role=role),
Device(name='Device 4', site=site, device_type=devicetype, role=role), Device(name='Device 1', site=sites[1], device_type=devicetype, role=role),
) )
Device.objects.bulk_create(devices) Device.objects.bulk_create(devices)
@ -3328,12 +3332,12 @@ class CableTestCase(
} }
cls.csv_data = ( cls.csv_data = (
"side_a_device,side_a_type,side_a_name,side_b_device,side_b_type,side_b_name", "side_a_site,side_a_device,side_a_type,side_a_name,side_b_site,side_b_device,side_b_type,side_b_name",
"Device 3,dcim.interface,Interface 1,Device 4,dcim.interface,Interface 1", "Site 1,Device 3,dcim.interface,Interface 1,Site 2,Device 1,dcim.interface,Interface 1",
"Device 3,dcim.interface,Interface 2,Device 4,dcim.interface,Interface 2", "Site 1,Device 3,dcim.interface,Interface 2,Site 2,Device 1,dcim.interface,Interface 2",
"Device 3,dcim.interface,Interface 3,Device 4,dcim.interface,Interface 3", "Site 1,Device 3,dcim.interface,Interface 3,Site 2,Device 1,dcim.interface,Interface 3",
"Device 1,dcim.interface,Device 2 Interface,Device 4,dcim.interface,Interface 4", "Site 1,Device 1,dcim.interface,Device 2 Interface,Site 2,Device 1,dcim.interface,Interface 4",
"Device 1,dcim.interface,Device 3 Interface,Device 4,dcim.interface,Interface 5", "Site 1,Device 1,dcim.interface,Device 3 Interface,Site 2,Device 1,dcim.interface,Interface 5",
) )
cls.csv_update_data = ( cls.csv_update_data = (