1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Clean up tests

This commit is contained in:
jeremystretch
2022-11-17 10:24:03 -05:00
parent 977b79ecee
commit d4a231585a
9 changed files with 353 additions and 288 deletions

View File

@@ -1954,37 +1954,37 @@ class CableTest(APIViewTestCases.APIViewTestCase):
class ConnectedDeviceTest(APITestCase):
def setUp(self):
super().setUp()
@classmethod
def setUpTestData(cls):
site = Site.objects.create(name='Site 1', slug='site-1')
manufacturer = Manufacturer.objects.create(name='Manufacturer 1', slug='manufacturer-1')
devicetype = DeviceType.objects.create(manufacturer=manufacturer, model='Device Type 1', slug='device-type-1')
devicerole = DeviceRole.objects.create(name='Device Role 1', slug='device-role-1', color='ff0000')
self.device1 = Device.objects.create(
device_type=devicetype, device_role=devicerole, name='TestDevice1', site=site
devices = (
Device(device_type=devicetype, device_role=devicerole, name='TestDevice1', site=site),
Device(device_type=devicetype, device_role=devicerole, name='TestDevice2', site=site),
)
self.device2 = Device.objects.create(
device_type=devicetype, device_role=devicerole, name='TestDevice2', site=site
Device.objects.bulk_create(devices)
interfaces = (
Interface(device=devices[0], name='eth0'),
Interface(device=devices[1], name='eth0'),
Interface(device=devices[0], name='eth1'), # Not connected
)
self.interface1 = Interface.objects.create(device=self.device1, name='eth0')
self.interface2 = Interface.objects.create(device=self.device2, name='eth0')
self.interface3 = Interface.objects.create(device=self.device1, name='eth1') # Not connected
Interface.objects.bulk_create(interfaces)
cable = Cable(a_terminations=[self.interface1], b_terminations=[self.interface2])
cable = Cable(a_terminations=[interfaces[0]], b_terminations=[interfaces[1]])
cable.save()
@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_get_connected_device(self):
url = reverse('dcim-api:connected-device-list')
url_params = f'?peer_device={self.device1.name}&peer_interface={self.interface1.name}'
url_params = f'?peer_device=TestDevice1&peer_interface=eth0'
response = self.client.get(url + url_params, **self.header)
self.assertHttpStatus(response, status.HTTP_200_OK)
self.assertEqual(response.data['name'], self.device2.name)
self.assertEqual(response.data['name'], 'TestDevice2')
url_params = f'?peer_device={self.device1.name}&peer_interface={self.interface3.name}'
url_params = f'?peer_device=TestDevice1&peer_interface=eth1'
response = self.client.get(url + url_params, **self.header)
self.assertHttpStatus(response, status.HTTP_404_NOT_FOUND)