def __create_sorted_dict_key(self, data): dictTmp = {} items = data.split('&') for i in (items): subItems = i.split('=') dictTmp[subItems[0]] = subItems[1] # sort dict return taputils.taputil_create_sorted_dict_key(dictTmp)
def __create_sorted_dict_key(self, data): dictTmp = {} items = data.split('&') for i in (items): subItems = i.split('=') dictTmp[subItems[0]] = subItems[1] # sort dict return taputils.taputil_create_sorted_dict_key(dictTmp)
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_abort_job(self): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) jobid = '12345' # Phase POST response responsePhase = DummyResponse() responsePhase.set_status_code(200) responsePhase.set_message("OK") responsePhase.set_data(method='POST', context=None, body=None, headers=None) req = "async/" + jobid + "/phase?PHASE=ABORT" connHandler.set_response(req, responsePhase) # 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) query = 'query' dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "QUERY": str(query) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = "async?" + sortedKey connHandler.set_response(req, responseLaunchJob) job = tap.launch_job_async(query, autorun=False) assert job is not None, "Expected a valid job" assert job.get_phase() == 'PENDING', \ "Wrong job phase. Expected: %s, found %s" % \ ('PENDING', job.get_phase()) # abort job job.abort() assert job.get_phase() == 'ABORT', \ "Wrong job phase. Expected: %s, found %s" % \ ('ABORT', job.get_phase()) # try to abort again with pytest.raises(Exception): job.abort()
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_launc_async_job(self): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) jobid = '12345' # Launch response responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(500) responseLaunchJob.set_message("ERROR") # 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) query = 'query' dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(query)} sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = "async?" + sortedKey connHandler.set_response(req, responseLaunchJob) # Phase response responsePhase = DummyResponse() responsePhase.set_status_code(500) responsePhase.set_message("ERROR") 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(500) responseResultsJob.set_message("ERROR") 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) with pytest.raises(Exception): tap.launch_job_async(query) responseLaunchJob.set_status_code(303) responseLaunchJob.set_message("OK") with pytest.raises(Exception): tap.launch_job_async(query) responsePhase.set_status_code(200) responsePhase.set_message("OK") with pytest.raises(Exception): tap.launch_job_async(query) responseResultsJob.set_status_code(200) responseResultsJob.set_message("OK") job = tap.launch_job_async(query) assert job is not None, "Expected a valid job" assert job.is_sync() is False, "Expected an asynchronous 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_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)"
def test_update_user_table(): tableName = 'table' 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_update.xml') tableData = utils.read_file_content(tableDataFile) dummyResponse.set_data(method='GET', context=None, body=tableData, headers=None) tableRequest = f"tables?tables={tableName}" connHandler.set_response(tableRequest, dummyResponse) with pytest.raises(Exception): tap.update_user_table() with pytest.raises(Exception): tap.update_user_table(table_name=tableName) with pytest.raises(Exception): tap.update_user_table(table_name=tableName, list_of_changes=[]) with pytest.raises(Exception): tap.update_user_table(table_name=tableName, list_of_changes=[[]]) with pytest.raises(Exception): tap.update_user_table(table_name=tableName, list_of_changes=[['', '', '']]) # Test Ra & Dec are provided list_of_changes = [['alpha', 'flags', 'Ra']] with pytest.raises(Exception): tap.update_user_table(table_name=tableName, list_of_changes=list_of_changes) list_of_changes = [['delta', 'flags', 'Dec']] with pytest.raises(Exception): tap.update_user_table(table_name=tableName, list_of_changes=list_of_changes) # OK responseEditTable = DummyResponse() responseEditTable.set_status_code(200) responseEditTable.set_message("OK") dictTmp = { "ACTION": "edit", "NUMTABLES": "1", "TABLE0": tableName, "TABLE0_COL0": "table6_oid", "TABLE0_COL0_FLAGS": "PK", "TABLE0_COL0_INDEXED": "True", "TABLE0_COL0_UCD": "", "TABLE0_COL0_UTYPE": "", "TABLE0_COL1": "source_id", "TABLE0_COL1_FLAGS": "None", "TABLE0_COL1_INDEXED": "False", "TABLE0_COL1_UCD": "None", "TABLE0_COL1_UTYPE": "None", "TABLE0_COL2": "alpha", "TABLE0_COL2_FLAGS": "Ra", "TABLE0_COL2_INDEXED": "False", "TABLE0_COL2_UCD": "", "TABLE0_COL2_UTYPE": "", "TABLE0_COL3": "delta", "TABLE0_COL3_FLAGS": "Dec", "TABLE0_COL3_INDEXED": "False", "TABLE0_COL3_UCD": "", "TABLE0_COL3_UTYPE": "", "TABLE0_NUMCOLS": "4" } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = f"tableEdit?{sortedKey}" connHandler.set_response(req, responseEditTable) list_of_changes = [['alpha', 'flags', 'Ra'], ['delta', 'flags', 'Dec']] tap.update_user_table(table_name=tableName, list_of_changes=list_of_changes)
def test_job_parameters(): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) 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', f'http://test:1111/tap/async/{jobid}' ]] responseLaunchJob.set_data(method='POST', context=None, body=None, headers=launchResponseHeaders) query = 'query' dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "QUERY": str(query) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = f"async?{sortedKey}" connHandler.set_response(req, 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 = f"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 = f"async/{jobid}/results/result" connHandler.set_response(req, responseResultsJob) responseResultsJob.set_status_code(200) responseResultsJob.set_message("OK") job = tap.launch_job_async(query, autorun=False) assert job is not None assert job.get_phase() == 'PENDING' # parameter response responseParameters = DummyResponse() responseParameters.set_status_code(200) responseParameters.set_message("OK") responseParameters.set_data(method='GET', context=None, body=None, headers=None) req = f"async/{jobid}?param1=value1" connHandler.set_response(req, responseParameters) # Phase POST response responsePhase = DummyResponse() responsePhase.set_status_code(200) responsePhase.set_message("OK") responsePhase.set_data(method='POST', context=None, body=None, headers=None) req = f"async/{jobid}/phase?PHASE=RUN" connHandler.set_response(req, responsePhase) # send parameter OK job.send_parameter("param1", "value1") # start job job.start() assert job.get_phase() == 'QUEUED' # try to send a parameter after execution with pytest.raises(Exception): job.send_parameter("param2", "value2")
def test_launch_async_job(): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) jobid = '12345' # Launch response responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(500) responseLaunchJob.set_message("ERROR") # list of list (httplib implementation for headers in response) launchResponseHeaders = [[ 'location', f'http://test:1111/tap/async/{jobid}' ]] responseLaunchJob.set_data(method='POST', context=None, body=None, headers=launchResponseHeaders) query = 'query' dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "PHASE": "RUN", "QUERY": str(query) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = f"async?{sortedKey}" connHandler.set_response(req, responseLaunchJob) # Phase response responsePhase = DummyResponse() responsePhase.set_status_code(500) responsePhase.set_message("ERROR") responsePhase.set_data(method='GET', context=None, body="COMPLETED", headers=None) req = f"async/{jobid}/phase" connHandler.set_response(req, responsePhase) # Results response responseResultsJob = DummyResponse() responseResultsJob.set_status_code(500) responseResultsJob.set_message("ERROR") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseResultsJob.set_data(method='GET', context=None, body=jobData, headers=None) req = f"async/{jobid}/results/result" connHandler.set_response(req, responseResultsJob) with pytest.raises(Exception): tap.launch_job_async(query) responseLaunchJob.set_status_code(303) responseLaunchJob.set_message("OK") with pytest.raises(Exception): tap.launch_job_async(query) responsePhase.set_status_code(200) responsePhase.set_message("OK") with pytest.raises(Exception): tap.launch_job_async(query) responseResultsJob.set_status_code(200) responseResultsJob.set_message("OK") job = tap.launch_job_async(query) assert job is not None assert job.async_ is True assert job.get_phase() == 'COMPLETED' assert job.failed is False # results results = job.get_results() assert len(results) == 3 __check_results_column(results, 'alpha', 'alpha', None, np.float64) __check_results_column(results, 'delta', 'delta', 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_start_job(self): connHandler = DummyConnHandler() tap = TapPlus("http://test:1111/tap", connhandler=connHandler) jobid = '12345' # Phase POST response responsePhase = DummyResponse() responsePhase.set_status_code(200) responsePhase.set_message("OK") responsePhase.set_data(method='POST', context=None, body=None, headers=None) req = "async/" + jobid + "/phase?PHASE=RUN" connHandler.set_response(req, responsePhase) # 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) query = 'query' dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "QUERY": str(query) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) req = "async?" + sortedKey connHandler.set_response(req, 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) responseResultsJob.set_status_code(200) responseResultsJob.set_message("OK") job = tap.launch_job_async(query, autorun=False) assert job is not None, "Expected a valid job" assert job.get_phase() == 'PENDING', \ "Wrong job phase. Expected: %s, found %s" % \ ('PENDING', job.get_phase()) # start job job.start() assert job.get_phase() == 'QUEUED', \ "Wrong job phase. Expected: %s, found %s" % \ ('QUEUED', job.get_phase()) # results results = job.get_results() assert len(results) == 3, \ "Wrong job results (num rows). Expected: %d, found %d" % \ (3, len(results)) assert job.get_phase() == 'COMPLETED', \ "Wrong job phase. Expected: %s, found %s" % \ ('COMPLETED', job.get_phase()) # try to start again with pytest.raises(Exception): job.start()
def test_launch_multipart_async_job(self): connHandler = DummyConnHandlerCadc() tap = TapPlusCadc("http://test:1111/tap", connhandler=connHandler) jobid = '1234' responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(200) responseLaunchJob.set_message("OK") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseHeaders = [['location', 'http://test:1111/tap/async/' + jobid]] responseLaunchJob.set_data(method='POST', context=None, body=jobData, headers=responseHeaders) query = 'select top 5 * from table' upload_name = 'testtable' upload_resource = data_path('test_tables.xml') dTmp = {"q": query} dTmpEncoded = connHandler.url_encode(dTmp) p = dTmpEncoded.find("=") q = dTmpEncoded[p + 1:] uTmp = {"u": str(upload_name) + ",param:" + str(upload_name)} uTmpEncoded = connHandler.url_encode(uTmp) pos = uTmpEncoded.find("=") upload = uTmpEncoded[pos + 1:] dictTmp = { "REQUEST": "doQuery", "LANG": "ADQL", "FORMAT": "votable", "tapclient": str(TAP_CLIENT_ID), "QUERY": str(q), "UPLOAD": str(upload) } sortedKey = taputils.taputil_create_sorted_dict_key(dictTmp) jobRequest = "async?" + sortedKey connHandler.set_response(jobRequest, responseLaunchJob) # Phase response responsePhase = DummyResponse() responsePhase.set_status_code(303) responsePhase.set_message("OK") responsePhaseHeaders = [[ 'location', 'http://test:1111/tap/async/' + jobid ]] responsePhase.set_data(method='POST', context=None, body="COMPLETED", headers=responsePhaseHeaders) req = "async/" + jobid + "/phase?PHASE=RUN" connHandler.set_response(req, responsePhase) # Job Phase response jobPhase = DummyResponse() jobPhase.set_status_code(200) jobPhase.set_message("OK") jobPhaseHeaders = [['location', 'http://test:1111/tap/async/' + jobid]] jobPhase.set_data(method='GET', context=None, body="COMPLETED", headers=jobPhaseHeaders) req = "async/" + jobid + "/phase" connHandler.set_response(req, jobPhase) # 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) job = tap.launch_job_async(query, upload_resource=upload_resource, upload_table_name=upload_name) assert job is not None, "Expected a valid job" 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)" # 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)