Skip to content

Commit 3e488cd

Browse files
Jorge Fernandez Hernandezbsipocz
authored andcommitted
EUCLIDPCR-1971 Increase coverage
1 parent 05bd99f commit 3e488cd

File tree

2 files changed

+75
-6
lines changed

2 files changed

+75
-6
lines changed

astroquery/utils/tap/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ def __uploadTableMultipart(self, resource, *, table_name=None, table_description
14101410
"TABLE_DESC": str(table_description),
14111411
"FORMAT": 'votable'}
14121412
log.info(f"Sending file: {resource}")
1413-
if resource.lower() == 'votable':
1413+
if resource_format.lower() == 'votable':
14141414
with open(resource, "r") as f:
14151415
chunk = f.read()
14161416
files = [['FILE', os.path.basename(resource), chunk]]

astroquery/utils/tap/tests/test_tap.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,10 @@ def test___findCookieInHeader():
969969

970970
assert (result == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj")
971971

972+
result = tap._Tap__findCookieInHeader(headers, verbose=True)
973+
974+
assert (result == "SESSION=ZjQ3MjIzMDAtNjNiYy00Mj")
975+
972976
headers = [('Date', 'Sat, 12 Apr 2025 05:10:47 GMT'),
973977
('Server', 'Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips mod_jk/1.2.43'),
974978
('Set-Cookie', 'JSESSIONID=E677B51BA5C4837347D1E17D4E36647E; Path=/data-server; Secure; HttpOnly'),
@@ -981,6 +985,29 @@ def test___findCookieInHeader():
981985

982986
assert (result == "JSESSIONID=E677B51BA5C4837347D1E17D4E36647E")
983987

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+
9841011

9851012
def test_upload_table():
9861013
conn_handler = DummyConnHandler()
@@ -999,19 +1026,19 @@ def test_upload_table():
9991026
table_name = 'my_table'
10001027
file_csv = get_pkg_data_filename(os.path.join("data", 'test_upload_file', '1744351221317O-result.csv'),
10011028
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')
10031030

10041031
assert (job.jobid == jobid)
10051032

10061033
file_ecsv = get_pkg_data_filename(os.path.join("data", 'test_upload_file', '1744351221317O-result.ecsv'),
10071034
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')
10091036

10101037
assert (job.jobid == jobid)
10111038

10121039
file_fits = get_pkg_data_filename(os.path.join("data", 'test_upload_file', '1744351221317O-result.fits'),
10131040
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')
10151042

10161043
assert (job.jobid == jobid)
10171044

@@ -1023,15 +1050,57 @@ def test_upload_table():
10231050

10241051
file_plain_vot = get_pkg_data_filename(os.path.join("data", 'test_upload_file', '1744351221317O-result_plain.vot'),
10251052
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")
10271054

10281055
assert (job.jobid == jobid)
10291056

1057+
# check invalid file
10301058
file_json = get_pkg_data_filename(os.path.join("data", 'test_upload_file', '1744351221317O-result.json'),
10311059
package=package)
10321060

10331061
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')
10351063

10361064
argument_ = "Format could not be identified based on the file name or contents, please provide a 'format' argument."
10371065
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

Comments
 (0)