def test_cone_search_async(self): connHandler = DummyConnHandler() tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler) tap = JwstClass(tap_plus_handler=tapplus, show_messages=False) 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) ra = 19 dec = 20 sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs') radius = Quantity(1.0, u.deg) 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) job = tap.cone_search(sc, radius, async_job=True) assert job is not None, "Expected a valid job" assert job.async_ is True, "Expected an asynchronous job" assert job.get_phase( ) == 'COMPLETED', f"Wrong job phase. Expected: {'COMPLETED'}, found {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: {3}, found {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, object) self.__check_results_column(results, 'table1_oid', 'table1_oid', None, np.int32)
def test_cone_search_sync(self): connHandler = DummyConnHandler() tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler) tap = JwstClass(tap_plus_handler=tapplus, show_messages=False) # Launch response: we use default response because the # query contains decimals responseLaunchJob = DummyResponse() responseLaunchJob.set_status_code(200) responseLaunchJob.set_message("OK") jobDataFile = data_path('job_1.vot') jobData = utils.read_file_content(jobDataFile) responseLaunchJob.set_data(method='POST', context=None, body=jobData, headers=None) ra = 19.0 dec = 20.0 sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs') radius = Quantity(1.0, u.deg) connHandler.set_default_response(responseLaunchJob) job = tap.cone_search(sc, radius) assert job is not None, "Expected a valid job" assert job.async_ is False, "Expected a synchronous job" assert job.get_phase( ) == 'COMPLETED', f"Wrong job phase. Expected: {'COMPLETED'}, found {job.get_phase()}" assert job.failed is False, "Wrong job status (set Failed = True)" # results results = job.get_results() assert len( results ) == 3, f"Wrong job results (num rows). Expected: {3}, found {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, object) self.__check_results_column(results, 'table1_oid', 'table1_oid', None, np.int32) # Test observation_id argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, observation_id=1) assert "observation_id must be string" in err.value.args[0] # Test cal_level argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, cal_level='a') assert "cal_level must be either 'Top' or an integer" in err.value.args[ 0] # Test only_public with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, only_public='a') assert "only_public must be boolean" in err.value.args[0] # Test dataproduct_type argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, prod_type=1) assert "prod_type must be string" in err.value.args[0] with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, prod_type='a') assert "prod_type must be one of: " in err.value.args[0] # Test instrument_name argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, instrument_name=1) assert "instrument_name must be string" in err.value.args[0] with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, instrument_name='a') assert "instrument_name must be one of: " in err.value.args[0] # Test filter_name argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, filter_name=1) assert "filter_name must be string" in err.value.args[0] # Test proposal_id argument with pytest.raises(ValueError) as err: tap.cone_search(sc, radius, proposal_id=123) assert "proposal_id must be string" in err.value.args[0]