def test_group_handle_serialization(database, tmpdir): """Test serialization of workflow group handles.""" config = Config().basedir(tmpdir) view = WorkflowGroupSerializer() with database.session() as session: manager = WorkflowGroupManager(session=session, fs=FileSystemStore(config)) 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]) manager.upload_file(group_id=group_id, file=io_file(data={'A': 1}), name='a.json') group = manager.get_group(group_id) doc = view.group_handle(group) validator('UserGroupHandle').validate(doc) assert len(doc[labels.GROUP_MEMBERS]) == 1
def test_group_listing_serialization(database, tmpdir): """Test serialization of workflow group listing.""" config = Config().basedir(tmpdir) view = WorkflowGroupSerializer() with database.session() as session: manager = WorkflowGroupManager(session=session, fs=FileSystemStore(config)) user_id = model.create_user(session, active=True) workflow_id = model.create_workflow(session) model.create_group(session, workflow_id, users=[user_id]) model.create_group(session, workflow_id, users=[user_id]) groups = manager.list_groups(workflow_id=workflow_id, user_id=user_id) assert len(groups) == 2 doc = view.group_listing(groups) validator('UserGroupListing').validate(doc) assert len(doc[labels.GROUP_LIST]) == 2
def test_workflow_leaderboard_serialization(database, tmpdir): """Test serialization of a workflow leaderboard.""" config = Config().basedir(tmpdir) schema = validator('WorkflowLeaderboard') view = WorkflowSerializer() with database.session() as session: manager = WorkflowManager(session=session, fs=FileSystemStore(config)) workflow = manager.create_workflow(source=BENCHMARK_DIR, name='Test', specfile=SPEC_FILE) ts = util.utc_now() ranking = [ RunResult(run_id='0', group_id='1', group_name='A', created_at=ts, started_at=ts, finished_at=ts, values={ 'len': 1, 'count': 10 }) ] doc = view.workflow_leaderboard(workflow, ranking=ranking) schema.validate(doc)
def test_file_listing_serialization(database, tmpdir): """Test serialization of file handles.""" view = UploadFileSerializer() filename = 'data.json' with database.session() as session: manager = WorkflowGroupManager(session=session, fs=FileSystemStorage(basedir=tmpdir)) 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]) fh = manager.upload_file(group_id=group_id, file=io_file(data={'A': 1}), name=filename) doc = view.file_handle(group_id=group_id, fh=fh) assert doc[labels.FILE_NAME] == filename validator('FileHandle').validate(doc) doc = view.file_listing( group_id=group_id, files=manager.list_uploaded_files(group_id=group_id)) validator('FileListing').validate(doc)
def test_user_listing_serialization(database): """Test serialization of user listings.""" schema = validator('UserListing') view = UserSerializer() with database.session() as session: manager = UserManager(session) manager.register_user('alice', 'mypwd') manager.register_user('bob', 'mypwd') doc = view.user_listing(manager.list_users()) schema.validate(doc) assert len(doc[labels.USER_LIST]) == 2
def test_workflow_listing_serialization(database, tmpdir): """Test serialization of workflow listings.""" config = Config().basedir(tmpdir) schema = validator('WorkflowListing') view = WorkflowSerializer() with database.session() as session: manager = WorkflowManager(session=session, fs=FileSystemStore(config)) model.create_workflow(session) model.create_workflow(session) workflows = manager.list_workflows() doc = view.workflow_listing(workflows) schema.validate(doc) assert len(doc[labels.WORKFLOW_LIST]) == 2
def test_service_descriptor(): """Test the service descriptor object.""" schema = validator('ServiceDescriptor') # Local service descriptor (no arguments). service = ServiceDescriptor.from_config(env=config.env()) schema.validate(service.to_dict()) assert service.routes().get(SERVICE_DESCRIPTOR) is not None assert service.routes().get('foo') is None # Remote service descriptor (init from local serialization). service = ServiceDescriptor(doc=service.to_dict(), routes={'foo': 'bar'}) schema.validate(service.to_dict()) assert service.routes().get(SERVICE_DESCRIPTOR) is not None schema.validate(service.to_dict()) assert service.routes().get('foo') == 'bar'
def test_workflow_handle_serialization(database, tmpdir): """Test serialization of workflow handles.""" config = Config().basedir(tmpdir) schema = validator('WorkflowHandle') view = WorkflowSerializer() with database.session() as session: manager = WorkflowManager(session=session, fs=FileSystemStore(config)) workflow = manager.create_workflow(source=BENCHMARK_DIR, name='Test', specfile=SPEC_FILE) doc = view.workflow_handle(workflow) schema.validate(doc) workflow = manager.get_workflow(workflow.workflow_id) schema.validate(doc) assert doc[labels.WORKFLOW_NAME] == 'Test'
def test_user_handle_serialization(database): """Test serialization of user handles.""" schema = validator('User') view = UserSerializer() with database.session() as session: manager = UserManager(session) user = manager.register_user('alice', 'mypwd') doc = view.user(user) schema.validate(doc) assert doc[labels.USER_NAME] == 'alice' assert labels.USER_TOKEN not in doc user = manager.login_user('alice', 'mypwd') doc = view.user(user, include_token=True) schema.validate(doc) assert doc[labels.USER_NAME] == 'alice' assert labels.USER_TOKEN in doc
def test_service_descriptor_serialization(username): """Validate the serialization of the service descriptor.""" schema = validator('ServiceDescriptor') serializer = ServiceDescriptorSerializer() doc = serializer.service_descriptor(name='Test', version='0.0.0', url='http://localhost:5000', routes={'home': '/'}, username=username) schema.validate(doc) assert serializer.get_name(doc) == 'Test' assert serializer.get_version(doc) == '0.0.0' assert serializer.get_url(doc) == 'http://localhost:5000' assert serializer.get_username(doc) == username assert serializer.get_routes(doc, {'foo': 'bar'}) == { 'home': '/', 'foo': 'bar' }
def test_run_serialization(database, tmpdir): """Test serialization of run handles and run listings.""" config = Config().basedir(tmpdir) view = RunSerializer() fs = FileSystemStore(config) # Setup temporary run folder. tmprundir = os.path.join(tmpdir, 'tmprun') tmpresultsdir = os.path.join(tmprundir, 'run', 'results') os.makedirs(tmprundir) os.makedirs(tmpresultsdir) f1 = os.path.join(tmprundir, 'A.json') util.write_object(f1, {'A': 1}) # 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', 'run/results/B.json']), rundir=tmprundir) 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
def test_password_request_serialization(): """Test serialization of the password reset request response.""" schema = validator('PasswordResetResponse') doc = UserSerializer().reset_request('0000') schema.validate(doc) assert doc[labels.REQUEST_ID] == '0000'