12
12
13
13
Created on 30 jun. 2016
14
14
"""
15
- import os
15
+ from pathlib import Path
16
16
from unittest .mock import patch
17
17
from urllib .parse import quote_plus , urlencode
18
18
25
25
from astroquery .utils .tap .conn .tests .DummyConnHandler import DummyConnHandler
26
26
from astroquery .utils .tap .conn .tests .DummyResponse import DummyResponse
27
27
from astroquery .utils .tap .core import TapPlus
28
- from astroquery .utils .tap .xmlparser import utils
29
28
from astroquery .utils .tap import taputils
30
29
31
30
32
- def data_path (filename ):
33
- data_dir = os .path .join (os .path .dirname (__file__ ), 'data' )
34
- return os .path .join (data_dir , filename )
31
+ TEST_DATA = {f .name : f .read_text () for f in Path (__file__ ).with_name ("data" ).iterdir ()}
35
32
36
33
37
34
def test_load_tables ():
38
35
connHandler = DummyConnHandler ()
39
36
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
40
37
responseLoadTable = DummyResponse (500 )
41
- tableDataFile = data_path ('test_tables.xml' )
42
- tableData = utils .read_file_content (tableDataFile )
43
- responseLoadTable .set_data (method = 'GET' , body = tableData )
38
+ responseLoadTable .set_data (method = 'GET' , body = TEST_DATA ["test_tables.xml" ])
44
39
tableRequest = "tables"
45
40
connHandler .set_response (tableRequest , responseLoadTable )
46
41
with pytest .raises (Exception ):
@@ -77,9 +72,7 @@ def test_load_tables_parameters():
77
72
connHandler = DummyConnHandler ()
78
73
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
79
74
responseLoadTable = DummyResponse (200 )
80
- tableDataFile = data_path ('test_tables.xml' )
81
- tableData = utils .read_file_content (tableDataFile )
82
- responseLoadTable .set_data (method = 'GET' , body = tableData )
75
+ responseLoadTable .set_data (method = 'GET' , body = TEST_DATA ["test_tables.xml" ])
83
76
tableRequest = "tables"
84
77
connHandler .set_response (tableRequest , responseLoadTable )
85
78
@@ -125,9 +118,7 @@ def test_load_table():
125
118
tap .load_table ()
126
119
127
120
responseLoadTable = DummyResponse (500 )
128
- tableDataFile = data_path ('test_table1.xml' )
129
- tableData = utils .read_file_content (tableDataFile )
130
- responseLoadTable .set_data (method = 'GET' , body = tableData )
121
+ responseLoadTable .set_data (method = 'GET' , body = TEST_DATA ["test_table1.xml" ])
131
122
tableSchema = "public"
132
123
tableName = "table1"
133
124
fullQualifiedTableName = f"{ tableSchema } .{ tableName } "
@@ -153,9 +144,7 @@ def test_launch_sync_job():
153
144
connHandler = DummyConnHandler ()
154
145
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
155
146
responseLaunchJob = DummyResponse (500 )
156
- jobDataFile = data_path ('job_1.vot' )
157
- jobData = utils .read_file_content (jobDataFile )
158
- responseLaunchJob .set_data (method = 'POST' , body = jobData )
147
+ responseLaunchJob .set_data (method = 'POST' , body = TEST_DATA ["job_1.vot" ])
159
148
query = 'select top 5 * from table'
160
149
dictTmp = {
161
150
"REQUEST" : "doQuery" ,
@@ -229,9 +218,7 @@ def test_launch_sync_job_redirect():
229
218
connHandler .set_response (jobRequest , responseLaunchJob )
230
219
# Results response
231
220
responseResultsJob = DummyResponse (500 )
232
- jobDataFile = data_path ('job_1.vot' )
233
- jobData = utils .read_file_content (jobDataFile )
234
- responseResultsJob .set_data (method = 'GET' , body = jobData )
221
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
235
222
connHandler .set_response (resultsReq , responseResultsJob )
236
223
237
224
with pytest .raises (Exception ):
@@ -316,9 +303,7 @@ def test_launch_async_job():
316
303
connHandler .set_response (req , responsePhase )
317
304
# Results response
318
305
responseResultsJob = DummyResponse (500 )
319
- jobDataFile = data_path ('job_1.vot' )
320
- jobData = utils .read_file_content (jobDataFile )
321
- responseResultsJob .set_data (method = 'GET' , body = jobData )
306
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
322
307
req = f"async/{ jobid } /results/result"
323
308
connHandler .set_response (req , responseResultsJob )
324
309
@@ -398,9 +383,7 @@ def test_start_job():
398
383
connHandler .set_response (req , responsePhase )
399
384
# Results response
400
385
responseResultsJob = DummyResponse (200 )
401
- jobDataFile = data_path ('job_1.vot' )
402
- jobData = utils .read_file_content (jobDataFile )
403
- responseResultsJob .set_data (method = 'GET' , body = jobData )
386
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
404
387
req = f"async/{ jobid } /results/result"
405
388
connHandler .set_response (req , responseResultsJob )
406
389
@@ -490,9 +473,7 @@ def test_job_parameters():
490
473
connHandler .set_response (req , responsePhase )
491
474
# Results response
492
475
responseResultsJob = DummyResponse (200 )
493
- jobDataFile = data_path ('job_1.vot' )
494
- jobData = utils .read_file_content (jobDataFile )
495
- responseResultsJob .set_data (method = 'GET' , body = jobData )
476
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
496
477
req = f"async/{ jobid } /results/result"
497
478
connHandler .set_response (req , responseResultsJob )
498
479
@@ -526,9 +507,7 @@ def test_list_async_jobs():
526
507
connHandler = DummyConnHandler ()
527
508
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
528
509
response = DummyResponse (500 )
529
- jobDataFile = data_path ('jobs_list.xml' )
530
- jobData = utils .read_file_content (jobDataFile )
531
- response .set_data (method = 'GET' , body = jobData )
510
+ response .set_data (method = 'GET' , body = TEST_DATA ["jobs_list.xml" ])
532
511
req = "async"
533
512
connHandler .set_response (req , response )
534
513
with pytest .raises (Exception ):
@@ -549,9 +528,7 @@ def test_data():
549
528
data_context = "data" ,
550
529
connhandler = connHandler )
551
530
responseResultsJob = DummyResponse (200 )
552
- jobDataFile = data_path ('job_1.vot' )
553
- jobData = utils .read_file_content (jobDataFile )
554
- responseResultsJob .set_data (method = 'GET' , body = jobData )
531
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
555
532
req = "?ID=1%2C2&format=votable"
556
533
connHandler .set_response (req , responseResultsJob )
557
534
req = "?ID=1%2C2"
@@ -585,9 +562,7 @@ def test_datalink():
585
562
datalink_context = "datalink" ,
586
563
connhandler = connHandler )
587
564
responseResultsJob = DummyResponse (200 )
588
- jobDataFile = data_path ('job_1.vot' )
589
- jobData = utils .read_file_content (jobDataFile )
590
- responseResultsJob .set_data (method = 'GET' , body = jobData )
565
+ responseResultsJob .set_data (method = 'GET' , body = TEST_DATA ["job_1.vot" ])
591
566
req = "links?ID=1,2"
592
567
connHandler .set_response (req , responseResultsJob )
593
568
@@ -750,9 +725,7 @@ def test_update_user_table():
750
725
connHandler = DummyConnHandler ()
751
726
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
752
727
dummyResponse = DummyResponse (200 )
753
- tableDataFile = data_path ('test_table_update.xml' )
754
- tableData = utils .read_file_content (tableDataFile )
755
- dummyResponse .set_data (method = 'GET' , body = tableData )
728
+ dummyResponse .set_data (method = 'GET' , body = TEST_DATA ["test_table_update.xml" ])
756
729
tableRequest = f"tables?tables={ tableName } "
757
730
connHandler .set_response (tableRequest , dummyResponse )
758
731
@@ -818,9 +791,7 @@ def test_rename_table():
818
791
connHandler = DummyConnHandler ()
819
792
tap = TapPlus ("http://test:1111/tap" , connhandler = connHandler )
820
793
dummyResponse = DummyResponse (200 )
821
- tableDataFile = data_path ('test_table_rename.xml' )
822
- tableData = utils .read_file_content (tableDataFile )
823
- dummyResponse .set_data (method = 'GET' , body = tableData )
794
+ dummyResponse .set_data (method = 'GET' , body = TEST_DATA ["test_table_rename.xml" ])
824
795
825
796
with pytest .raises (Exception ):
826
797
tap .rename_table ()
0 commit comments