Skip to content

Commit 89d6793

Browse files
committed
test case, refactor _parse_result function
Uncomment lines
1 parent e2ad9c8 commit 89d6793

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

astroquery/mast/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Conf(_config.ConfigNamespace):
1515
"""
1616

1717
server = _config.ConfigItem(
18-
'https://masttest.stsci.edu',
18+
'https://mast.stsci.edu',
1919
'Name of the MAST server.')
2020
ssoserver = _config.ConfigItem(
2121
'https://ssoportal.stsci.edu',

astroquery/mast/missions.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,37 @@ def mission(self, value):
8181
self._mission = value.lower() # case-insensitive
8282
self._service_api_connection.set_service_params(self.service_dict, f'search/{self.mission}')
8383

84+
def _extract_products(self, response):
85+
"""
86+
Extract products from the response of a `~requests.Response` object.
87+
88+
Parameters
89+
----------
90+
response : `~requests.Response`
91+
The response object containing the products data.
92+
93+
Returns
94+
-------
95+
list
96+
A list of products extracted from the response.
97+
"""
98+
def normalize_products(products):
99+
"""
100+
Normalize the products list to ensure it is flat and not nested.
101+
"""
102+
if products and isinstance(products[0], list):
103+
return products[0]
104+
return products
105+
106+
if isinstance(response, list): # multiple async responses from batching
107+
combined = []
108+
for resp in response:
109+
products = normalize_products(resp.json().get('products', []))
110+
combined.extend(products)
111+
return combined
112+
else: # single response
113+
return normalize_products(response.json().get('products', []))
114+
84115
def _parse_result(self, response, *, verbose=False): # Used by the async_to_sync decorator functionality
85116
"""
86117
Parse the results of a `~requests.Response` objects and return an `~astropy.table.Table` of results.
@@ -106,23 +137,11 @@ def _parse_result(self, response, *, verbose=False): # Used by the async_to_syn
106137
if len(results) >= self.limit:
107138
warnings.warn("Maximum results returned, may not include all sources within radius.",
108139
MaxResultsWarning)
109-
elif self.service == self._list_products:
110-
# Results from post_list_products endpoint need to be handled differently
111-
if isinstance(response, list): # multiple async responses from batching
112-
combined_products = []
113-
for resp in response:
114-
if self.mission == 'roman':
115-
combined_products.extend(resp.json().get('products', [])[0])
116-
else:
117-
combined_products.extend(resp.json().get('products', []))
118-
return Table(combined_products)
119-
120-
if self.mission == 'roman':
121-
results = Table(response.json()['products'][0]) # single async response
122-
else:
123-
results = Table(response.json()['products'])
140+
return results
124141

125-
return results
142+
elif self.service == self._list_products:
143+
products = self._extract_products(response)
144+
return Table(products)
126145

127146
def _validate_criteria(self, **criteria):
128147
"""
@@ -544,7 +563,7 @@ def download_file(self, uri, *, local_path=None, cache=True, verbose=True):
544563

545564
# Construct the full data URL based on mission
546565
if self.mission in ['hst', 'jwst', 'roman']:
547-
# HST and JWST have a dedicated endpoint for retrieving products
566+
# HST, JWST, and RST have a dedicated endpoint for retrieving products
548567
base_url = self._service_api_connection.MISSIONS_DOWNLOAD_URL + self.mission + '/api/v0.1/retrieve_product'
549568
keyword = 'product_name'
550569
else:

astroquery/mast/tests/test_mast_remote.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,18 @@ def check_result(result, path):
365365
@pytest.mark.parametrize("mission, query_params", [
366366
('jwst', {'fileSetName': 'jw01189001001_02101_00001'}),
367367
('classy', {'Target': 'J0021+0052'}),
368-
('ullyses', {'host_galaxy_name': 'WLM', 'select_cols': ['observation_id']})
368+
('ullyses', {'host_galaxy_name': 'WLM', 'select_cols': ['observation_id']}),
369+
('roman', {'program': 3}),
369370
])
370371
def test_missions_workflow(self, tmp_path, mission, query_params):
371372
# Test workflow with other missions
372373
m = MastMissions(mission=mission)
373374

375+
# Roman requires extra setup to point towards the test server
376+
if mission == 'roman':
377+
m._service_api_connection.SERVICE_URL = 'https://masttest.stsci.edu'
378+
m._service_api_connection.REQUEST_URL = 'https://masttest.stsci.edu/search/roman/api/v0.1/'
379+
374380
# Criteria query
375381
datasets = m.query_criteria(**query_params)
376382
assert isinstance(datasets, Table)

0 commit comments

Comments
 (0)