Skip to content

Commit af8d510

Browse files
authored
Merge pull request #2525 from eerovaher/shorter-tapplus-tests
Shorten `esa/jwst` and `gaia` tests
2 parents a750c43 + 040f676 commit af8d510

File tree

6 files changed

+108
-374
lines changed

6 files changed

+108
-374
lines changed

astroquery/esa/jwst/tests/test_jwsttap.py

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,10 @@ def test_query_region(self):
233233

234234
# Launch response: we use default response because the
235235
# query contains decimals
236-
responseLaunchJob = DummyResponse()
237-
responseLaunchJob.set_status_code(200)
238-
responseLaunchJob.set_message("OK")
236+
responseLaunchJob = DummyResponse(200)
239237
jobDataFile = data_path('job_1.vot')
240238
jobData = utils.read_file_content(jobDataFile)
241-
responseLaunchJob.set_data(method='POST',
242-
context=None,
243-
body=jobData,
244-
headers=None)
239+
responseLaunchJob.set_data(method='POST', body=jobData)
245240
# The query contains decimals: force default response
246241
connHandler.set_default_response(responseLaunchJob)
247242
sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree),
@@ -372,36 +367,21 @@ def test_query_region_async(self):
372367
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
373368
jobid = '12345'
374369
# Launch response
375-
responseLaunchJob = DummyResponse()
376-
responseLaunchJob.set_status_code(303)
377-
responseLaunchJob.set_message("OK")
370+
responseLaunchJob = DummyResponse(303)
378371
# list of list (httplib implementation for headers in response)
379372
launchResponseHeaders = [['location', 'http://test:1111/tap/async/' + jobid]]
380-
responseLaunchJob.set_data(method='POST',
381-
context=None,
382-
body=None,
383-
headers=launchResponseHeaders)
373+
responseLaunchJob.set_data(method='POST', headers=launchResponseHeaders)
384374
connHandler.set_default_response(responseLaunchJob)
385375
# Phase response
386-
responsePhase = DummyResponse()
387-
responsePhase.set_status_code(200)
388-
responsePhase.set_message("OK")
389-
responsePhase.set_data(method='GET',
390-
context=None,
391-
body="COMPLETED",
392-
headers=None)
376+
responsePhase = DummyResponse(200)
377+
responsePhase.set_data(method='GET', body="COMPLETED")
393378
req = "async/" + jobid + "/phase"
394379
connHandler.set_response(req, responsePhase)
395380
# Results response
396-
responseResultsJob = DummyResponse()
397-
responseResultsJob.set_status_code(200)
398-
responseResultsJob.set_message("OK")
381+
responseResultsJob = DummyResponse(200)
399382
jobDataFile = data_path('job_1.vot')
400383
jobData = utils.read_file_content(jobDataFile)
401-
responseResultsJob.set_data(method='GET',
402-
context=None,
403-
body=jobData,
404-
headers=None)
384+
responseResultsJob.set_data(method='GET', body=jobData)
405385
req = "async/" + jobid + "/results/result"
406386
connHandler.set_response(req, responseResultsJob)
407387
sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree),
@@ -461,15 +441,10 @@ def test_cone_search_sync(self):
461441
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
462442
# Launch response: we use default response because the
463443
# query contains decimals
464-
responseLaunchJob = DummyResponse()
465-
responseLaunchJob.set_status_code(200)
466-
responseLaunchJob.set_message("OK")
444+
responseLaunchJob = DummyResponse(200)
467445
jobDataFile = data_path('job_1.vot')
468446
jobData = utils.read_file_content(jobDataFile)
469-
responseLaunchJob.set_data(method='POST',
470-
context=None,
471-
body=jobData,
472-
headers=None)
447+
responseLaunchJob.set_data(method='POST', body=jobData)
473448
ra = 19.0
474449
dec = 20.0
475450
sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
@@ -553,40 +528,25 @@ def test_cone_search_async(self):
553528
tap = JwstClass(tap_plus_handler=tapplus, show_messages=False)
554529
jobid = '12345'
555530
# Launch response
556-
responseLaunchJob = DummyResponse()
557-
responseLaunchJob.set_status_code(303)
558-
responseLaunchJob.set_message("OK")
531+
responseLaunchJob = DummyResponse(303)
559532
# list of list (httplib implementation for headers in response)
560533
launchResponseHeaders = [['location', 'http://test:1111/tap/async/' + jobid]]
561-
responseLaunchJob.set_data(method='POST',
562-
context=None,
563-
body=None,
564-
headers=launchResponseHeaders)
534+
responseLaunchJob.set_data(method='POST', headers=launchResponseHeaders)
565535
ra = 19
566536
dec = 20
567537
sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
568538
radius = Quantity(1.0, u.deg)
569539
connHandler.set_default_response(responseLaunchJob)
570540
# Phase response
571-
responsePhase = DummyResponse()
572-
responsePhase.set_status_code(200)
573-
responsePhase.set_message("OK")
574-
responsePhase.set_data(method='GET',
575-
context=None,
576-
body="COMPLETED",
577-
headers=None)
541+
responsePhase = DummyResponse(200)
542+
responsePhase.set_data(method='GET', body="COMPLETED")
578543
req = "async/" + jobid + "/phase"
579544
connHandler.set_response(req, responsePhase)
580545
# Results response
581-
responseResultsJob = DummyResponse()
582-
responseResultsJob.set_status_code(200)
583-
responseResultsJob.set_message("OK")
546+
responseResultsJob = DummyResponse(200)
584547
jobDataFile = data_path('job_1.vot')
585548
jobData = utils.read_file_content(jobDataFile)
586-
responseResultsJob.set_data(method='GET',
587-
context=None,
588-
body=jobData,
589-
headers=None)
549+
responseResultsJob.set_data(method='GET', body=jobData)
590550
req = "async/" + jobid + "/results/result"
591551
connHandler.set_response(req, responseResultsJob)
592552
job = tap.cone_search(sc, radius, async_job=True)

astroquery/gaia/tests/test_gaiatap.py

Lines changed: 26 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,11 @@ class TestTap:
4444
def test_show_message(self):
4545
connHandler = DummyConnHandler()
4646

47-
dummy_response = DummyResponse()
48-
dummy_response.set_status_code(200)
49-
dummy_response.set_message("OK")
47+
dummy_response = DummyResponse(200)
5048

5149
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
5250

53-
dummy_response.set_data(method='GET',
54-
context=None,
55-
body=message_text,
56-
headers=None)
51+
dummy_response.set_data(method='GET', body=message_text)
5752
connHandler.set_default_response(dummy_response)
5853

5954
# show_server_messages
@@ -67,16 +62,11 @@ def test_query_object(self):
6762
conn_handler = DummyConnHandler()
6863
# Launch response: we use default response because the query contains
6964
# decimals
70-
dummy_response = DummyResponse()
71-
dummy_response.set_status_code(200)
72-
dummy_response.set_message("OK")
65+
dummy_response = DummyResponse(200)
7366

7467
message_text = "1653401204784D[type: -100,-1]=Gaia dev is under maintenance"
7568

76-
dummy_response.set_data(method='GET',
77-
context=None,
78-
body=message_text,
79-
headers=None)
69+
dummy_response.set_data(method='GET', body=message_text)
8070
conn_handler.set_default_response(dummy_response)
8171

8272
# show_server_messages
@@ -87,15 +77,10 @@ def test_query_object(self):
8777
tap = GaiaClass(conn_handler, tapplus, show_server_messages=True)
8878
# Launch response: we use default response because the query contains
8979
# decimals
90-
response_launch_job = DummyResponse()
91-
response_launch_job.set_status_code(200)
92-
response_launch_job.set_message("OK")
80+
response_launch_job = DummyResponse(200)
9381
job_data_file = data_path('job_1.vot')
9482
job_data = utils.read_file_content(job_data_file)
95-
response_launch_job.set_data(method='POST',
96-
context=None,
97-
body=job_data,
98-
headers=None)
83+
response_launch_job.set_data(method='POST', body=job_data)
9984
# The query contains decimals: force default response
10085
conn_handler.set_default_response(response_launch_job)
10186
sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree),
@@ -168,38 +153,23 @@ def test_query_object_async(self):
168153
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
169154
jobid = '12345'
170155
# Launch response
171-
response_launch_job = DummyResponse()
172-
response_launch_job.set_status_code(303)
173-
response_launch_job.set_message("OK")
156+
response_launch_job = DummyResponse(303)
174157
# list of list (httplib implementation for headers in response)
175158
launch_response_headers = [
176159
['location', 'http://test:1111/tap/async/' + jobid]
177160
]
178-
response_launch_job.set_data(method='POST',
179-
context=None,
180-
body=None,
181-
headers=launch_response_headers)
161+
response_launch_job.set_data(method='POST', headers=launch_response_headers)
182162
conn_handler.set_default_response(response_launch_job)
183163
# Phase response
184-
response_phase = DummyResponse()
185-
response_phase.set_status_code(200)
186-
response_phase.set_message("OK")
187-
response_phase.set_data(method='GET',
188-
context=None,
189-
body="COMPLETED",
190-
headers=None)
164+
response_phase = DummyResponse(200)
165+
response_phase.set_data(method='GET', body="COMPLETED")
191166
req = "async/" + jobid + "/phase"
192167
conn_handler.set_response(req, response_phase)
193168
# Results response
194-
response_results_job = DummyResponse()
195-
response_results_job.set_status_code(200)
196-
response_results_job.set_message("OK")
169+
response_results_job = DummyResponse(200)
197170
job_data_file = data_path('job_1.vot')
198171
job_data = utils.read_file_content(job_data_file)
199-
response_results_job.set_data(method='GET',
200-
context=None,
201-
body=job_data,
202-
headers=None)
172+
response_results_job.set_data(method='GET', body=job_data)
203173
req = "async/" + jobid + "/results/result"
204174
conn_handler.set_response(req, response_results_job)
205175
sc = SkyCoord(ra=29.0, dec=15.0, unit=(u.degree, u.degree),
@@ -263,15 +233,10 @@ def test_cone_search_sync(self):
263233
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
264234
# Launch response: we use default response because the query contains
265235
# decimals
266-
response_launch_job = DummyResponse()
267-
response_launch_job.set_status_code(200)
268-
response_launch_job.set_message("OK")
236+
response_launch_job = DummyResponse(200)
269237
job_data_file = data_path('job_1.vot')
270238
job_data = utils.read_file_content(job_data_file)
271-
response_launch_job.set_data(method='POST',
272-
context=None,
273-
body=job_data,
274-
headers=None)
239+
response_launch_job.set_data(method='POST', body=job_data)
275240
ra = 19.0
276241
dec = 20.0
277242
sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
@@ -316,42 +281,27 @@ def test_cone_search_async(self):
316281
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
317282
jobid = '12345'
318283
# Launch response
319-
response_launch_job = DummyResponse()
320-
response_launch_job.set_status_code(303)
321-
response_launch_job.set_message("OK")
284+
response_launch_job = DummyResponse(303)
322285
# list of list (httplib implementation for headers in response)
323286
launch_response_headers = [
324287
['location', 'http://test:1111/tap/async/' + jobid]
325288
]
326-
response_launch_job.set_data(method='POST',
327-
context=None,
328-
body=None,
329-
headers=launch_response_headers)
289+
response_launch_job.set_data(method='POST', headers=launch_response_headers)
330290
ra = 19
331291
dec = 20
332292
sc = SkyCoord(ra=ra, dec=dec, unit=(u.degree, u.degree), frame='icrs')
333293
radius = Quantity(1.0, u.deg)
334294
conn_handler.set_default_response(response_launch_job)
335295
# Phase response
336-
response_phase = DummyResponse()
337-
response_phase.set_status_code(200)
338-
response_phase.set_message("OK")
339-
response_phase.set_data(method='GET',
340-
context=None,
341-
body="COMPLETED",
342-
headers=None)
296+
response_phase = DummyResponse(200)
297+
response_phase.set_data(method='GET', body="COMPLETED")
343298
req = "async/" + jobid + "/phase"
344299
conn_handler.set_response(req, response_phase)
345300
# Results response
346-
response_results_job = DummyResponse()
347-
response_results_job.set_status_code(200)
348-
response_results_job.set_message("OK")
301+
response_results_job = DummyResponse(200)
349302
job_data_file = data_path('job_1.vot')
350303
job_data = utils.read_file_content(job_data_file)
351-
response_results_job.set_data(method='GET',
352-
context=None,
353-
body=job_data,
354-
headers=None)
304+
response_results_job.set_data(method='GET', body=job_data)
355305
req = "async/" + jobid + "/results/result"
356306
conn_handler.set_response(req, response_results_job)
357307
job = tap.cone_search_async(sc, radius)
@@ -474,38 +424,23 @@ def test_xmatch(self):
474424
tap = GaiaClass(conn_handler, tapplus, show_server_messages=False)
475425
jobid = '12345'
476426
# Launch response
477-
response_launch_job = DummyResponse()
478-
response_launch_job.set_status_code(303)
479-
response_launch_job.set_message("OK")
427+
response_launch_job = DummyResponse(303)
480428
# list of list (httplib implementation for headers in response)
481429
launch_response_headers = [
482430
['location', 'http://test:1111/tap/async/' + jobid]
483431
]
484-
response_launch_job.set_data(method='POST',
485-
context=None,
486-
body=None,
487-
headers=launch_response_headers)
432+
response_launch_job.set_data(method='POST', headers=launch_response_headers)
488433
conn_handler.set_default_response(response_launch_job)
489434
# Phase response
490-
response_phase = DummyResponse()
491-
response_phase.set_status_code(200)
492-
response_phase.set_message("OK")
493-
response_phase.set_data(method='GET',
494-
context=None,
495-
body="COMPLETED",
496-
headers=None)
435+
response_phase = DummyResponse(200)
436+
response_phase.set_data(method='GET', body="COMPLETED")
497437
req = "async/" + jobid + "/phase"
498438
conn_handler.set_response(req, response_phase)
499439
# Results response
500-
response_results_job = DummyResponse()
501-
response_results_job.set_status_code(200)
502-
response_results_job.set_message("OK")
440+
response_results_job = DummyResponse(200)
503441
job_data_file = data_path('job_1.vot')
504442
job_data = utils.read_file_content(job_data_file)
505-
response_results_job.set_data(method='GET',
506-
context=None,
507-
body=job_data,
508-
headers=None)
443+
response_results_job.set_data(method='GET', body=job_data)
509444
req = "async/" + jobid + "/results/result"
510445
conn_handler.set_response(req, response_results_job)
511446
query = ("SELECT crossmatch_positional(",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, name=None):
2929
self.cookie = None
3030
self.ishttps = False
3131

32-
def request(self, method, context, body, headers):
32+
def request(self, method, context=None, body=None, headers=None):
3333
self.response.set_data(method, context, body, headers)
3434

3535
def getresponse(self):

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class DummyResponse:
2121
classdocs
2222
'''
2323

24-
def __init__(self):
24+
STATUS_MESSAGES = {200: "OK", 303: "OK", 500: "ERROR"}
25+
26+
def __init__(self, status_code=None):
2527
self.reason = ""
26-
self.status = 0
28+
self.set_status_code(status_code)
2729
self.index = 0
2830
self.set_data(None, None, None, None)
2931

30-
def set_status_code(self, status):
31-
self.status = status
32-
33-
def set_message(self, reason):
34-
self.reason = reason
32+
def set_status_code(self, status_code):
33+
self.status = status_code
34+
self.reason = self.STATUS_MESSAGES.get(status_code)
3535

36-
def set_data(self, method, context, body, headers):
36+
def set_data(self, method, context=None, body=None, headers=None):
3737
self.method = method
3838
self.context = context
3939
self.body = body

0 commit comments

Comments
 (0)