Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Bumped up test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fgbulsoni committed Sep 12, 2017
1 parent 4de99b8 commit 9154667
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 6 additions & 3 deletions library/oneview_server_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def __present(self, data, resource):
self.__validations_for_os_custom_attributes(data, merged_data, resource)

if not ResourceComparator.compare(resource, merged_data):

resource = self.__update_server_profile(merged_data, resource)
changed = True
msg = self.MSG_UPDATED
Expand All @@ -333,9 +334,11 @@ def __present(self, data, resource):
# Swaps True values for 'true' string, and False values for 'false' string to avoid common user errors.
def __validations_for_os_custom_attributes(self, data, merged_data, resource):
if data.get('osDeploymentSettings') is None or resource.get('osDeploymentSettings') is None:
return False
elif data.get('osDeploymentSettings').get('osCustomAttributes') is None:
return False
return
elif data.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
return
elif resource.get('osDeploymentSettings', {}).get('osCustomAttributes') is None:
return
attributes_merged = merged_data.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
attributes_resource = resource.get('osDeploymentSettings', {}).get('osCustomAttributes', None)
dp_uri = resource.get('osDeploymentSettings', {}).get('osDeploymentPlanUri', None)
Expand Down
32 changes: 32 additions & 0 deletions test/test_oneview_server_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,6 +1904,38 @@ def test_should_unassign_server_hardware(self):
ansible_facts=mock_facts
)

def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_resource(self):
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
sp_get_value['osDeploymentSettings'] = {}
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))

self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
self.mock_ansible_module.params = deepcopy(PARAMS_FOR_UPDATE)

ServerProfileModule().run()

self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])

def test_validating_os_custom_attr_should_return_if_no_attributes_found_on_data(self):
sp_get_value = deepcopy(CREATED_BASIC_PROFILE)
sp_get_value['osDeploymentSettings'] = {}
sp_exit_value = deepcopy(CREATED_BASIC_PROFILE)
sp_exit_value.update(deepcopy(PARAMS_FOR_UPDATE['data']))
sp_exit_value['osDeploymentSettings']['osCustomAttributes'] = None

params_for_update = deepcopy(PARAMS_FOR_UPDATE)
params_for_update['data']['osDeploymentSettings']['osCustomAttributes'] = None

self.mock_ov_client.server_profiles.get_by_name.return_value = sp_get_value
self.mock_ov_client.server_profiles.update.return_value = deepcopy(CREATED_BASIC_PROFILE)
self.mock_ansible_module.params = params_for_update

ServerProfileModule().run()

self.mock_ov_client.server_profiles.update.assert_called_once_with(sp_exit_value, sp_exit_value['uri'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 9154667

Please sign in to comment.