Просмотр исходного кода

Fix test_module_component_adoption

kkthxbye-code 3 лет назад
Родитель
Сommit
9c3dfdfd14
1 измененных файлов с 11 добавлено и 21 удалено
  1. 11 21
      netbox/dcim/tests/test_views.py

+ 11 - 21
netbox/dcim/tests/test_views.py

@@ -1882,25 +1882,16 @@ class ModuleTestCase(
         form_data = self.form_data.copy()
         device = Device.objects.get(pk=form_data['device'])
 
-        # Create a module with replicated components
-        form_data['module_bay'] = ModuleBay.objects.filter(device=device)[0]
-        form_data['replicate_components'] = True
-        request = {
-            'path': self._get_url('add'),
-            'data': post_data(form_data),
-        }
-        self.assertHttpStatus(self.client.post(**request), 302)
-
-        # Check that the interface was created
-        initial_interface = Interface.objects.filter(device=device, name=interface_name).first()
-        self.assertIsNotNone(initial_interface)
+        # Create an interface to be adopted
+        interface = Interface(device=device, name=interface_name, type=InterfaceTypeChoices.TYPE_10GE_FIXED)
+        interface.save()
 
-        # Save the module id associated with the interface
-        initial_module_id = initial_interface.module.id
+        # Ensure that interface is created with no module
+        self.assertIsNone(interface.module)
 
-        # Create a second module (in the next bay) with adopted components
-        # The module id of the interface should change
-        form_data['module_bay'] = ModuleBay.objects.filter(device=device)[1]
+        # Create a module with adopted components
+        form_data['module_bay'] = ModuleBay.objects.filter(device=device).first()
+        form_data['module_type'] = module_type
         form_data['replicate_components'] = False
         form_data['adopt_components'] = True
         request = {
@@ -1911,11 +1902,10 @@ class ModuleTestCase(
         self.assertHttpStatus(self.client.post(**request), 302)
 
         # Re-retrieve interface to get new module id
-        initial_interface.refresh_from_db()
-        updated_module_id = initial_interface.module.id
+        interface.refresh_from_db()
 
-        # Check that the module id has changed
-        self.assertNotEqual(initial_module_id, updated_module_id)
+        # Check that the Interface now has a module
+        self.assertIsNotNone(interface.module)
 
 
 class ConsolePortTestCase(ViewTestCases.DeviceComponentViewTestCase):