diff --git a/netbox/dcim/forms/bulk_create.py b/netbox/dcim/forms/bulk_create.py index 43b852928..7dc0684ac 100644 --- a/netbox/dcim/forms/bulk_create.py +++ b/netbox/dcim/forms/bulk_create.py @@ -3,7 +3,7 @@ from django import forms from dcim.models import * from extras.forms import CustomFieldsMixin from extras.models import Tag -from utilities.forms import DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model +from utilities.forms import BootstrapMixin, DynamicModelMultipleChoiceField, ExpandableNameField, form_from_model from .object_create import ComponentCreateForm __all__ = ( @@ -24,7 +24,7 @@ __all__ = ( # Device components # -class DeviceBulkAddComponentForm(CustomFieldsMixin, ComponentCreateForm): +class DeviceBulkAddComponentForm(BootstrapMixin, CustomFieldsMixin, ComponentCreateForm): pk = forms.ModelMultipleChoiceField( queryset=Device.objects.all(), widget=forms.MultipleHiddenInput() @@ -44,7 +44,7 @@ class ConsolePortBulkCreateForm( DeviceBulkAddComponentForm ): model = ConsolePort - field_order = ('name_pattern', 'label_pattern', 'type', 'mark_connected', 'description', 'tags') + field_order = ('name', 'label', 'type', 'mark_connected', 'description', 'tags') class ConsoleServerPortBulkCreateForm( @@ -52,7 +52,7 @@ class ConsoleServerPortBulkCreateForm( DeviceBulkAddComponentForm ): model = ConsoleServerPort - field_order = ('name_pattern', 'label_pattern', 'type', 'speed', 'description', 'tags') + field_order = ('name', 'label', 'type', 'speed', 'description', 'tags') class PowerPortBulkCreateForm( @@ -60,7 +60,7 @@ class PowerPortBulkCreateForm( DeviceBulkAddComponentForm ): model = PowerPort - field_order = ('name_pattern', 'label_pattern', 'type', 'maximum_draw', 'allocated_draw', 'description', 'tags') + field_order = ('name', 'label', 'type', 'maximum_draw', 'allocated_draw', 'description', 'tags') class PowerOutletBulkCreateForm( @@ -68,7 +68,7 @@ class PowerOutletBulkCreateForm( DeviceBulkAddComponentForm ): model = PowerOutlet - field_order = ('name_pattern', 'label_pattern', 'type', 'feed_leg', 'description', 'tags') + field_order = ('name', 'label', 'type', 'feed_leg', 'description', 'tags') class InterfaceBulkCreateForm( @@ -79,7 +79,7 @@ class InterfaceBulkCreateForm( ): model = Interface field_order = ( - 'name_pattern', 'label_pattern', 'type', 'enabled', 'speed', 'duplex', 'mtu', 'mgmt_only', 'poe_mode', + 'name', 'label', 'type', 'enabled', 'speed', 'duplex', 'mtu', 'mgmt_only', 'poe_mode', 'poe_type', 'mark_connected', 'description', 'tags', ) @@ -96,12 +96,12 @@ class RearPortBulkCreateForm( DeviceBulkAddComponentForm ): model = RearPort - field_order = ('name_pattern', 'label_pattern', 'type', 'positions', 'mark_connected', 'description', 'tags') + field_order = ('name', 'label', 'type', 'positions', 'mark_connected', 'description', 'tags') class ModuleBayBulkCreateForm(DeviceBulkAddComponentForm): model = ModuleBay - field_order = ('name_pattern', 'label_pattern', 'position_pattern', 'description', 'tags') + field_order = ('name', 'label', 'position_pattern', 'description', 'tags') position_pattern = ExpandableNameField( label='Position', @@ -112,7 +112,7 @@ class ModuleBayBulkCreateForm(DeviceBulkAddComponentForm): class DeviceBayBulkCreateForm(DeviceBulkAddComponentForm): model = DeviceBay - field_order = ('name_pattern', 'label_pattern', 'description', 'tags') + field_order = ('name', 'label', 'description', 'tags') class InventoryItemBulkCreateForm( @@ -121,6 +121,6 @@ class InventoryItemBulkCreateForm( ): model = InventoryItem field_order = ( - 'name_pattern', 'label_pattern', 'role', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered', + 'name', 'label', 'role', 'manufacturer', 'part_id', 'serial', 'asset_tag', 'discovered', 'description', 'tags', ) diff --git a/netbox/dcim/forms/object_create.py b/netbox/dcim/forms/object_create.py index 75283509a..4924587a0 100644 --- a/netbox/dcim/forms/object_create.py +++ b/netbox/dcim/forms/object_create.py @@ -79,23 +79,38 @@ class ComponentCreateForm(forms.Form): # class ConsolePortTemplateCreateForm(ComponentCreateForm, model_forms.ConsolePortTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.ConsolePortTemplateForm.Meta): + exclude = ('name', 'label') class ConsoleServerPortTemplateCreateForm(ComponentCreateForm, model_forms.ConsoleServerPortTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.ConsoleServerPortTemplateForm.Meta): + exclude = ('name', 'label') class PowerPortTemplateCreateForm(ComponentCreateForm, model_forms.PowerPortTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.PowerPortTemplateForm.Meta): + exclude = ('name', 'label') class PowerOutletTemplateCreateForm(ComponentCreateForm, model_forms.PowerOutletTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.PowerOutletTemplateForm.Meta): + exclude = ('name', 'label') class InterfaceTemplateCreateForm(ComponentCreateForm, model_forms.InterfaceTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.InterfaceTemplateForm.Meta): + exclude = ('name', 'label') class FrontPortTemplateCreateForm(ComponentCreateForm, model_forms.FrontPortTemplateForm): @@ -104,6 +119,10 @@ class FrontPortTemplateCreateForm(ComponentCreateForm, model_forms.FrontPortTemp label='Rear ports', help_text='Select one rear port assignment for each front port being created.', ) + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.FrontPortTemplateForm.Meta): + exclude = ('name', 'label') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -149,11 +168,17 @@ class FrontPortTemplateCreateForm(ComponentCreateForm, model_forms.FrontPortTemp class RearPortTemplateCreateForm(ComponentCreateForm, model_forms.RearPortTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.RearPortTemplateForm.Meta): + exclude = ('name', 'label') class DeviceBayTemplateCreateForm(ComponentCreateForm, model_forms.DeviceBayTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.DeviceBayTemplateForm.Meta): + exclude = ('name', 'label') class ModuleBayTemplateCreateForm(ComponentCreateForm, model_forms.ModuleBayTemplateForm): @@ -162,10 +187,17 @@ class ModuleBayTemplateCreateForm(ComponentCreateForm, model_forms.ModuleBayTemp required=False, help_text='Alphanumeric ranges are supported. (Must match the number of names being created.)' ) + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.ModuleBayTemplateForm.Meta): + exclude = ('name', 'label') class InventoryItemTemplateCreateForm(ComponentCreateForm, model_forms.InventoryItemTemplateForm): - pass + field_order = ('device_type', 'name', 'label') + + class Meta(model_forms.InventoryItemTemplateForm.Meta): + exclude = ('name', 'label') # @@ -173,23 +205,38 @@ class InventoryItemTemplateCreateForm(ComponentCreateForm, model_forms.Inventory # class ConsolePortCreateForm(ComponentCreateForm, model_forms.ConsolePortForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.ConsolePortForm.Meta): + exclude = ('name', 'label') class ConsoleServerPortCreateForm(ComponentCreateForm, model_forms.ConsoleServerPortForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.ConsoleServerPortForm.Meta): + exclude = ('name', 'label') class PowerPortCreateForm(ComponentCreateForm, model_forms.PowerPortForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.PowerPortForm.Meta): + exclude = ('name', 'label') class PowerOutletCreateForm(ComponentCreateForm, model_forms.PowerOutletForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.PowerOutletForm.Meta): + exclude = ('name', 'label') class InterfaceCreateForm(ComponentCreateForm, model_forms.InterfaceForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.InterfaceForm.Meta): + exclude = ('name', 'label') class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm): @@ -198,6 +245,10 @@ class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm): label='Rear ports', help_text='Select one rear port assignment for each front port being created.', ) + field_order = ('device', 'name', 'label') + + class Meta(model_forms.FrontPortForm.Meta): + exclude = ('name', 'label') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -236,11 +287,17 @@ class FrontPortCreateForm(ComponentCreateForm, model_forms.FrontPortForm): class RearPortCreateForm(ComponentCreateForm, model_forms.RearPortForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.RearPortForm.Meta): + exclude = ('name', 'label') class DeviceBayCreateForm(ComponentCreateForm, model_forms.DeviceBayForm): - pass + field_order = ('device', 'name', 'label') + + class Meta(model_forms.DeviceBayForm.Meta): + exclude = ('name', 'label') class ModuleBayCreateForm(ComponentCreateForm, model_forms.ModuleBayForm): @@ -249,11 +306,17 @@ class ModuleBayCreateForm(ComponentCreateForm, model_forms.ModuleBayForm): required=False, help_text='Alphanumeric ranges are supported. (Must match the number of names being created.)' ) + field_order = ('device', 'name', 'label') + + class Meta(model_forms.ModuleBayForm.Meta): + exclude = ('name', 'label') -class InventoryItemCreateForm(ComponentCreateForm): - # Device is assigned by the model form - field_order = ('name_pattern', 'label_pattern') +class InventoryItemCreateForm(ComponentCreateForm, model_forms.InventoryItemForm): + field_order = ('device', 'name', 'label') + + class Meta(model_forms.InventoryItemForm.Meta): + exclude = ('name', 'label') # diff --git a/netbox/dcim/tables/template_code.py b/netbox/dcim/tables/template_code.py index d34003ee5..dfc77b854 100644 --- a/netbox/dcim/tables/template_code.py +++ b/netbox/dcim/tables/template_code.py @@ -239,7 +239,7 @@ INTERFACE_BUTTONS = """
  • Inventory Item
  • {% endif %} {% if perms.dcim.add_interface %} -
  • Child Interface
  • +
  • Child Interface
  • {% endif %} {% if perms.ipam.add_l2vpntermination %}
  • L2VPN Termination
  • diff --git a/netbox/dcim/tests/test_forms.py b/netbox/dcim/tests/test_forms.py index aad282725..5dbcf89ae 100644 --- a/netbox/dcim/tests/test_forms.py +++ b/netbox/dcim/tests/test_forms.py @@ -129,8 +129,8 @@ class LabelTestCase(TestCase): """ interface_data = { 'device': self.device.pk, - 'name_pattern': 'eth[0-9]', - 'label_pattern': 'Interface[0-9]', + 'name': 'eth[0-9]', + 'label': 'Interface[0-9]', } form = InterfaceCreateForm(interface_data) @@ -142,10 +142,10 @@ class LabelTestCase(TestCase): """ bad_interface_data = { 'device': self.device.pk, - 'name_pattern': 'eth[0-9]', - 'label_pattern': 'Interface[0-1]', + 'name': 'eth[0-9]', + 'label': 'Interface[0-1]', } form = InterfaceCreateForm(bad_interface_data) self.assertFalse(form.is_valid()) - self.assertIn('label_pattern', form.errors) + self.assertIn('label', form.errors) diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index a25267166..d06a495f3 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -1082,6 +1082,7 @@ front-ports: class ConsolePortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = ConsolePortTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1106,7 +1107,7 @@ class ConsolePortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestC cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Console Port Template [4-6]', + 'name': 'Console Port Template [4-6]', 'type': ConsolePortTypeChoices.TYPE_RJ45, } @@ -1117,6 +1118,7 @@ class ConsolePortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestC class ConsoleServerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = ConsoleServerPortTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1141,7 +1143,7 @@ class ConsoleServerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateVie cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Console Server Port Template [4-6]', + 'name': 'Console Server Port Template [4-6]', 'type': ConsolePortTypeChoices.TYPE_RJ45, } @@ -1152,6 +1154,7 @@ class ConsoleServerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateVie class PowerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = PowerPortTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1178,7 +1181,7 @@ class PowerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Power Port Template [4-6]', + 'name': 'Power Port Template [4-6]', 'type': PowerPortTypeChoices.TYPE_IEC_C14, 'maximum_draw': 100, 'allocated_draw': 50, @@ -1193,6 +1196,7 @@ class PowerPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas class PowerOutletTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = PowerOutletTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1220,7 +1224,7 @@ class PowerOutletTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestC cls.bulk_create_data = { 'device_type': devicetype.pk, - 'name_pattern': 'Power Outlet Template [4-6]', + 'name': 'Power Outlet Template [4-6]', 'type': PowerOutletTypeChoices.TYPE_IEC_C13, 'power_port': powerports[0].pk, 'feed_leg': PowerOutletFeedLegChoices.FEED_LEG_B, @@ -1234,6 +1238,7 @@ class PowerOutletTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestC class InterfaceTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = InterfaceTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1259,9 +1264,9 @@ class InterfaceTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Interface Template [4-6]', + 'name': 'Interface Template [4-6]', # Test that a label can be applied to each generated interface templates - 'label_pattern': 'Interface Template Label [3-5]', + 'label': 'Interface Template Label [3-5]', 'type': InterfaceTypeChoices.TYPE_1GE_GBIC, 'mgmt_only': True, } @@ -1274,6 +1279,7 @@ class InterfaceTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas class FrontPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = FrontPortTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1306,7 +1312,7 @@ class FrontPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas cls.bulk_create_data = { 'device_type': devicetype.pk, - 'name_pattern': 'Front Port [4-6]', + 'name': 'Front Port [4-6]', 'type': PortTypeChoices.TYPE_8P8C, 'rear_port_set': [ '{}:1'.format(rp.pk) for rp in rearports[3:6] @@ -1320,6 +1326,7 @@ class FrontPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas class RearPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = RearPortTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1345,7 +1352,7 @@ class RearPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Rear Port Template [4-6]', + 'name': 'Rear Port Template [4-6]', 'type': PortTypeChoices.TYPE_8P8C, 'positions': 2, } @@ -1357,6 +1364,7 @@ class RearPortTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase class ModuleBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = ModuleBayTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1380,7 +1388,7 @@ class ModuleBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Module Bay Template [4-6]', + 'name': 'Module Bay Template [4-6]', } cls.bulk_edit_data = { @@ -1390,6 +1398,7 @@ class ModuleBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas class DeviceBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = DeviceBayTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1413,7 +1422,7 @@ class DeviceBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Device Bay Template [4-6]', + 'name': 'Device Bay Template [4-6]', } cls.bulk_edit_data = { @@ -1423,6 +1432,7 @@ class DeviceBayTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCas class InventoryItemTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTestCase): model = InventoryItemTemplate + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1454,7 +1464,7 @@ class InventoryItemTemplateTestCase(ViewTestCases.DeviceComponentTemplateViewTes cls.bulk_create_data = { 'device_type': devicetypes[1].pk, - 'name_pattern': 'Inventory Item Template [4-6]', + 'name': 'Inventory Item Template [4-6]', 'manufacturer': manufacturers[1].pk, } @@ -1912,6 +1922,7 @@ class ModuleTestCase( class ConsolePortTestCase(ViewTestCases.DeviceComponentViewTestCase): model = ConsolePort + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1935,9 +1946,9 @@ class ConsolePortTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Console Port [4-6]', + 'name': 'Console Port [4-6]', # Test that a label can be applied to each generated console ports - 'label_pattern': 'Serial[3-5]', + 'label': 'Serial[3-5]', 'type': ConsolePortTypeChoices.TYPE_RJ45, 'description': 'A console port', 'tags': sorted([t.pk for t in tags]), @@ -1970,6 +1981,7 @@ class ConsolePortTestCase(ViewTestCases.DeviceComponentViewTestCase): class ConsoleServerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): model = ConsoleServerPort + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -1993,7 +2005,7 @@ class ConsoleServerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Console Server Port [4-6]', + 'name': 'Console Server Port [4-6]', 'type': ConsolePortTypeChoices.TYPE_RJ45, 'description': 'A console server port', 'tags': [t.pk for t in tags], @@ -2026,6 +2038,7 @@ class ConsoleServerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): class PowerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): model = PowerPort + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2051,7 +2064,7 @@ class PowerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Power Port [4-6]]', + 'name': 'Power Port [4-6]]', 'type': PowerPortTypeChoices.TYPE_IEC_C14, 'maximum_draw': 100, 'allocated_draw': 50, @@ -2088,6 +2101,7 @@ class PowerPortTestCase(ViewTestCases.DeviceComponentViewTestCase): class PowerOutletTestCase(ViewTestCases.DeviceComponentViewTestCase): model = PowerOutlet + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2119,7 +2133,7 @@ class PowerOutletTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Power Outlet [4-6]', + 'name': 'Power Outlet [4-6]', 'type': PowerOutletTypeChoices.TYPE_IEC_C13, 'power_port': powerports[1].pk, 'feed_leg': PowerOutletFeedLegChoices.FEED_LEG_B, @@ -2153,6 +2167,7 @@ class PowerOutletTestCase(ViewTestCases.DeviceComponentViewTestCase): class InterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase): model = Interface + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2217,7 +2232,7 @@ class InterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Interface [4-6]', + 'name': 'Interface [4-6]', 'type': InterfaceTypeChoices.TYPE_1GE_GBIC, 'enabled': False, 'bridge': interfaces[4].pk, @@ -2277,6 +2292,7 @@ class InterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase): class FrontPortTestCase(ViewTestCases.DeviceComponentViewTestCase): model = FrontPort + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2312,7 +2328,7 @@ class FrontPortTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Front Port [4-6]', + 'name': 'Front Port [4-6]', 'type': PortTypeChoices.TYPE_8P8C, 'rear_port_set': [ '{}:1'.format(rp.pk) for rp in rearports[3:6] @@ -2348,6 +2364,7 @@ class FrontPortTestCase(ViewTestCases.DeviceComponentViewTestCase): class RearPortTestCase(ViewTestCases.DeviceComponentViewTestCase): model = RearPort + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2372,7 +2389,7 @@ class RearPortTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Rear Port [4-6]', + 'name': 'Rear Port [4-6]', 'type': PortTypeChoices.TYPE_8P8C, 'positions': 3, 'description': 'A rear port', @@ -2406,6 +2423,7 @@ class RearPortTestCase(ViewTestCases.DeviceComponentViewTestCase): class ModuleBayTestCase(ViewTestCases.DeviceComponentViewTestCase): model = ModuleBay + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2428,7 +2446,7 @@ class ModuleBayTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Module Bay [4-6]', + 'name': 'Module Bay [4-6]', 'description': 'A module bay', 'tags': [t.pk for t in tags], } @@ -2447,6 +2465,7 @@ class ModuleBayTestCase(ViewTestCases.DeviceComponentViewTestCase): class DeviceBayTestCase(ViewTestCases.DeviceComponentViewTestCase): model = DeviceBay + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2472,7 +2491,7 @@ class DeviceBayTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Device Bay [4-6]', + 'name': 'Device Bay [4-6]', 'description': 'A device bay', 'tags': [t.pk for t in tags], } @@ -2491,6 +2510,7 @@ class DeviceBayTestCase(ViewTestCases.DeviceComponentViewTestCase): class InventoryItemTestCase(ViewTestCases.DeviceComponentViewTestCase): model = InventoryItem + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls): @@ -2525,7 +2545,7 @@ class InventoryItemTestCase(ViewTestCases.DeviceComponentViewTestCase): cls.bulk_create_data = { 'device': device.pk, - 'name_pattern': 'Inventory Item [4-6]', + 'name': 'Inventory Item [4-6]', 'role': roles[1].pk, 'manufacturer': manufacturer.pk, 'parent': None, diff --git a/netbox/utilities/testing/views.py b/netbox/utilities/testing/views.py index 7fa9f66bc..93cb88088 100644 --- a/netbox/utilities/testing/views.py +++ b/netbox/utilities/testing/views.py @@ -466,6 +466,7 @@ class ViewTestCases: """ bulk_create_count = 3 bulk_create_data = {} + validation_excluded_fields = [] @override_settings(EXEMPT_VIEW_PERMISSIONS=[]) def test_create_multiple_objects_without_permission(self): @@ -500,7 +501,7 @@ class ViewTestCases: self.assertHttpStatus(response, 302) self.assertEqual(initial_count + self.bulk_create_count, self._get_queryset().count()) for instance in self._get_queryset().order_by('-pk')[:self.bulk_create_count]: - self.assertInstanceEqual(instance, self.bulk_create_data) + self.assertInstanceEqual(instance, self.bulk_create_data, exclude=self.validation_excluded_fields) @override_settings(EXEMPT_VIEW_PERMISSIONS=[]) def test_create_multiple_objects_with_constrained_permission(self): @@ -532,7 +533,7 @@ class ViewTestCases: self.assertHttpStatus(response, 302) self.assertEqual(initial_count + self.bulk_create_count, self._get_queryset().count()) for instance in self._get_queryset().order_by('-pk')[:self.bulk_create_count]: - self.assertInstanceEqual(instance, self.bulk_create_data) + self.assertInstanceEqual(instance, self.bulk_create_data, exclude=self.validation_excluded_fields) class BulkImportObjectsViewTestCase(ModelViewTestCase): """ diff --git a/netbox/virtualization/tests/test_views.py b/netbox/virtualization/tests/test_views.py index 01d4394f3..4693d0ce2 100644 --- a/netbox/virtualization/tests/test_views.py +++ b/netbox/virtualization/tests/test_views.py @@ -251,6 +251,7 @@ class VirtualMachineTestCase(ViewTestCases.PrimaryObjectViewTestCase): class VMInterfaceTestCase(ViewTestCases.DeviceComponentViewTestCase): model = VMInterface + validation_excluded_fields = ('name', 'label') @classmethod def setUpTestData(cls):