def test_should_do_nothing_when_deleting_a_non_existent_plan_script(self): self.resource.get_by.return_value = [] self.mock_ansible_module.params = PARAMS_DELETE PlanScriptModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=PlanScriptModule.MSG_ALREADY_ABSENT)
def test_delete_plan_script(self): self.resource.get_by.return_value = [self.PLAN_SCRIPT] self.mock_ansible_module.params = PARAMS_DELETE PlanScriptModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=PlanScriptModule.MSG_DELETED)
def test_should_not_update_when_data_is_equals(self): self.resource.get_by.return_value = [PARAMS_UPDATE['data']] self.mock_ansible_module.params = PARAMS_UPDATE PlanScriptModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=PlanScriptModule.MSG_ALREADY_PRESENT, ansible_facts=dict(plan_script=PARAMS_UPDATE['data']))
def test_update_plan_script(self): self.resource.get_by.return_value = [self.PLAN_SCRIPT] self.resource.update.return_value = {"name": "name"} self.mock_ansible_module.params = PARAMS_UPDATE PlanScriptModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=PlanScriptModule.MSG_UPDATED, ansible_facts=dict(plan_script={"name": "name"}))
def test_should_fail_when_mandatory_attributes_are_missing(self): self.resource.get_by.return_value = [] del PARAMS_DIFFERENCE['data']['content'] self.mock_ansible_module.params = PARAMS_DIFFERENCE PlanScriptModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=PlanScriptModule.MSG_CONTENT_ATTRIBUTE_MANDATORY)
def test_retrieve_plan_script_content_differences(self): self.resource.get_by.return_value = [self.PLAN_SCRIPT] self.resource.retrieve_differences.return_value = {"differences": []} self.mock_ansible_module.params = PARAMS_DIFFERENCE PlanScriptModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=PlanScriptModule.MSG_DIFFERENCES_RETRIEVED, ansible_facts=dict(plan_script_differences={"differences": []}))
def test_create_new_plan_script(self): self.resource.get_by.return_value = [] self.resource.create.return_value = {"name": "Demo Plan Script"} self.mock_ansible_module.params = PARAMS_CREATE PlanScriptModule().run() self.resource.create.assert_called_once_with( {'name': 'Demo Plan Script'}) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=PlanScriptModule.MSG_CREATED, ansible_facts=dict(plan_script={"name": "Demo Plan Script"}))