11
11
from astropy .utils .diff import report_diff_values
12
12
13
13
14
- DATA_FILES = {
14
+ OUTPUTMODE_FILE_MAP = {
15
15
"Regular" : "MOST_regular.html" ,
16
16
"Full" : "MOST_full_with_tarballs.html" ,
17
17
"VOTable" : "MOST_VOTable.xml" ,
@@ -25,57 +25,66 @@ def data_path(filename):
25
25
return os .path .join (data_dir , filename )
26
26
27
27
28
- @pytest .fixture
29
- def patch_get (request ):
30
- mp = request .getfixturevalue ("monkeypatch" )
31
- mp .setattr (Most , '_request' , get_mockreturn )
32
- return mp
33
-
28
+ def get_mocked_return (method = None , url = None , data = None , timeout = 120 , ** kwargs ):
29
+ if "results.tbl" in url :
30
+ url = "most_results_table.tbl"
31
+ elif "imgframes_matched_final_table.tbl" in url :
32
+ url = "most_imgframes_matched_final_table.tbl"
33
+ elif "applications" in url :
34
+ url = "MOST_application.html"
34
35
35
- def get_mockreturn (method = None , url = None , data = None , timeout = 120 , ** kwargs ):
36
36
if method == "GET" :
37
37
filename = data_path (url )
38
38
else :
39
- filename = data_path (DATA_FILES [data ["output_mode" ]])
39
+ filename = data_path (OUTPUTMODE_FILE_MAP [data ["output_mode" ]])
40
+
40
41
with open (filename , 'rb' ) as infile :
41
42
content = infile .read ()
43
+
42
44
return MockResponse (content , ** kwargs )
43
45
44
46
45
- def test_validation (patch_get ):
47
+ @pytest .fixture
48
+ def patch_get_regular (request ):
49
+ mp = request .getfixturevalue ("monkeypatch" )
50
+ mp .setattr (Most , '_request' , get_mocked_return )
51
+ return mp
52
+
53
+
54
+ def test_validation (patch_get_regular ):
46
55
with pytest .raises (ValueError ):
47
- Most .query ()
56
+ Most .query_object ()
48
57
49
58
with pytest .raises (ValueError ):
50
- Most .query (catalog = "wise_allsky_4band" )
59
+ Most .query_object (catalog = "wise_allsky_4band" )
51
60
52
61
# make sure no funny business happens with
53
62
# overwriting of default values
54
- Most .query (
63
+ Most .query_object (
55
64
catalog = "wise_allsky_4band" ,
56
65
obj_name = "Victoria"
57
66
)
58
- Most .query (
67
+ Most .query_object (
59
68
catalog = "wise_allsky_4band" ,
60
69
obj_name = "Victoria" ,
61
- input_type = "name_input"
70
+ input_mode = "name_input"
62
71
)
63
72
64
73
with pytest .raises (ValueError ):
65
74
# fails because insufficient orbital parameters specified
66
- Most .query (
75
+ Most .query_object (
67
76
catalog = "wise_allsky_4band" ,
68
77
output_mode = "Brief" ,
69
- input_type = "manual_input" ,
78
+ input_mode = "manual_input" ,
70
79
obj_type = "Asteroid" ,
71
80
perih_dist = 1.5 ,
72
81
eccentricity = 0.5
73
82
)
74
83
75
- Most .query (
84
+ Most .query_object (
76
85
catalog = "wise_allsky_4band" ,
77
86
output_mode = "Brief" ,
78
- input_type = "manual_input" ,
87
+ input_mode = "manual_input" ,
79
88
obj_type = "Asteroid" ,
80
89
semimajor_axis = 2.68 ,
81
90
eccentricity = 0.33 ,
@@ -84,45 +93,45 @@ def test_validation(patch_get):
84
93
with pytest .raises (ValueError ):
85
94
# Comets require perihel_dist keyword
86
95
# instead of smimajor_axis
87
- Most .query (
96
+ Most .query_object (
88
97
catalog = "wise_allsky_4band" ,
89
98
output_mode = "Brief" ,
90
- input_type = "manual_input" ,
99
+ input_mode = "manual_input" ,
91
100
obj_type = "Comet" ,
92
101
semimajor_axis = 2.68 ,
93
102
eccentricity = 0.33
94
103
)
95
104
96
105
with pytest .raises (ValueError ):
97
106
# object type is case sensitive
98
- Most .query (
107
+ Most .query_object (
99
108
catalog = "wise_allsky_4band" ,
100
109
output_mode = "Brief" ,
101
- input_type = "manual_input" ,
110
+ input_mode = "manual_input" ,
102
111
obj_type = "comet" ,
103
112
semimajor_axis = 2.68 ,
104
113
eccentricity = 0.33
105
114
)
106
115
107
116
with pytest .raises (ValueError ):
108
117
# missing mpc_data and obj_type
109
- Most .query (
118
+ Most .query_object (
110
119
catalog = "wise_allsky_4band" ,
111
120
output_mode = "Brief" ,
112
- input_type = "mpc_input"
121
+ input_mode = "mpc_input"
113
122
)
114
123
115
- Most .query (
124
+ Most .query_object (
116
125
catalog = "wise_allsky_4band" ,
117
126
output_mode = "Brief" ,
118
- input_type = "mpc_input" ,
127
+ input_mode = "mpc_input" ,
119
128
obj_type = "Asteroid" ,
120
129
mpc_data = "K10N010+2010+08+16.1477+1.494525+0.533798+153.4910+113.2118+12.8762+20100621+17.0+4.0+P/2010+N1+(WISE)+MPC+75712" # noqa: E501
121
130
)
122
131
123
132
124
- def test_regular (patch_get ):
125
- response = Most .query (obj_name = "Victoria" )
133
+ def test_regular (patch_get_regular ):
134
+ response = Most .query_object (obj_name = "Victoria" )
126
135
127
136
assert "results" in response
128
137
assert "metadata" in response
@@ -132,19 +141,19 @@ def test_regular(patch_get):
132
141
133
142
results = Table .read (data_path ("most_results_table.tbl" ), format = "ipac" )
134
143
metadata = Table .read (data_path ("most_imgframes_matched_final_table.tbl" ), format = "ipac" )
135
- url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194 /MOST/pid10499 /ds9region/ds9_orbit_path.reg"
144
+ url = "https://irsa.ipac.caltech.edu/workspace/TMP_noPis4_23270 /MOST/pid30587 /ds9region/ds9_orbit_path.reg"
136
145
137
146
silent_stream = io .StringIO ()
138
147
assert report_diff_values (results , response ["results" ], silent_stream )
139
148
assert report_diff_values (metadata , response ["metadata" ], silent_stream )
140
149
assert url == response ["region" ]
141
150
142
151
143
- def test_get_full_with_tarballs (patch_get ):
144
- response = Most .query (
152
+ def test_get_full_with_tarballs (patch_get_regular ):
153
+ response = Most .query_object (
145
154
obj_name = "Victoria" ,
146
155
output_mode = "Full" ,
147
- fits_region_files = True
156
+ with_tarballs = True
148
157
)
149
158
150
159
assert "results" in response
@@ -155,9 +164,9 @@ def test_get_full_with_tarballs(patch_get):
155
164
156
165
results = Table .read (data_path ("most_results_table.tbl" ), format = "ipac" )
157
166
metadata = Table .read (data_path ("most_imgframes_matched_final_table.tbl" ), format = "ipac" )
158
- url = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194 /MOST/pid10499 /ds9region/ds9_orbit_path.reg"
159
- region_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194 /MOST/pid10499 /ds9region_A850RA.tar"
160
- fits_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_XIBNAd_17194 /MOST/pid10499 /fitsimage_A850RA.tar.gz"
167
+ url = "https://irsa.ipac.caltech.edu/workspace/TMP_noPis4_23270 /MOST/pid1957 /ds9region/ds9_orbit_path.reg"
168
+ region_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_noPis4_23270 /MOST/pid1957 /ds9region_A850RA.tar"
169
+ fits_tar = "https://irsa.ipac.caltech.edu/workspace/TMP_noPis4_23270 /MOST/pid1957 /fitsimage_A850RA.tar.gz"
161
170
162
171
silent_stream = io .StringIO ()
163
172
assert report_diff_values (results , response ["results" ], silent_stream )
@@ -167,8 +176,8 @@ def test_get_full_with_tarballs(patch_get):
167
176
assert fits_tar == response ["fits_tarball" ]
168
177
169
178
170
- def test_votable (patch_get ):
171
- response = Most .query (
179
+ def test_votable (patch_get_regular ):
180
+ response = Most .query_object (
172
181
output_mode = "VOTable" ,
173
182
obj_name = "Victoria"
174
183
)
@@ -178,8 +187,23 @@ def test_votable(patch_get):
178
187
assert report_diff_values (response , vtbl , silent_stream )
179
188
180
189
181
- def test_gator (patch_get ):
182
- response = Most .query (
190
+ def test_list_catalogs (patch_get_regular ):
191
+ expected = [
192
+ '2mass' , 'spitzer_bcd' , 'ptf' , 'sofia' , 'wise_merge' , 'wise_allsky_4band' ,
193
+ 'wise_allsky_3band' , 'wise_allsky_2band' , 'wise_neowiser' ,
194
+ 'wise_neowiser_yr1' , 'wise_neowiser_yr2' , 'wise_neowiser_yr3' ,
195
+ 'wise_neowiser_yr4' , 'wise_neowiser_yr5' , 'wise_neowiser_yr6' ,
196
+ 'wise_neowiser_yr7' , 'wise_neowiser_yr8' , 'wise_neowiser_yr9' , 'ztf' ,
197
+ 'wise_merge_int' , 'wise_neowiser_int' , 'wise_neowiser_yr10'
198
+ ]
199
+
200
+ response = Most .list_catalogs ()
201
+
202
+ assert response == expected
203
+
204
+
205
+ def test_gator (patch_get_regular ):
206
+ response = Most .query_object (
183
207
output_mode = "Gator" ,
184
208
obj_name = "Victoria"
185
209
)
0 commit comments