def test_create_project_handles_503(requests_mock): requests_mock.post('http://testing-es-url/api/v1/projects', text='', status_code=503) with pytest.raises(ServiceError): rest_client.project_create('http://testing-es-url', {'id': 'schema'}, 'restype', 'myname', 'mynote')
def test_create_project_default_data(requests_mock): requests_mock.post('http://testing-es-url/api/v1/projects', json={'status': 'ok'}, status_code=201) rest_client.project_create('http://testing-es-url', {'id': 'schema'}, 'restype', 'myname') posted_data = requests_mock.last_request.json() assert all(expected_field in posted_data for expected_field in {'schema', 'result_type', 'number_parties', 'name', 'notes'}) assert 'created by clkhash' in posted_data['notes'] assert posted_data['number_parties'] == 2
def test_create_project_handles_400(requests_mock): requests_mock.post('http://testing-es-url/api/v1/projects', json={ 'title': 'not ok', 'status': 400 }, status_code=400) with pytest.raises(ServiceError): rest_client.project_create('http://testing-es-url', {'id': 'schema'}, 'restype', 'myname', 'mynote')
def create_project(type, schema, server, name, output, verbose): """Create a new project on an entity matching server. See entity matching service documentation for details on mapping type and schema Returns authentication details for the created project. """ if verbose: log("Entity Matching Server: {}".format(server)) if schema is not None: schema_json = json.load(schema) # Validate the schema clkhash.schema.validate_schema_dict(schema_json) else: raise ValueError( "Schema must be provided when creating new linkage project") name = name if name is not None else '' # Creating new project try: project_creation_reply = project_create(server, schema_json, type, name) except ServiceError as e: log("Unexpected response - {}".format(e.status_code)) log(e.text) raise SystemExit else: log("Project created") json.dump(project_creation_reply, output)
def run_experiments(config): server = config['server'] rest_client.server_get_status(server) results = {'experiments': []} for experiment in config['experiments']: try: threshold = experiment['threshold'] logger.info('running experiment: {}'.format(experiment)) size_a, size_b = get_exp_sizes(experiment) # create project credentials = rest_client.project_create( server, config['schema'], 'mapping', "benchy_{}".format(experiment)) try: # upload clks upload_binary_clks(config, size_a, size_b, credentials) # create run run = rest_client.run_create( server, credentials['project_id'], credentials['result_token'], threshold, "{}_{}".format(experiment, threshold)) # wait for result run_id = run['run_id'] logger.info(f'waiting for run {run_id} to finish') status = rest_client.wait_for_run(server, credentials['project_id'], run['run_id'], credentials['result_token'], timeout=config['timeout']) if status['state'] != 'completed': raise RuntimeError( 'run did not finish!\n{}'.format(status)) logger.info('experiment successful. Evaluating results now...') mapping = rest_client.run_get_result_text( server, credentials['project_id'], run['run_id'], credentials['result_token']) mapping = json.loads(mapping)['mapping'] mapping = {int(k): int(v) for k, v in mapping.items()} tt = score_mapping(mapping, *load_truth(config, size_a, size_b)) result = compose_result(status, tt, experiment, (size_a, size_b), threshold) results['experiments'].append(result) logger.info('cleaning up...') delete_resources(config, credentials, run) except Exception as e: delete_resources(config, credentials, run) raise e except Exception as e: e_trace = format_exc() logger.warning("experiment '{}' failed: {}".format( experiment, e_trace)) results['experiments'].append({ 'name': experiment, 'status': 'ERROR', 'description': e_trace }) return results
def _create_project(self, schema=None, result_type='permutations', name='', notes='', parties=2): if schema is None: schema = json.load(open(SIMPLE_SCHEMA_PATH, 'rt')) return rest_client.project_create(self.url, schema, result_type, name, notes, parties)
def _create_project(self, schema=None, result_type='permutations', name='', notes='', parties=2): if schema is None: schema = json.load(open(SIMPLE_SCHEMA_PATH, 'rt')) try: response = rest_client.project_create(self.url, schema, result_type, name, notes, parties) self._created_projects.append(response) return response except ServiceError: raise