Esempio n. 1
0
 def test_cone_search_async(self):
     connHandler = DummyConnHandler()
     tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
     tap = GaiaClass(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)
     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_async(sc, radius)
     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)
 def test_cone_search_async(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)
     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_async(sc, radius)
     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)
Esempio n. 3
0
    def test_cone_search_async(self):
        conn_handler = DummyConnHandler()
        tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
        tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
        jobid = '12345'
        # Launch response
        response_launch_job = DummyResponse()
        response_launch_job.set_status_code(303)
        response_launch_job.set_message("OK")
        # list of list (httplib implementation for headers in response)
        launch_response_headers = [[
            'location', 'http://test:1111/tap/async/' + jobid
        ]]
        response_launch_job.set_data(method='POST',
                                     context=None,
                                     body=None,
                                     headers=launch_response_headers)
        ra = 19
        dec = 20
        sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
        radius = Quantity(1.0, u.deg)
        conn_handler.set_default_response(response_launch_job)
        # Phase response
        response_phase = DummyResponse()
        response_phase.set_status_code(200)
        response_phase.set_message("OK")
        response_phase.set_data(method='GET',
                                context=None,
                                body="COMPLETED",
                                headers=None)
        req = "async/" + jobid + "/phase"
        conn_handler.set_response(req, response_phase)
        # Results response
        response_results_job = DummyResponse()
        response_results_job.set_status_code(200)
        response_results_job.set_message("OK")
        job_data_file = data_path('job_1.vot')
        job_data = utils.read_file_content(job_data_file)
        response_results_job.set_data(method='GET',
                                      context=None,
                                      body=job_data,
                                      headers=None)
        req = "async/" + jobid + "/results/result"
        conn_handler.set_response(req, response_results_job)
        job = tap.cone_search_async(sc, radius)
        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,
                                    object)
        self.__check_results_column(results, 'table1_oid', 'table1_oid', None,
                                    np.int32)

        # Regression test for #2093 and #2099 - changing the MAIN_GAIA_TABLE
        # had no effect.
        # The preceding tests should have used the default value.
        assert 'gaiadr2.gaia_source' in job.parameters['query']
        # Test changing the table name through conf.
        conf.MAIN_GAIA_TABLE = 'name_from_conf'
        job = tap.cone_search_async(sc, radius)
        assert 'name_from_conf' in job.parameters['query']
        # Changing the value through the class should overrule conf.
        tap.MAIN_GAIA_TABLE = 'name_from_class'
        job = tap.cone_search_async(sc, radius)
        assert 'name_from_class' in job.parameters['query']
        # Cleanup.
        conf.reset('MAIN_GAIA_TABLE')