def test_delete_workflow(self): execution_db_help.standard_load() workflows = [Workflow('wf{}'.format(i), uuid4()) for i in range(2)] for workflow in workflows: self.app.running_context.execution_db.session.add(workflow) target_playbook = Playbook('play1', workflows=workflows) self.app.running_context.execution_db.session.add(target_playbook) self.app.running_context.execution_db.session.flush() workflow_ids = [workflow.id for workflow in workflows] original_num_playbooks = len( self.app.running_context.execution_db.session.query( Playbook).all()) self.delete_with_status_check('/api/workflows/{}'.format( workflow_ids[0]), headers=self.headers, status_code=NO_CONTENT) self.assertEqual(len(list(target_playbook.workflows)), len(workflow_ids) - 1) self.assertNotIn( workflow_ids[0], [workflow.id for workflow in target_playbook.workflows]) self.assertEqual( len( self.app.running_context.execution_db.session.query( Playbook).all()), original_num_playbooks)
def test_delete_workflow_invalid_workflow_id_format(self): execution_db_help.standard_load() original_num_playbooks = len( executiondb.execution_db.session.query(Playbook).all()) self.check_invalid_uuid('delete', '/api/workflows/37b', 'workflow') self.assertEqual( len(executiondb.execution_db.session.query(Playbook).all()), original_num_playbooks)
def test_update_playbook_invalid_id_format(self): execution_db_help.standard_load() expected = {playbook.name for playbook in self.app.running_context.execution_db.session.query(Playbook).all()} data = {'id': '475', 'name': self.change_playbook_name} self.check_invalid_uuid('patch', '/api/playbooks', 'playbook', content_type="application/json", data=json.dumps(data)) self.assertSetEqual( {playbook.name for playbook in self.app.running_context.execution_db.session.query(Playbook).all()}, expected)
def test_delete_playbook_invalid_id_format(self): execution_db_help.standard_load() previous_num_playbooks = len( executiondb.execution_db.session.query(Playbook).all()) self.check_invalid_id('delete', '/api/playbooks/{}'.format(uuid4()), 'playbook') self.assertEqual( previous_num_playbooks, len(executiondb.execution_db.session.query(Playbook).all()))
def test_delete_workflow_invalid_workflow_id(self): execution_db_help.standard_load() original_num_playbooks = len( self.app.running_context.execution_db.session.query( Playbook).all()) self.check_invalid_id('delete', '/api/workflows/{}'.format(uuid4()), 'workflow') self.assertEqual( len( self.app.running_context.execution_db.session.query( Playbook).all()), original_num_playbooks)
def test_read_workflows(self): execution_db_help.standard_load() workflows = { str(workflow.id) for workflow in self.app.running_context.execution_db.session. query(Workflow).all() } response = self.get_with_status_check('/api/workflows', headers=self.headers) self.assertSetEqual({workflow['id'] for workflow in response}, workflows)
def test_delete_last_workflow(self): execution_db_help.standard_load() workflow = Workflow('wf', uuid4()) self.app.running_context.execution_db.session.add(workflow) target_playbook = Playbook('play1', workflows=[workflow]) self.app.running_context.execution_db.session.add(target_playbook) self.app.running_context.execution_db.session.flush() original_num_playbooks = len(self.app.running_context.execution_db.session.query(Playbook).all()) self.delete_with_status_check('/api/workflows/{}'.format(workflow.id), headers=self.headers, status_code=NO_CONTENT) self.assertIsNone(self.app.running_context.execution_db.session.query(Playbook).filter_by(name='play1').first()) self.assertEqual(len(self.app.running_context.execution_db.session.query(Playbook).all()), original_num_playbooks - 1)
def test_update_workflow_invalid_new_workflow(self): from walkoff.executiondb.schemas import WorkflowSchema from walkoff.executiondb import ExecutionDatabase playbook = execution_db_help.standard_load() workflow = playbook.workflows[0] expected_json = WorkflowSchema().dump(workflow) expected_json['name'] = self.change_workflow_name expected_json['actions'][0]['action_name'] = 'invalid' expected_json.pop('is_valid') response = self.put_with_status_check('/api/workflows', data=json.dumps(expected_json), headers=self.headers, content_type='application/json') response.pop('is_valid') errors = response['actions'][0].pop('errors') self.assertEqual(len(errors), 1) self.assertDictEqual(response, expected_json) self.assertIsNotNone( ExecutionDatabase.instance.session.query(Workflow).filter_by( id=workflow.id).first()) self.assertIsNone( ExecutionDatabase.instance.session.query(Workflow).join( Workflow.playbook).filter( Workflow.name == self.add_workflow_name).first())
def test_create_workflow_with_env_vars(self): playbook = execution_db_help.standard_load() self.empty_workflow_json['playbook_id'] = str(playbook.id) self.empty_workflow_json['environment_variables'].append({ 'name': 'call', 'value': 'changeme', 'description': 'test description' }) self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps(self.empty_workflow_json), content_type="application/json") final_workflows = playbook.workflows workflow = next((workflow for workflow in final_workflows if workflow.name == self.add_workflow_name), None) self.assertEqual(len(workflow.environment_variables), 1) self.assertIsNotNone(workflow.environment_variables[0].id) self.assertEqual(workflow.environment_variables[0].name, 'call') self.assertEqual(workflow.environment_variables[0].value, 'changeme') self.assertEqual(workflow.environment_variables[0].description, 'test description')
def test_execute_workflow_change_arguments(self): playbook = execution_db_help.standard_load() workflow = executiondb.execution_db.session.query(Workflow).filter_by( playbook_id=playbook.id).first() action_ids = [ action.id for action in workflow.actions if action.name == 'start' ] setup_subscriptions_for_action(workflow.id, action_ids) result = {'count': 0} @WalkoffEvent.ActionExecutionSuccess.connect def y(sender, **kwargs): result['count'] += 1 data = { "workflow_id": str(workflow.id), "arguments": [{ "name": "call", "value": "CHANGE INPUT" }] } self.post_with_status_check('/api/workflowqueue', headers=self.headers, status_code=SUCCESS_ASYNC, content_type="application/json", data=json.dumps(data)) flask_server.running_context.executor.wait_and_reset(1) self.assertEqual(result['count'], 1)
def test_export_workflow(self): playbook = execution_db_help.standard_load() response = self.get_with_status_check( '/api/playbooks/{}?mode=export'.format(playbook.id), headers=self.headers) self.assertDictEqual(PlaybookSchema().dump(playbook).data, response)
def test_execute_workflow_change_arguments(self): playbook = execution_db_help.standard_load() workflow = self.app.running_context.execution_db.session.query( Workflow).filter_by(playbook_id=playbook.id).first() result = {'count': 0} @WalkoffEvent.ActionExecutionSuccess.connect def y(sender, **kwargs): result['count'] += 1 result['output'] = kwargs['data']['data']['result'] data = { "workflow_id": str(workflow.id), "arguments": [{ "name": "call", "value": "CHANGE INPUT" }] } response = self.post_with_status_check('/api/workflowqueue', headers=self.headers, status_code=SUCCESS_ASYNC, content_type="application/json", data=json.dumps(data)) current_app.running_context.executor.wait_and_reset(1) self.assertEqual(result['count'], 1) self.assertEqual(result['output'], 'REPEATING: CHANGE INPUT')
def test_read_workflow(self): playbook = execution_db_help.standard_load() target_workflow = playbook.workflows[0] response = self.get_with_status_check( '/api/workflows/{}'.format(target_workflow.id), headers=self.headers) self.assertDictEqual(self.strip_ids(response), self.strip_ids(WorkflowSchema().dump(target_workflow)))
def test_copy_workflow_different_playbook(self): playbook = execution_db_help.standard_load() for workflow in playbook.workflows: workflow_id = workflow.id transfer_playbook = self.app.running_context.execution_db.session.query( Playbook).filter_by(name='dataflowTest').first() data = { "name": self.add_workflow_name, "playbook_id": str(transfer_playbook.id) } self.post_with_status_check( '/api/workflows?source={}'.format(workflow_id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_CREATED, content_type="application/json") for workflow in playbook.workflows: if workflow.name == 'helloWorldWorkflow': original_workflow = workflow copy_workflow = self.app.running_context.execution_db.session.query( Workflow).filter_by(name=self.add_workflow_name).first() self.assertEqual(len(playbook.workflows), 1) self.assertEqual(len(transfer_playbook.workflows), 2) self.assertIsNotNone(copy_workflow) self.assertNotEqual(original_workflow.start, copy_workflow.start) self.assertEqual(len(original_workflow.actions), len(copy_workflow.actions))
def test_delete_playbook(self): playbook = execution_db_help.standard_load() self.delete_with_status_check('/api/playbooks/{}'.format(playbook.id), headers=self.headers, status_code=NO_CONTENT) self.assertIsNone( self.app.running_context.execution_db.session.query(Playbook).filter_by(id=playbook.id).first())
def test_copy_workflow_different_playbook(self): playbook = execution_db_help.standard_load() for workflow in playbook.workflows: workflow_id = workflow.id transfer_playbook = self.app.running_context.execution_db.session.query(Playbook).filter_by( name='dataflowTest').first() data = {"name": self.add_workflow_name, "playbook_id": str(transfer_playbook.id)} self.post_with_status_check('/api/workflows?source={}'.format(workflow_id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_CREATED, content_type="application/json") for workflow in playbook.workflows: if workflow.name == 'helloWorldWorkflow': original_workflow = workflow copy_workflow = self.app.running_context.execution_db.session.query(Workflow).filter_by( name=self.add_workflow_name).first() self.assertEqual(len(playbook.workflows), 1) self.assertEqual(len(transfer_playbook.workflows), 2) self.assertIsNotNone(copy_workflow) self.assertNotEqual(original_workflow.start, copy_workflow.start) self.assertEqual(len(original_workflow.actions), len(copy_workflow.actions))
def test_execute_workflow(self): playbook = execution_db_help.standard_load() workflow = self.app.running_context.execution_db.session.query( Workflow).filter_by(playbook_id=playbook.id).first() result = {'count': 0} @WalkoffEvent.ActionExecutionSuccess.connect def y(sender, **kwargs): result['count'] += 1 response = self.post_with_status_check( '/api/workflowqueue', headers=self.headers, status_code=SUCCESS_ASYNC, content_type="application/json", data=json.dumps({'workflow_id': str(workflow.id)})) current_app.running_context.executor.wait_and_reset(1) self.assertIn('id', response) self.assertEqual(result['count'], 1) workflow_status = self.app.running_context.execution_db.session.query( WorkflowStatus).filter_by(execution_id=response['id']).first() self.assertIsNotNone(workflow_status) self.assertEqual(workflow_status.status.name, 'completed')
def test_read_playbook(self): playbook = execution_db_help.standard_load() response = self.get_with_status_check('/api/playbooks/{}'.format(playbook.id), headers=self.headers) expected_workflows = [self.strip_ids(WorkflowSchema().dump(workflow)) for workflow in playbook.workflows] self.assertEqual(response['name'], 'test') self.assertEqual(len(response['workflows']), len(expected_workflows)) self.assertListEqual([self.strip_ids(workflow) for workflow in response['workflows']], expected_workflows)
def test_copy_workflow(self): playbook = execution_db_help.standard_load() for workflow in playbook.workflows: workflow_id = workflow.id response = self.post_with_status_check('/api/workflows?source={0}'.format(workflow_id), headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps( {'name': self.add_workflow_name, 'playbook_id': str(playbook.id)}), content_type="application/json") self.assertEqual(len(playbook.workflows), 2) for workflow in playbook.workflows: self.assertIn(workflow.name, ['helloWorldWorkflow', self.add_workflow_name]) if workflow.name == 'helloWorldWorkflow': workflow_original = workflow elif workflow.name == self.add_workflow_name: workflow_copy = workflow copy_workflow_json = WorkflowSchema().dump(workflow_copy) original_workflow_json = WorkflowSchema().dump(workflow_original) copy_workflow_json.pop('name', None) original_workflow_json.pop('name', None) self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start']) copy_workflow_json.pop('start') original_workflow_json.pop('start') self.assertEqual(len(workflow_original.actions), len(workflow_copy.actions))
def test_copy_workflow(self): playbook = execution_db_help.standard_load() for workflow in playbook.workflows: workflow_id = workflow.id response = self.post_with_status_check( '/api/workflows?source={0}'.format(workflow_id), headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps({ 'name': self.add_workflow_name, 'playbook_id': str(playbook.id) }), content_type="application/json") self.assertEqual(len(playbook.workflows), 2) for workflow in playbook.workflows: self.assertIn(workflow.name, ['helloWorldWorkflow', self.add_workflow_name]) if workflow.name == 'helloWorldWorkflow': workflow_original = workflow elif workflow.name == self.add_workflow_name: workflow_copy = workflow copy_workflow_json = WorkflowSchema().dump(workflow_copy).data original_workflow_json = WorkflowSchema().dump(workflow_original).data copy_workflow_json.pop('name', None) original_workflow_json.pop('name', None) self.assertNotEqual(original_workflow_json['start'], copy_workflow_json['start']) copy_workflow_json.pop('start') original_workflow_json.pop('start') self.assertEqual(len(workflow_original.actions), len(workflow_copy.actions))
def test_read_playbook_workflows_from_query(self): playbook = execution_db_help.standard_load() response = self.get_with_status_check('/api/workflows?playbook={}'.format(playbook.id), headers=self.headers) expected_workflows = [self.strip_ids(WorkflowSchema().dump(workflow)) for workflow in playbook.workflows] self.assertEqual(len(response), len(expected_workflows)) self.assertListEqual([self.strip_ids(workflow) for workflow in response], expected_workflows)
def test_copy_playbook_duplicate_name(self): playbook = execution_db_help.standard_load() data = {"name": 'dataflowTest'} self.post_with_status_check('/api/playbooks?source={}'.format(playbook.id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_EXISTS_ERROR, content_type="application/json")
def test_update_playbook_name(self): playbook = execution_db_help.standard_load() data = {'id': str(playbook.id), 'name': self.change_playbook_name} response = self.patch_with_status_check('/api/playbooks', data=json.dumps(data), headers=self.headers, content_type='application/json') self.assertEqual(response['name'], self.change_playbook_name)
def test_export_workflow(self): from walkoff.helpers import strip_device_ids, strip_argument_ids playbook = execution_db_help.standard_load() response = self.get_with_status_check('/api/playbooks/{}?mode=export'.format(playbook.id), headers=self.headers) expected = PlaybookSchema().dump(playbook) strip_device_ids(expected) strip_argument_ids(expected) self.assertDictEqual(response, expected)
def test_update_playbook_duplicate_name(self): playbook = execution_db_help.standard_load() data = {'id': str(playbook.id), 'name': 'dataflowTest'} self.patch_with_status_check('/api/playbooks', data=json.dumps(data), headers=self.headers, content_type='application/json', status_code=OBJECT_EXISTS_ERROR)
def test_delete_playbook(self): playbook = execution_db_help.standard_load() self.delete_with_status_check('/api/playbooks/{}'.format(playbook.id), headers=self.headers, status_code=NO_CONTENT) self.assertIsNone( self.app.running_context.execution_db.session.query( Playbook).filter_by(id=playbook.id).first())
def test_read_workflow(self): playbook = execution_db_help.standard_load() target_workflow = playbook.workflows[0] response = self.get_with_status_check('/api/workflows/{}'.format( target_workflow.id), headers=self.headers) self.assertDictEqual( self.strip_ids(response), self.strip_ids(WorkflowSchema().dump(target_workflow).data))
def test_copy_playbook_duplicate_name(self): playbook = execution_db_help.standard_load() data = {"name": 'dataflowTest'} self.post_with_status_check('/api/playbooks?source={}'.format( playbook.id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_EXISTS_ERROR, content_type="application/json")
def test_update_playbook_name(self): playbook = execution_db_help.standard_load() data = {'id': str(playbook.id), 'name': self.change_playbook_name} response = self.patch_with_status_check( '/api/playbooks', data=json.dumps(data), headers=self.headers, content_type='application/json') self.assertEqual(response['name'], self.change_playbook_name)
def test_update_playbook_invalid_id_format(self): execution_db_help.standard_load() expected = { playbook.name for playbook in self.app.running_context.execution_db.session. query(Playbook).all() } data = {'id': '475', 'name': self.change_playbook_name} self.check_invalid_uuid('patch', '/api/playbooks', 'playbook', content_type="application/json", data=json.dumps(data)) self.assertSetEqual( { playbook.name for playbook in self.app.running_context.execution_db.session. query(Playbook).all() }, expected)
def test_delete_last_workflow(self): execution_db_help.standard_load() workflow = Workflow('wf', uuid4()) executiondb.execution_db.session.add(workflow) target_playbook = Playbook('play1', workflows=[workflow]) executiondb.execution_db.session.add(target_playbook) executiondb.execution_db.session.flush() original_num_playbooks = len( executiondb.execution_db.session.query(Playbook).all()) self.delete_with_status_check('/api/workflows/{}'.format(workflow.id), headers=self.headers, status_code=NO_CONTENT) self.assertIsNone( executiondb.execution_db.session.query(Playbook).filter_by( name='play1').first()) self.assertEqual( len(executiondb.execution_db.session.query(Playbook).all()), original_num_playbooks - 1)
def test_export_workflow(self): from walkoff.helpers import strip_device_ids, strip_argument_ids playbook = execution_db_help.standard_load() response = self.get_with_status_check( '/api/playbooks/{}?mode=export'.format(playbook.id), headers=self.headers) expected = PlaybookSchema().dump(playbook).data strip_device_ids(expected) strip_argument_ids(expected) self.assertDictEqual(response, expected)
def test_delete_workflow(self): execution_db_help.standard_load() workflows = [Workflow('wf{}'.format(i), uuid4()) for i in range(2)] for workflow in workflows: self.app.running_context.execution_db.session.add(workflow) target_playbook = Playbook('play1', workflows=workflows) self.app.running_context.execution_db.session.add(target_playbook) self.app.running_context.execution_db.session.flush() workflow_ids = [workflow.id for workflow in workflows] original_num_playbooks = len(self.app.running_context.execution_db.session.query(Playbook).all()) self.delete_with_status_check('/api/workflows/{}'.format(workflow_ids[0]), headers=self.headers, status_code=NO_CONTENT) self.assertEqual(len(list(target_playbook.workflows)), len(workflow_ids) - 1) self.assertNotIn(workflow_ids[0], [workflow.id for workflow in target_playbook.workflows]) self.assertEqual(len(self.app.running_context.execution_db.session.query(Playbook).all()), original_num_playbooks)
def test_create_workflow_with_errors(self): playbook = execution_db_help.standard_load() self.empty_workflow_json['actions'][0]['action_name'] = 'invalid' self.empty_workflow_json['start'] = str(uuid4()) self.empty_workflow_json['playbook_id'] = str(playbook.id) response = self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps(self.empty_workflow_json), content_type="application/json") self.assertEqual(len(response['errors']), 1) self.assertEqual(len(response['actions'][0]['errors']), 1)
def test_create_workflow_with_errors(self): playbook = execution_db_help.standard_load() self.empty_workflow_json['actions'][0]['action_name'] = 'invalid' self.empty_workflow_json['start'] = str(uuid4()) self.empty_workflow_json['playbook_id'] = str(playbook.id) response = self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps( self.empty_workflow_json), content_type="application/json") self.assertEqual(len(response['errors']), 1) self.assertEqual(len(response['actions'][0]['errors']), 1)
def test_copy_playbook(self): playbook = execution_db_help.standard_load() data = {"name": self.add_playbook_name} self.post_with_status_check('/api/playbooks?source={}'.format(playbook.id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_CREATED, content_type="application/json") copy_playbook = self.app.running_context.execution_db.session.query(Playbook).filter_by( name=self.add_playbook_name).first() self.assertIsNotNone(copy_playbook) self.assertEqual(len(playbook.workflows), len(copy_playbook.workflows))
def test_read_playbook(self): playbook = execution_db_help.standard_load() response = self.get_with_status_check('/api/playbooks/{}'.format( playbook.id), headers=self.headers) expected_workflows = [ self.strip_ids(WorkflowSchema().dump(workflow).data) for workflow in playbook.workflows ] self.assertEqual(response['name'], 'test') self.assertEqual(len(response['workflows']), len(expected_workflows)) self.assertListEqual( [self.strip_ids(workflow) for workflow in response['workflows']], expected_workflows)
def test_read_playbook_workflows_from_query(self): playbook = execution_db_help.standard_load() response = self.get_with_status_check( '/api/workflows?playbook={}'.format(playbook.id), headers=self.headers) expected_workflows = [ self.strip_ids(WorkflowSchema().dump(workflow)) for workflow in playbook.workflows ] self.assertEqual(len(response), len(expected_workflows)) self.assertListEqual( [self.strip_ids(workflow) for workflow in response], expected_workflows)
def test_create_workflow(self): playbook = execution_db_help.standard_load() initial_workflows_len = len(playbook.workflows) self.empty_workflow_json['playbook_id'] = str(playbook.id) response = self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps(self.empty_workflow_json), content_type="application/json") self.empty_workflow_json['id'] = response['id'] final_workflows = playbook.workflows self.assertEqual(len(final_workflows), initial_workflows_len + 1) workflow = next((workflow for workflow in final_workflows if workflow.name == self.add_workflow_name), None) self.assertIsNotNone(workflow)
def test_copy_playbook(self): playbook = execution_db_help.standard_load() data = {"name": self.add_playbook_name} self.post_with_status_check('/api/playbooks?source={}'.format( playbook.id), data=json.dumps(data), headers=self.headers, status_code=OBJECT_CREATED, content_type="application/json") copy_playbook = self.app.running_context.execution_db.session.query( Playbook).filter_by(name=self.add_playbook_name).first() self.assertIsNotNone(copy_playbook) self.assertEqual(len(playbook.workflows), len(copy_playbook.workflows))
def test_execute_workflow_change_env_vars(self): playbook = execution_db_help.standard_load() workflow = self.app.running_context.execution_db.session.query( Workflow).filter_by(playbook_id=playbook.id).first() env_var_id = str(uuid4()) workflow.actions[0].arguments[0].value = None workflow.actions[0].arguments[0].reference = env_var_id action_ids = [ action.id for action in workflow.actions if action.name == 'start' ] setup_subscriptions_for_action(workflow.id, action_ids) result = {'count': 0, 'output': None} @WalkoffEvent.ActionExecutionSuccess.connect def y(sender, **kwargs): result['count'] += 1 result['output'] = kwargs['data']['data']['result'] data = { "workflow_id": str(workflow.id), "environment_variables": [{ "id": env_var_id, "value": "CHANGE INPUT" }] } response = self.post_with_status_check('/api/workflowqueue', headers=self.headers, status_code=SUCCESS_ASYNC, content_type="application/json", data=json.dumps(data)) current_app.running_context.executor.wait_and_reset(1) self.assertEqual(result['count'], 1) self.assertEqual(result['output'], 'REPEATING: CHANGE INPUT') action = current_app.running_context.execution_db.session.query( ActionStatus).filter(ActionStatus._workflow_status_id == UUID( response['id'])).first() arguments = json.loads(action.arguments) self.assertEqual(arguments[0]["name"], "call") self.assertIn('reference', arguments[0])
def test_create_workflow_with_env_vars(self): playbook = execution_db_help.standard_load() self.empty_workflow_json['playbook_id'] = str(playbook.id) self.empty_workflow_json['environment_variables'].append({'name': 'call', 'value': 'changeme', 'description': 'test description'}) self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps(self.empty_workflow_json), content_type="application/json") final_workflows = playbook.workflows workflow = next((workflow for workflow in final_workflows if workflow.name == self.add_workflow_name), None) self.assertEqual(len(workflow.environment_variables), 1) self.assertIsNotNone(workflow.environment_variables[0].id) self.assertEqual(workflow.environment_variables[0].name, 'call') self.assertEqual(workflow.environment_variables[0].value, 'changeme') self.assertEqual(workflow.environment_variables[0].description, 'test description')
def test_update_workflow(self): from walkoff.executiondb.schemas import WorkflowSchema playbook = execution_db_help.standard_load() workflow = playbook.workflows[0] expected_json = WorkflowSchema().dump(workflow) expected_json['name'] = self.change_workflow_name expected_json.pop('is_valid') response = self.put_with_status_check('/api/workflows', data=json.dumps(expected_json), headers=self.headers, content_type='application/json') response.pop('is_valid') self.assertDictEqual(response, expected_json) self.assertIsNotNone( self.app.running_context.execution_db.session.query(Workflow).filter_by(id=workflow.id).first()) self.assertIsNone( self.app.running_context.execution_db.session.query(Workflow).join(Workflow.playbook).filter( Workflow.name == self.add_workflow_name).first())
def test_create_workflow(self): playbook = execution_db_help.standard_load() initial_workflows_len = len(playbook.workflows) self.empty_workflow_json['playbook_id'] = str(playbook.id) response = self.post_with_status_check('/api/workflows', headers=self.headers, status_code=OBJECT_CREATED, data=json.dumps( self.empty_workflow_json), content_type="application/json") self.empty_workflow_json['id'] = response['id'] final_workflows = playbook.workflows self.assertEqual(len(final_workflows), initial_workflows_len + 1) workflow = next((workflow for workflow in final_workflows if workflow.name == self.add_workflow_name), None) self.assertIsNotNone(workflow)
def test_update_workflow(self): from walkoff.executiondb.schemas import WorkflowSchema playbook = execution_db_help.standard_load() workflow = playbook.workflows[0] expected_json = WorkflowSchema().dump(workflow).data expected_json['name'] = self.change_workflow_name response = self.put_with_status_check('/api/workflows', data=json.dumps(expected_json), headers=self.headers, content_type='application/json') self.assertDictEqual(response, expected_json) self.assertIsNotNone( self.app.running_context.execution_db.session.query( Workflow).filter_by(id=workflow.id).first()) self.assertIsNone( self.app.running_context.execution_db.session.query(Workflow).join( Workflow.playbook).filter( Workflow.name == self.add_workflow_name).first())
def test_update_workflow_invalid_new_workflow(self): from walkoff.executiondb.schemas import WorkflowSchema from walkoff.executiondb import ExecutionDatabase playbook = execution_db_help.standard_load() workflow = playbook.workflows[0] expected_json = WorkflowSchema().dump(workflow) expected_json['name'] = self.change_workflow_name expected_json['actions'][0]['action_name'] = 'invalid' expected_json.pop('is_valid') response = self.put_with_status_check('/api/workflows', data=json.dumps(expected_json), headers=self.headers, content_type='application/json') response.pop('is_valid') errors = response['actions'][0].pop('errors') self.assertEqual(len(errors), 1) self.assertDictEqual(response, expected_json) self.assertIsNotNone( ExecutionDatabase.instance.session.query(Workflow).filter_by(id=workflow.id).first()) self.assertIsNone( ExecutionDatabase.instance.session.query(Workflow).join(Workflow.playbook).filter( Workflow.name == self.add_workflow_name).first())
def test_read_workflows(self): execution_db_help.standard_load() workflows = {str(workflow.id) for workflow in self.app.running_context.execution_db.session.query(Workflow).all()} response = self.get_with_status_check('/api/workflows', headers=self.headers) self.assertSetEqual({workflow['id'] for workflow in response}, workflows)
def test_read_workflow_invalid_workflow_id_format(self): execution_db_help.standard_load() self.check_invalid_uuid('get', '/api/workflows/42', 'workflow')
def test_delete_playbook_invalid_id_format(self): execution_db_help.standard_load() previous_num_playbooks = len(self.app.running_context.execution_db.session.query(Playbook).all()) self.check_invalid_id('delete', '/api/playbooks/{}'.format(uuid4()), 'playbook') self.assertEqual(previous_num_playbooks, len(self.app.running_context.execution_db.session.query(Playbook).all()))
def test_delete_workflow_invalid_workflow_id_format(self): execution_db_help.standard_load() original_num_playbooks = len(self.app.running_context.execution_db.session.query(Playbook).all()) self.check_invalid_uuid('delete', '/api/workflows/37b', 'workflow') self.assertEqual(len(self.app.running_context.execution_db.session.query(Playbook).all()), original_num_playbooks)