@@ -35,12 +35,16 @@ def test_01_search_part_01(self):
35
35
if len (argv ) > 1 :
36
36
argv .pop (- 1 )
37
37
argv .append ('SEARCH' )
38
- search_result = choose_process ()
39
- search_result = json .loads (search_result )
40
- self .assertTrue (isinstance (search_result , list ), f'search_result is not list: { search_result } ' )
41
- self .assertEqual (len (search_result ), 4000 , f'wrong length' )
42
- search_result = set ([k ['id' ] for k in search_result ])
43
- self .assertEqual (len (search_result ),4000 , f'wrong length. not unique' )
38
+ with tempfile .TemporaryDirectory () as tmp_dir_name :
39
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
40
+ search_result_str = choose_process ()
41
+ search_result = json .loads (search_result_str )
42
+ self .assertTrue (isinstance (search_result , list ), f'search_result is not list: { search_result } ' )
43
+ self .assertEqual (len (search_result ), 4000 , f'wrong length' )
44
+ search_result = set ([k ['id' ] for k in search_result ])
45
+ self .assertEqual (len (search_result ),4000 , f'wrong length. not unique' )
46
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
47
+ self .assertEqual (sorted (json .dumps (FileUtils .read_json (os .environ ['OUTPUT_FILE' ]))), sorted (search_result_str ), f'not identical result' )
44
48
return
45
49
46
50
def test_01_search_part_02 (self ):
@@ -220,6 +224,7 @@ def test_02_download(self):
220
224
argv .pop (- 1 )
221
225
argv .append ('DOWNLOAD' )
222
226
with tempfile .TemporaryDirectory () as tmp_dir_name :
227
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
223
228
os .environ ['DOWNLOAD_DIR' ] = tmp_dir_name
224
229
download_result = choose_process ()
225
230
self .assertTrue (isinstance (download_result , list ), f'download_result is not list: { download_result } ' )
@@ -228,6 +233,7 @@ def test_02_download(self):
228
233
for each_granule in zip (granule_json , download_result ):
229
234
remote_filename = os .path .basename (each_granule [0 ]['assets' ]['data' ]['href' ])
230
235
self .assertEqual (each_granule [1 ]['assets' ]['data' ]['href' ], os .path .join (tmp_dir_name , remote_filename ), f"mismatched: { each_granule [0 ]['assets' ]['data' ]['href' ]} " )
236
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
231
237
return
232
238
233
239
def test_02_download__daac (self ):
@@ -242,6 +248,7 @@ def test_02_download__daac(self):
242
248
argv .pop (- 1 )
243
249
argv .append ('DOWNLOAD' )
244
250
with tempfile .TemporaryDirectory () as tmp_dir_name :
251
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
245
252
os .environ ['DOWNLOAD_DIR' ] = tmp_dir_name
246
253
download_result = choose_process ()
247
254
self .assertTrue (isinstance (download_result , list ), f'download_result is not list: { download_result } ' )
@@ -254,6 +261,7 @@ def test_02_download__daac(self):
254
261
remote_filename = os .path .basename (each_granule [0 ]['assets' ]['data' ]['href' ])
255
262
self .assertEqual (each_granule [1 ]['assets' ]['data' ]['href' ], os .path .join (tmp_dir_name , remote_filename ),
256
263
f"mismatched: { each_granule [0 ]['assets' ]['data' ]['href' ]} " )
264
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
257
265
return
258
266
259
267
def test_02_download__daac__from_file (self ):
@@ -268,6 +276,7 @@ def test_02_download__daac__from_file(self):
268
276
argv .pop (- 1 )
269
277
argv .append ('DOWNLOAD' )
270
278
with tempfile .TemporaryDirectory () as tmp_dir_name :
279
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
271
280
granule_json_file = os .path .join (tmp_dir_name , 'input_file.json' )
272
281
downloading_dir = os .path .join (tmp_dir_name , 'downloading_dir' )
273
282
FileUtils .mk_dir_p (downloading_dir )
@@ -285,6 +294,7 @@ def test_02_download__daac__from_file(self):
285
294
remote_filename = os .path .basename (each_granule [0 ]['assets' ]['data' ]['href' ])
286
295
self .assertEqual (each_granule [1 ]['assets' ]['data' ]['href' ], os .path .join (downloading_dir , remote_filename ),
287
296
f"mismatched: { each_granule [0 ]['assets' ]['data' ]['href' ]} " )
297
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
288
298
return
289
299
290
300
def test_02_download__daac_error (self ):
@@ -299,6 +309,7 @@ def test_02_download__daac_error(self):
299
309
argv .pop (- 1 )
300
310
argv .append ('DOWNLOAD' )
301
311
with tempfile .TemporaryDirectory () as tmp_dir_name :
312
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
302
313
# TODO this is downloading a login page HTML
303
314
os .environ ['DOWNLOAD_DIR' ] = tmp_dir_name
304
315
download_result = choose_process ()
@@ -307,6 +318,7 @@ def test_02_download__daac_error(self):
307
318
error_file = os .path .join (tmp_dir_name , 'error.log' )
308
319
if FileUtils .file_exist (error_file ):
309
320
self .assertTrue (False , f'some downloads failed. error.log exists. { FileUtils .read_json (error_file )} ' )
321
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
310
322
return
311
323
312
324
def test_02_download__from_file (self ):
@@ -316,6 +328,7 @@ def test_02_download__from_file(self):
316
328
argv .append ('DOWNLOAD' )
317
329
os .environ ['GRANULES_DOWNLOAD_TYPE' ] = 'S3'
318
330
with tempfile .TemporaryDirectory () as tmp_dir_name :
331
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
319
332
granule_json_file = os .path .join (tmp_dir_name , 'input_file.json' )
320
333
downloading_dir = os .path .join (tmp_dir_name , 'downloading_dir' )
321
334
FileUtils .mk_dir_p (downloading_dir )
@@ -333,6 +346,7 @@ def test_02_download__from_file(self):
333
346
remote_filename = os .path .basename (each_granule [0 ]['assets' ]['data' ]['href' ])
334
347
self .assertEqual (each_granule [1 ]['assets' ]['data' ]['href' ], os .path .join (downloading_dir , remote_filename ),
335
348
f"mismatched: { each_granule [0 ]['assets' ]['data' ]['href' ]} " )
349
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
336
350
return
337
351
338
352
def test_03_upload (self ):
@@ -354,6 +368,7 @@ def test_03_upload(self):
354
368
argv .append ('UPLOAD' )
355
369
356
370
with tempfile .TemporaryDirectory () as tmp_dir_name :
371
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
357
372
os .environ ['UPLOAD_DIR' ] = tmp_dir_name
358
373
with open (os .path .join (tmp_dir_name , 'test_file01.nc' ), 'w' ) as ff :
359
374
ff .write ('sample_file' )
@@ -465,6 +480,7 @@ def test_03_upload(self):
465
480
self .assertTrue ('data' in upload_result ['assets' ], 'missing assets#data' )
466
481
self .assertTrue ('href' in upload_result ['assets' ]['data' ], 'missing assets#data#href' )
467
482
self .assertTrue (upload_result ['assets' ]['data' ]['href' ].startswith (f's3://{ os .environ ["STAGING_BUCKET" ]} /' ))
483
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
468
484
return
469
485
470
486
def test_03_upload_catalog (self ):
@@ -487,6 +503,7 @@ def test_03_upload_catalog(self):
487
503
argv .append ('UPLOAD' )
488
504
489
505
with tempfile .TemporaryDirectory () as tmp_dir_name :
506
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
490
507
os .environ ['UPLOAD_DIR' ] = '' # not needed
491
508
os .environ ['CATALOG_FILE' ] = os .path .join (tmp_dir_name , 'catalog.json' )
492
509
with open (os .path .join (tmp_dir_name , 'test_file01.nc' ), 'w' ) as ff :
@@ -629,6 +646,7 @@ def test_03_upload_catalog(self):
629
646
self .assertTrue ('data' in upload_result ['assets' ], 'missing assets#data' )
630
647
self .assertTrue ('href' in upload_result ['assets' ]['data' ], 'missing assets#data#href' )
631
648
self .assertTrue (upload_result ['assets' ]['data' ]['href' ].startswith (f's3://{ os .environ ["STAGING_BUCKET" ]} /' ))
649
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
632
650
return
633
651
634
652
def test_04_catalog (self ):
@@ -646,6 +664,9 @@ def test_04_catalog(self):
646
664
if len (argv ) > 1 :
647
665
argv .pop (- 1 )
648
666
argv .append ('CATALOG' )
649
- catalog_result = choose_process ()
650
- self .assertEqual ('registered' , catalog_result , 'wrong status' )
667
+ with tempfile .TemporaryDirectory () as tmp_dir_name :
668
+ os .environ ['OUTPUT_FILE' ] = os .path .join (tmp_dir_name , 'some_output' , 'output.json' )
669
+ catalog_result = choose_process ()
670
+ self .assertEqual ('registered' , catalog_result , 'wrong status' )
671
+ self .assertTrue (FileUtils .file_exist (os .environ ['OUTPUT_FILE' ]), f'missing output file' )
651
672
return
0 commit comments