Fix test_module_component_adoption

This commit is contained in:
kkthxbye-code 2022-05-05 09:30:13 +02:00
parent c52aa2196d
commit 9c3dfdfd14

View File

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