Пример #1
0
 def test_logout(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     parameters = {}
     parameters['verbose'] = False
     tap.logout()
     dummyTapHandler.check_call('logout', parameters)
Пример #2
0
    def test_get_product_by_filename(self):
        dummyTapHandler = DummyTapHandler()
        jwst = JwstClass(tap_plus_handler=dummyTapHandler,
                         data_handler=dummyTapHandler,
                         show_messages=False)
        # default parameters
        with pytest.raises(ValueError) as err:
            jwst.get_product()
        assert "Missing required argument: 'artifact_id' or 'file_name'" in err.value.args[
            0]

        # test with parameters
        dummyTapHandler.reset()

        parameters = {}
        parameters['output_file'] = 'file_name_id'
        parameters['verbose'] = False

        param_dict = {}
        param_dict['RETRIEVAL_TYPE'] = 'PRODUCT'
        param_dict['DATA_RETRIEVAL_ORIGIN'] = 'ASTROQUERY'
        param_dict['ARTIFACTID'] = '00000000-0000-0000-8740-65e2827c9895'
        parameters['params_dict'] = param_dict

        jwst.get_product(file_name='file_name_id')
        dummyTapHandler.check_call('load_data', parameters)
Пример #3
0
 def test_remove_jobs(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     job_list = ['dummyJob']
     parameters = {}
     parameters['jobs_list'] = job_list
     parameters['verbose'] = False
     tap.remove_jobs(job_list)
     dummyTapHandler.check_call('remove_jobs', parameters)
Пример #4
0
 def test_save_results(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     job = 'dummyJob'
     parameters = {}
     parameters['job'] = job
     parameters['verbose'] = False
     tap.save_results(job)
     dummyTapHandler.check_call('save_results', parameters)
Пример #5
0
 def test_login(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     parameters = {}
     parameters['user'] = '******'
     parameters['password'] = '******'
     parameters['credentials_file'] = None
     parameters['verbose'] = False
     tap.login(user='******', password='******')
     dummyTapHandler.check_call('login', parameters)
Пример #6
0
 def test_list_async_jobs(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     # 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)
Пример #7
0
 def test_load_table(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     # 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)
Пример #8
0
 def test_get_related_observations(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     obs = 'dummyObs'
     tap.get_related_observations(observation_id=obs)
     parameters = {}
     parameters[
         'query'] = f"select * from jwst.main m where m.members like '%{obs}%'"
     parameters['name'] = None
     parameters['output_file'] = None
     parameters['output_format'] = 'votable'
     parameters['verbose'] = False
     parameters['dump_to_file'] = False
     parameters['upload_resource'] = None
     parameters['upload_table_name'] = None
     dummyTapHandler.check_call('launch_job', parameters)
Пример #9
0
 def test_launch_async_job(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     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(query, async_job=True)
     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(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,
                    async_job=True)
     dummyTapHandler.check_call('launch_job_async', parameters)
Пример #10
0
 def test_load_tables(self):
     dummyTapHandler = DummyTapHandler()
     tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     # 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(only_names=True,
                     include_shared_tables=True,
                     verbose=True)
     dummyTapHandler.check_call('load_tables', parameters)
Пример #11
0
 def test_get_product(self):
     dummyTapHandler = DummyTapHandler()
     jwst = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
     # default parameters
     parameters = {}
     parameters['artifact_id'] = None
     with pytest.raises(ValueError) as err:
         jwst.get_product()
     assert "Missing required argument: 'artifact_id'" in err.value.args[0]
     # test with parameters
     dummyTapHandler.reset()
     parameters = {}
     params_dict = {}
     params_dict['RETRIEVAL_TYPE'] = 'PRODUCT'
     params_dict['DATA_RETRIEVAL_ORIGIN'] = 'ASTROQUERY'
     params_dict['ARTIFACTID'] = '00000000-0000-0000-8740-65e2827c9895'
     parameters['params_dict'] = params_dict
     parameters[
         'output_file'] = 'jw00617023001_02102_00001_nrcb4_uncal.fits'
     parameters['verbose'] = False
     jwst.get_product(artifact_id='00000000-0000-0000-8740-65e2827c9895')
     dummyTapHandler.check_call('load_data', parameters)
Пример #12
0
    def test_query_get_product(self):
        dummyTapHandler = DummyTapHandler()
        tap = JwstClass(tap_plus_handler=dummyTapHandler, show_messages=False)
        file = 'test_file'
        parameters = {}
        parameters[
            'query'] = f"select * from jwst.artifact a where a.filename = '{file}'"
        parameters['name'] = None
        parameters['output_file'] = None
        parameters['output_format'] = 'votable'
        parameters['verbose'] = False
        parameters['dump_to_file'] = False
        parameters['upload_resource'] = None
        parameters['upload_table_name'] = None
        tap._query_get_product(file_name=file)
        dummyTapHandler.check_call('launch_job', parameters)

        artifact = 'test_artifact'
        parameters[
            'query'] = f"select * from jwst.artifact a where a.artifactid = '{artifact}'"
        tap._query_get_product(artifact_id=artifact)
        dummyTapHandler.check_call('launch_job', parameters)
Пример #13
0
    def test_get_products_list(self):
        dummyTapHandler = DummyTapHandler()
        jwst = JwstClass(tap_plus_handler=dummyTapHandler,
                         data_handler=dummyTapHandler,
                         show_messages=False)
        # default parameters
        with pytest.raises(ValueError) as err:
            jwst.get_product_list()
        assert "Missing required argument: 'observation_id'" in err.value.args[
            0]

        # test with parameters
        dummyTapHandler.reset()

        observation_id = "jw00777011001_02104_00001_nrcblong"
        cal_level_condition = " AND m.calibrationlevel = m.max_cal_level"
        prodtype_condition = ""

        query = (
            f"select distinct a.uri, a.artifactid, a.filename, "
            f"a.contenttype, a.producttype, p.calibrationlevel, p.public "
            f"FROM {conf.JWST_PLANE_TABLE} p JOIN {conf.JWST_ARTIFACT_TABLE} "
            f"a ON (p.planeid=a.planeid) WHERE a.planeid "
            f"IN {planeids};")

        parameters = {}
        parameters['query'] = query
        parameters['name'] = None
        parameters['output_file'] = None
        parameters['output_format'] = 'votable'
        parameters['verbose'] = False
        parameters['dump_to_file'] = False
        parameters['upload_resource'] = None
        parameters['upload_table_name'] = None

        jwst.get_product_list(observation_id=observation_id)
        dummyTapHandler.check_call('launch_job', parameters)
Пример #14
0
    def test_get_obs_products(self):
        dummyTapHandler = DummyTapHandler()
        jwst = JwstClass(tap_plus_handler=dummyTapHandler,
                         data_handler=dummyTapHandler,
                         show_messages=False)
        # default parameters
        with pytest.raises(ValueError) as err:
            jwst.get_obs_products()
        assert "Missing required argument: 'observation_id'" in err.value.args[
            0]

        # test with parameters
        dummyTapHandler.reset()

        output_file_full_path_dir = os.getcwd(
        ) + os.sep + "temp_test_jwsttap_get_obs_products_1"
        try:
            os.makedirs(output_file_full_path_dir, exist_ok=True)
        except OSError as err:
            print(
                f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}"
            )
            raise err

        observation_id = 'jw00777011001_02104_00001_nrcblong'

        parameters = {}
        parameters['verbose'] = False

        param_dict = {}
        param_dict['RETRIEVAL_TYPE'] = 'OBSERVATION'
        param_dict['DATA_RETRIEVAL_ORIGIN'] = 'ASTROQUERY'
        param_dict['planeid'] = planeids
        param_dict['calibrationlevel'] = 'ALL'
        parameters['params_dict'] = param_dict

        # Test single product tar
        file = data_path('single_product_retrieval.tar')
        output_file_full_path = output_file_full_path_dir + os.sep + os.path.basename(
            file)
        shutil.copy(file, output_file_full_path)
        parameters['output_file'] = output_file_full_path

        expected_files = []
        extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval_1.fits'
        expected_files.append(extracted_file_1)
        try:
            files_returned = (jwst.get_obs_products(
                observation_id=observation_id,
                cal_level='ALL',
                output_file=output_file_full_path))
            dummyTapHandler.check_call('load_data', parameters)
            self.__check_extracted_files(files_expected=expected_files,
                                         files_returned=files_returned)
        finally:
            shutil.rmtree(output_file_full_path_dir)

        # Test single file
        output_file_full_path_dir = os.getcwd() + os.sep +\
            "temp_test_jwsttap_get_obs_products_2"
        try:
            os.makedirs(output_file_full_path_dir, exist_ok=True)
        except OSError as err:
            print(
                f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}"
            )
            raise err

        file = data_path('single_product_retrieval_1.fits')
        output_file_full_path = output_file_full_path_dir + os.sep +\
            os.path.basename(file)
        shutil.copy(file, output_file_full_path)

        parameters['output_file'] = output_file_full_path

        expected_files = []
        expected_files.append(output_file_full_path)

        try:
            files_returned = (jwst.get_obs_products(
                observation_id=observation_id,
                output_file=output_file_full_path))
            dummyTapHandler.check_call('load_data', parameters)
            self.__check_extracted_files(files_expected=expected_files,
                                         files_returned=files_returned)
        finally:
            # self.__remove_folder_contents(folder=output_file_full_path_dir)
            shutil.rmtree(output_file_full_path_dir)

        # Test single file zip
        output_file_full_path_dir = os.getcwd(
        ) + os.sep + "temp_test_jwsttap_get_obs_products_3"
        try:
            os.makedirs(output_file_full_path_dir, exist_ok=True)
        except OSError as err:
            print(
                f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}"
            )
            raise err

        file = data_path('single_product_retrieval_3.fits.zip')
        output_file_full_path = output_file_full_path_dir + os.sep +\
            os.path.basename(file)
        shutil.copy(file, output_file_full_path)

        parameters['output_file'] = output_file_full_path

        expected_files = []
        extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval.fits'
        expected_files.append(extracted_file_1)

        try:
            files_returned = (jwst.get_obs_products(
                observation_id=observation_id,
                output_file=output_file_full_path))
            dummyTapHandler.check_call('load_data', parameters)
            self.__check_extracted_files(files_expected=expected_files,
                                         files_returned=files_returned)
        finally:
            # self.__remove_folder_contents(folder=output_file_full_path_dir)
            shutil.rmtree(output_file_full_path_dir)

        # Test single file gzip
        output_file_full_path_dir = (os.getcwd() + os.sep +
                                     "temp_test_jwsttap_get_obs_products_4")
        try:
            os.makedirs(output_file_full_path_dir, exist_ok=True)
        except OSError as err:
            print(
                f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}"
            )
            raise err

        file = data_path('single_product_retrieval_2.fits.gz')
        output_file_full_path = output_file_full_path_dir + os.sep + os.path.basename(
            file)
        shutil.copy(file, output_file_full_path)

        parameters['output_file'] = output_file_full_path

        expected_files = []
        extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval_2.fits.gz'
        expected_files.append(extracted_file_1)

        try:
            files_returned = (jwst.get_obs_products(
                observation_id=observation_id,
                output_file=output_file_full_path))
            dummyTapHandler.check_call('load_data', parameters)
            self.__check_extracted_files(files_expected=expected_files,
                                         files_returned=files_returned)
        finally:
            # self.__remove_folder_contents(folder=output_file_full_path_dir)
            shutil.rmtree(output_file_full_path_dir)

        # Test tar with 3 files, a normal one, a gzip one and a zip one
        output_file_full_path_dir = (os.getcwd() + os.sep +
                                     "temp_test_jwsttap_get_obs_products_5")
        try:
            os.makedirs(output_file_full_path_dir, exist_ok=True)
        except OSError as err:
            print(
                f"Creation of the directory {output_file_full_path_dir} failed: {err.strerror}"
            )
            raise err

        file = data_path('three_products_retrieval.tar')
        output_file_full_path = output_file_full_path_dir + os.sep + os.path.basename(
            file)
        shutil.copy(file, output_file_full_path)

        parameters['output_file'] = output_file_full_path

        expected_files = []
        extracted_file_1 = output_file_full_path_dir + os.sep + 'single_product_retrieval_1.fits'
        expected_files.append(extracted_file_1)
        extracted_file_2 = output_file_full_path_dir + os.sep + 'single_product_retrieval_2.fits.gz'
        expected_files.append(extracted_file_2)
        extracted_file_3 = output_file_full_path_dir + os.sep + 'single_product_retrieval_3.fits.zip'
        expected_files.append(extracted_file_3)

        try:
            files_returned = (jwst.get_obs_products(
                observation_id=observation_id,
                output_file=output_file_full_path))
            dummyTapHandler.check_call('load_data', parameters)
            self.__check_extracted_files(files_expected=expected_files,
                                         files_returned=files_returned)
        finally:
            # self.__remove_folder_contents(folder=output_file_full_path_dir)
            shutil.rmtree(output_file_full_path_dir)