def test_create_new_deployment_plan(self): self.i3s.deployment_plans.get_by.return_value = [] self.i3s.build_plans.get_by.return_value = [{ 'uri': '/rest/build-plans/1' }] self.i3s.deployment_plans.create.return_value = {"name": "name"} self.mock_ansible_module.params = self.DEPLOYMENT_PLAN_CREATE DeploymentPlanModule().run() self.i3s.deployment_plans.create.assert_called_once_with({ 'oeBuildPlanURI': '/rest/build-plans/1', 'hpProvided': 'false', 'description': 'Description of this Deployment Plan', 'name': 'Demo Deployment Plan' }) self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=DeploymentPlanModule.MSG_CREATED, ansible_facts=dict(deployment_plan={"name": "name"}))
def test_delete_deployment_plan(self): self.i3s.deployment_plans.get_by.return_value = [self.DEPLOYMENT_PLAN] self.mock_ansible_module.params = self.DEPLOYMENT_PLAN_DELETE DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=DeploymentPlanModule.MSG_DELETED)
def test_delete_deployment_plan(self): self.resource.get_by_name.return_value = self.DEPLOYMENT_PLAN self.mock_ansible_module.params = PARAMS_DELETE DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=DeploymentPlanModule.MSG_DELETED)
def test_should_fail_when_build_plan_not_found(self): self.i3s.deployment_plans.get_by.return_value = [] self.i3s.build_plans.get_by.return_value = None self.mock_ansible_module.params = self.DEPLOYMENT_PLAN_CREATE DeploymentPlanModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( msg=DeploymentPlanModule.MSG_BUILD_PLAN_WAS_NOT_FOUND)
def test_should_do_nothing_when_deleting_a_non_existent_deployment_plan( self): self.i3s.deployment_plans.get_by.return_value = [] self.mock_ansible_module.params = self.DEPLOYMENT_PLAN_DELETE DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=DeploymentPlanModule.MSG_ALREADY_ABSENT)
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 DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=DeploymentPlanModule.MSG_ALREADY_PRESENT, ansible_facts=dict(deployment_plan=PARAMS_UPDATE['data']))
def test_should_not_update_when_data_is_equals(self): self.resource.get_by_name.return_value = self.DEPLOYMENT_PLAN self.mock_ansible_module.params = PARAMS_FOR_PRESENT DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=False, msg=DeploymentPlanModule.MSG_ALREADY_PRESENT, ansible_facts=dict(deployment_plan=self.DEPLOYMENT_PLAN.data))
def test_update_deployment_plan(self): self.i3s.deployment_plans.get_by.return_value = [self.DEPLOYMENT_PLAN] self.i3s.deployment_plans.update.return_value = {"name": "name"} self.mock_ansible_module.params = self.DEPLOYMENT_PLAN_UPDATE DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=DeploymentPlanModule.MSG_UPDATED, ansible_facts=dict(deployment_plan={"name": "name"}))
def test_should_fail_when_build_plan_not_found(self): self.resource.get_by.return_value = [] self.mock_ov_client.build_plans.get_by.return_value = None del PARAMS_CREATE['data']['oeBuildPlanURI'] PARAMS_CREATE['data']['oeBuildPlanName'] = 'Demo Build Plan' self.mock_ansible_module.params = PARAMS_CREATE DeploymentPlanModule().run() self.mock_ansible_module.fail_json.assert_called_once_with( exception=mock.ANY, msg=DeploymentPlanModule.MSG_BUILD_PLAN_WAS_NOT_FOUND)
def test_update_deployment_plan(self): self.resource.get_by_name.return_value = self.DEPLOYMENT_PLAN self.resource.data = {"name": "name"} self.resource.update.return_value = self.resource self.mock_ansible_module.params = PARAMS_UPDATE DeploymentPlanModule().run() self.mock_ansible_module.exit_json.assert_called_once_with( changed=True, msg=DeploymentPlanModule.MSG_UPDATED, ansible_facts=dict(deployment_plan=self.DEPLOYMENT_PLAN.data))