Skip to content

Commit

Permalink
testL added get_tap_service_query_failed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MicheleDelliVeneri committed Dec 18, 2024
1 parent e7e91b8 commit eb71258
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/test_alma_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
query_by_science,
query_alma,
fetch_science_types,
validate_science_filters, compute_distance,
validate_science_filters,
compute_distance,
TAP_URLS
)
from astropy import units as u
from pyvo.dal import DALServiceError
from tenacity import RetryError
from pyvo.dal import TAPService
import pandas as pd
import os
import numpy as np
Expand All @@ -32,6 +35,26 @@ def test_get_tap_service_failure(self):
with self.assertRaises(Exception):
get_tap_service()

@patch("app.alma_utils.TAPService")
@patch("app.alma_utils.logger")
def test_tap_service_query_failed(self, mock_logger, mock_tap_service):
"""Test exception when TAP service query fails for a URL."""
# Mock TAPService to simulate query failure for the first URL
mock_service = Mock()
mock_service.search.side_effect = [Exception("Query failed"), Mock()]
mock_tap_service.side_effect = [mock_service, mock_service]

result = get_tap_service()

# Ensure the TAPService was called for both URLs
self.assertEqual(mock_tap_service.call_count, 2)
self.assertIsNotNone(result)

# Verify the logger was called with the appropriate error message
mock_logger.error.assert_any_call(
"TAP service query failed for https://almascience.eso.org/tap: Query failed"
)

@patch("app.alma_utils.TAPService")
def test_query_alma_success(self, mock_tap_service):
"""Test query_alma with successful query."""
Expand Down

0 comments on commit eb71258

Please sign in to comment.