|
1 | 1 | # Licensed under a 3-clause BSD style license - see LICENSE.rst
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from pathlib import Path
|
4 | 5 | import numpy as np
|
5 | 6 | import os
|
@@ -769,6 +770,23 @@ def test_observations_download_file_escaped(self, tmp_path):
|
769 | 770 | f = fits.open(Path(tmp_path, filename))
|
770 | 771 | f.close()
|
771 | 772 |
|
| 773 | + def test_observations_download_file_no_length(self, tmp_path, caplog): |
| 774 | + # test that `download_file` correctly handles the case where the server |
| 775 | + # does not return a Content-Length header for a cached file |
| 776 | + # initial download |
| 777 | + in_uri = "mast:HLA/url/cgi-bin/getdata.cgi?filename=hst_05206_01_wfpc2_f375n_wf_daophot_trm.cat" |
| 778 | + filename = Path(in_uri).name |
| 779 | + result = Observations.download_file(uri=in_uri, local_path=tmp_path) |
| 780 | + assert result == ("COMPLETE", None, None) |
| 781 | + assert Path(tmp_path, filename).exists() |
| 782 | + |
| 783 | + # download again, should warn and re-download file |
| 784 | + with caplog.at_level(logging.WARNING): |
| 785 | + result = Observations.download_file(uri=in_uri, local_path=tmp_path) |
| 786 | + assert "Could not verify length of cached file" in caplog.text |
| 787 | + assert result == ("COMPLETE", None, None) |
| 788 | + assert Path(tmp_path, filename).exists() |
| 789 | + |
772 | 790 | @pytest.mark.parametrize("test_data_uri, expected_cloud_uri", [
|
773 | 791 | ("mast:HST/product/u24r0102t_c1f.fits",
|
774 | 792 | "s3://stpubdata/hst/public/u24r/u24r0102t/u24r0102t_c1f.fits"),
|
|
0 commit comments