Skip to content

Commit a67b820

Browse files
committed
Merge pull request #441 from keflavich/alma/validator
Validate *values* of ALMA queries
2 parents 57700a2 + d7b04e4 commit a67b820

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

astroquery/alma/core.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,41 @@ def query_async(self, payload, cache=True, public=True, science=True):
128128
if science:
129129
payload['scan_intent-asu'] = '=*TARGET*'
130130

131-
self._validate_payload(payload)
131+
self.validate_query(payload)
132132

133133
response = self._request('GET', url, params=payload,
134134
timeout=self.TIMEOUT, cache=cache)
135135
response.raise_for_status()
136136

137137
return response
138+
139+
def validate_query(self, payload, cache=True):
140+
"""
141+
Use the ALMA query validator service to check whether the keywords are
142+
valid
143+
"""
144+
145+
# Check that the keywords specified are allowed
146+
self._validate_payload(payload)
147+
148+
vurl = self._get_dataarchive_url() + '/aq/validate'
149+
150+
bad_kws = {}
151+
152+
for kw in payload:
153+
vpayload = {'field':kw,
154+
kw: payload[kw]}
155+
response = self._request('GET', vurl, params=vpayload, cache=cache,
156+
timeout=self.TIMEOUT)
157+
158+
if response.content:
159+
bad_kws[kw] = response.content
160+
161+
if bad_kws:
162+
raise InvalidQueryError("Invalid query parameters: "
163+
"{0}".format(bad_kws))
164+
165+
138166

139167
def _get_dataarchive_url(self):
140168
"""

astroquery/alma/tests/data/empty.html

Whitespace-only changes.

astroquery/alma/tests/test_alma.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def data_path(filename):
1919
'http://almascience.eso.org/rh/submission/d45d0552-8479-4482-9833-fecdef3f8b90':
2020
'staging_submission.html',
2121
'http://almascience.eso.org/aq/':
22-
'querypage.html'
22+
'querypage.html',
23+
'http://almascience.eso.org/aq/validate':
24+
'empty.html'
2325
},
2426
'POST': {'http://almascience.eso.org/rh/submission':
2527
'initial_response.html'}

0 commit comments

Comments
 (0)