Skip to content

Commit

Permalink
Merge pull request #3069 from snbianco/ASB-28015-cloud-error-msg
Browse files Browse the repository at this point in the history
Bugfix in get_cloud_uri_list, added test case
  • Loading branch information
bsipocz authored Jul 17, 2024
2 parents 08ff1b8 + d10a28c commit 2a27dff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion astroquery/mast/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ def get_cloud_uri_list(self, data_products, include_bucket=True, full_url=False)
elif full_url:
path = "http://s3.amazonaws.com/{}/{}".format(self.pubdata_bucket, path)
uri_list.append(path)
else:
uri_list.append(path)
except self.botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] != "404":
raise
Expand Down Expand Up @@ -192,7 +194,7 @@ def download_file(self, data_product, local_path, cache=True, verbose=True):
warnings.simplefilter("ignore")
bucket_path = self.get_cloud_uri(data_product, False)
if not bucket_path:
raise Exception("Unable to locate file {}.".format(data_product['productFilename']))
raise Exception("Unable to locate file {}.".format(data_product['dataURI']))

# Ask the webserver (in this case S3) what the expected content length is and use that.
info_lookup = s3_client.head_object(Bucket=self.pubdata_bucket, Key=bucket_path)
Expand Down
14 changes: 14 additions & 0 deletions astroquery/mast/tests/test_mast_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,20 @@ def check_result(result, path):
result = Observations.download_file(uri, local_path=local_path_file)
check_result(result, local_path_file)

@pytest.mark.parametrize("in_uri", [
'mast:HLA/url/cgi-bin/getdata.cgi?download=1&filename=hst_05206_01_wfpc2_f375n_wf_daophot_trm.cat',
'mast:HST/product/u24r0102t_c3m.fits'
])
def test_observations_download_file_cloud(self, tmp_path, in_uri):
pytest.importorskip("boto3")

Observations.enable_cloud_dataset()

filename = Path(in_uri).name
result = Observations.download_file(uri=in_uri, cloud_only=True, local_path=tmp_path)
assert result == ('COMPLETE', None, None)
assert Path(tmp_path, filename).exists()

@pytest.mark.parametrize("test_data_uri, expected_cloud_uri", [
("mast:HST/product/u24r0102t_c1f.fits",
"s3://stpubdata/hst/public/u24r/u24r0102t/u24r0102t_c1f.fits"),
Expand Down

0 comments on commit 2a27dff

Please sign in to comment.