def test_should_do_nothing_when_enclosure_group_not_exist(self): self.resource.get_by_name.return_value = None self.mock_ansible_module.params = yaml.load( YAML_ENCLOSURE_GROUP_ABSENT) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=EnclosureGroupModule.MSG_ALREADY_ABSENT)
def test_should_remove_enclosure_group(self): self.resource.get_by.return_value = [DICT_DEFAULT_ENCLOSURE_GROUP] self.mock_ansible_module.params = yaml.load( YAML_ENCLOSURE_GROUP_ABSENT) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureGroupModule.MSG_DELETED)
def test_should_not_update_when_data_is_equals(self): self.resource.get_by.return_value = [DICT_DEFAULT_ENCLOSURE_GROUP] self.mock_ansible_module.params = yaml.load(YAML_ENCLOSURE_GROUP) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=EnclosureGroupModule.MSG_ALREADY_PRESENT, ansible_facts=dict(enclosure_group=DICT_DEFAULT_ENCLOSURE_GROUP))
def test_should_create_new_enclosure_group(self): self.resource.get_by.return_value = [] self.resource.create.return_value = {"name": "name"} self.mock_ansible_module.params = yaml.load(YAML_ENCLOSURE_GROUP) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureGroupModule.MSG_CREATED, ansible_facts=dict(enclosure_group={"name": "name"}))
def test_update_when_data_has_modified_attributes(self): data_merged = DICT_DEFAULT_ENCLOSURE_GROUP.copy() data_merged['newName'] = 'New Name' self.resource.data = DICT_DEFAULT_ENCLOSURE_GROUP self.mock_ansible_module.params = yaml.load( YAML_ENCLOSURE_GROUP_CHANGES) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureGroupModule.MSG_UPDATED, ansible_facts=dict(enclosure_group=self.resource.data))
def test_update_when_script_attribute_was_modified(self): data_merged = DICT_DEFAULT_ENCLOSURE_GROUP.copy() data_merged['newName'] = 'New Name' data_merged['uri'] = '/rest/uri' self.resource.data = data_merged self.resource.get_script.return_value = "# test script" self.mock_ansible_module.params = yaml.load( YAML_ENCLOSURE_GROUP_CHANGE_SCRIPT) EnclosureGroupModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=EnclosureGroupModule.MSG_UPDATED, ansible_facts=dict(enclosure_group=self.resource.data))