def test_project_run(self): p = self._create_project() p_id = p['project_id'] upload_response_1 = rest_client.project_upload_clks( self.url, p_id, p['update_tokens'][0], self.clk_data_1) upload_response_2 = rest_client.project_upload_clks( self.url, p_id, p['update_tokens'][1], self.clk_data_2) run_response = rest_client.run_create(self.url, p_id, p['result_token'], 0.999, name='clkhash rest client test') assert 'run_id' in run_response r_id = run_response['run_id'] with pytest.raises(ServiceError): rest_client.run_get_status(self.url, p_id, 'invalid-run-id', p['result_token']) with pytest.raises(ServiceError): rest_client.run_get_status(self.url, p_id, r_id, 'invalid-token') status1 = rest_client.run_get_status(self.url, p_id, r_id, p['result_token']) assert 'state' in status1 assert 'stages' in status1 print(rest_client.format_run_status(status1)) # Check we can watch the run progress this will raise if not # completed in 10 seconds for status_update in rest_client.watch_run_status( self.url, p_id, r_id, p['result_token'], 10, 0.5): print(rest_client.format_run_status(status_update)) # Check that we can still "wait" on a completed run and get a valid # status status2 = rest_client.wait_for_run(self.url, p_id, r_id, p['result_token'], 10) assert status2['state'] == 'completed' coord_result_raw = rest_client.run_get_result_text( self.url, p_id, r_id, p['result_token']) coord_result = json.loads(coord_result_raw) assert 'mask' in coord_result assert len(coord_result['mask']) == 1000 assert coord_result['mask'].count(1) > 10 result_a = json.loads( rest_client.run_get_result_text( self.url, p_id, r_id, upload_response_1['receipt_token'])) result_b = json.loads( rest_client.run_get_result_text( self.url, p_id, r_id, upload_response_2['receipt_token'])) assert 'permutation' in result_a assert 'rows' in result_a assert 1000 == result_b['rows'] == result_a['rows'] rest_client.run_delete(self.url, p_id, r_id, p['result_token']) rest_client.project_delete(self.url, p_id, p['result_token'])
def test_project_run_before_data(self): p = self._create_project() p_id = p['project_id'] upload_response_1 = rest_client.project_upload_clks(self.url, p_id, p['update_tokens'][0], self.clk_data_1) run_response = rest_client.run_create(self.url, p_id, p['result_token'], 0.999, name='clkhash rest client test') with pytest.raises(ServiceError): json.loads(rest_client.run_get_result_text(self.url, p_id, run_response['run_id'], upload_response_1['receipt_token']))
def upload(clk_json, project, apikey, server, output, verbose): """Upload CLK data to entity matching server. Given a json file containing hashed clk data as CLK_JSON, upload to the entity resolution service. Use "-" to read from stdin. """ if verbose: log("Uploading CLK data from {}".format(clk_json.name)) log("To Entity Matching Server: {}".format(server)) log("Project ID: {}".format(project)) log("Uploading CLK data to the server") response = project_upload_clks(server, project, apikey, clk_json) if verbose: log(response) json.dump(response, output)
def test_upload_clks(self): schema_object = json.load(open(SAMPLE_DATA_SCHEMA_PATH, 'rt')) p = self._create_project(schema=schema_object) upload_response = rest_client.project_upload_clks(self.url, p['project_id'], p['update_tokens'][0], self.clk_data_1) assert 'receipt_token' in upload_response