def test_should_update_description_in_api300(self): self.mock_ov_client.api_version = 300 self.resource.get_by_name.return_value = self.resource PARAMS_RESOURCE_ASSIGNMENTS_UPDATED_DESCRIPTION = dict( config='config.json', state='resource_assignments_updated', data=dict(name='ScopeName', resourceAssignments=dict(description='Test')) ) resource_data = PARAMS_RESOURCE_ASSIGNMENTS_UPDATED_DESCRIPTION.copy() self.resource.data = resource_data patch_return = resource_data.copy() patch_return['scopeUris'] = ['test'] patch_return_obj = self.resource.copy() patch_return_obj.data = patch_return self.resource.patch.return_value = patch_return_obj self.mock_ansible_module.params = copy.deepcopy(PARAMS_RESOURCE_ASSIGNMENTS_UPDATED_DESCRIPTION) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(scope=PARAMS_RESOURCE_ASSIGNMENTS_UPDATED_DESCRIPTION), msg=ScopeModule.MSG_RESOURCE_ASSIGNMENTS_UPDATED )
def test_should_remove_scope_when_found(self): self.resource.get_by_name.return_value = RESOURCE self.mock_ansible_module.params = copy.deepcopy(PARAMS_FOR_ABSENT) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_DELETED)
def test_should_not_delete_when_scope_not_found(self): self.resource.get_by_name.return_value = None self.mock_ansible_module.params = copy.deepcopy(PARAMS_FOR_ABSENT) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ScopeModule.MSG_ALREADY_ABSENT)
def test_should_fail_when_scope_not_found(self): self.resource.get_by_name.return_value = None self.mock_ansible_module.params = copy.deepcopy( PARAMS_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=ScopeModule.MSG_RESOURCE_NOT_FOUND)
def test_should_not_update_when_data_is_equals(self): self.resource.get_by_name.return_value = RESOURCE self.mock_ansible_module.params = copy.deepcopy(PARAMS_FOR_PRESENT) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ScopeModule.MSG_ALREADY_PRESENT, ansible_facts=dict(scope=RESOURCE))
def test_should_update_when_data_has_changes(self): self.resource.get_by_name.return_value = RESOURCE self.resource.update.return_value = RESOURCE_UPDATED self.mock_ansible_module.params = copy.deepcopy(PARAMS_WITH_CHANGES) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_UPDATED, ansible_facts=dict(scope=RESOURCE_UPDATED))
def test_should_create_new_scope_when_not_found(self): self.resource.get_by_name.return_value = None self.resource.create.return_value = RESOURCE self.mock_ansible_module.params = copy.deepcopy(PARAMS_FOR_PRESENT) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_CREATED, ansible_facts=dict(scope=RESOURCE))
def test_should_not_update_when_data_is_equals(self): self.resource.get_by_name.return_value = self.resource self.resource.data = PARAMS_FOR_PRESENT self.mock_ansible_module.params = PARAMS_FOR_PRESENT ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_UPDATED, ansible_facts=dict(scope=PARAMS_FOR_PRESENT))
def test_should_update_resource_assignments(self): self.resource.get_by_name.return_value = RESOURCE self.resource.update_resource_assignments.return_value = RESOURCE self.mock_ansible_module.params = copy.deepcopy( PARAMS_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(scope=RESOURCE), msg=ScopeModule.MSG_RESOURCE_ASSIGNMENTS_UPDATED)
def test_should_fail_resource_assignments_when_scope_not_found(self): self.mock_ov_client.api_version = 300 self.resource.get_by_name.return_value = None self.mock_ansible_module.params = copy.deepcopy(PARAMS_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( failed=True, changed=False, msg=ScopeModule.MSG_RESOURCE_NOT_FOUND )
def test_should_not_update_when_data_is_equals(self): response_data = PARAMS_FOR_PRESENT['data'] self.resource.data = response_data self.mock_ansible_module.params = PARAMS_FOR_PRESENT ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=ScopeModule.MSG_ALREADY_PRESENT, ansible_facts=dict(scope=response_data) )
def test_should_update_when_new_add_resources(self): self.resource.get_by_name.return_value = self.resource current_data = copy.deepcopy(RESOURCE_ASSIGNMENTS) self.resource.data = current_data self.mock_ansible_module.params = PARAMS_WITH_CHANGES_HAVING_RESOURCES_1 ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_UPDATED, ansible_facts=dict(scope=current_data) )
def test_should_update_when_data_has_changes(self): data_merged = PARAMS_FOR_PRESENT.copy() data_merged['name'] = 'ScopeNameRenamed' self.resource.data = PARAMS_FOR_PRESENT self.mock_ansible_module.params = PARAMS_WITH_CHANGES ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=ScopeModule.MSG_UPDATED, ansible_facts=dict(scope=PARAMS_FOR_PRESENT))
def test_should_add_and_remove_resource_assignments_in_api500(self): self.mock_ov_client.api_version = 500 self.resource.get_by_name.return_value = RESOURCE self.resource.patch.return_value = RESOURCE self.mock_ansible_module.params = copy.deepcopy( PARAMS_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(scope=RESOURCE), msg=ScopeModule.MSG_RESOURCE_ASSIGNMENTS_UPDATED)
def test_should_not_update_resource_assignments_in_api300(self): self.mock_ov_client.api_version = 300 self.resource.get_by_name.return_value = self.resource resource_data = PARAMS_NO_RESOURCE_ASSIGNMENTS.copy() self.resource.data = resource_data self.resource.update_resource_assignments.return_value = self.resource self.mock_ansible_module.params = copy.deepcopy(PARAMS_NO_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, ansible_facts=dict(scope=PARAMS_NO_RESOURCE_ASSIGNMENTS), msg=ScopeModule.MSG_RESOURCE_ASSIGNMENTS_NOT_UPDATED )
def test_should_add_and_remove_resource_assignments_in_api300(self): self.mock_ov_client.api_version = 300 self.resource.get_by_name.return_value = self.resource resource_data = PARAMS_RESOURCE_ASSIGNMENTS.copy() self.resource.data = resource_data patch_return = resource_data.copy() patch_return['scopeUris'] = ['test'] patch_return_obj = self.resource.copy() patch_return_obj.data = patch_return self.resource.patch.return_value = patch_return_obj self.mock_ansible_module.params = copy.deepcopy(PARAMS_RESOURCE_ASSIGNMENTS) ScopeModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, ansible_facts=dict(scope=PARAMS_RESOURCE_ASSIGNMENTS), msg=ScopeModule.MSG_RESOURCE_ASSIGNMENTS_UPDATED )