def success_run(database: DB, fs: StorageVolume, basedir: str) -> Tuple[str, str, str, str]: """Create a successful run with two result files: - A.json - results/B.json Returns the identifier of the created workflow, group, run, and user. """ # Setup temporary run folder. runfs = FileSystemStorage(basedir=os.path.join(basedir, 'tmprun')) runfs.store(file=io_file({'A': 1}), dst='A.json') runfs.store(file=io_file({'B': 1}), dst=util.join('results', 'B.json')) with database.session() as session: user_id = create_user(session, active=True) workflow_id = create_workflow(session) group_id = create_group(session, workflow_id, users=[user_id]) groups = WorkflowGroupManager(session=session, fs=fs) runs = RunManager(session=session, fs=fs) run = runs.create_run(group=groups.get_group(group_id)) run_id = run.run_id state = run.state() runs.update_run( run_id=run_id, state=state.start().success(files=['A.json', 'results/B.json']), runstore=runfs) return workflow_id, group_id, run_id, user_id
def test_run_serialization(database, tmpdir): """Test serialization of run handles and run listings.""" view = RunSerializer() fs = FileSystemStorage(basedir=tmpdir) # Setup temporary run folder. runfs = FileSystemStorage(basedir=os.path.join(tmpdir, 'tmprun')) runfs.store(file=io_file({'A': 1}), dst='A.json') runfs.store(file=io_file({'B': 2}), dst='results/B.json') # Create runs. with database.session() as session: user_id = model.create_user(session, active=True) workflow_id = model.create_workflow(session) group_id = model.create_group(session, workflow_id, users=[user_id]) # Create successful run. groups = WorkflowGroupManager(session=session, fs=fs) runs = RunManager(session=session, fs=fs) run = runs.create_run(group=groups.get_group(group_id)) run_id = run.run_id state = run.state() runs.update_run( run_id, state.start().success(files=['A.json', 'results/B.json']), runstore=runfs) run = runs.get_run(run_id) doc = view.run_handle(run) validator('RunHandle').validate(doc) # Create error run. run = runs.create_run(group=groups.get_group(group_id)) run_id = run.run_id state = run.state() runs.update_run(run_id=run_id, state=state) messages = ['There', 'were', 'many errors'] runs.update_run(run_id=run_id, state=state.error(messages)) run = runs.get_run(run_id) doc = view.run_handle(run) validator('RunHandle').validate(doc) # Validate run listing. doc = view.run_listing(runs=runs.list_runs(group_id)) validator('RunListing').validate(doc) assert len(doc[labels.RUN_LIST]) == 2