Skip to content

Commit 2caf84a

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
GAIAPCR-1341 New tests
1 parent 1578714 commit 2caf84a

File tree

2 files changed

+87
-21
lines changed

2 files changed

+87
-21
lines changed

astroquery/utils/tap/conn/tests/test_conn.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,40 @@ def test_login():
115115
assert r.get_method() == 'POST'
116116
assert r.get_context() == context
117117
assert r.get_body() == data
118+
119+
120+
def test_find_header():
121+
host = "testHost"
122+
tap = TapConn(ishttps=False, host=host)
123+
124+
headers = [('Date', 'Sat, 12 Apr 2025 05:10:47 GMT'),
125+
('Server', 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43'),
126+
('Set-Cookie', 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly'),
127+
('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'),
128+
('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'), ('Pragma', 'no-cache'),
129+
('Expires', '0'), ('X-Frame-Options', 'SAMEORIGIN'), ('Set-Cookie',
130+
'SESSION=ZjQ3MjIzMDAtNjNiYy00Mjk3LTk5YzctNjczMGY5NWMxOGU3; Path=/data-server; Secure; HttpOnly; SameSite=Lax'),
131+
('Transfer-Encoding', 'chunked'), ('Content-Type', 'text/plain; charset=UTF-8')]
132+
key = 'Set-Cookie'
133+
result = tap.find_header(headers, key)
134+
135+
assert (result == "JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly")
136+
137+
138+
def test_find_all_headers():
139+
host = "testHost"
140+
tap = TapConn(ishttps=False, host=host)
141+
142+
headers = [('Date', 'Sat, 12 Apr 2025 05:10:47 GMT'),
143+
('Server', 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43'),
144+
('Set-Cookie', 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly'),
145+
('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '0'),
146+
('Cache-Control', 'no-cache, no-store, max-age=0, must-revalidate'), ('Pragma', 'no-cache'),
147+
('Expires', '0'), ('X-Frame-Options', 'SAMEORIGIN'),
148+
('Set-Cookie', 'SESSION=ZjQ3MjIzMDAtNjNiYy00Mj; Path=/data-server; Secure; HttpOnly; SameSite=Lax'),
149+
('Transfer-Encoding', 'chunked'), ('Content-Type', 'text/plain; charset=UTF-8')]
150+
key = 'Set-Cookie'
151+
result = tap.find_all_headers(headers, key)
152+
153+
assert (result[0] == "JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly")
154+
assert (result[1] == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj; Path=/data-server; Secure; HttpOnly; SameSite=Lax")

astroquery/utils/tap/tests/test_tap.py

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
1313
Created on 30 jun. 2016
1414
"""
15+
import gzip
1516
from pathlib import Path
1617
from unittest.mock import patch
1718
from urllib.parse import quote_plus, urlencode
1819

19-
import gzip
2020
import numpy as np
2121
import pytest
22+
from astropy.table import Table
2223
from requests import HTTPError
2324

24-
from astroquery.utils.tap.model.tapcolumn import TapColumn
25-
25+
from astroquery.utils.tap import taputils
2626
from astroquery.utils.tap.conn.tests.DummyConnHandler import DummyConnHandler
2727
from astroquery.utils.tap.conn.tests.DummyResponse import DummyResponse
2828
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
3130

3231

3332
def read_file(filename):
@@ -115,8 +114,8 @@ def test_load_tables_parameters():
115114

116115

117116
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)
120119

121120
# No arguments
122121
with pytest.raises(Exception):
@@ -128,7 +127,7 @@ def test_load_table():
128127
tableName = "table1"
129128
fullQualifiedTableName = f"{tableSchema}.{tableName}"
130129
tableRequest = f"tables?tables={fullQualifiedTableName}"
131-
connHandler.set_response(tableRequest, responseLoadTable)
130+
conn_handler.set_response(tableRequest, responseLoadTable)
132131

133132
with pytest.raises(Exception):
134133
tap.load_table(fullQualifiedTableName)
@@ -871,26 +870,26 @@ def test_rename_table():
871870

872871

873872
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:
877876
return table
878877
# not found: raise exception
879-
pytest.fail(f"Table '{qualifiedName}' not found")
878+
pytest.fail(f"Table '{qualified_name}' not found")
880879

881880

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:
885884
return c
886885
# not found: raise exception
887-
pytest.fail(f"Column '{columnName}' not found")
886+
pytest.fail(f"Column '{column_name}' not found")
888887

889888

890-
def __check_column(column, description, unit, dataType, flag):
889+
def __check_column(column, description, unit, data_type, flag):
891890
assert column.description == description
892891
assert column.unit == unit
893-
assert column.data_type == dataType
892+
assert column.data_type == data_type
894893
assert column.flag == flag
895894

896895

@@ -906,11 +905,11 @@ def __check_results_column(results, columnName, description, unit,
906905
def test_login(mock_login):
907906
conn_handler = DummyConnHandler()
908907
tap = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
909-
tap.login("user", "password")
908+
tap.login(user="user", password="password")
910909
assert (mock_login.call_count == 1)
911910
mock_login.side_effect = HTTPError("Login error")
912911
with pytest.raises(HTTPError):
913-
tap.login("user", "password")
912+
tap.login(user="user", password="password")
914913
assert (mock_login.call_count == 2)
915914

916915

@@ -923,7 +922,7 @@ def test_login_gui(mock_login_gui, mock_login):
923922
assert (mock_login_gui.call_count == 0)
924923
mock_login_gui.side_effect = HTTPError("Login error")
925924
with pytest.raises(HTTPError):
926-
tap.login("user", "password")
925+
tap.login(user="user", password="password")
927926
assert (mock_login.call_count == 1)
928927

929928

@@ -951,3 +950,33 @@ def test_upload_table():
951950
tap.upload_table(upload_resource=table, table_name=table_name)
952951

953952
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

Comments
 (0)