12
12
13
13
Created on 30 jun. 2016
14
14
"""
15
+ import gzip
15
16
from pathlib import Path
16
17
from unittest .mock import patch
17
18
from urllib .parse import quote_plus , urlencode
18
19
19
- import gzip
20
20
import numpy as np
21
21
import pytest
22
+ from astropy .table import Table
22
23
from requests import HTTPError
23
24
24
- from astroquery .utils .tap .model .tapcolumn import TapColumn
25
-
25
+ from astroquery .utils .tap import taputils
26
26
from astroquery .utils .tap .conn .tests .DummyConnHandler import DummyConnHandler
27
27
from astroquery .utils .tap .conn .tests .DummyResponse import DummyResponse
28
28
from astroquery .utils .tap .core import TapPlus
29
- from astroquery .utils .tap import taputils
30
- from astropy .table import Table
29
+ from astroquery .utils .tap .model .tapcolumn import TapColumn
31
30
32
31
33
32
def read_file (filename ):
@@ -115,8 +114,8 @@ def test_load_tables_parameters():
115
114
116
115
117
116
def test_load_table ():
118
- connHandler = DummyConnHandler ()
119
- tap = TapPlus (url = "http://test:1111/tap" , connhandler = connHandler )
117
+ conn_handler = DummyConnHandler ()
118
+ tap = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
120
119
121
120
# No arguments
122
121
with pytest .raises (Exception ):
@@ -128,7 +127,7 @@ def test_load_table():
128
127
tableName = "table1"
129
128
fullQualifiedTableName = f"{ tableSchema } .{ tableName } "
130
129
tableRequest = f"tables?tables={ fullQualifiedTableName } "
131
- connHandler .set_response (tableRequest , responseLoadTable )
130
+ conn_handler .set_response (tableRequest , responseLoadTable )
132
131
133
132
with pytest .raises (Exception ):
134
133
tap .load_table (fullQualifiedTableName )
@@ -871,26 +870,26 @@ def test_rename_table():
871
870
872
871
873
872
def __find_table (schemaName , tableName , tables ):
874
- qualifiedName = f"{ schemaName } .{ tableName } "
875
- for table in ( tables ) :
876
- if table .get_qualified_name () == qualifiedName :
873
+ qualified_name = f"{ schemaName } .{ tableName } "
874
+ for table in tables :
875
+ if table .get_qualified_name () == qualified_name :
877
876
return table
878
877
# not found: raise exception
879
- pytest .fail (f"Table '{ qualifiedName } ' not found" )
878
+ pytest .fail (f"Table '{ qualified_name } ' not found" )
880
879
881
880
882
- def __find_column (columnName , columns ):
883
- for c in ( columns ) :
884
- if c .name == columnName :
881
+ def __find_column (column_name , columns ):
882
+ for c in columns :
883
+ if c .name == column_name :
885
884
return c
886
885
# not found: raise exception
887
- pytest .fail (f"Column '{ columnName } ' not found" )
886
+ pytest .fail (f"Column '{ column_name } ' not found" )
888
887
889
888
890
- def __check_column (column , description , unit , dataType , flag ):
889
+ def __check_column (column , description , unit , data_type , flag ):
891
890
assert column .description == description
892
891
assert column .unit == unit
893
- assert column .data_type == dataType
892
+ assert column .data_type == data_type
894
893
assert column .flag == flag
895
894
896
895
@@ -906,11 +905,11 @@ def __check_results_column(results, columnName, description, unit,
906
905
def test_login (mock_login ):
907
906
conn_handler = DummyConnHandler ()
908
907
tap = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
909
- tap .login ("user" , "password" )
908
+ tap .login (user = "user" , password = "password" )
910
909
assert (mock_login .call_count == 1 )
911
910
mock_login .side_effect = HTTPError ("Login error" )
912
911
with pytest .raises (HTTPError ):
913
- tap .login ("user" , "password" )
912
+ tap .login (user = "user" , password = "password" )
914
913
assert (mock_login .call_count == 2 )
915
914
916
915
@@ -923,7 +922,7 @@ def test_login_gui(mock_login_gui, mock_login):
923
922
assert (mock_login_gui .call_count == 0 )
924
923
mock_login_gui .side_effect = HTTPError ("Login error" )
925
924
with pytest .raises (HTTPError ):
926
- tap .login ("user" , "password" )
925
+ tap .login (user = "user" , password = "password" )
927
926
assert (mock_login .call_count == 1 )
928
927
929
928
@@ -951,3 +950,33 @@ def test_upload_table():
951
950
tap .upload_table (upload_resource = table , table_name = table_name )
952
951
953
952
assert str (exc_info .value ) == f"Table name is not allowed to contain a dot: { table_name } "
953
+
954
+
955
+ def test___findCookieInHeader ():
956
+ conn_handler = DummyConnHandler ()
957
+ tap = TapPlus (url = "http://test:1111/tap" , connhandler = conn_handler )
958
+
959
+ headers = [('Date' , 'Sat, 12 Apr 2025 05:10:47 GMT' ),
960
+ ('Server' , 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43' ),
961
+ ('Set-Cookie' , 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly' ),
962
+ ('X-Content-Type-Options' , 'nosniff' ), ('X-XSS-Protection' , '0' ),
963
+ ('Cache-Control' , 'no-cache, no-store, max-age=0, must-revalidate' ), ('Pragma' , 'no-cache' ),
964
+ ('Expires' , '0' ), ('X-Frame-Options' , 'SAMEORIGIN' ),
965
+ ('Set-Cookie' , 'SESSION=ZjQ3MjIzMDAtNjNiYy00Mj; Path=/data-server; Secure; HttpOnly; SameSite=Lax' ),
966
+ ('Transfer-Encoding' , 'chunked' ), ('Content-Type' , 'text/plain; charset=UTF-8' )]
967
+
968
+ result = tap ._Tap__findCookieInHeader (headers )
969
+
970
+ assert (result == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj" )
971
+
972
+ headers = [('Date' , 'Sat, 12 Apr 2025 05:10:47 GMT' ),
973
+ ('Server' , 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43' ),
974
+ ('Set-Cookie' , 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly' ),
975
+ ('X-Content-Type-Options' , 'nosniff' ), ('X-XSS-Protection' , '0' ),
976
+ ('Cache-Control' , 'no-cache, no-store, max-age=0, must-revalidate' ), ('Pragma' , 'no-cache' ),
977
+ ('Expires' , '0' ), ('X-Frame-Options' , 'SAMEORIGIN' ),
978
+ ('Transfer-Encoding' , 'chunked' ), ('Content-Type' , 'text/plain; charset=UTF-8' )]
979
+
980
+ result = tap ._Tap__findCookieInHeader (headers )
981
+
982
+ assert (result == "JSESSIONID=E677B51BA5C4837347D1E17D4E36647E" )
0 commit comments