@@ -186,6 +186,57 @@ def mock_datalink_querier():
186
186
return GaiaClass (tap_plus_conn_handler = conn_handler , datalink_handler = tapplus , show_server_messages = False )
187
187
188
188
189
+ @pytest .fixture (scope = "module" )
190
+ def mock_datalink_querier_ecsv ():
191
+ conn_handler = DummyConnHandler ()
192
+ tapplus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
193
+
194
+ launch_response = DummyResponse (200 )
195
+ launch_response .set_data (method = "POST" , body = DL_PRODUCTS_ECSV )
196
+ # The query contains decimals: default response is more robust.
197
+ conn_handler .set_default_response (launch_response )
198
+ conn_handler .set_response (
199
+ '?DATA_STRUCTURE=INDIVIDUAL&FORMAT=ecsv&ID=5937083312263887616&RELEASE=Gaia+DR3&RETRIEVAL_TYPE=ALL'
200
+ '&USE_ZIP_ALWAYS=true&VALID_DATA=false' ,
201
+ launch_response )
202
+
203
+ return GaiaClass (tap_plus_conn_handler = conn_handler , datalink_handler = tapplus , show_server_messages = False )
204
+
205
+
206
+ @pytest .fixture (scope = "module" )
207
+ def mock_datalink_querier_csv ():
208
+ conn_handler = DummyConnHandler ()
209
+ tapplus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
210
+
211
+ launch_response = DummyResponse (200 )
212
+ launch_response .set_data (method = "POST" , body = DL_PRODUCTS_CSV )
213
+ # The query contains decimals: default response is more robust.
214
+ conn_handler .set_default_response (launch_response )
215
+ conn_handler .set_response (
216
+ '?DATA_STRUCTURE=INDIVIDUAL&FORMAT=csv&ID=5937083312263887616&RELEASE=Gaia+DR3&RETRIEVAL_TYPE=ALL'
217
+ '&USE_ZIP_ALWAYS=true&VALID_DATA=false' ,
218
+ launch_response )
219
+
220
+ return GaiaClass (tap_plus_conn_handler = conn_handler , datalink_handler = tapplus , show_server_messages = False )
221
+
222
+
223
+ @pytest .fixture (scope = "module" )
224
+ def mock_datalink_querier_fits ():
225
+ conn_handler = DummyConnHandler ()
226
+ tapplus = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
227
+
228
+ launch_response = DummyResponse (200 )
229
+ launch_response .set_data (method = "POST" , body = DL_PRODUCTS_FITS )
230
+ # The query contains decimals: default response is more robust.
231
+ conn_handler .set_default_response (launch_response )
232
+ conn_handler .set_response (
233
+ '?DATA_STRUCTURE=INDIVIDUAL&FORMAT=fits&ID=5937083312263887616&RELEASE=Gaia+DR3&RETRIEVAL_TYPE=ALL'
234
+ '&USE_ZIP_ALWAYS=true&VALID_DATA=false' ,
235
+ launch_response )
236
+
237
+ return GaiaClass (tap_plus_conn_handler = conn_handler , datalink_handler = tapplus , show_server_messages = False )
238
+
239
+
189
240
@pytest .fixture (scope = "module" )
190
241
def mock_querier_ecsv ():
191
242
conn_handler = DummyConnHandler ()
@@ -730,12 +781,108 @@ def test_cone_search_and_changing_MAIN_GAIA_TABLE(mock_querier_async):
730
781
assert "name_from_class" in job .parameters ["query" ]
731
782
732
783
733
- def test_load_data (mock_datalink_querier ):
734
- mock_datalink_querier .load_data (ids = [5937083312263887616 ], data_release = 'Gaia DR3' , data_structure = 'INDIVIDUAL' ,
735
- retrieval_type = "ALL" ,
736
- linking_parameter = 'SOURCE_ID' , valid_data = False , band = None ,
737
- avoid_datatype_check = False ,
738
- format = "votable" , dump_to_file = True , overwrite_output_file = True , verbose = False )
784
+ def test_load_data_vot (mock_datalink_querier ):
785
+ result_dict = mock_datalink_querier .load_data (ids = [5937083312263887616 ], data_release = 'Gaia DR3' ,
786
+ data_structure = 'INDIVIDUAL' ,
787
+ retrieval_type = "ALL" ,
788
+ linking_parameter = 'SOURCE_ID' , valid_data = False , band = None ,
789
+ avoid_datatype_check = False ,
790
+ format = "votable" , dump_to_file = True , overwrite_output_file = True ,
791
+ verbose = False )
792
+
793
+ assert os .path .exists ('datalink_output.zip' )
794
+
795
+ extracted_files = []
796
+
797
+ with zipfile .ZipFile ('datalink_output.zip' , "r" ) as zip_ref :
798
+ extracted_files .extend (zip_ref .namelist ())
799
+
800
+ assert len (extracted_files ) == 3
801
+
802
+ assert len (result_dict ) == 3
803
+
804
+ files = list (result_dict .keys ())
805
+ files .sort ()
806
+ assert files [0 ] == 'MCMC_MSC-Gaia DR3 5937083312263887616.xml'
807
+ assert files [1 ] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.xml'
808
+ assert files [2 ] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.xml'
809
+
810
+ os .remove (os .path .join (os .getcwd (), 'datalink_output.zip' ))
811
+
812
+ assert not os .path .exists ('datalink_output.zip' )
813
+
814
+
815
+ def test_load_data_ecsv (mock_datalink_querier_ecsv ):
816
+ result_dict = mock_datalink_querier .load_data (ids = [5937083312263887616 ], data_release = 'Gaia DR3' ,
817
+ data_structure = 'INDIVIDUAL' ,
818
+ retrieval_type = "ALL" ,
819
+ linking_parameter = 'SOURCE_ID' , valid_data = False , band = None ,
820
+ avoid_datatype_check = False ,
821
+ format = "ecsv" , dump_to_file = True , overwrite_output_file = True ,
822
+ verbose = False )
823
+
824
+ assert os .path .exists ('datalink_output.zip' )
825
+
826
+ extracted_files = []
827
+
828
+ with zipfile .ZipFile ('datalink_output.zip' , "r" ) as zip_ref :
829
+ extracted_files .extend (zip_ref .namelist ())
830
+
831
+ assert len (extracted_files ) == 3
832
+
833
+ assert len (result_dict ) == 3
834
+
835
+ files = list (result_dict .keys ())
836
+ files .sort ()
837
+ assert files [0 ] == 'MCMC_MSC-Gaia DR3 5937083312263887616.ecsv'
838
+ assert files [1 ] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.ecsv'
839
+ assert files [2 ] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.ecsv'
840
+
841
+ os .remove (os .path .join (os .getcwd (), 'datalink_output.zip' ))
842
+
843
+ assert not os .path .exists ('datalink_output.zip' )
844
+
845
+
846
+ def test_load_data_csv (mock_datalink_querier_ecsv ):
847
+ result_dict = mock_datalink_querier .load_data (ids = [5937083312263887616 ], data_release = 'Gaia DR3' ,
848
+ data_structure = 'INDIVIDUAL' ,
849
+ retrieval_type = "ALL" ,
850
+ linking_parameter = 'SOURCE_ID' , valid_data = False , band = None ,
851
+ avoid_datatype_check = False ,
852
+ format = "csv" , dump_to_file = True , overwrite_output_file = True ,
853
+ verbose = False )
854
+
855
+ assert os .path .exists ('datalink_output.zip' )
856
+
857
+ extracted_files = []
858
+
859
+ with zipfile .ZipFile ('datalink_output.zip' , "r" ) as zip_ref :
860
+ extracted_files .extend (zip_ref .namelist ())
861
+
862
+ assert len (extracted_files ) == 3
863
+
864
+ assert len (result_dict ) == 3
865
+
866
+ files = list (result_dict .keys ())
867
+ files .sort ()
868
+ assert files [0 ] == 'MCMC_MSC-Gaia DR3 5937083312263887616.csv'
869
+ assert files [1 ] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.csv'
870
+ assert files [2 ] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.csv'
871
+
872
+ os .remove (os .path .join (os .getcwd (), 'datalink_output.zip' ))
873
+
874
+ assert not os .path .exists ('datalink_output.zip' )
875
+
876
+
877
+ @pytest .mark .skip (reason = "Thes fits files generate an error relatate to the unit 'log(cm.s**-2)" )
878
+ def test_load_data_fits (mock_datalink_querier_fits ):
879
+ result_dict = mock_datalink_querier .load_data (ids = [5937083312263887616 ], data_release = 'Gaia DR3' ,
880
+ data_structure = 'INDIVIDUAL' ,
881
+ retrieval_type = "ALL" ,
882
+ linking_parameter = 'SOURCE_ID' , valid_data = False , band = None ,
883
+ avoid_datatype_check = False ,
884
+ format = "fits" , dump_to_file = True , overwrite_output_file = True ,
885
+ verbose = False )
739
886
740
887
assert os .path .exists ('datalink_output.zip' )
741
888
@@ -746,6 +893,14 @@ def test_load_data(mock_datalink_querier):
746
893
747
894
assert len (extracted_files ) == 3
748
895
896
+ assert len (result_dict ) == 3
897
+
898
+ files = list (result_dict .keys ())
899
+ files .sort ()
900
+ assert files [0 ] == 'MCMC_MSC-Gaia DR3 5937083312263887616.fits'
901
+ assert files [1 ] == 'XP_CONTINUOUS-Gaia DR3 5937083312263887616.fits'
902
+ assert files [2 ] == 'XP_SAMPLED-Gaia DR3 5937083312263887616.fits'
903
+
749
904
os .remove (os .path .join (os .getcwd (), 'datalink_output.zip' ))
750
905
751
906
assert not os .path .exists ('datalink_output.zip' )
0 commit comments