diff --git a/astroquery/mast/observations.py b/astroquery/mast/observations.py index 433f4cba94..8ff1b0ba9e 100644 --- a/astroquery/mast/observations.py +++ b/astroquery/mast/observations.py @@ -753,7 +753,8 @@ def get_cloud_uris(self, data_products, include_bucket=True, full_url=False): """ if self._cloud_connection is None: - raise AttributeError("Must enable s3 dataset before attempting to query the s3 information") + raise RemoteServiceError('Please enable anonymous cloud access by calling `enable_cloud_dataset` method. ' + 'See MAST Labs documentation for an example: https://mast-labs.stsci.io/#example-data-access-with-astroquery-observations') return self._cloud_connection.get_cloud_uri_list(data_products, include_bucket, full_url) @@ -784,8 +785,10 @@ def get_cloud_uri(self, data_product, include_bucket=True, full_url=False): """ if self._cloud_connection is None: - raise AttributeError("Must enable s3 dataset before attempting to query the s3 information") + raise RemoteServiceError('Please enable anonymous cloud access by calling `enable_cloud_dataset` method. ' + 'See MAST Labs documentation for an example: https://mast-labs.stsci.io/#example-data-access-with-astroquery-observations') + # Query for product URIs return self._cloud_connection.get_cloud_uri(data_product, include_bucket, full_url) diff --git a/astroquery/mast/tests/test_mast_remote.py b/astroquery/mast/tests/test_mast_remote.py index ca98a31cdc..f23de11c98 100644 --- a/astroquery/mast/tests/test_mast_remote.py +++ b/astroquery/mast/tests/test_mast_remote.py @@ -294,6 +294,38 @@ def test_observations_download_file(self, tmpdir): result = mast.Observations.download_file(uri) assert result == ('COMPLETE', None, None) + def test_get_cloud_uri(self): + test_obs_id = '25568122' + + # get a product list + product = mast.Observations.get_product_list(test_obs_id)[24] + + assert len(product) > 0, f'No product found for OBSID {test_obs_id}. Unable to move forward with getting URIs from the cloud.' + + # enable access to public AWS S3 bucket + mast.Observations.enable_cloud_dataset() + + # get uri + uri = mast.Observations.get_cloud_uri(product) + + assert len(uri) > 0, f'Product for OBSID {test_obs_id} was not found in the cloud.' + + def test_get_cloud_uris(self): + test_obs_id = '25568122' + + # get a product list + products = mast.Observations.get_product_list(test_obs_id)[24:] + + assert len(products) > 0, f'No products found for OBSID {test_obs_id}. Unable to move forward with getting URIs from the cloud.' + + # enable access to public AWS S3 bucket + mast.Observations.enable_cloud_dataset() + + # get uris + uris = mast.Observations.get_cloud_uris(products) + + assert len(uris) > 0, f'Products for OBSID {test_obs_id} were not found in the cloud.' + ###################### # CatalogClass tests # ######################