Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 16c7e3cf authored by Arkadiusz SZCZECINSKI's avatar Arkadiusz SZCZECINSKI
Browse files

:test_tube: add test for assgn 2 types to VM

parent 94febf90
No related branches found
No related tags found
1 merge request!32Test/vm assigned virtual machine type view
Pipeline #259902 failed
......@@ -17,7 +17,7 @@ class VmAssignedVmTypeFormTestCase(
model = VmAssignedVirtualMachineType
form = VmAssignedVmTypeForm
def test_create_valid_assigned_extra_config(self):
def test_create_valid_vm_assigned_virtual_machine_type(self):
"""Create a valid Extra Config Assignment"""
clt_content_type = ContentType.objects.get_for_model(ClusterType)
......@@ -48,110 +48,62 @@ class VmAssignedVmTypeFormTestCase(
obj_perm.users.add(self.user) # pylint: disable=no-member
obj_perm.object_types.add(ContentType.objects.get_for_model(self.model)) # pylint: disable=no-member
# def test_create_vm_with_two_extra_config_value_assigment(self):
# """Test the assignment of 2 extra configs to the same Cluster Type """
# clt_content_type = ContentType.objects.get_for_model(ClusterType)
# vm_content_type = ContentType.objects.get_for_model(VirtualMachine)
# cluster_type = ClusterType.objects.create(name="Test ClusterType1", slug="ClusterType1")
# cluster = Cluster.objects.create(name="Test Cluster1", type=cluster_type)
# virtual_machine = VirtualMachine.objects.create(name="Test VM",status="active",cluster=cluster)
# extra_config = ProviderTypeExtraConfig.objects.create(
# extra_config_name="Test Structure2",
# extra_config_structure={'test_extra2': [{'id': {'required': 'true','type': 'String'}}]},
# extra_config_description="Test Structure for Test2",
# assigned_object_type=clt_content_type,
# assigned_object_id=cluster_type.pk
# )
# VmAssignedExtraConfig.objects.create(
# assigned_object_type=vm_content_type,
# assigned_object_id=virtual_machine.pk,
# provider_type_extra_config= extra_config,
# extra_config_values= {"id":"TestID"},
# provider_type_extra_config_assignment_desc= "Test Extra Config Assignment",
# )
# form = VmAssignedExtraConfigForm(data= {
# "virtual_machine": virtual_machine.pk,
# "provider_type_extra_config": extra_config.pk,
# "extra_config_values": {"id":"TestID"},
# "provider_type_extra_config_assignment_desc": "Test Extra Config Assignment",
# })
# self.assertFalse(form.is_valid())
# # Setup object permissions for the test user
# obj_perm = ObjectPermission(
# name='Test permission',
# actions=['add', 'change']
# )
# obj_perm.save()
# obj_perm.users.add(self.user) # pylint: disable=no-member
# obj_perm.object_types.add(ContentType.objects.get_for_model(self.model)) # pylint: disable=no-member
# self.assertIn(
# "Can't assign more than one Extra Config to the same Virtual Machine",
# form.errors.get("__all__",[])
# )
# def test_invalid_assigned_extra_config_format(self):
# """
# Test invalid extra config invalid format.
# """
# clt_content_type = ContentType.objects.get_for_model(ClusterType)
# cluster_type = ClusterType.objects.create(name="Test ClusterType1", slug="ClusterType1")
# cluster = Cluster.objects.create(name="Test Cluster1", type=cluster_type)
# virtual_machine = VirtualMachine.objects.create(name="Test VM",status="active",cluster=cluster)
# extra_config = ProviderTypeExtraConfig.objects.create(
# extra_config_name="Test Structure",
# extra_config_structure={'test_extra1': [{'id': {'required': 'true','type': 'String'}}]},
# extra_config_description="Test Structure for Test",
# assigned_object_type=clt_content_type,
# assigned_object_id=cluster_type.pk
# )
# # Set up valid form data
# invalid_valid_form_data = {
# "virtual_machine": virtual_machine.pk,
# "provider_type_extra_config": extra_config.pk,
# "extra_config_values": {"id":"TestID"},
# "provider_type_extra_config_assignment_desc": "Test Extra Config Assignment",
# }
# #Invalid JSON
# invalid_form_data = invalid_valid_form_data.copy()
# invalid_form_data["extra_config_values"] = "Invalid" # Invalid format
# form = self.form(data=invalid_form_data)
# self.assertFalse(form.is_valid())
# self.assertIn(
# "Enter a valid JSON.",
# form.errors.get("extra_config_values", []),
# )
# #List Validation
# invalid_form_data["extra_config_values"] = {"description":"description"} # Wrong field
# form = self.form(data=invalid_form_data)
# self.assertFalse(form.is_valid())
# self.assertIn(
# "Missing or empty required field: 'id' with type string",
# form.errors.get("extra_config_values", []),
# )
# #Missing property Type
# invalid_form_data["extra_config_values"] = {"id":True} # Wrong type
# form = self.form(data=invalid_form_data)
# self.assertFalse(form.is_valid())
# self.assertIn(
# "Incorrect type for field 'id': expected string, got bool",
# form.errors.get("extra_config_values", []),
# )
def test_invalid_vm_assigned_virtual_machine_type(self):
"""
Test invalid extra config invalid format.
"""
clt_content_type = ContentType.objects.get_for_model(ClusterType)
cluster_type = ClusterType.objects.create(name="Test ClusterType1", slug="ClusterType1")
cluster = Cluster.objects.create(name="Test Cluster1", type=cluster_type)
vm_type = VirtualMachineType.objects.create(virtual_machine_type_name='VMType1',
assigned_object=cluster_type,
virtual_machine_type_desc='AWS description')
vm_type2 = VirtualMachineType.objects.create(virtual_machine_type_name='VMType2',
assigned_object=cluster_type,
virtual_machine_type_desc='AWS description')
virtual_machine = VirtualMachine.objects.create(name="Test VM",status="active",cluster=cluster)
# Assign VirtualMachineTypes to VirtualMachines
VmAssignedVirtualMachineType.objects.create(virtual_machine_type=vm_type, assigned_object_id=virtual_machine.pk)
# Set up valid form data
invalid_valid_form_data = {
"virtual_machine": virtual_machine.pk,
"virtual_machine_type_assignment_desc": 'Test virtual_machine_type_assignment',
"virtual_machine_type": vm_type2.pk
}
#Invalid assigment 2 types to 1 VM
# invalid_form_data = invalid_valid_form_data.copy()
# invalid_form_data["virtual_machine_type"] = vm_type2.pk # assign second type
form = self.form(data=invalid_valid_form_data)
self.assertFalse(form.is_valid())
self.assertIn(
"Can't assign more than one Type to the same Virtual Machine",
form.errors.get("virtual_machine_type", []),
)
#List Validation
# invalid_form_data["extra_config_values"] = {"description":"description"} # Wrong field
# form = self.form(data=invalid_form_data)
# self.assertFalse(form.is_valid())
# self.assertIn(
# "Missing or empty required field: 'id' with type string",
# form.errors.get("extra_config_values", []),
# )
# #Missing property Type
# invalid_form_data["extra_config_values"] = {"id":True} # Wrong type
# form = self.form(data=invalid_form_data)
# self.assertFalse(form.is_valid())
# self.assertIn(
# "Incorrect type for field 'id': expected string, got bool",
# form.errors.get("extra_config_values", []),
# )
# def tearDown(self) -> None:# pylint: disable=invalid-name
# """Method called immediately after the test method has been called and the result recorded."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment