diff --git a/netbox/dcim/forms/bulk_import.py b/netbox/dcim/forms/bulk_import.py index 5906e7395..cdb59e9eb 100644 --- a/netbox/dcim/forms/bulk_import.py +++ b/netbox/dcim/forms/bulk_import.py @@ -292,12 +292,10 @@ class DeviceTypeImportForm(NetBoxModelImportForm): required=False, help_text=_('The default platform for devices of this type (optional)') ) - weight = forms.DecimalField( required=False, - help_text=_("Device weight"), + help_text=_('Device weight'), ) - weight_unit = CSVChoiceField( choices=WeightUnitChoices, required=False, @@ -308,7 +306,7 @@ class DeviceTypeImportForm(NetBoxModelImportForm): model = DeviceType fields = [ 'manufacturer', 'default_platform', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', - 'subdevice_role', 'airflow', 'description', 'comments', 'weight', 'weight_unit', + 'subdevice_role', 'airflow', 'description', 'weight', 'weight_unit', 'comments', ] @@ -317,12 +315,10 @@ class ModuleTypeImportForm(NetBoxModelImportForm): queryset=Manufacturer.objects.all(), to_field_name='name' ) - weight = forms.DecimalField( required=False, - help_text=_("Module weight"), + help_text=_('Module weight'), ) - weight_unit = CSVChoiceField( choices=WeightUnitChoices, required=False, @@ -331,7 +327,7 @@ class ModuleTypeImportForm(NetBoxModelImportForm): class Meta: model = ModuleType - fields = ['manufacturer', 'model', 'part_number', 'description', 'comments', 'weight', 'weight_unit'] + fields = ['manufacturer', 'model', 'part_number', 'description', 'weight', 'weight_unit', 'comments'] class DeviceRoleImportForm(NetBoxModelImportForm): diff --git a/netbox/dcim/tests/test_views.py b/netbox/dcim/tests/test_views.py index e286ae370..44e6ef2a9 100644 --- a/netbox/dcim/tests/test_views.py +++ b/netbox/dcim/tests/test_views.py @@ -681,11 +681,15 @@ class DeviceTypeTestCase( """ IMPORT_DATA = """ manufacturer: Generic -default_platform: Platform model: TEST-1000 slug: test-1000 +default_platform: Platform u_height: 2 +is_full_depth: false +airflow: front-to-rear subdevice_role: parent +weight: 10 +weight_unit: kg comments: Test comment console-ports: - name: Console Port 1 @@ -794,8 +798,16 @@ inventory-items: self.assertHttpStatus(response, 200) device_type = DeviceType.objects.get(model='TEST-1000') - self.assertEqual(device_type.comments, 'Test comment') + self.assertEqual(device_type.manufacturer.pk, manufacturer.pk) self.assertEqual(device_type.default_platform.pk, platform.pk) + self.assertEqual(device_type.slug, 'test-1000') + self.assertEqual(device_type.u_height, 2) + self.assertFalse(device_type.is_full_depth) + self.assertEqual(device_type.airflow, DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR) + self.assertEqual(device_type.subdevice_role, SubdeviceRoleChoices.ROLE_PARENT) + self.assertEqual(device_type.weight, 10) + self.assertEqual(device_type.weight_unit, WeightUnitChoices.UNIT_KILOGRAM) + self.assertEqual(device_type.comments, 'Test comment') # Verify all of the components were created self.assertEqual(device_type.consoleporttemplates.count(), 3) @@ -852,56 +864,6 @@ inventory-items: ii1 = InventoryItemTemplate.objects.first() self.assertEqual(ii1.name, 'Inventory Item 1') - @override_settings(EXEMPT_VIEW_PERMISSIONS=['*']) - def test_import_devicetype_with_weight(self): - """ - Custom import test for JSON-based imports specifically including device weight - """ - IMPORT_DATA = """ -{ - "manufacturer": "Manufacturer 1", - "model": "ABCDEFG", - "slug": "abcdefg", - "u_height": 1, - "is_full_depth": false, - "airflow": "front-to-rear", - "description": "DeviceType with weight", - "weight": 10, - "weight_unit": "kg" -} -""" - # Add all required permissions to the test user - self.add_permissions( - 'dcim.view_devicetype', - 'dcim.add_devicetype', - 'dcim.add_consoleporttemplate', - 'dcim.add_consoleserverporttemplate', - 'dcim.add_powerporttemplate', - 'dcim.add_poweroutlettemplate', - 'dcim.add_interfacetemplate', - 'dcim.add_frontporttemplate', - 'dcim.add_rearporttemplate', - 'dcim.add_modulebaytemplate', - 'dcim.add_devicebaytemplate', - 'dcim.add_inventoryitemtemplate', - ) - - form_data = { - 'data': IMPORT_DATA, - 'format': 'json' - } - response = self.client.post(reverse('dcim:devicetype_import'), data=form_data, follow=True) - self.assertHttpStatus(response, 200) - - device_type = DeviceType.objects.get(model='ABCDEFG') - self.assertEqual(device_type.slug, "abcdefg") - self.assertEqual(device_type.u_height, 1) - self.assertFalse(device_type.is_full_depth) - self.assertEqual(device_type.airflow, DeviceAirflowChoices.AIRFLOW_FRONT_TO_REAR) - self.assertEqual(device_type.description, 'DeviceType with weight') - self.assertEqual(device_type.weight, 10) - self.assertEqual(device_type.weight_unit, WeightUnitChoices.UNIT_KILOGRAM) - def test_export_objects(self): url = reverse('dcim:devicetype_list') self.add_permissions('dcim.view_devicetype') @@ -1069,6 +1031,8 @@ class ModuleTypeTestCase( IMPORT_DATA = """ manufacturer: Generic model: TEST-1000 +weight: 10 +weight_unit: lb comments: Test comment console-ports: - name: Console Port 1 @@ -1132,7 +1096,8 @@ front-ports: """ # Create the manufacturer - Manufacturer(name='Generic', slug='generic').save() + manufacturer = Manufacturer(name='Generic', slug='generic') + manufacturer.save() # Add all required permissions to the test user self.add_permissions( @@ -1155,6 +1120,9 @@ front-ports: self.assertHttpStatus(response, 200) module_type = ModuleType.objects.get(model='TEST-1000') + self.assertEqual(module_type.manufacturer.pk, manufacturer.pk) + self.assertEqual(module_type.weight, 10) + self.assertEqual(module_type.weight_unit, WeightUnitChoices.UNIT_POUND) self.assertEqual(module_type.comments, 'Test comment') # Verify all the components were created @@ -1196,46 +1164,6 @@ front-ports: self.assertEqual(fp1.rear_port, rp1) self.assertEqual(fp1.rear_port_position, 1) - @override_settings(EXEMPT_VIEW_PERMISSIONS=['*']) - def test_import_moduletype_with_weight(self): - """ - Custom import test for JSON-based imports specifically including module weight - """ - IMPORT_DATA = """ -{ - "manufacturer": "Manufacturer 2", - "model": "TEST-1001", - "weight": 10, - "weight_unit": "lb" -} -""" - - # Add all required permissions to the test user - self.add_permissions( - 'dcim.view_moduletype', - 'dcim.add_moduletype', - 'dcim.add_consoleporttemplate', - 'dcim.add_consoleserverporttemplate', - 'dcim.add_powerporttemplate', - 'dcim.add_poweroutlettemplate', - 'dcim.add_interfacetemplate', - 'dcim.add_frontporttemplate', - 'dcim.add_rearporttemplate', - ) - - form_data = { - 'data': IMPORT_DATA, - 'format': 'json' - } - response = self.client.post(reverse('dcim:moduletype_import'), data=form_data, follow=True) - self.assertHttpStatus(response, 200) - - module_type = ModuleType.objects.get(model='TEST-1001') - - # Verify the weight is correct - self.assertEqual(module_type.weight, 10) - self.assertEqual(module_type.weight_unit, WeightUnitChoices.UNIT_POUND) - def test_export_objects(self): url = reverse('dcim:moduletype_list') self.add_permissions('dcim.view_moduletype')