Skip to content

Commit 4ffc5f1

Browse files
committed
BUGFIX: ALMA private queries, plus checking that queries succeed
(1) When running `save=True` in GET requests, there was no check that the request was sucessful - this is fixed. (2) ALMA queries require passing the username, not the previously-hard-coded "anonymous", when performing queries & logged in. So far, there is no way to test for this!
1 parent 0f55d01 commit 4ffc5f1

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

astroquery/alma/core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,15 @@ def stage_data(self, uids):
293293
summary.raise_for_status()
294294
self._staging_log['json_data'] = json_data = summary.json()
295295

296+
username = self._username if hasattr(self, '_username') else 'anonymous'
297+
296298
url_decomposed = urlparse(data_page_url)
297299
base_url = ('{uri.scheme}://{uri.netloc}/'
298-
'dataPortal/requests/anonymous/'
300+
'dataPortal/requests/{username}/'
299301
'{staging_page_id}/ALMA'.format(uri=url_decomposed,
300-
staging_page_id=dpid))
302+
staging_page_id=dpid,
303+
username=username,
304+
))
301305
tbl = self._json_summary_to_table(json_data, base_url=base_url)
302306

303307
# staging_root = BeautifulSoup(data_page.content)
@@ -444,6 +448,7 @@ def _login(self, username, store_password=False):
444448

445449
if authenticated:
446450
log.info("Authentication successful!")
451+
self._username = username
447452
else:
448453
log.exception("Authentication failed!")
449454
# When authenticated, save password in keyring if needed

astroquery/alma/tests/test_alma_remote.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def test_stage_data(self, temp_dir):
7070
assert b'2011.0.00217.S' in result_s['Project code']
7171
uid = result_s['Asdm uid'][0]
7272

73-
alma.stage_data([uid])
73+
result = alma.stage_data([uid])
74+
75+
assert os.path.split(result['URL'][0]) == 'uid___A002_X47ed8e_X6c.asdm.sdm.tar'
7476

7577
def test_doc_example(self, temp_dir):
7678
alma = Alma()

astroquery/query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None):
180180
the local ``_session``
181181
"""
182182
response = self._session.get(url, timeout=timeout, stream=True,
183-
auth=auth)
183+
auth=auth)
184+
response.raise_for_status()
184185
if 'content-length' in response.headers:
185186
length = int(response.headers['content-length'])
186187
else:

0 commit comments

Comments
 (0)