def test_should_do_nothing_when_storage_volume_template_not_exist(self):
        self.resource.get_by.return_value = []

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False, msg=StorageVolumeTemplateModule.MSG_ALREADY_ABSENT)
    def test_should_remove_storage_volume_template(self):
        self.resource.get_by.return_value = [STORAGE_VOLUME_TEMPLATE]

        self.mock_ansible_module.params = PARAMS_FOR_ABSENT

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True, msg=StorageVolumeTemplateModule.MSG_DELETED)
Exemplo n.º 3
0
    def test_should_raise_exception_when_key_is_missing(self):
        self.resource.get_by.return_value = [STORAGE_VOLUME_TEMPLATE]
        self.resource.remove.side_effect = Exception(FAKE_MSG_ERROR)

        self.mock_ansible_module.params = PARAMS_FOR_MISSING_KEY

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            msg=StorageVolumeTemplateModule.MSG_MANDATORY_FIELD_MISSING)
    def test_should_not_update_when_data_is_equals(self):
        self.resource.get_by.return_value = [STORAGE_VOLUME_TEMPLATE]

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=StorageVolumeTemplateModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(
                storage_volume_template=STORAGE_VOLUME_TEMPLATE))
    def test_should_update_the_storage_volume_template(self):
        self.resource.get_by.return_value = [STORAGE_VOLUME_TEMPLATE]
        self.resource.update.return_value = {"name": "name"}

        self.mock_ansible_module.params = PARAMS_WITH_CHANGES

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=StorageVolumeTemplateModule.MSG_UPDATED,
            ansible_facts=dict(storage_volume_template={"name": "name"}))
    def test_should_create_new_storage_volume_template(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = {"name": "name"}

        self.mock_ansible_module.params = PARAMS_FOR_PRESENT

        StorageVolumeTemplateModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=StorageVolumeTemplateModule.MSG_CREATED,
            ansible_facts=dict(storage_volume_template={"name": "name"}))