@@ -714,6 +714,34 @@ def test_get_product_exceptions():
714
714
assert str (exc_info .value ).startswith ("'file_name' and 'product_id' are both None" )
715
715
716
716
717
+ @patch .object (TapPlus , 'load_data' )
718
+ def test_get_product_exceptions_2 (mock_load_data , caplog ):
719
+ conn_handler = DummyConnHandler ()
720
+ tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
721
+ connhandler = conn_handler )
722
+ # Launch response: we use default response because the query contains decimals
723
+ responseLaunchJob = DummyResponse (200 )
724
+ responseLaunchJob .set_data (method = 'POST' , context = None , body = '' , headers = None )
725
+
726
+ conn_handler .set_default_response (responseLaunchJob )
727
+
728
+ mock_load_data .side_effect = HTTPError ("launch_job_async HTTPError" )
729
+
730
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
731
+
732
+ tap .get_product (file_name = 'hola.fits' , output_file = None )
733
+
734
+ mssg = "Cannot retrieve products for file_name hola.fits or product_id None. HTTP error: launch_job_async HTTPError"
735
+ assert caplog .records [0 ].msg == mssg
736
+
737
+ mock_load_data .side_effect = Exception ("launch_job_async Exception" )
738
+
739
+ tap .get_product (file_name = 'hola.fits' , output_file = None )
740
+
741
+ mssg = "Cannot retrieve products for file_name hola.fits or product_id None: launch_job_async Exception"
742
+ assert caplog .records [1 ].msg == mssg
743
+
744
+
717
745
def test_get_obs_products ():
718
746
conn_handler = DummyConnHandler ()
719
747
tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
@@ -763,6 +791,34 @@ def test_get_obs_products_exceptions():
763
791
assert str (exc_info .value ).startswith ("Invalid product type XXXXXXXX. Valid values: ['observation', 'mosaic']" )
764
792
765
793
794
+ @patch .object (TapPlus , 'load_data' )
795
+ def test_get_obs_products_exceptions_2 (mock_load_data , caplog ):
796
+ conn_handler = DummyConnHandler ()
797
+ tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
798
+ connhandler = conn_handler )
799
+ # Launch response: we use default response because the query contains decimals
800
+ responseLaunchJob = DummyResponse (200 )
801
+ responseLaunchJob .set_data (method = 'POST' , context = None , body = '' , headers = None )
802
+
803
+ conn_handler .set_default_response (responseLaunchJob )
804
+
805
+ mock_load_data .side_effect = HTTPError ("launch_job_async HTTPError" )
806
+
807
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
808
+
809
+ tap .get_observation_products (id = 12345 , product_type = 'observation' , filter = 'VIS' , output_file = None )
810
+
811
+ mssg = "Cannot retrieve products for observation 12345. HTTP error: launch_job_async HTTPError"
812
+ assert caplog .records [0 ].msg == mssg
813
+
814
+ mock_load_data .side_effect = Exception ("launch_job_async Exception" )
815
+
816
+ tap .get_observation_products (id = 12345 , product_type = 'observation' , filter = 'VIS' , output_file = None )
817
+
818
+ mssg = "Cannot retrieve products for observation 12345: launch_job_async Exception"
819
+ assert caplog .records [1 ].msg == mssg
820
+
821
+
766
822
def test_get_cutout ():
767
823
conn_handler = DummyConnHandler ()
768
824
tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'cutout' , client_id = 'ASTROQUERY' ,
@@ -843,6 +899,43 @@ def test_get_cutout_exception():
843
899
assert str (exc_info .value ).startswith ('Missing required argument' )
844
900
845
901
902
+ @patch .object (TapPlus , 'load_data' )
903
+ def test_get_cutout_exceptions_2 (mock_load_data , caplog ):
904
+ conn_handler = DummyConnHandler ()
905
+ tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'cutout' , client_id = 'ASTROQUERY' ,
906
+ connhandler = conn_handler )
907
+
908
+ cutout_handler = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
909
+ connhandler = conn_handler )
910
+ # tap.set_cutout_context()
911
+ # Launch response: we use default response because the query contains decimals
912
+ responseLaunchJob = DummyResponse (200 )
913
+ responseLaunchJob .set_data (method = 'POST' , context = None , body = '' , headers = None )
914
+
915
+ conn_handler .set_default_response (responseLaunchJob )
916
+
917
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , cutout_handler = cutout_handler ,
918
+ show_server_messages = False )
919
+
920
+ mock_load_data .side_effect = HTTPError ("launch_job_async HTTPError" )
921
+
922
+ tap .get_cutout (file_path = 'hola.fits' , instrument = 'NISP' , id = '19704' , coordinate = SKYCOORD , radius = 1 * u .arcmin ,
923
+ output_file = None )
924
+
925
+ mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP. HTTP error: "
926
+ "launch_job_async HTTPError" )
927
+ assert caplog .records [0 ].msg == mssg
928
+
929
+ mock_load_data .side_effect = Exception ("launch_job_async Exception" )
930
+
931
+ tap .get_cutout (file_path = 'hola.fits' , instrument = 'NISP' , id = '19704' , coordinate = SKYCOORD , radius = 1 * u .arcmin ,
932
+ output_file = None )
933
+
934
+ mssg = ("Cannot retrieve the product for file_path hola.fits, obsId 19704, and collection NISP: launch_job_async "
935
+ "Exception" )
936
+ assert caplog .records [1 ].msg == mssg
937
+
938
+
846
939
def test_get_spectrum ():
847
940
conn_handler = DummyConnHandler ()
848
941
tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
@@ -862,6 +955,35 @@ def test_get_spectrum():
862
955
remove_temp_dir ()
863
956
864
957
958
+ @patch .object (TapPlus , 'load_data' )
959
+ def test_get_spectrum_exceptions_2 (mock_load_data , caplog ):
960
+ conn_handler = DummyConnHandler ()
961
+ tap_plus = TapPlus (url = "http://test:1111/tap" , data_context = 'data' , client_id = 'ASTROQUERY' ,
962
+ connhandler = conn_handler )
963
+ # Launch response: we use default response because the query contains decimals
964
+ responseLaunchJob = DummyResponse (200 )
965
+ responseLaunchJob .set_data (method = 'POST' , context = None , body = '' , headers = None )
966
+
967
+ conn_handler .set_default_response (responseLaunchJob )
968
+
969
+ tap = EuclidClass (tap_plus_conn_handler = conn_handler , datalink_handler = tap_plus , show_server_messages = False )
970
+
971
+ mock_load_data .side_effect = HTTPError ("launch_job_async HTTPError" )
972
+
973
+ tap .get_spectrum (source_id = '2417660845403252054' , schema = 'sedm_sc8' , output_file = None )
974
+
975
+ mssg = ("Cannot retrieve spectrum for source_id 2417660845403252054, schema sedm_sc8. HTTP error: launch_job_async "
976
+ "HTTPError" )
977
+ assert caplog .records [0 ].msg == mssg
978
+
979
+ mock_load_data .side_effect = Exception ("launch_job_async Exception" )
980
+
981
+ tap .get_spectrum (source_id = '2417660845403252054' , schema = 'sedm_sc8' , output_file = None )
982
+
983
+ mssg = "Cannot retrieve spectrum for source_id 2417660845403252054, schema sedm_sc8: launch_job_async Exception"
984
+ assert caplog .records [1 ].msg == mssg
985
+
986
+
865
987
def remove_temp_dir ():
866
988
dirs = glob .glob ('./temp_*' )
867
989
for dir_path in dirs :
0 commit comments