Skip to content

Commit 754237f

Browse files
Jorge Fernandez HernandezJorge Fernandez Hernandez
authored andcommitted
EUCLIDPCR-1863 New tests
1 parent b9cd513 commit 754237f

File tree

1 file changed

+83
-3
lines changed

1 file changed

+83
-3
lines changed

astroquery/esa/euclid/tests/test_euclidtap.py

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,35 @@ def test_launch_sync_job(tmp_path_factory):
317317
assert 3 == len(results), len(results)
318318

319319

320-
def test_launch_async_job():
321-
conn_handler = DummyConnHandler()
320+
@patch.object(TapPlus, 'launch_job')
321+
def test_launch_sync_job_exception(mock_launch_job, caplog):
322+
query = "select alpha, delta, source_id, table1_oid from caca"
322323

324+
conn_handler = DummyConnHandler()
323325
tap_plus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
324-
query = "select alpha, delta, source_id, table1_oid from caca"
325326

327+
launch_response = DummyResponse(200)
328+
launch_response.set_data(method="POST", body=JOB_DATA)
329+
conn_handler.set_default_response(launch_response)
330+
331+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
332+
333+
mock_launch_job.side_effect = HTTPError("launch_job HTTPError")
334+
335+
tap.launch_job(query, output_format="votable")
336+
337+
mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca: HTTP error: launch_job HTTPError"
338+
assert caplog.records[0].msg == mssg
339+
340+
mock_launch_job.side_effect = Exception("launch_job Exception")
341+
342+
tap.launch_job(query, output_format="votable")
343+
344+
mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca, launch_job Exception"
345+
assert caplog.records[1].msg == mssg
346+
347+
348+
def test_launch_async_job():
326349
conn_handler = DummyConnHandler()
327350
tap_plus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
328351
jobid = '12345'
@@ -346,6 +369,8 @@ def test_launch_async_job():
346369
req = "async/" + jobid + "/results/result"
347370
conn_handler.set_response(req, responseResultsJob)
348371

372+
query = "select alpha, delta, source_id, table1_oid from caca"
373+
349374
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
350375

351376
job = tap.launch_job_async(query, output_format="votable")
@@ -391,6 +416,29 @@ def test_launch_async_job():
391416
assert 3 == len(results), len(results)
392417

393418

419+
@patch.object(TapPlus, 'launch_job_async')
420+
def test_launch_async_job_exception(mock_launch_job_async, caplog):
421+
conn_handler = DummyConnHandler()
422+
tap_plus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
423+
424+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
425+
query = "select alpha, delta, source_id, table1_oid from caca"
426+
427+
mock_launch_job_async.side_effect = HTTPError("launch_job_async HTTPError")
428+
429+
tap.launch_job_async(query, output_format="votable")
430+
431+
mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca: HTTP error: launch_job_async HTTPError"
432+
assert caplog.records[0].msg == mssg
433+
434+
mock_launch_job_async.side_effect = Exception("launch_job_async Exception")
435+
436+
tap.launch_job_async(query, output_format="votable")
437+
438+
mssg = "Query failed: select alpha, delta, source_id, table1_oid from caca, launch_job_async Exception"
439+
assert caplog.records[1].msg == mssg
440+
441+
394442
def test_list_async_jobs():
395443
conn_handler = DummyConnHandler()
396444
tap_plus = TapPlus(url="http://test:1111/tap", connhandler=conn_handler)
@@ -682,6 +730,38 @@ def test_get_obs_products():
682730

683731
assert result is not None
684732

733+
result = tap.get_observation_products(id='13', product_type='mosaic', filter='VIS', output_file=None)
734+
735+
assert result is not None
736+
737+
738+
def test_get_obs_products_exceptions():
739+
conn_handler = DummyConnHandler()
740+
tap_plus = TapPlus(url="http://test:1111/tap", data_context='data', client_id='ASTROQUERY',
741+
connhandler=conn_handler)
742+
# Launch response: we use default response because the query contains decimals
743+
responseLaunchJob = DummyResponse(200)
744+
responseLaunchJob.set_data(method='POST', context=None, body='', headers=None)
745+
746+
conn_handler.set_default_response(responseLaunchJob)
747+
748+
tap = EuclidClass(tap_plus_conn_handler=conn_handler, datalink_handler=tap_plus, show_server_messages=False)
749+
750+
with pytest.raises(ValueError) as exc_info:
751+
tap.get_observation_products(id=None, product_type='observation', filter='VIS', output_file=None)
752+
753+
assert str(exc_info.value).startswith("Missing required argument: 'observation_id'")
754+
755+
with pytest.raises(ValueError) as exc_info:
756+
tap.get_observation_products(id=12, product_type=None, filter='VIS', output_file=None)
757+
758+
assert str(exc_info.value).startswith("Missing required argument: 'product_type'")
759+
760+
with pytest.raises(ValueError) as exc_info:
761+
tap.get_observation_products(id=12, product_type='XXXXXXXX', filter='VIS', output_file=None)
762+
763+
assert str(exc_info.value).startswith("Invalid product type XXXXXXXX. Valid values: ['observation', 'mosaic']")
764+
685765

686766
def test_get_cutout():
687767
conn_handler = DummyConnHandler()

0 commit comments

Comments
 (0)