Skip to content

Commit a56a1f0

Browse files
committed
Add new API v2 tests (#1)
1 parent f60ba4d commit a56a1f0

11 files changed

Lines changed: 234 additions & 289 deletions

tests/test_api.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_api_count(api):
6565
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
6666
assert responses.calls[0].response.text == result_count
6767

68-
assert resp == 1591
68+
assert resp == 1636
6969

7070

7171
@responses.activate
@@ -106,27 +106,27 @@ def test_api_data_limit_none(api):
106106
assert len(responses.calls) == 2
107107
if six.PY3:
108108
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
109-
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=1591'
109+
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&target=pan&limit=1636'
110110
else:
111-
assert 'limit=1591' in responses.calls[1].request.url
111+
assert 'limit=1636' in responses.calls[1].request.url
112112
assert responses.calls[1].response.text == data
113113

114-
assert len(resp) == 1591
114+
assert len(resp) == 1636
115115

116116
@responses.activate
117117
def test_api_metadata(api):
118-
metadata = open('tests/api/metadata/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
118+
metadata = open('tests/api/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
119119
responses.add(responses.GET,
120-
'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json',
120+
'http://localhost/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json',
121121
body=metadata)
122122

123-
resp = api.metadata('S_IMG_CO_ISS_1459551972_N')
123+
resp = api.metadata('COISS_2001-1459551663_1459568594-N1459551972_1')
124124

125125
assert len(responses.calls) == 1
126-
assert responses.calls[0].request.url == 'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json'
126+
assert responses.calls[0].request.url == 'http://localhost/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json'
127127
assert responses.calls[0].response.text == metadata
128128

129-
assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N'
129+
assert resp.opus_id == 'COISS_2001-1459551663_1459568594-N1459551972_1'
130130

131131
@responses.activate
132132
def test_api_images(api):
@@ -162,24 +162,24 @@ def test_api_images_limit_none(api):
162162
assert len(responses.calls) == 2
163163
if six.PY3:
164164
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
165-
assert responses.calls[1].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=1591'
165+
assert responses.calls[1].request.url == 'http://localhost/images/med.json?planet=Saturn&target=pan&limit=1636'
166166
assert responses.calls[1].response.text == images
167167

168168

169169
@responses.activate
170170
def test_api_image(api):
171-
image = open('tests/api/image/med/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
171+
image = open('tests/api/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
172172
responses.add(responses.GET,
173-
'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json',
173+
'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json',
174174
body=image)
175175

176-
resp = api.image('S_IMG_CO_ISS_1459551972_N')
176+
resp = api.image('COISS_2001-1459551663_1459568594-N1459551972_1')
177177

178178
assert len(responses.calls) == 1
179-
assert responses.calls[0].request.url == 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json'
179+
assert responses.calls[0].request.url == 'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json'
180180
assert responses.calls[0].response.text == image
181181

182-
assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N'
182+
assert resp.opus_id == 'COISS_2001-1459551663_1459568594-N1459551972_1'
183183

184184

185185
def test_api_images_size_err(api):
@@ -189,24 +189,24 @@ def test_api_images_size_err(api):
189189

190190
def test_api_image_size_err(api):
191191
with pytest.raises(ValueError):
192-
api.image('S_IMG_CO_ISS_1459551972_N', size='abc')
192+
api.image('COISS_2001-1459551663_1459568594-N1459551972_1', size='abc')
193193

194194

195195
@responses.activate
196196
def test_api_file(api):
197197
json = open(
198-
'tests/api/files/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
198+
'tests/api/files/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
199199
responses.add(responses.GET,
200-
'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json',
200+
'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json',
201201
body=json)
202202

203-
resp = api.file('S_IMG_CO_ISS_1459551972_N')
203+
resp = api.file('COISS_2001-1459551663_1459568594-N1459551972_1')
204204

205205
assert len(responses.calls) == 1
206-
assert responses.calls[0].request.url == 'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json'
206+
assert responses.calls[0].request.url == 'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json'
207207
assert responses.calls[0].response.text == json
208208

209-
assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N'
209+
assert resp.opus_id == 'COISS_2001-1459551663_1459568594-N1459551972_1'
210210

211211

212212
@responses.activate
@@ -243,7 +243,7 @@ def test_api_files_limit_none(api):
243243
assert len(responses.calls) == 2
244244
if six.PY3:
245245
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn&target=pan'
246-
assert responses.calls[1].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=1591'
246+
assert responses.calls[1].request.url == 'http://localhost/files.json?planet=Saturn&target=pan&limit=1636'
247247
assert responses.calls[1].response.text == files
248248

249249

@@ -260,25 +260,25 @@ def test_api_mults(api):
260260
assert responses.calls[0].request.url == 'http://localhost/meta/mults/target.json?planet=Saturn'
261261
assert responses.calls[0].response.text == mults
262262

263-
assert len(resp) == 63
263+
assert len(resp) == 67
264264

265265
@responses.activate
266266
def test_api_range(api):
267-
range_endpoints = open('tests/api/meta/range/endpoints/ringradius1.json', 'r').read()
267+
range_endpoints = open('tests/api/meta/range/endpoints/RINGGEOringradius1.json', 'r').read()
268268
responses.add(responses.GET,
269-
'http://localhost/meta/range/endpoints/ringradius1.json',
269+
'http://localhost/meta/range/endpoints/RINGGEOringradius1.json',
270270
body=range_endpoints)
271271

272-
resp = api.range('ringradius1', target='Saturn')
272+
resp = api.range('RINGGEOringradius1', target='Saturn')
273273

274274
assert len(responses.calls) == 1
275-
assert responses.calls[0].request.url == 'http://localhost/meta/range/endpoints/ringradius1.json?target=Saturn'
275+
assert responses.calls[0].request.url == 'http://localhost/meta/range/endpoints/RINGGEOringradius1.json?target=Saturn'
276276
assert responses.calls[0].response.text == range_endpoints
277277

278-
assert 'OPUS API Range endpoints for field: `ringradius1`' in repr(resp)
279-
assert resp['min'] == 60000
278+
assert 'OPUS API Range endpoints for field: `RINGGEOringradius1`' in repr(resp)
279+
assert resp['min'] == 90.707
280280
assert resp['max'] == 1.29e+07
281-
assert resp['null'] == 115573
281+
assert resp['null'] == 125531
282282

283283

284284
@responses.activate
@@ -309,23 +309,23 @@ def test_api_fields(api):
309309
assert responses.calls[0].request.url == 'http://localhost/fields.json'
310310
assert responses.calls[0].response.text == fields
311311

312-
assert len(resp) == 304
312+
assert len(resp) == 247
313313

314314

315315
@responses.activate
316316
def test_api_category(api):
317-
category = open('tests/api/categories/obs_general.json', 'r').read()
317+
category = open('tests/api/categories/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
318318
responses.add(responses.GET,
319-
'http://localhost/categories/obs_general.json',
319+
'http://localhost/categories/COISS_2001-1459551663_1459568594-N1459551972_1.json',
320320
body=category)
321321

322-
resp = api.category('obs_general')
322+
resp = api.category('COISS_2001-1459551663_1459568594-N1459551972_1')
323323

324324
assert len(responses.calls) == 1
325-
assert responses.calls[0].request.url == 'http://localhost/categories/obs_general.json'
325+
assert responses.calls[0].request.url == 'http://localhost/categories/COISS_2001-1459551663_1459568594-N1459551972_1.json'
326326
assert responses.calls[0].response.text == category
327327

328-
assert resp.name == 'obs_general'
328+
assert len(resp) == 8
329329

330330

331331
@responses.activate
@@ -341,4 +341,4 @@ def test_api_categories(api):
341341
assert responses.calls[0].request.url == 'http://localhost/categories.json'
342342
assert responses.calls[0].response.text == categories
343343

344-
assert len(resp) == 3
344+
assert len(resp) == 6

tests/test_categories.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66

77
@pytest.fixture
88
def category():
9-
json = JSON.loads(open('tests/api/categories/obs_general.json', 'r').read())
10-
return Category(json)
9+
json = JSON.loads(open('tests/api/categories/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read())
10+
return Categories(json)
1111

1212
@pytest.fixture
1313
def categories():
1414
json = JSON.loads(open('tests/api/categories.json', 'r').read())
1515
return Categories(json)
1616

1717
def test_category_repr(category):
18-
assert repr(category) == 'General Constraints (obs_general)'
18+
r = repr(category)
19+
assert 'OPUS API list of all categories (8)' in r
20+
assert 'Cassini ISS Constraints (obs_instrument_coiss)' in r
1921

2022

2123
def test_categories_repr(categories):
2224
r = repr(categories)
23-
assert 'OPUS API list of all categories (3)' in r
24-
assert 'General Constraints (obs_general)' in r
25+
assert 'OPUS API list of all categories (6)' in r
26+
assert 'Ring Geometry Constraints (obs_ring_geometry)' in r

tests/test_cli.py

Lines changed: 29 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ def test_cli_data_limite_none(api):
7070
assert len(responses.calls) == 2
7171
if six.PY3:
7272
assert responses.calls[0].request.url == 'http://localhost/meta/result_count.json?planet=Saturn'
73-
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&limit=1591'
73+
assert responses.calls[1].request.url == 'http://localhost/data.json?planet=Saturn&limit=1636'
7474
else:
75-
assert 'limit=1591' in responses.calls[1].request.url
75+
assert 'limit=1636' in responses.calls[1].request.url
7676

7777
assert responses.calls[1].response.text == json
78-
assert len(resp) == 1591
78+
assert len(resp) == 1636
7979

8080

8181
@responses.activate
@@ -89,60 +89,60 @@ def test_data_argv_none(api):
8989

9090
@responses.activate
9191
def test_cli_metadata(api):
92-
json = open('tests/api/metadata/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
92+
json = open('tests/api/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
9393
responses.add(responses.GET,
94-
'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json',
94+
'http://localhost/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json',
9595
body=json)
9696

97-
argv = 'S_IMG_CO_ISS_1459551972_N'.split()
97+
argv = 'COISS_2001-1459551663_1459568594-N1459551972_1'.split()
9898
resp = cli.metadata(argv, api=api)
9999

100100
assert len(responses.calls) == 1
101-
assert responses.calls[0].request.url == 'http://localhost/metadata/S_IMG_CO_ISS_1459551972_N.json'
101+
assert responses.calls[0].request.url == 'http://localhost/metadata_v2/COISS_2001-1459551663_1459568594-N1459551972_1.json'
102102
assert responses.calls[0].response.text == json
103103

104-
assert resp.ring_obs_id == 'S_IMG_CO_ISS_1459551972_N'
104+
assert resp.opus_id == 'COISS_2001-1459551663_1459568594-N1459551972_1'
105105

106106

107107
@responses.activate
108108
def test_cli_image(api):
109-
img = open('tests/api/image/med/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
109+
img = open('tests/api/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
110110
responses.add(responses.GET,
111-
'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json',
111+
'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json',
112112
body=img)
113113

114-
argv = 'S_IMG_CO_ISS_1459551972_N --size med'.split()
114+
argv = 'COISS_2001-1459551663_1459568594-N1459551972_1 --size med'.split()
115115
resp = cli.image(argv, api=api)
116116

117117
assert len(responses.calls) == 1
118-
assert responses.calls[0].request.url == 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json'
118+
assert responses.calls[0].request.url == 'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json'
119119
assert responses.calls[0].response.text == img
120120

121121
assert resp == 'https://pds-rings.seti.org/holdings/previews/COISS_2xxx/COISS_2001/data/1459551663_1459568594/N1459551972_1_med.jpg'
122122

123123

124124
@responses.activate
125125
def test_cli_image_download(api):
126-
img = open('tests/api/image/med/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
126+
img = open('tests/api/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
127127
responses.add(responses.GET,
128-
'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json',
128+
'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json',
129129
body=img)
130130

131131
fname = 'N1459551972_1_med.jpg'
132132
jpg = 'https://pds-rings.seti.org/holdings/previews/COISS_2xxx/COISS_2001/data/1459551663_1459568594/N1459551972_1_med.jpg'
133133

134-
with open('tests/api/image/med/'+fname, 'rb') as img:
134+
with open('tests/data/'+fname, 'rb') as img:
135135
responses.add(responses.GET, jpg,
136136
body=img.read(), status=200,
137137
content_type='image/jpeg',
138138
stream=True
139139
)
140140

141-
argv = 'S_IMG_CO_ISS_1459551972_N --output tests/test.jpg'.split()
141+
argv = 'COISS_2001-1459551663_1459568594-N1459551972_1 --output tests/test.jpg'.split()
142142
resp = cli.image(argv, api=api)
143143

144144
assert len(responses.calls) == 2
145-
assert responses.calls[0].request.url == 'http://localhost/image/med/S_IMG_CO_ISS_1459551972_N.json'
145+
assert responses.calls[0].request.url == 'http://localhost/image/med/COISS_2001-1459551663_1459568594-N1459551972_1.json'
146146
assert responses.calls[1].request.url == jpg
147147

148148
assert resp == 'tests/test.jpg'
@@ -152,27 +152,27 @@ def test_cli_image_download(api):
152152

153153
@responses.activate
154154
def test_cli_files(api):
155-
json = open('tests/api/files/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
155+
json = open('tests/api/files/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
156156
responses.add(responses.GET,
157-
'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json',
157+
'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json',
158158
body=json)
159159

160-
argv = 'S_IMG_CO_ISS_1459551972_N'.split()
160+
argv = 'COISS_2001-1459551663_1459568594-N1459551972_1'.split()
161161
resp = cli.files(argv, api=api)
162162

163163
assert len(responses.calls) == 1
164-
assert responses.calls[0].request.url == 'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json'
164+
assert responses.calls[0].request.url == 'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json'
165165
assert responses.calls[0].response.text == json
166166

167-
assert 'OPUS API Files for observation: S_IMG_CO_ISS_1459551972_N' in resp
167+
assert 'OPUS API Files for observation: COISS_2001-1459551663_1459568594-N1459551972_1' in resp
168168
assert 'LBL: https://pds-rings.seti.org/holdings/calibrated/COISS_2xxx/COISS_2001/data/1459551663_1459568594/N1459551972_1_CALIB.LBL' in resp
169169

170170

171171
@responses.activate
172172
def test_cli_files_downlad(api):
173-
json = open('tests/api/files/S_IMG_CO_ISS_1459551972_N.json', 'r').read()
173+
json = open('tests/api/files/COISS_2001-1459551663_1459568594-N1459551972_1.json', 'r').read()
174174
responses.add(responses.GET,
175-
'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json',
175+
'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json',
176176
body=json)
177177

178178
fname = 'N1459551972_1.LBL'
@@ -185,11 +185,11 @@ def test_cli_files_downlad(api):
185185
stream=True
186186
)
187187

188-
argv = 'S_IMG_CO_ISS_1459551972_N -f RAW_IMAGE LBL --output tests/test.lbl'.split()
188+
argv = 'COISS_2001-1459551663_1459568594-N1459551972_1 -f RAW_DATA LBL --output tests/test.lbl'.split()
189189
resp = cli.files(argv, api=api)
190190

191191
assert len(responses.calls) == 2
192-
assert responses.calls[0].request.url == 'http://localhost/files/S_IMG_CO_ISS_1459551972_N.json'
192+
assert responses.calls[0].request.url == 'http://localhost/files/COISS_2001-1459551663_1459568594-N1459551972_1.json'
193193
assert responses.calls[1].request.url == lbl
194194

195195
assert resp == 'tests/test.lbl'
@@ -229,32 +229,8 @@ def test_cli_field_all(api):
229229
assert responses.calls[0].response.text == json
230230

231231
r = repr(resp)
232-
assert 'OPUS API list of all fields available (304):' in r
233-
assert 'GLOBAL' in r
234-
assert 'TITAN' in r
235-
236-
@responses.activate
237-
def test_cli_field_group(api):
238-
json = open('tests/api/fields.json', 'r').read()
239-
responses.add(responses.GET,
240-
'http://localhost/fields/TITAN.json',
241-
body='{}')
242-
responses.add(responses.GET,
243-
'http://localhost/fields.json',
244-
body=json)
245-
246-
argv = 'TITAN'.split()
247-
resp = cli.field(argv, api=api)
248-
249-
assert len(responses.calls) == 2
250-
assert responses.calls[0].request.url == 'http://localhost/fields/TITAN.json'
251-
assert responses.calls[0].response.text == '{}'
252-
assert responses.calls[1].request.url == 'http://localhost/fields.json'
253-
assert responses.calls[1].response.text == json
254-
255-
r = repr(resp)
256-
assert 'OPUS API Surface Geometry fields (31) for `Titan`:' in r
257-
assert 'Sub-Solar IAU West Longitude (subsolarIAUlongitude)' in r
232+
assert 'OPUS API list of all fields available (247):' in r
233+
assert 'planet' in r
258234

259235
@responses.activate
260236
def test_cli_field_err(api):
@@ -269,10 +245,8 @@ def test_cli_field_err(api):
269245
argv = 'abc'.split()
270246
resp = cli.field(argv, api=api)
271247

272-
assert len(responses.calls) == 2
248+
assert len(responses.calls) == 1
273249
assert responses.calls[0].request.url == 'http://localhost/fields/abc.json'
274250
assert responses.calls[0].response.text == '{}'
275-
assert responses.calls[1].request.url == 'http://localhost/fields.json'
276-
assert responses.calls[1].response.text == json
277251

278252
assert resp == 'Unknown field. To list all the available fields, run: `opus-field --all`'

0 commit comments

Comments
 (0)