From 6b9fa5e76f22343f54bc3aa19a282dd5475bda61 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 5 Feb 2020 11:14:07 -0500 Subject: [PATCH] Enable tests for component bulk edit views --- netbox/dcim/tests/test_views.py | 55 ++++++++++++++++++----- netbox/utilities/testing/testcases.py | 3 +- netbox/virtualization/tests/test_views.py | 17 +++++-- netbox/virtualization/views.py | 2 - 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index baf80b522..328e0e603 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -726,7 +726,6 @@ class ConsoleServerPortTestCase(StandardTestCases.Views): # TODO test_create_object = None - test_bulk_edit_objects = None @classmethod def setUpTestData(cls): @@ -757,6 +756,12 @@ class ConsoleServerPortTestCase(StandardTestCases.Views): "Device 1,Console Server Port 6", ) + cls.bulk_edit_data = { + 'device': device.pk, + 'type': ConsolePortTypeChoices.TYPE_RJ45, + 'description': 'New description', + } + class PowerPortTestCase(StandardTestCases.Views): model = PowerPort @@ -808,7 +813,6 @@ class PowerOutletTestCase(StandardTestCases.Views): # TODO test_create_object = None - test_bulk_edit_objects = None @classmethod def setUpTestData(cls): @@ -847,23 +851,32 @@ class PowerOutletTestCase(StandardTestCases.Views): "Device 1,Power Outlet 6", ) + cls.bulk_edit_data = { + 'device': device.pk, + 'type': PowerOutletTypeChoices.TYPE_IEC_C13, + 'power_port': powerports[1].pk, + 'feed_leg': PowerOutletFeedLegChoices.FEED_LEG_B, + 'description': 'New description', + } + class InterfaceTestCase(StandardTestCases.Views): model = Interface # TODO test_create_object = None - test_bulk_edit_objects = None @classmethod def setUpTestData(cls): device = create_test_device('Device 1') - Interface.objects.bulk_create([ + interfaces = ( Interface(device=device, name='Interface 1'), Interface(device=device, name='Interface 2'), Interface(device=device, name='Interface 3'), - ]) + Interface(device=device, name='LAG', type=InterfaceTypeChoices.TYPE_LAG), + ) + Interface.objects.bulk_create(interfaces) vlans = ( VLAN(vid=1, name='VLAN1', site=device.site), @@ -879,11 +892,11 @@ class InterfaceTestCase(StandardTestCases.Views): 'name': 'Interface X', 'type': InterfaceTypeChoices.TYPE_1GE_GBIC, 'enabled': False, - 'lag': None, + 'lag': interfaces[3].pk, 'mac_address': EUI('01:02:03:04:05:06'), 'mtu': 2000, 'mgmt_only': True, - 'description': 'New description', + 'description': 'A front port', 'mode': InterfaceModeChoices.MODE_TAGGED, 'untagged_vlan': vlans[0].pk, 'tagged_vlans': [v.pk for v in vlans[1:4]], @@ -901,6 +914,20 @@ class InterfaceTestCase(StandardTestCases.Views): "Device 1,Interface 6,1000BASE-T (1GE)", ) + cls.bulk_edit_data = { + 'device': device.pk, + 'type': InterfaceTypeChoices.TYPE_1GE_GBIC, + 'enabled': False, + 'lag': interfaces[3].pk, + 'mac_address': EUI('01:02:03:04:05:06'), + 'mtu': 2000, + 'mgmt_only': True, + 'description': 'New description', + 'mode': InterfaceModeChoices.MODE_TAGGED, + 'untagged_vlan': vlans[0].pk, + 'tagged_vlans': [v.pk for v in vlans[1:4]], + } + class FrontPortTestCase(StandardTestCases.Views): model = FrontPort @@ -910,7 +937,6 @@ class FrontPortTestCase(StandardTestCases.Views): # TODO test_create_object = None - test_bulk_edit_objects = None @classmethod def setUpTestData(cls): @@ -952,6 +978,11 @@ class FrontPortTestCase(StandardTestCases.Views): "Device 1,Front Port 6,8P8C,Rear Port 6,1", ) + cls.bulk_edit_data = { + 'type': PortTypeChoices.TYPE_8P8C, + 'description': 'New description', + } + class RearPortTestCase(StandardTestCases.Views): model = RearPort @@ -961,7 +992,6 @@ class RearPortTestCase(StandardTestCases.Views): # TODO test_create_object = None - test_bulk_edit_objects = None @classmethod def setUpTestData(cls): @@ -978,7 +1008,7 @@ class RearPortTestCase(StandardTestCases.Views): 'name': 'Rear Port X', 'type': PortTypeChoices.TYPE_8P8C, 'positions': 3, - 'description': 'New description', + 'description': 'A rear port', 'tags': 'Alpha,Bravo,Charlie', # Extraneous model fields @@ -992,6 +1022,11 @@ class RearPortTestCase(StandardTestCases.Views): "Device 1,Rear Port 6,8P8C,1", ) + cls.bulk_edit_data = { + 'type': PortTypeChoices.TYPE_8P8C, + 'description': 'New description', + } + class DeviceBayTestCase(StandardTestCases.Views): model = DeviceBay diff --git a/netbox/utilities/testing/testcases.py b/netbox/utilities/testing/testcases.py index 094629676..7f9d6259e 100644 --- a/netbox/utilities/testing/testcases.py +++ b/netbox/utilities/testing/testcases.py @@ -270,7 +270,8 @@ class StandardTestCases: @override_settings(EXEMPT_VIEW_PERMISSIONS=[]) def test_bulk_edit_objects(self): - pk_list = self.model.objects.values_list('pk', flat=True) + # Bulk edit the first three objects only + pk_list = self.model.objects.values_list('pk', flat=True)[:3] request = { 'path': self._get_url('bulk_edit'), diff --git a/netbox/virtualization/tests/test_views.py b/netbox/virtualization/tests/test_views.py index 40a3b6c53..35ab03269 100644 --- a/netbox/virtualization/tests/test_views.py +++ b/netbox/virtualization/tests/test_views.py @@ -202,7 +202,6 @@ class InterfaceTestCase(StandardTestCases.Views): # TODO test_create_object = None - test_bulk_edit_objects = None def _get_base_url(self): # Interface belongs to the DCIM app, so we have to override the base URL @@ -222,9 +221,9 @@ class InterfaceTestCase(StandardTestCases.Views): VirtualMachine.objects.bulk_create(virtualmachines) Interface.objects.bulk_create([ - Interface(virtual_machine=virtualmachines[0], name='Interface 1'), - Interface(virtual_machine=virtualmachines[0], name='Interface 2'), - Interface(virtual_machine=virtualmachines[0], name='Interface 3'), + Interface(virtual_machine=virtualmachines[0], name='Interface 1', type=InterfaceTypeChoices.TYPE_VIRTUAL), + Interface(virtual_machine=virtualmachines[0], name='Interface 2', type=InterfaceTypeChoices.TYPE_VIRTUAL), + Interface(virtual_machine=virtualmachines[0], name='Interface 3', type=InterfaceTypeChoices.TYPE_VIRTUAL), ]) vlans = ( @@ -262,3 +261,13 @@ class InterfaceTestCase(StandardTestCases.Views): "Device 1,Interface 5,1000BASE-T (1GE)", "Device 1,Interface 6,1000BASE-T (1GE)", ) + + cls.bulk_edit_data = { + 'virtual_machine': virtualmachines[1].pk, + 'enabled': False, + 'mtu': 2000, + 'description': 'New description', + 'mode': InterfaceModeChoices.MODE_TAGGED, + # 'untagged_vlan': vlans[0].pk, + # 'tagged_vlans': [v.pk for v in vlans[1:4]], + } diff --git a/netbox/virtualization/views.py b/netbox/virtualization/views.py index 646fb000d..4198fbe40 100644 --- a/netbox/virtualization/views.py +++ b/netbox/virtualization/views.py @@ -353,7 +353,6 @@ class InterfaceDeleteView(PermissionRequiredMixin, ObjectDeleteView): class InterfaceBulkEditView(PermissionRequiredMixin, BulkEditView): permission_required = 'dcim.change_interface' queryset = Interface.objects.all() - parent_model = VirtualMachine table = tables.InterfaceTable form = forms.InterfaceBulkEditForm @@ -361,7 +360,6 @@ class InterfaceBulkEditView(PermissionRequiredMixin, BulkEditView): class InterfaceBulkDeleteView(PermissionRequiredMixin, BulkDeleteView): permission_required = 'dcim.delete_interface' queryset = Interface.objects.all() - parent_model = VirtualMachine table = tables.InterfaceTable