Ejemplo n.º 1
0
 def test_get_datalinks(self):
     dummy_handler = DummyTapHandler()
     tap = GaiaClass(dummy_handler,
                     dummy_handler,
                     show_server_messages=False)
     ids = ["1", "2", "3", "4"]
     verbose = True
     parameters = {}
     parameters['ids'] = ids
     parameters['verbose'] = verbose
     tap.get_datalinks(ids, verbose)
     dummy_handler.check_call('get_datalinks', parameters)
Ejemplo n.º 2
0
 def test_cone_search_sync(self):
     connHandler = DummyConnHandler()
     tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
     tap = GaiaClass(connHandler, tapplus)
     # 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', \
         "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)
Ejemplo n.º 3
0
 def test_list_async_jobs(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['verbose'] = False
     tap.list_async_jobs()
     dummyTapHandler.check_call('list_async_jobs', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters['verbose'] = True
     tap.list_async_jobs(verbose=True)
     dummyTapHandler.check_call('list_async_jobs', parameters)
Ejemplo n.º 4
0
 def test_cone_search_sync(self):
     connHandler = DummyConnHandler()
     tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
     tap = GaiaClass(tapplus)
     # 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', \
         "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)
Ejemplo n.º 5
0
 def test_load_table(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['table'] = 'table'
     parameters['verbose'] = False
     tap.load_table('table')
     dummyTapHandler.check_call('load_table', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters = {}
     parameters['table'] = 'table'
     parameters['verbose'] = True
     tap.load_table('table', verbose=True)
     dummyTapHandler.check_call('load_table', parameters)
Ejemplo n.º 6
0
 def test_launch_async_job(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     query = "query"
     # default parameters
     parameters = {}
     parameters['query'] = query
     parameters['name'] = None
     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
     tap.launch_job_async(query)
     dummyTapHandler.check_call('launch_job_async', parameters)
     # test with parameters
     dummyTapHandler.reset()
     name = 'name'
     output_file = 'output'
     output_format = 'format'
     verbose = True
     dump_to_file = True
     background = True
     upload_resource = 'upload_res'
     upload_table_name = 'upload_table'
     parameters['query'] = query
     parameters['name'] = name
     parameters['output_file'] = output_file
     parameters['output_format'] = output_format
     parameters['verbose'] = verbose
     parameters['dump_to_file'] = dump_to_file
     parameters['background'] = background
     parameters['upload_resource'] = upload_resource
     parameters['upload_table_name'] = upload_table_name
     tap.launch_job_async(query,
                          name=name,
                          output_file=output_file,
                          output_format=output_format,
                          verbose=verbose,
                          dump_to_file=dump_to_file,
                          background=background,
                          upload_resource=upload_resource,
                          upload_table_name=upload_table_name)
     dummyTapHandler.check_call('launch_job_async', parameters)
Ejemplo n.º 7
0
 def test_load_tables(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['only_names'] = False
     parameters['include_shared_tables'] = False
     parameters['verbose'] = False
     tap.load_tables()
     dummyTapHandler.check_call('load_tables', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters = {}
     parameters['only_names'] = True
     parameters['include_shared_tables'] = True
     parameters['verbose'] = True
     tap.load_tables(True, True, True)
     dummyTapHandler.check_call('load_tables', parameters)
    def test_query_object(self):
        connHandler = DummyConnHandler()
        tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
        tap = GaiaClass(connHandler, tapplus)
        # 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_object(sc)
        assert "Missing required argument: 'width'" in err.value.args[0]

        width = Quantity(12, u.deg)

        with pytest.raises(ValueError) as err:
            tap.query_object(sc, width=width)
        assert "Missing required argument: 'height'" in err.value.args[0]

        height = Quantity(10, u.deg)
        table = tap.query_object(sc, width=width, height=height)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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,
                                    np.object)
        self.__check_results_column(table, 'table1_oid', 'table1_oid', None,
                                    np.int32)
        # by radius
        radius = Quantity(1, u.deg)
        table = tap.query_object(sc, radius=radius)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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,
                                    np.object)
        self.__check_results_column(table, 'table1_oid', 'table1_oid', None,
                                    np.int32)
Ejemplo n.º 9
0
    def test_load_data(self):
        dummy_handler = DummyTapHandler()
        tap = GaiaClass(dummy_handler,
                        dummy_handler,
                        show_server_messages=False)

        ids = "1,2,3,4"
        retrieval_type = "epoch_photometry"
        valid_data = True
        band = None
        format = "votable"
        verbose = True
        data_structure = "INDIVIDUAL"
        output_file = os.path.abspath("output_file")
        path_to_end_with = os.path.join("gaia", "test", "output_file")
        if not output_file.endswith(path_to_end_with):
            output_file = os.path.abspath(path_to_end_with)

        params_dict = {}
        params_dict['VALID_DATA'] = "true"
        params_dict['ID'] = ids
        params_dict['FORMAT'] = str(format)
        params_dict['RETRIEVAL_TYPE'] = str(retrieval_type)
        params_dict['DATA_STRUCTURE'] = str(data_structure)
        params_dict['USE_ZIP_ALWAYS'] = 'true'

        tap.load_data(ids=ids,
                      retrieval_type=retrieval_type,
                      valid_data=valid_data,
                      band=band,
                      format=format,
                      verbose=verbose,
                      output_file=output_file)
        parameters = {}
        parameters['params_dict'] = params_dict
        # Output file name contains a timestamp: cannot be verified
        of = dummy_handler._DummyTapHandler__parameters['output_file']
        parameters['output_file'] = of
        parameters['verbose'] = verbose
        dummy_handler.check_call('load_data', parameters)
Ejemplo n.º 10
0
 def test_login_gui(self, mock_login_gui, mock_login):
     conn_handler = DummyConnHandler()
     tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
     tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
     tap.login_gui()
     assert (mock_login_gui.call_count == 1)
     mock_login_gui.side_effect = HTTPError("Login error")
     tap.login("user", "password")
     assert (mock_login.call_count == 1)
Ejemplo n.º 11
0
 def test_logout(self, mock_logout):
     conn_handler = DummyConnHandler()
     tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
     tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
     tap.logout()
     assert (mock_logout.call_count == 2)
     mock_logout.side_effect = HTTPError("Login error")
     tap.logout()
     assert (mock_logout.call_count == 3)
 def test_list_async_jobs(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['verbose'] = False
     tap.list_async_jobs()
     dummyTapHandler.check_call('list_async_jobs', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters['verbose'] = True
     tap.list_async_jobs(verbose=True)
     dummyTapHandler.check_call('list_async_jobs', parameters)
Ejemplo n.º 13
0
    def test_show_message(self):
        connHandler = DummyConnHandler()

        dummy_response = DummyResponse()
        dummy_response.set_status_code(200)
        dummy_response.set_message("OK")

        message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"

        dummy_response.set_data(method='GET',
                                context=None,
                                body=message_text,
                                headers=None)
        connHandler.set_default_response(dummy_response)

        # show_server_messages
        tableRequest = 'notification?action=GetNotifications'
        connHandler.set_response(tableRequest, dummy_response)

        tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
        tap = GaiaClass(connHandler, tapplus, show_server_messages=True)
 def test_load_table(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['table'] = 'table'
     parameters['verbose'] = False
     tap.load_table('table')
     dummyTapHandler.check_call('load_table', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters = {}
     parameters['table'] = 'table'
     parameters['verbose'] = True
     tap.load_table('table', verbose=True)
     dummyTapHandler.check_call('load_table', parameters)
 def test_launch_async_job(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     query = "query"
     # default parameters
     parameters = {}
     parameters['query'] = query
     parameters['name'] = None
     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
     tap.launch_job_async(query)
     dummyTapHandler.check_call('launch_job_async', parameters)
     # test with parameters
     dummyTapHandler.reset()
     name = 'name'
     output_file = 'output'
     output_format = 'format'
     verbose = True
     dump_to_file = True
     background = True
     upload_resource = 'upload_res'
     upload_table_name = 'upload_table'
     parameters['query'] = query
     parameters['name'] = name
     parameters['output_file'] = output_file
     parameters['output_format'] = output_format
     parameters['verbose'] = verbose
     parameters['dump_to_file'] = dump_to_file
     parameters['background'] = background
     parameters['upload_resource'] = upload_resource
     parameters['upload_table_name'] = upload_table_name
     tap.launch_job_async(query,
                          name=name,
                          output_file=output_file,
                          output_format=output_format,
                          verbose=verbose,
                          dump_to_file=dump_to_file,
                          background=background,
                          upload_resource=upload_resource,
                          upload_table_name=upload_table_name)
     dummyTapHandler.check_call('launch_job_async', parameters)
 def test_load_tables(self):
     dummyTapHandler = DummyTapHandler()
     tap = GaiaClass(dummyTapHandler)
     # default parameters
     parameters = {}
     parameters['only_names'] = False
     parameters['include_shared_tables'] = False
     parameters['verbose'] = False
     tap.load_tables()
     dummyTapHandler.check_call('load_tables', parameters)
     # test with parameters
     dummyTapHandler.reset()
     parameters = {}
     parameters['only_names'] = True
     parameters['include_shared_tables'] = True
     parameters['verbose'] = True
     tap.load_tables(True, True, True)
     dummyTapHandler.check_call('load_tables', parameters)
    def test_load_data(self):
        dummyHandler = DummyTapHandler()
        tap = GaiaClass(dummyHandler, dummyHandler)

        ids = "1,2,3,4"
        retrieval_type = "epoch_photometry"
        valid_data = True
        band = None
        format = "votable"
        verbose = True

        params_dict = {}
        params_dict['VALID_DATA'] = "true"
        params_dict['ID'] = ids
        params_dict['FORMAT'] = str(format)
        params_dict['RETRIEVAL_TYPE'] = str(retrieval_type)

        tap.load_data(ids=ids,
                      retrieval_type=retrieval_type,
                      valid_data=valid_data,
                      band=band,
                      format=format,
                      verbose=verbose)
        parameters = {}
        parameters['params_dict'] = params_dict
        parameters['output_file'] = None
        parameters['verbose'] = verbose

        dummyHandler.check_call('load_data', parameters)
        tap.load_data(ids=ids,
                      retrieval_type=retrieval_type,
                      valid_data=valid_data,
                      band=band,
                      format=format,
                      verbose=verbose)
        dummyHandler.check_call('load_data', parameters)
    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_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)
Ejemplo n.º 20
0
    def test_query_object(self):
        conn_handler = DummyConnHandler()
        # Launch response: we use default response because the query contains
        # decimals
        dummy_response = DummyResponse()
        dummy_response.set_status_code(200)
        dummy_response.set_message("OK")

        message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"

        dummy_response.set_data(method='GET',
                                context=None,
                                body=message_text,
                                headers=None)
        conn_handler.set_default_response(dummy_response)

        # show_server_messages
        tableRequest = 'notification?action=GetNotifications'
        conn_handler.set_response(tableRequest, dummy_response)

        tapplus = TapPlus("http://test:1111/tap", connhandler=conn_handler)
        tap = GaiaClass(conn_handler, tapplus, show_server_messages=True)
        # Launch response: we use default response because the query contains
        # decimals
        response_launch_job = DummyResponse()
        response_launch_job.set_status_code(200)
        response_launch_job.set_message("OK")
        job_data_file = data_path('job_1.vot')
        job_data = utils.read_file_content(job_data_file)
        response_launch_job.set_data(method='POST',
                                     context=None,
                                     body=job_data,
                                     headers=None)
        # The query contains decimals: force default response
        conn_handler.set_default_response(response_launch_job)
        sc = SkyCoord(ra=29.0,
                      dec=15.0,
                      unit=(u.degree, u.degree),
                      frame='icrs')
        with pytest.raises(ValueError) as err:
            tap.query_object(sc)
        assert "Missing required argument: width" in err.value.args[0]

        width = Quantity(12, u.deg)

        with pytest.raises(ValueError) as err:
            tap.query_object(sc, width=width)
        assert "Missing required argument: height" in err.value.args[0]

        height = Quantity(10, u.deg)
        table = tap.query_object(sc, width=width, height=height)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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_object(sc, radius=radius)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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)
Ejemplo n.º 21
0
    def test_query_object(self):
        connHandler = DummyConnHandler()
        tapplus = TapPlus("http://test:1111/tap", connhandler=connHandler)
        tap = GaiaClass(tapplus)
        # 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_object(sc)
        assert "Missing required argument: 'width'" in err.value.args[0]

        width = Quantity(12, u.deg)

        with pytest.raises(ValueError) as err:
            tap.query_object(sc, width=width)
        assert "Missing required argument: 'height'" in err.value.args[0]

        height = Quantity(10, u.deg)
        table = tap.query_object(sc, width=width, height=height)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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,
                                    np.object)
        self.__check_results_column(table,
                                    'table1_oid',
                                    'table1_oid',
                                    None,
                                    np.int32)
        # by radius
        radius = Quantity(1, u.deg)
        table = tap.query_object(sc, radius=radius)
        assert len(table) == 3, \
            "Wrong job results (num rows). Expected: %d, found %d" % \
            (3, 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,
                                    np.object)
        self.__check_results_column(table,
                                    'table1_oid',
                                    'table1_oid',
                                    None,
                                    np.int32)
Ejemplo n.º 22
0
 def test_query_object_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)
     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_object_async(sc, width=width, height=height)
     assert len(table) == 3, \
         "Wrong job results (num rows). Expected: %d, found %d" % \
         (3, 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,
                                 np.object)
     self.__check_results_column(table,
                                 'table1_oid',
                                 'table1_oid',
                                 None,
                                 np.int32)
     # by radius
     radius = Quantity(1, u.deg)
     table = tap.query_object_async(sc, radius=radius)
     assert len(table) == 3, \
         "Wrong job results (num rows). Expected: %d, found %d" % \
         (3, 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,
                                 np.object)
     self.__check_results_column(table,
                                 'table1_oid',
                                 'table1_oid',
                                 None,
                                 np.int32)
Ejemplo n.º 23
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')
 def test_query_object_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)
     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_object_async(sc, width=width, height=height)
     assert len(table) == 3, \
         "Wrong job results (num rows). Expected: %d, found %d" % \
         (3, 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,
                                 np.object)
     self.__check_results_column(table, 'table1_oid', 'table1_oid', None,
                                 np.int32)
     # by radius
     radius = Quantity(1, u.deg)
     table = tap.query_object_async(sc, radius=radius)
     assert len(table) == 3, \
         "Wrong job results (num rows). Expected: %d, found %d" % \
         (3, 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,
                                 np.object)
     self.__check_results_column(table, 'table1_oid', 'table1_oid', None,
                                 np.int32)
Ejemplo n.º 25
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)