@@ -969,6 +969,10 @@ def test___findCookieInHeader():
969
969
970
970
assert (result == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj" )
971
971
972
+ result = tap ._Tap__findCookieInHeader (headers , verbose = True )
973
+
974
+ assert (result == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj" )
975
+
972
976
headers = [('Date' , 'Sat, 12 Apr 2025 05:10:47 GMT' ),
973
977
('Server' , 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43' ),
974
978
('Set-Cookie' , 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly' ),
@@ -981,6 +985,29 @@ def test___findCookieInHeader():
981
985
982
986
assert (result == "JSESSIONID=E677B51BA5C4837347D1E17D4E36647E" )
983
987
988
+ headers = [('Date' , 'Sat, 12 Apr 2025 05:10:47 GMT' ),
989
+ ('Server' , 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43' ),
990
+ ('X-Content-Type-Options' , 'nosniff' ), ('X-XSS-Protection' , '0' ),
991
+ ('Cache-Control' , 'no-cache, no-store, max-age=0, must-revalidate' ), ('Pragma' , 'no-cache' ),
992
+ ('Expires' , '0' ), ('X-Frame-Options' , 'SAMEORIGIN' ),
993
+ ('Transfer-Encoding' , 'chunked' ), ('Content-Type' , 'text/plain; charset=UTF-8' )]
994
+
995
+ result = tap ._Tap__findCookieInHeader (headers )
996
+
997
+ assert (result is None )
998
+
999
+ headers = [('Date' , 'Sat, 12 Apr 2025 05:10:47 GMT' ),
1000
+ ('Server' , 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43' ),
1001
+ ('Set-Cookie' , 'HOLA=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly' ),
1002
+ ('X-Content-Type-Options' , 'nosniff' ), ('X-XSS-Protection' , '0' ),
1003
+ ('Cache-Control' , 'no-cache, no-store, max-age=0, must-revalidate' ), ('Pragma' , 'no-cache' ),
1004
+ ('Expires' , '0' ), ('X-Frame-Options' , 'SAMEORIGIN' ),
1005
+ ('Transfer-Encoding' , 'chunked' ), ('Content-Type' , 'text/plain; charset=UTF-8' )]
1006
+
1007
+ result = tap ._Tap__findCookieInHeader (headers )
1008
+
1009
+ assert (result is None )
1010
+
984
1011
985
1012
def test_upload_table ():
986
1013
conn_handler = DummyConnHandler ()
@@ -999,19 +1026,19 @@ def test_upload_table():
999
1026
table_name = 'my_table'
1000
1027
file_csv = get_pkg_data_filename (os .path .join ("data" , 'test_upload_file' , '1744351221317O-result.csv' ),
1001
1028
package = package )
1002
- job = tap .upload_table (upload_resource = file_csv , table_name = table_name )
1029
+ job = tap .upload_table (upload_resource = file_csv , table_name = table_name , format = 'csv' )
1003
1030
1004
1031
assert (job .jobid == jobid )
1005
1032
1006
1033
file_ecsv = get_pkg_data_filename (os .path .join ("data" , 'test_upload_file' , '1744351221317O-result.ecsv' ),
1007
1034
package = package )
1008
- job = tap .upload_table (upload_resource = file_ecsv , table_name = table_name )
1035
+ job = tap .upload_table (upload_resource = file_ecsv , table_name = table_name , format = 'ecsv' )
1009
1036
1010
1037
assert (job .jobid == jobid )
1011
1038
1012
1039
file_fits = get_pkg_data_filename (os .path .join ("data" , 'test_upload_file' , '1744351221317O-result.fits' ),
1013
1040
package = package )
1014
- job = tap .upload_table (upload_resource = file_fits , table_name = table_name )
1041
+ job = tap .upload_table (upload_resource = file_fits , table_name = table_name , format = 'fits' )
1015
1042
1016
1043
assert (job .jobid == jobid )
1017
1044
@@ -1023,15 +1050,57 @@ def test_upload_table():
1023
1050
1024
1051
file_plain_vot = get_pkg_data_filename (os .path .join ("data" , 'test_upload_file' , '1744351221317O-result_plain.vot' ),
1025
1052
package = package )
1026
- job = tap .upload_table (upload_resource = file_plain_vot , table_name = table_name )
1053
+ job = tap .upload_table (upload_resource = file_plain_vot , table_name = table_name , table_description = "my description" )
1027
1054
1028
1055
assert (job .jobid == jobid )
1029
1056
1057
+ # check invalid file
1030
1058
file_json = get_pkg_data_filename (os .path .join ("data" , 'test_upload_file' , '1744351221317O-result.json' ),
1031
1059
package = package )
1032
1060
1033
1061
with pytest .raises (IORegistryError ) as exc_info :
1034
- job = tap .upload_table (upload_resource = file_json , table_name = table_name )
1062
+ job = tap .upload_table (upload_resource = file_json , table_name = table_name , format = 'json' )
1035
1063
1036
1064
argument_ = "Format could not be identified based on the file name or contents, please provide a 'format' argument."
1037
1065
assert (argument_ in str (exc_info .value ))
1066
+
1067
+ # Make use of an astropy table
1068
+ table = Table .read (str (file_ecsv ))
1069
+ job = tap .upload_table (upload_resource = table , table_name = table_name , table_description = "my description" ,
1070
+ format = 'ecsv' )
1071
+
1072
+ assert (job .jobid == jobid )
1073
+
1074
+ # check missing parameters
1075
+ with pytest .raises (ValueError ) as exc_info :
1076
+ job = tap .upload_table (upload_resource = file_json , table_name = None )
1077
+
1078
+ argument_ = "Missing mandatory argument 'table_name'"
1079
+ assert (argument_ in str (exc_info .value ))
1080
+
1081
+ with pytest .raises (ValueError ) as exc_info :
1082
+ job = tap .upload_table (upload_resource = None , table_name = "my_table" )
1083
+
1084
+ argument_ = "Missing mandatory argument 'upload_resource'"
1085
+ assert (argument_ in str (exc_info .value ))
1086
+
1087
+ job = tap .upload_table (upload_resource = "https://gea.esa.esac.int" , table_name = table_name ,
1088
+ table_description = "my description" ,
1089
+ format = 'ecsv' )
1090
+
1091
+ assert (job .jobid == jobid )
1092
+
1093
+ # check exception
1094
+ dummyResponse = DummyResponse (500 )
1095
+ conn_handler .set_default_response (dummyResponse )
1096
+ launchResponseHeaders = [
1097
+ ['location' , f'http://test:1111/tap/async/{ jobid } ' ],
1098
+ ['multipart/form-data' , 'boundary={aaaaaaaaaaaaaa}' ]
1099
+ ]
1100
+ dummyResponse .set_data (method = 'POST' , headers = launchResponseHeaders )
1101
+
1102
+ with pytest .raises (AttributeError ) as exc_info :
1103
+ job = tap .upload_table (upload_resource = file_csv , table_name = table_name , format = 'csv' )
1104
+
1105
+ argument_ = "'NoneType' object has no attribute 'decode'"
1106
+ assert (argument_ in str (exc_info .value ))
0 commit comments