mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Changes to tests as per Jeremy
This commit is contained in:
parent
b093f432bb
commit
ccd31322d8
@ -2681,6 +2681,13 @@ class InterfaceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
)
|
)
|
||||||
VRF.objects.bulk_create(vrfs)
|
VRF.objects.bulk_create(vrfs)
|
||||||
|
|
||||||
|
# Virtual Device Context Creation
|
||||||
|
vdcs = (
|
||||||
|
VirtualDeviceContext(device=devices[3], name='VDC 1', identifier=1, status=VirtualDeviceContextStatusChoices.STATUS_ACTIVE),
|
||||||
|
VirtualDeviceContext(device=devices[3], name='VDC 2', identifier=2, status=VirtualDeviceContextStatusChoices.STATUS_PLANNED),
|
||||||
|
)
|
||||||
|
VirtualDeviceContext.objects.bulk_create(vdcs)
|
||||||
|
|
||||||
# VirtualChassis assignment for filtering
|
# VirtualChassis assignment for filtering
|
||||||
virtual_chassis = VirtualChassis.objects.create(master=devices[0])
|
virtual_chassis = VirtualChassis.objects.create(master=devices[0])
|
||||||
Device.objects.filter(pk=devices[0].pk).update(virtual_chassis=virtual_chassis, vc_position=1, vc_priority=1)
|
Device.objects.filter(pk=devices[0].pk).update(virtual_chassis=virtual_chassis, vc_position=1, vc_priority=1)
|
||||||
@ -2793,6 +2800,12 @@ class InterfaceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
)
|
)
|
||||||
Interface.objects.bulk_create(interfaces)
|
Interface.objects.bulk_create(interfaces)
|
||||||
|
|
||||||
|
interfaces[3].vdcs.set([vdcs[0], vdcs[1]])
|
||||||
|
interfaces[4].vdcs.set([vdcs[0], vdcs[1]])
|
||||||
|
interfaces[5].vdcs.set([vdcs[0]])
|
||||||
|
interfaces[6].vdcs.set([vdcs[0]])
|
||||||
|
interfaces[7].vdcs.set([vdcs[1]])
|
||||||
|
|
||||||
# Cables
|
# Cables
|
||||||
Cable(a_terminations=[interfaces[0]], b_terminations=[interfaces[3]]).save()
|
Cable(a_terminations=[interfaces[0]], b_terminations=[interfaces[3]]).save()
|
||||||
Cable(a_terminations=[interfaces[1]], b_terminations=[interfaces[4]]).save()
|
Cable(a_terminations=[interfaces[1]], b_terminations=[interfaces[4]]).save()
|
||||||
@ -2997,6 +3010,22 @@ class InterfaceTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
params = {'vrf': [vrfs[0].rd, vrfs[1].rd]}
|
params = {'vrf': [vrfs[0].rd, vrfs[1].rd]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_vdc(self):
|
||||||
|
params = {'vdc': ['VDC 1']}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||||
|
|
||||||
|
devices = Device.objects.last()
|
||||||
|
vdc = VirtualDeviceContext.objects.filter(device=devices, name='VDC 2')
|
||||||
|
params = {'vdc_id': vdc.values_list('pk', flat=True)}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
|
def test_vdc_identifier(self):
|
||||||
|
devices = Device.objects.last()
|
||||||
|
vdc = VirtualDeviceContext.objects.filter(device=devices, name='VDC 2')
|
||||||
|
params = {'vdc_identifier': vdc.values_list('identifier', flat=True)}
|
||||||
|
print(params)
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
|
|
||||||
class FrontPortTestCase(TestCase, ChangeLoggedFilterSetTests):
|
class FrontPortTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
queryset = FrontPort.objects.all()
|
queryset = FrontPort.objects.all()
|
||||||
@ -4254,7 +4283,9 @@ class PowerFeedTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 1)
|
||||||
|
|
||||||
|
|
||||||
class VirtualDeviceContextBaseTestCase:
|
class VirtualDeviceContextTestCase(TestCase, ChangeLoggedFilterSetTests):
|
||||||
|
queryset = VirtualDeviceContext.objects.all()
|
||||||
|
filterset = VirtualDeviceContextFilterSet
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
@ -4266,21 +4297,6 @@ class VirtualDeviceContextBaseTestCase:
|
|||||||
)
|
)
|
||||||
Site.objects.bulk_create(sites)
|
Site.objects.bulk_create(sites)
|
||||||
|
|
||||||
locations = (
|
|
||||||
Location(name='Location 1', site=sites[0], slug='location-1'),
|
|
||||||
Location(name='Location 2', site=sites[1], slug='location-1'),
|
|
||||||
Location(name='Location 3', site=sites[2], slug='location-1'),
|
|
||||||
)
|
|
||||||
for location in locations:
|
|
||||||
location.save()
|
|
||||||
|
|
||||||
racks = (
|
|
||||||
Rack(name='Rack 1', site=sites[0], location=locations[0]),
|
|
||||||
Rack(name='Rack 2', site=sites[1], location=locations[1]),
|
|
||||||
Rack(name='Rack 3', site=sites[2], location=locations[2]),
|
|
||||||
)
|
|
||||||
Rack.objects.bulk_create(racks)
|
|
||||||
|
|
||||||
tenants = (
|
tenants = (
|
||||||
Tenant(name='Tenant 1', slug='tenant-1'),
|
Tenant(name='Tenant 1', slug='tenant-1'),
|
||||||
Tenant(name='Tenant 2', slug='tenant-2'),
|
Tenant(name='Tenant 2', slug='tenant-2'),
|
||||||
@ -4293,9 +4309,9 @@ class VirtualDeviceContextBaseTestCase:
|
|||||||
device_role = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1')
|
device_role = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1')
|
||||||
|
|
||||||
devices = (
|
devices = (
|
||||||
Device(name='Device 1', device_type=device_type, device_role=device_role, site=sites[0], rack=racks[0], location=locations[0], position=1),
|
Device(name='Device 1', device_type=device_type, device_role=device_role, site=sites[0]),
|
||||||
Device(name='Device 2', device_type=device_type, device_role=device_role, site=sites[1], rack=racks[1], location=locations[1], position=1),
|
Device(name='Device 2', device_type=device_type, device_role=device_role, site=sites[1]),
|
||||||
Device(name='Device 3', device_type=device_type, device_role=device_role, site=sites[2], rack=racks[2], location=locations[2], position=1),
|
Device(name='Device 3', device_type=device_type, device_role=device_role, site=sites[2]),
|
||||||
)
|
)
|
||||||
Device.objects.bulk_create(devices)
|
Device.objects.bulk_create(devices)
|
||||||
|
|
||||||
@ -4310,38 +4326,24 @@ class VirtualDeviceContextBaseTestCase:
|
|||||||
VirtualDeviceContext.objects.bulk_create(vdcs)
|
VirtualDeviceContext.objects.bulk_create(vdcs)
|
||||||
|
|
||||||
interfaces = (
|
interfaces = (
|
||||||
Interface(device=devices[0], name='Interface 1', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
Interface(device=devices[0], name='Interface 1', type='virtual'),
|
||||||
Interface(device=devices[0], name='Interface 2', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
Interface(device=devices[0], name='Interface 2', type='virtual'),
|
||||||
Interface(device=devices[1], name='Interface 3', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[1], name='Interface 4', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[2], name='Interface 5', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[2], name='Interface 6', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[0], name='Interface 7', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[0], name='Interface 8', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[1], name='Interface 9', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[1], name='Interface 10', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[2], name='Interface 11', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
Interface(device=devices[2], name='Interface 12', type=InterfaceTypeChoices.TYPE_1GE_FIXED),
|
|
||||||
)
|
)
|
||||||
Interface.objects.bulk_create(interfaces)
|
Interface.objects.bulk_create(interfaces)
|
||||||
|
|
||||||
interfaces[0].vdcs.set([vdcs[0], vdcs[1]])
|
interfaces[0].vdcs.set([vdcs[0]])
|
||||||
interfaces[1].vdcs.set([vdcs[0], vdcs[1]])
|
interfaces[1].vdcs.set([vdcs[1]])
|
||||||
interfaces[2].vdcs.set([vdcs[2], vdcs[3]])
|
|
||||||
interfaces[3].vdcs.set([vdcs[2], vdcs[3]])
|
|
||||||
interfaces[4].vdcs.set([vdcs[4], vdcs[5]])
|
|
||||||
interfaces[5].vdcs.set([vdcs[4], vdcs[5]])
|
|
||||||
interfaces[6].vdcs.set([vdcs[0]])
|
|
||||||
interfaces[7].vdcs.set([vdcs[1]])
|
|
||||||
interfaces[8].vdcs.set([vdcs[2]])
|
|
||||||
interfaces[9].vdcs.set([vdcs[3]])
|
|
||||||
interfaces[10].vdcs.set([vdcs[4]])
|
|
||||||
interfaces[11].vdcs.set([vdcs[5]])
|
|
||||||
|
|
||||||
|
addresses = (
|
||||||
|
IPAddress(assigned_object=interfaces[0], address='10.1.1.1/24'),
|
||||||
|
IPAddress(assigned_object=interfaces[1], address='10.1.1.2/24'),
|
||||||
|
)
|
||||||
|
IPAddress.objects.bulk_create(addresses)
|
||||||
|
|
||||||
class VirtualDeviceContextTestCase(VirtualDeviceContextBaseTestCase, TestCase, ChangeLoggedFilterSetTests):
|
vdcs[0].primary_ip4 = addresses[0]
|
||||||
queryset = VirtualDeviceContext.objects.all()
|
vdcs[0].save()
|
||||||
filterset = VirtualDeviceContextFilterSet
|
vdcs[1].primary_ip4 = addresses[1]
|
||||||
|
vdcs[1].save()
|
||||||
|
|
||||||
def test_device(self):
|
def test_device(self):
|
||||||
params = {'device': ['Device 1', 'Device 2']}
|
params = {'device': ['Device 1', 'Device 2']}
|
||||||
@ -4351,24 +4353,13 @@ class VirtualDeviceContextTestCase(VirtualDeviceContextBaseTestCase, TestCase, C
|
|||||||
params = {'status': ['active']}
|
params = {'status': ['active']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 3)
|
||||||
|
|
||||||
|
def test_device_id(self):
|
||||||
class VirtualDeviceContextInterfaceTestCase(VirtualDeviceContextBaseTestCase, TestCase, ChangeLoggedFilterSetTests):
|
devices = Device.objects.filter(name__in=['Device 1', 'Device 2'])
|
||||||
queryset = Interface.objects.all()
|
params = {'device_id': [devices[0].pk, devices[1].pk]}
|
||||||
filterset = InterfaceFilterSet
|
|
||||||
|
|
||||||
def test_vdc(self):
|
|
||||||
params = {'vdc': ['VDC 1']}
|
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 9)
|
|
||||||
|
|
||||||
devices = Device.objects.first()
|
|
||||||
vdc = VirtualDeviceContext.objects.filter(device=devices)
|
|
||||||
params = {'vdc_id': vdc.values_list('pk', flat=True)}
|
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||||
|
|
||||||
def test_vdc_identifier(self):
|
def test_has_primary_ip(self):
|
||||||
devices = Device.objects.first()
|
params = {'has_primary_ip': True}
|
||||||
vdc = VirtualDeviceContext.objects.filter(device=devices)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
params = {'vdc_identifier': vdc.values_list('identifier', flat=True)}
|
params = {'has_primary_ip': False}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 4)
|
||||||
|
|
||||||
# TODO: Connection filters
|
|
||||||
|
@ -590,7 +590,7 @@ class CableTestCase(TestCase):
|
|||||||
cable.clean()
|
cable.clean()
|
||||||
|
|
||||||
|
|
||||||
class CableTestCase(TestCase):
|
class VirtualDeviceContextTestCase(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
@ -606,12 +606,32 @@ class CableTestCase(TestCase):
|
|||||||
device_type=devicetype, device_role=devicerole, name='TestDevice1', site=site
|
device_type=devicetype, device_role=devicerole, name='TestDevice1', site=site
|
||||||
)
|
)
|
||||||
|
|
||||||
self.vdc1 = VirtualDeviceContext.objects.create(device=self.device, name="VDC 1", identifier=1)
|
def test_vdc_and_interface_creation(self):
|
||||||
self.vdc2 = VirtualDeviceContext.objects.create(device=self.device, name="VDC 2", identifier=1)
|
|
||||||
|
|
||||||
self.interface1 = Interface.objects.create(device=self.device1, name='Eth1/1', type='10gbase-t')
|
vdc = VirtualDeviceContext(device=self.device, name="VDC 1", identifier=1, status='active')
|
||||||
self.interface2 = Interface.objects.create(device=self.device2, name='Eth1/2', type='10gbase-t')
|
vdc.full_clean()
|
||||||
self.interface3 = Interface.objects.create(device=self.device2, name='Eth1/3', type='10gbase-t')
|
vdc.save()
|
||||||
|
|
||||||
self.interface2.vdcs.set([self.vdc1])
|
interface = Interface(device=self.device, name='Eth1/1', type='10gbase-t')
|
||||||
self.interface3.vdcs.set([self.vdc2])
|
interface.full_clean()
|
||||||
|
interface.save()
|
||||||
|
|
||||||
|
interface.vdcs.set([vdc])
|
||||||
|
|
||||||
|
def test_vdc_duplicate_name(self):
|
||||||
|
vdc1 = VirtualDeviceContext(device=self.device, name="VDC 1", identifier=1, status='active')
|
||||||
|
vdc1.full_clean()
|
||||||
|
vdc1.save()
|
||||||
|
|
||||||
|
vdc2 = VirtualDeviceContext(device=self.device, name="VDC 1", identifier=2, status='active')
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
vdc2.full_clean()
|
||||||
|
|
||||||
|
def test_vdc_duplicate_identifier(self):
|
||||||
|
vdc1 = VirtualDeviceContext(device=self.device, name="VDC 1", identifier=1, status='active')
|
||||||
|
vdc1.full_clean()
|
||||||
|
vdc1.save()
|
||||||
|
|
||||||
|
vdc2 = VirtualDeviceContext(device=self.device, name="VDC 2", identifier=1, status='active')
|
||||||
|
with self.assertRaises(ValidationError):
|
||||||
|
vdc2.full_clean()
|
||||||
|
@ -3077,54 +3077,13 @@ class PowerFeedTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
response = self.client.get(reverse('dcim:powerfeed_trace', kwargs={'pk': powerfeed.pk}))
|
response = self.client.get(reverse('dcim:powerfeed_trace', kwargs={'pk': powerfeed.pk}))
|
||||||
self.assertHttpStatus(response, 200)
|
self.assertHttpStatus(response, 200)
|
||||||
|
|
||||||
# TODO: VDC Test Cases
|
|
||||||
|
|
||||||
|
|
||||||
class VirtualDeviceContextTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
class VirtualDeviceContextTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
||||||
model = VirtualDeviceContext
|
model = VirtualDeviceContext
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpTestData(cls):
|
def setUpTestData(cls):
|
||||||
|
devices = [create_test_device(name='Device 1')]
|
||||||
sites = (
|
|
||||||
Site(name='Site 1', slug='site-1'),
|
|
||||||
Site(name='Site 2', slug='site-2'),
|
|
||||||
)
|
|
||||||
Site.objects.bulk_create(sites)
|
|
||||||
|
|
||||||
location = Location(site=sites[0], name='Location 1', slug='location-1')
|
|
||||||
location.save()
|
|
||||||
|
|
||||||
racks = (
|
|
||||||
Rack(name='Rack 1', site=sites[0], location=location),
|
|
||||||
Rack(name='Rack 2', site=sites[1]),
|
|
||||||
)
|
|
||||||
Rack.objects.bulk_create(racks)
|
|
||||||
|
|
||||||
manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
|
|
||||||
|
|
||||||
devicetypes = (
|
|
||||||
DeviceType(model='Device Type 1', slug='device-type-1', manufacturer=manufacturer),
|
|
||||||
DeviceType(model='Device Type 2', slug='device-type-2', manufacturer=manufacturer),
|
|
||||||
)
|
|
||||||
DeviceType.objects.bulk_create(devicetypes)
|
|
||||||
|
|
||||||
deviceroles = (
|
|
||||||
DeviceRole(name='Device Role 1', slug='device-role-1'),
|
|
||||||
DeviceRole(name='Device Role 2', slug='device-role-2'),
|
|
||||||
)
|
|
||||||
DeviceRole.objects.bulk_create(deviceroles)
|
|
||||||
|
|
||||||
platforms = (
|
|
||||||
Platform(name='Platform 1', slug='platform-1'),
|
|
||||||
Platform(name='Platform 2', slug='platform-2'),
|
|
||||||
)
|
|
||||||
Platform.objects.bulk_create(platforms)
|
|
||||||
|
|
||||||
devices = (
|
|
||||||
Device(name='Device 1', site=sites[0], rack=racks[0], device_type=devicetypes[0], device_role=deviceroles[0], platform=platforms[0]),
|
|
||||||
)
|
|
||||||
Device.objects.bulk_create(devices)
|
|
||||||
|
|
||||||
vdcs = (
|
vdcs = (
|
||||||
VirtualDeviceContext(name='VDC 1', identifier=1, device=devices[0], status='active'),
|
VirtualDeviceContext(name='VDC 1', identifier=1, device=devices[0], status='active'),
|
||||||
|
Loading…
Reference in New Issue
Block a user