def test_launch_sync_job(self): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(500) responseLaunchJob.set_message("ERROR") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseLaunchJob.set_data(method='POST', context=None, body=jobData, headers=None) query = 'select top 5 * from table' dTmp = {"q": query} dTmpEncoded = connHandler.url_encode(dTmp) p = dTmpEncoded.find("=") q = dTmpEncoded[p + 1:] dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(q) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) jobRequest = "sync?" + sortedKey connHandler.set_response(jobRequest, responseLaunchJob) with pytest.raises(Exception): tap.launch_job(query) responseLaunchJob.set_status_code(200) responseLaunchJob.set_message("OK") job = tap.launch_job(query) assert job is not None, "Expected a valid job" assert job.async_ is False, "Expected a synchronous job" assert job.get_phase() == 'COMPLETED', \ "Wrong job phase. Expected: %s, found %s" % \ ('COMPLETED', job.get_phase()) assert job.failed is False, "Wrong job status (set Failed = True)" # results results = job.get_results() assert len(results) == 3, \ "Wrong job results (num rows). Expected: %d, found %d" % \ (3, len(results)) self.__check_results_column(results, 'alpha', 'alpha', None, np.float64) self.__check_results_column(results, 'delta', 'delta', None, np.float64) self.__check_results_column(results, 'source_id', 'source_id', None, np.object) self.__check_results_column(results, 'table1_oid', 'table1_oid', None, np.int32)
def test_launch_sync_job(): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(500) responseLaunchJob.set_message("ERROR") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseLaunchJob.set_data(method='POST', context=None, body=jobData, headers=None) query = 'select top 5 * from table' dTmp = {"q": query} dTmpEncoded = connHandler.url_encode(dTmp) p = dTmpEncoded.find("=") q = dTmpEncoded[p + 1:] dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(q) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) jobRequest = f"sync?{sortedKey}" connHandler.set_response(jobRequest, responseLaunchJob) with pytest.raises(Exception): tap.launch_job(query) responseLaunchJob.set_status_code(200) responseLaunchJob.set_message("OK") job = tap.launch_job(query) assert job is not None assert job.async_ is False assert job.get_phase() == 'COMPLETED' assert job.failed is False # results results = job.get_results() assert len(results) == 3 __check_results_column(results, 'ra', 'ra', None, np.float64) __check_results_column(results, 'dec', 'dec', None, np.float64) __check_results_column(results, 'source_id', 'source_id', None, object) __check_results_column(results, 'table1_oid', 'table1_oid', None, np.int32)
def test_rename_table(): tableName = 'user_test.table_test_rename' newTableName = 'user_test.table_test_rename_new' newColumnNames = {'ra': 'alpha', 'dec': 'delta'} connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) dummyResponse = DummyResponse() dummyResponse.set_status_code(200) dummyResponse.set_message("OK") tableDataFile = data_path('test_table_rename.xml') tableData = utils.read_file_content(tableDataFile) dummyResponse.set_data(method='GET', context=None, body=tableData, headers=None) with pytest.raises(Exception): tap.rename_table() with pytest.raises(Exception): tap.rename_table(table_name=tableName) with pytest.raises(Exception): tap.rename_table(table_name=tableName, new_table_name=None, new_column_names_dict=None) # Test OK. responseRenameTable = DummyResponse() responseRenameTable.set_status_code(200) responseRenameTable.set_message("OK") dictArgs = { "action": "rename", "new_column_names": "ra:alpha,dec:delta", "new_table_name": newTableName, "table_name": tableName, } data = connHandler.url_encode(dictArgs) req = f"TableTool?{data}" connHandler.set_response(req, responseRenameTable) tap.rename_table(table_name=tableName, new_table_name=newTableName, new_column_names_dict=newColumnNames)
def test_launch_sync_job(self): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(500) responseLaunchJob.set_message("ERROR") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseLaunchJob.set_data(method='POST', context=None, body=jobData, headers=None) query = 'select top 5 * from table' dTmp = {"q": query} dTmpEncoded = connHandler.url_encode(dTmp) p = dTmpEncoded.find("=") q = dTmpEncoded[p+1:] dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(q)} sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) jobRequest = "sync?" + sortedKey connHandler.set_response(jobRequest, responseLaunchJob) with pytest.raises(Exception): tap.launch_job(query) responseLaunchJob.set_status_code(200) responseLaunchJob.set_message("OK") job = tap.launch_job(query) assert job is not None, "Expected a valid job" assert job.is_sync(), "Expected a synchronous job" assert job.get_phase() == 'COMPLETED', \ "Wrong job phase. Expected: %s, found %s" % \ ('COMPLETED', job.get_phase()) assert job.is_failed() is False, "Wrong job status (set Failed = True)" # results results = job.get_results() assert len(results) == 3, \ "Wrong job results (num rows). Expected: %d, found %d" % \ (3, len(results)) self.__check_results_column(results, 'alpha', 'alpha', None, np.float64) self.__check_results_column(results, 'delta', 'delta', None, np.float64) self.__check_results_column(results, 'source_id', 'source_id', None, np.object) self.__check_results_column(results, 'table1_oid', 'table1_oid', None, np.int32)
def test_xmatch(self): connHandler = DummyConnHandler() tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler) tap = GaiaClass(connHandler, tapplus) jobid = '12345' # Launch response responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(303) responseLaunchJob.set_message("OK") # list of list (httplib implementation for headers in response) launchResponseHeaders = [[ 'location', 'http://test:1111/tap/async/' + jobid ]] responseLaunchJob.set_data(method='POST', context=None, body=None, headers=launchResponseHeaders) connHandler.set_default_response(responseLaunchJob) # Phase response responsePhase = DummyResponse() responsePhase.set_status_code(200) responsePhase.set_message("OK") responsePhase.set_data(method='GET', context=None, body="COMPLETED", headers=None) req = "async/" + jobid + "/phase" connHandler.set_response(req, responsePhase) # Results response responseResultsJob = DummyResponse() responseResultsJob.set_status_code(200) responseResultsJob.set_message("OK") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseResultsJob.set_data(method='GET', context=None, body=jobData, headers=None) req = "async/" + jobid + "/results/result" connHandler.set_response(req, responseResultsJob) query = ("SELECT crossmatch_positional(", "'schemaA','tableA','schemaB','tableB',1.0,'results')", "FROM dual;") dTmp = {"q": query} dTmpEncoded = connHandler.url_encode(dTmp) p = dTmpEncoded.find("=") q = dTmpEncoded[p + 1:] dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(q) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) jobRequest = "sync?" + sortedKey connHandler.set_response(jobRequest, responseLaunchJob) # check parameters # missing table A with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a=None, full_qualified_table_name_b='schemaB.tableB', results_table_name='results') assert "Table name A argument is mandatory" in err.value.args[0] # missing schema A with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='results') assert "Not found schema name in full qualified table A: 'tableA'" \ in err.value.args[0] # missing table B with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b=None, results_table_name='results') assert "Table name B argument is mandatory" in err.value.args[0] # missing schema B with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='tableB', results_table_name='results') assert "Not found schema name in full qualified table B: 'tableB'" \ in err.value.args[0] # missing results table with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name=None) assert "Results table name argument is mandatory" in err.value.args[0] # wrong results table (with schema) with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='schema.results') assert "Please, do not specify schema for 'results_table_name'" \ in err.value.args[0] # radius < 0.1 with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='results', radius=0.01) assert "Invalid radius value. Found 0.01, valid range is: 0.1 to 10.0" \ in err.value.args[0] # radius > 10.0 with pytest.raises(ValueError) as err: tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='results', radius=10.1) assert "Invalid radius value. Found 10.1, valid range is: 0.1 to 10.0" \ in err.value.args[0] # check default parameters parameters = {} query = "SELECT crossmatch_positional(\ 'schemaA','tableA',\ 'schemaB','tableB',\ 1.0,\ 'results')\ FROM dual;" parameters['query'] = query parameters['name'] = 'results' parameters['output_file'] = None parameters['output_format'] = 'votable' parameters['verbose'] = False parameters['dump_to_file'] = False parameters['background'] = False parameters['upload_resource'] = None parameters['upload_table_name'] = None job = tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='results') assert job.async_ is True, "Expected an asynchronous job" assert job.get_phase() == 'COMPLETED', \ "Wrong job phase. Expected: %s, found %s" % \ ('COMPLETED', job.get_phase()) assert job.failed is False, "Wrong job status (set Failed = True)" job = tap.cross_match(full_qualified_table_name_a='schemaA.tableA', full_qualified_table_name_b='schemaB.tableB', results_table_name='results', background=True) assert job.async_ is True, "Expected an asynchronous job" assert job.get_phase() == 'EXECUTING', \ "Wrong job phase. Expected: %s, found %s" % \ ('EXECUTING', job.get_phase()) assert job.failed is False, "Wrong job status (set Failed = True)"