@@ -317,12 +317,35 @@ def test_launch_sync_job(tmp_path_factory):
317
317
assert 3 == len (results ), len (results )
318
318
319
319
320
- def test_launch_async_job ():
321
- conn_handler = DummyConnHandler ()
320
+ @patch .object (TapPlus , 'launch_job' )
321
+ def test_launch_sync_job_exception (mock_launch_job , caplog ):
322
+ query = "select alpha, delta, source_id, table1_oid from caca"
322
323
324
+ conn_handler = DummyConnHandler ()
323
325
tap_plus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
324
- query = "select alpha, delta, source_id, table1_oid from caca"
325
326
327
+ launch_response = DummyResponse (200 )
328
+ launch_response .set_data (method = "POST" , body = JOB_DATA )
329
+ conn_handler .set_default_response (launch_response )
330
+
331
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
332
+
333
+ mock_launch_job .side_effect = HTTPError ("launch_job HTTPError" )
334
+
335
+ tap .launch_job (query , output_format = "votable" )
336
+
337
+ mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca: HTTP error: launch_job HTTPError"
338
+ assert caplog .records [0 ].msg == mssg
339
+
340
+ mock_launch_job .side_effect = Exception ("launch_job Exception" )
341
+
342
+ tap .launch_job (query , output_format = "votable" )
343
+
344
+ mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca, launch_job Exception"
345
+ assert caplog .records [1 ].msg == mssg
346
+
347
+
348
+ def test_launch_async_job ():
326
349
conn_handler = DummyConnHandler ()
327
350
tap_plus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
328
351
jobid = '12345'
@@ -346,6 +369,8 @@ def test_launch_async_job():
346
369
req = "async/" + jobid + "/results/result"
347
370
conn_handler .set_response (req , responseResultsJob )
348
371
372
+ query = "select alpha, delta, source_id, table1_oid from caca"
373
+
349
374
tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
350
375
351
376
job = tap .launch_job_async (query , output_format = "votable" )
@@ -391,6 +416,29 @@ def test_launch_async_job():
391
416
assert 3 == len (results ), len (results )
392
417
393
418
419
+ @patch .object (TapPlus , 'launch_job_async' )
420
+ def test_launch_async_job_exception (mock_launch_job_async , caplog ):
421
+ conn_handler = DummyConnHandler ()
422
+ tap_plus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
423
+
424
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
425
+ query = "select alpha, delta, source_id, table1_oid from caca"
426
+
427
+ mock_launch_job_async .side_effect = HTTPError ("launch_job_async HTTPError" )
428
+
429
+ tap .launch_job_async (query , output_format = "votable" )
430
+
431
+ mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca: HTTP error: launch_job_async HTTPError"
432
+ assert caplog .records [0 ].msg == mssg
433
+
434
+ mock_launch_job_async .side_effect = Exception ("launch_job_async Exception" )
435
+
436
+ tap .launch_job_async (query , output_format = "votable" )
437
+
438
+ mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca, launch_job_async Exception"
439
+ assert caplog .records [1 ].msg == mssg
440
+
441
+
394
442
def test_list_async_jobs ():
395
443
conn_handler = DummyConnHandler ()
396
444
tap_plus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
@@ -682,6 +730,38 @@ def test_get_obs_products():
682
730
683
731
assert result is not None
684
732
733
+ result = tap .get_observation_products (id = '13' , product_type = 'mosaic' , filter = 'VIS' , output_file = None )
734
+
735
+ assert result is not None
736
+
737
+
738
+ def test_get_obs_products_exceptions ():
739
+ conn_handler = DummyConnHandler ()
740
+ tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
741
+ connhandler = conn_handler )
742
+ # Launch response: we use default response because the query contains decimals
743
+ responseLaunchJob = DummyResponse (200 )
744
+ responseLaunchJob .set_data (method = 'POST' , context = None , body = '' , headers = None )
745
+
746
+ conn_handler .set_default_response (responseLaunchJob )
747
+
748
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
749
+
750
+ with pytest .raises (ValueError ) as exc_info :
751
+ tap .get_observation_products (id = None , product_type = 'observation' , filter = 'VIS' , output_file = None )
752
+
753
+ assert str (exc_info .value ).startswith ("Missing required argument: 'observation_id'" )
754
+
755
+ with pytest .raises (ValueError ) as exc_info :
756
+ tap .get_observation_products (id = 12 , product_type = None , filter = 'VIS' , output_file = None )
757
+
758
+ assert str (exc_info .value ).startswith ("Missing required argument: 'product_type'" )
759
+
760
+ with pytest .raises (ValueError ) as exc_info :
761
+ tap .get_observation_products (id = 12 , product_type = 'XXXXXXXX' , filter = 'VIS' , output_file = None )
762
+
763
+ assert str (exc_info .value ).startswith ("Invalid product type XXXXXXXX. Valid values: ['observation', 'mosaic']" )
764
+
685
765
686
766
def test_get_cutout ():
687
767
conn_handler = DummyConnHandler ()
0 commit comments