def test_query_region_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) 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) sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree), frame='icrs') width = Quantity(12, u.deg) height = Quantity(10, u.deg) table = tap.query_region(sc, width=width, height=height, async_job=True) assert len( table ) == 3, f"Wrong job results (num rows). Expected: {3}, found {len(table)}" self.__check_results_column(table, 'alpha', 'alpha', None, np.float64) self.__check_results_column(table, 'delta', 'delta', None, np.float64) self.__check_results_column(table, 'source_id', 'source_id', None, object) self.__check_results_column(table, 'table1_oid', 'table1_oid', None, np.int32) # by radius radius = Quantity(1, u.deg) table = tap.query_region(sc, radius=radius, async_job=True) assert len( table ) == 3, f"Wrong job results (num rows). Expected: {3}, found {len(table)}" self.__check_results_column(table, 'alpha', 'alpha', None, np.float64) self.__check_results_column(table, 'delta', 'delta', None, np.float64) self.__check_results_column(table, 'source_id', 'source_id', None, object) self.__check_results_column(table, 'table1_oid', 'table1_oid', None, np.int32)
def test_query_region(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) # The query contains decimals: force default response connHandler.set_default_response(responseLaunchJob) sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree), frame='icrs') with pytest.raises(ValueError) as err: tap.query_region(sc) assert "Missing required argument: 'width'" in err.value.args[0] width = Quantity(12, u.deg) height = Quantity(10, u.deg) with pytest.raises(ValueError) as err: tap.query_region(sc, width=width) assert "Missing required argument: 'height'" in err.value.args[0] assert (isinstance(tap.query_region(sc, width=width, height=height), Table)) # Test observation_id argument with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, observation_id=1) assert "observation_id must be string" in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, observation_id="observation"), Table)) # raise ValueError # Test cal_level argument with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, cal_level='a') assert "cal_level must be either 'Top' or an integer" in err.value.args[ 0] assert (isinstance( tap.query_region(sc, width=width, height=height, cal_level='Top'), Table)) assert (isinstance( tap.query_region(sc, width=width, height=height, cal_level=1), Table)) # Test only_public with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, only_public='a') assert "only_public must be boolean" in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, only_public=True), Table)) # Test dataproduct_type argument with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, prod_type=1) assert "prod_type must be string" in err.value.args[0] with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, prod_type='a') assert "prod_type must be one of: " in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, prod_type='image'), Table)) # Test instrument_name argument with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, instrument_name=1) assert "instrument_name must be string" in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, instrument_name='NIRCAM'), Table)) with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, 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.query_region(sc, width=width, height=height, filter_name=1) assert "filter_name must be string" in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, filter_name='filter'), Table)) # Test proposal_id argument with pytest.raises(ValueError) as err: tap.query_region(sc, width=width, height=height, proposal_id=123) assert "proposal_id must be string" in err.value.args[0] assert (isinstance( tap.query_region(sc, width=width, height=height, proposal_id='123'), Table)) table = tap.query_region(sc, width=width, height=height) assert len( table ) == 3, f"Wrong job results (num rows). Expected: {3}, found {len(table)}" self.__check_results_column(table, 'alpha', 'alpha', None, np.float64) self.__check_results_column(table, 'delta', 'delta', None, np.float64) self.__check_results_column(table, 'source_id', 'source_id', None, object) self.__check_results_column(table, 'table1_oid', 'table1_oid', None, np.int32) # by radius radius = Quantity(1, u.deg) table = tap.query_region(sc, radius=radius) assert len( table ) == 3, f"Wrong job results (num rows). Expected: {3}, found {len(table)}" self.__check_results_column(table, 'alpha', 'alpha', None, np.float64) self.__check_results_column(table, 'delta', 'delta', None, np.float64) self.__check_results_column(table, 'source_id', 'source_id', None, object) self.__check_results_column(table, 'table1_oid', 'table1_oid', None, np.int32)