Skip to content

Commit 883bd60

Browse files
Adrian Damianbsipocz
authored andcommitted
Bumped coverage
1 parent 905c557 commit 883bd60

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

astroquery/alma/core.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -708,21 +708,21 @@ def download_files(self, files, savedir=None, cache=True,
708708
downloaded_files = []
709709
if savedir is None:
710710
savedir = self.cache_location
711-
for fileLink in unique(files):
712-
log.debug("Downloading {0} to {1}".format(fileLink, savedir))
711+
for file_link in unique(files):
712+
log.debug("Downloading {0} to {1}".format(file_link, savedir))
713713
try:
714-
check_filename = self._request('HEAD', fileLink, auth=auth)
714+
check_filename = self._request('HEAD', file_link, auth=auth)
715715
check_filename.raise_for_status()
716716
except requests.HTTPError as ex:
717717
if ex.response.status_code == 401:
718718
if skip_unauthorized:
719719
log.info("Access denied to {url}. Skipping to"
720-
" next file".format(url=fileLink))
720+
" next file".format(url=file_link))
721721
continue
722722
else:
723723
raise(ex)
724724

725-
if 'text/html' in check_filename.headers['Content-Type']:
725+
if 'text/html' in check_filename.headers.get('Content-Type', ''):
726726
raise ValueError("Bad query. This can happen if you "
727727
"attempt to download proprietary "
728728
"data when not logged in")
@@ -731,7 +731,7 @@ def download_files(self, files, savedir=None, cache=True,
731731
filename = re.search("filename=(.*)",
732732
check_filename.headers['Content-Disposition']).groups()[0]
733733
except KeyError:
734-
log.info(f"Unable to find filename for {fileLink} "
734+
log.info(f"Unable to find filename for {file_link} "
735735
"(missing Content-Disposition in header). "
736736
"Skipping to next file.")
737737
continue
@@ -741,7 +741,7 @@ def download_files(self, files, savedir=None, cache=True,
741741
filename)
742742

743743
try:
744-
self._download_file(fileLink,
744+
self._download_file(file_link,
745745
filename,
746746
timeout=self.TIMEOUT,
747747
auth=auth,
@@ -755,22 +755,22 @@ def download_files(self, files, savedir=None, cache=True,
755755
if ex.response.status_code == 401:
756756
if skip_unauthorized:
757757
log.info("Access denied to {url}. Skipping to"
758-
" next file".format(url=fileLink))
758+
" next file".format(url=file_link))
759759
continue
760760
else:
761761
raise(ex)
762762
elif ex.response.status_code == 403:
763-
log.error("Access denied to {url}".format(url=fileLink))
764-
if 'dataPortal' in fileLink and 'sso' not in fileLink:
763+
log.error("Access denied to {url}".format(url=file_link))
764+
if 'dataPortal' in file_link and 'sso' not in file_link:
765765
log.error("The URL may be incorrect. Try using "
766766
"{0} instead of {1}"
767-
.format(fileLink.replace('dataPortal/',
768-
'dataPortal/sso/'),
769-
fileLink))
767+
.format(file_link.replace('dataPortal/',
768+
'dataPortal/sso/'),
769+
file_link))
770770
raise ex
771771
elif ex.response.status_code == 500:
772772
# empirically, this works the second time most of the time...
773-
self._download_file(fileLink,
773+
self._download_file(file_link,
774774
filename,
775775
timeout=self.TIMEOUT,
776776
auth=auth,

astroquery/alma/tests/test_alma.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,3 +410,20 @@ def test_galactic_query():
410410
radius=1*u.deg, get_query_payload=True)
411411

412412
assert result['ra_dec'] == SkyCoord(0*u.deg, 0*u.deg, frame='galactic').icrs.to_string() + ", 1.0"
413+
414+
415+
def test_download_files():
416+
def _requests_mock(method, url, **kwargs):
417+
response = Mock()
418+
response.headers = {
419+
'Content-Disposition': 'attachment; '
420+
'filename="{}"'.format(url.split('/')[-1])}
421+
return response
422+
423+
def _download_file_mock(url, file_name, **kwargs):
424+
return file_name
425+
alma = Alma()
426+
alma._request = Mock(side_effect=_requests_mock)
427+
alma._download_file = Mock(side_effect=_download_file_mock)
428+
downloaded_files = alma.download_files(['https://location/file1'])
429+
assert len(downloaded_files) == 1

astroquery/alma/tests/test_alma_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def test_download_and_extract(self, temp_dir, alma):
312312
aux_tar_file = [x for x in data_info['access_url'] if 'auxiliary' in x]
313313
assert 1 == len(aux_tar_file)
314314
download_mock = MagicMock()
315-
# following line require to make alma picklable
315+
# following line is required to make alma picklable
316316
download_mock.__reduce__ = lambda self: (MagicMock, ())
317317
alma._download_file = download_mock
318318

0 commit comments

Comments
 (0)