def _run_workflow(time_elapsed_seconds=0.5, finish=True): """Mock a workflow run.""" id_ = uuid4() workflow = Workflow( id_=str(id_), name="test_{}".format(id_), owner_id=new_user.id_, reana_specification=[], type_="serial", logs="", status=RunStatus.created, ) # start workflow workflow.status = RunStatus.running session.add(workflow) session.commit() termination_value = datetime.now() + timedelta( seconds=time_elapsed_seconds) class MockDatetime(datetime): @classmethod def now(cls): return termination_value if finish: with mock.patch("reana_db.models.datetime", MockDatetime): Workflow.update_workflow_status(session, workflow.id_, RunStatus.finished) return workflow
def test_delete_all_workflow_runs(app, session, default_user, yadage_workflow_with_name): """Test deletion of all runs of a given workflow.""" # add 5 workflows in the database with the same name for i in range(5): workflow = Workflow( id_=uuid.uuid4(), name=yadage_workflow_with_name["name"], owner_id=default_user.id_, reana_specification=yadage_workflow_with_name[ "reana_specification"], operational_options={}, type_=yadage_workflow_with_name["reana_specification"]["workflow"] ["type"], logs="", ) session.add(workflow) if i == 4: workflow.status = RunStatus.running not_deleted_one = workflow.id_ session.commit() first_workflow = (session.query(Workflow).filter_by( name=yadage_workflow_with_name["name"]).first()) delete_workflow(first_workflow, all_runs=True) for workflow in session.query(Workflow).filter_by( name=first_workflow.name).all(): if not_deleted_one == workflow.id_: assert workflow.status == RunStatus.running else: assert workflow.status == RunStatus.deleted
def test_get_workflow_status_with_name(app, session, default_user, cwl_workflow_with_name): """Test get workflow status.""" with app.test_client() as client: # create workflow workflow_uuid = uuid.uuid4() workflow_name = 'my_test_workflow' workflow = Workflow( id_=workflow_uuid, name=workflow_name, status=WorkflowStatus.finished, owner_id=default_user.id_, reana_specification=cwl_workflow_with_name['reana_specification'], type_=cwl_workflow_with_name[ 'reana_specification']['type'], logs='') session.add(workflow) session.commit() workflow = Workflow.query.filter( Workflow.name == workflow_name).first() res = client.get(url_for('api.get_workflow_status', workflow_id_or_name=workflow_name + '.1'), query_string={"user": default_user.id_}, content_type='application/json', data=json.dumps(cwl_workflow_with_name)) json_response = json.loads(res.data.decode()) assert json_response.get('status') == workflow.status.name workflow.status = WorkflowStatus.finished session.commit() res = client.get(url_for('api.get_workflow_status', workflow_id_or_name=workflow_name + '.1'), query_string={"user": default_user.id_}, content_type='application/json', data=json.dumps(cwl_workflow_with_name)) json_response = json.loads(res.data.decode()) assert json_response.get('status') == workflow.status.name
def test_delete_all_workflow_runs(app, session, default_user, yadage_workflow_with_name, hard_delete): """Test deletion of all runs of a given workflow.""" # add 5 workflows in the database with the same name for i in range(5): workflow = Workflow(id_=uuid.uuid4(), name=yadage_workflow_with_name['name'], owner_id=default_user.id_, reana_specification=yadage_workflow_with_name[ 'reana_specification'], operational_options={}, type_=yadage_workflow_with_name[ 'reana_specification']['workflow']['type'], logs='') session.add(workflow) if i == 4: workflow.status = WorkflowStatus.running not_deleted_one = workflow.id_ session.commit() first_workflow = session.query(Workflow).\ filter_by(name=yadage_workflow_with_name['name']).first() delete_workflow(first_workflow, all_runs=True, hard_delete=hard_delete) if not hard_delete: for workflow in session.query(Workflow).\ filter_by(name=first_workflow.name).all(): if not_deleted_one == workflow.id_: assert workflow.status == WorkflowStatus.running else: assert workflow.status == WorkflowStatus.deleted else: # the one running should not be deleted assert len(session.query(Workflow). filter_by(name=first_workflow.name).all()) == 1