Skip to content

Commit d122e3d

Browse files
syed-gilanibsipocz
authored andcommitted
added a unit test for checking if KeyError is raised
1 parent 2660b2c commit d122e3d

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"messages": [],
3+
"info": [
4+
{
5+
"name": "sci_release_date",
6+
"type": "DATETIME"
7+
},
8+
{
9+
"name": "sci_actual_duration",
10+
"type": "FLOAT"
11+
},
12+
{
13+
"name": "sci_dec",
14+
"type": "FLOAT"
15+
},
16+
{
17+
"name": "sci_pep_id",
18+
"type": "INTEGER"
19+
},
20+
{
21+
"name": "sci_spec_1234",
22+
"type": "VARCHAR"
23+
},
24+
{
25+
"name": "sci_aper_1234",
26+
"type": "VARCHAR"
27+
},
28+
{
29+
"name": "sci_data_set_name",
30+
"type": "VARCHAR"
31+
},
32+
{
33+
"name": "sci_preview_name",
34+
"type": "VARCHAR"
35+
},
36+
{
37+
"name": "sci_targname",
38+
"type": "VARCHAR"
39+
},
40+
{
41+
"name": "sci_instrume",
42+
"type": "VARCHAR"
43+
},
44+
{
45+
"name": "search_key",
46+
"type": "VARCHAR"
47+
},
48+
{
49+
"name": "sci_central_wavelength",
50+
"type": "FLOAT"
51+
},
52+
{
53+
"name": "sci_status",
54+
"type": "VARCHAR"
55+
},
56+
{
57+
"name": "sci_stop_time",
58+
"type": "DATETIME"
59+
},
60+
{
61+
"name": "scp_scan_type",
62+
"type": "VARCHAR"
63+
},
64+
{
65+
"name": "sci_hlsp",
66+
"type": "INTEGER"
67+
},
68+
{
69+
"name": "sci_refnum",
70+
"type": "INTEGER"
71+
},
72+
{
73+
"name": "sci_start_time",
74+
"type": "DATETIME"
75+
},
76+
{
77+
"name": "sci_ra",
78+
"type": "FLOAT"
79+
}
80+
],
81+
"search_params": {
82+
"target": [
83+
"40.66963 -0.01328"
84+
],
85+
"radius": 3,
86+
"radius_units": "arcminutes",
87+
"offset": 0,
88+
"limit": 5000,
89+
"sort_by": [
90+
"ang_sep",
91+
"sci_targname",
92+
"sci_data_set_name"
93+
],
94+
"sort_desc": [
95+
false,
96+
false,
97+
false
98+
],
99+
"skip_count": false,
100+
"select_cols": [
101+
"sci_data_set_name",
102+
"sci_targname",
103+
"sci_ra",
104+
"sci_dec",
105+
"sci_refnum",
106+
"sci_start_time",
107+
"sci_stop_time",
108+
"sci_actual_duration",
109+
"sci_instrume",
110+
"sci_aper_1234",
111+
"sci_spec_1234",
112+
"sci_central_wavelength",
113+
"sci_pep_id",
114+
"sci_release_date",
115+
"sci_preview_name",
116+
"scp_scan_type",
117+
"sci_hlsp",
118+
"sci_status"
119+
],
120+
"search_key": [],
121+
"user_fields": [],
122+
"conditions": [
123+
{
124+
"sci_obs_type": ""
125+
},
126+
{
127+
"sci_aec": "S"
128+
},
129+
{
130+
"sci_instrume": "STIS,ACS,WFC3,COS,FGS,FOC,FOS,HRS,HSP,NICMOS,WFPC,WFPC2"
131+
}
132+
]
133+
},
134+
"totalResults": 3,
135+
}

astroquery/mast/tests/test_mast.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ def service_mockreturn(self, method="POST", url=None, data=None, timeout=10, use
116116
filename = data_path(DATA_FILES['z_survey'])
117117
else:
118118
filename = data_path(DATA_FILES['z_cutout_fit'])
119+
elif use_json and data['radius'] == 5:
120+
filename = data_path(DATA_FILES["mission_incorrect_results"])
119121
elif use_json:
120122
filename = data_path(DATA_FILES["mission_search_results"])
121123
content = open(filename, 'rb').read()
@@ -228,6 +230,36 @@ def test_missions_query_criteria_async(patch_post):
228230
assert isinstance(responses, MockResponse)
229231

230232

233+
def test_missions_query_criteria_async_with_missing_results(patch_post):
234+
pep_id = {'sci_pep_id': '12556'}
235+
obs_type = {'sci_obs_type': "SPECTRUM"}
236+
instruments = {'sci_instrume': "stis,acs,wfc3,cos,fos,foc,nicmos,ghrs"}
237+
datasets = {'sci_data_set_name': ""}
238+
pi_lname = {'sci_pi_last_name': ""}
239+
actual_duration = {'sci_actual_duration': ""}
240+
spec_1234 = {'sci_spec_1234': ""}
241+
release_date = {'sci_release_date': ""}
242+
start_time = {'sci_start_time': ""}
243+
obs_type = {'sci_obs_type': 'all'}
244+
aec = {'sci_aec': 'S'}
245+
aperture = {'sci_aper_1234': 'WF3'}
246+
247+
with pytest.raises(KeyError) as e_info:
248+
responses = mast.MastMissions.query_criteria_async(coordinates=regionCoords,
249+
radius=5,
250+
conditions=[pep_id,
251+
obs_type,
252+
instruments,
253+
datasets,
254+
pi_lname,
255+
spec_1234,
256+
release_date,
257+
start_time,
258+
obs_type,
259+
aec,
260+
aperture])
261+
262+
231263
###################
232264
# MastClass tests #
233265
###################

0 commit comments

Comments
 (0)