def test_delete(self, mock_registry): db_obj = fakes.FakeWorkflow() mock_registry.Workflow.get_by_uuid.return_value = db_obj handler = workflow_handler.WorkflowHandler(self.ctx) handler.delete('test_id') mock_registry.Workflow.get_by_uuid.assert_called_once_with( self.ctx, 'test_id')
def test_create(self, mock_wf_insert, mock_pa, mock_registry): app_obj = fakes.FakeApp() app_id = app_obj.id test_cmd = app_obj.workflow_config['test_cmd'] run_cmd = app_obj.workflow_config['run_cmd'] mock_registry.App.get_by_id.return_value = app_obj workflow_data = { "actions": ["unittest", "build", "deploy"], "app_id": app_id, "source": app_obj.source, "config": app_obj.workflow_config, "actions": app_obj.trigger_actions } fp = fakes.FakePlan() mock_registry.Plan.return_value = fp fa = fakes.FakeAssembly() fa.plan_uuid = fp.uuid mock_registry.Assembly.return_value = fa wf_obj = fakes.FakeWorkflow() wf_obj.app_id = app_obj.id wf_obj.assembly = fa.id mock_registry.Workflow.return_value = wf_obj fi = fakes.FakeImage() mock_registry.Image.return_value = fi handler = workflow_handler.WorkflowHandler(self.ctx) res = handler.create(workflow_data, commit_sha='master', status_url='', du_id='') self.assertEqual(wf_obj, res) git_info = { 'source_url': app_obj.source['repository'], 'commit_sha': app_obj.source['revision'], 'repo_token': app_obj.source['repo_token'], 'private': app_obj.source['private'], 'private_ssh_key': app_obj.source['private_ssh_key'], 'status_url': '', } mock_pa.assert_called_once_with( verb='launch_workflow', workflow=['unittest', 'build', 'deploy'], build_id=fa.id, name=fi.name, assembly_id=fa.id, git_info=git_info, test_cmd=test_cmd, ports=app_obj.ports, base_image_id=fi.base_image_id, source_format=fi.source_format, image_format=fi.image_format, run_cmd=run_cmd, du_id='')
def post(self, data): """Create a new workflow.""" request.check_request_for_https() if not data: raise exception.BadRequest(reason='No data.') ahandler = app_handler.AppHandler(pecan.request.security_context) app_model = ahandler.get(self.app_id) handler = wf_handler.WorkflowHandler(pecan.request.security_context) data.app_id = app_model.id data.config = app_model.workflow_config data.source = app_model.source wf_data = data.as_dict(workflow.Workflow) du_id = None if data.du_id: du_id = data.du_id self._verify_du_exists(pecan.request.security_context, du_id) return workflow.Workflow.from_db_model( handler.create(wf_data, commit_sha='', status_url='', du_id=du_id), pecan.request.host_url)
def test_workflow_get_all(self, mock_reg): mock_reg.WorkflowList.get_all.return_value = {} handler = workflow_handler.WorkflowHandler(self.ctx) res = handler.get_all(app_id='123') self.assertIsNotNone(res) mock_reg.WorkflowList.get_all.assert_called_once_with(self.ctx, app_id='123')
def get(self): """Return this workflow.""" request.check_request_for_https() handler = wf_handler.WorkflowHandler(pecan.request.security_context) wf_model = handler.get(self.wf_id) wf_model = workflow.Workflow.from_db_model(wf_model, pecan.request.host_url) return wf_model
def get_all(self): """Return all of one app's workflows, based on the query provided.""" request.check_request_for_https() handler = wf_handler.WorkflowHandler(pecan.request.security_context) all_wfs = [workflow.Workflow.from_db_model(obj, pecan.request.host_url) for obj in handler.get_all(app_id=self.app_id)] return all_wfs
def test_workflow_get(self, mock_registry): mock_registry.return_value.Workflow.get_by_uuid.return_value = { 'app_id': '1234' } handler = workflow_handler.WorkflowHandler(self.ctx) res = handler.get('test_id') self.assertIsNotNone(res) get_by_uuid = mock_registry.Workflow.get_by_uuid get_by_uuid.assert_called_once_with(self.ctx, 'test_id')
def _build_artifact(self, app, commit_sha='', status_url=None, wf=None): if wf is None: wf = ['unittest', 'build', 'deploy'] wfhand = workflow_handler.WorkflowHandler(self.context) wfdata = { 'app_id': app.id, 'name': "%s" % app.name, 'description': '', 'source': app.source, 'config': app.workflow_config, 'actions': wf } wfhand.create(wfdata, commit_sha=commit_sha, status_url=status_url)
def _build_artifact(self, app, commit_sha='', status_url=None, wf=None): # TODO(devkulkarni): Check why wf is being passed # if wf is None: # wf = ['unittest', 'build', 'deploy'] wfhand = workflow_handler.WorkflowHandler(self.context) wfdata = { 'app_id': app.id, 'name': "%s" % app.name, 'description': '', 'source': app.source, 'config': app.workflow_config, 'actions': app.trigger_actions } wfhand.create(wfdata, commit_sha=commit_sha, status_url=status_url, du_id=None)