Skip to content

Commit

Permalink
Add some missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stvoutsin committed Jan 17, 2025
1 parent 042b54e commit d8b8983
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions pyvo/dal/tests/test_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,118 @@ def test_get_udf(self, tapservice):
assert func.form == "ivo_hasword(haystack TEXT, needle TEXT) -> INTEGER"


def test_invalid_service_url_format():
service = TAPService('http://[invalid-url')

with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Invalid service URL" in error_message
assert "Please provide a valid URL in the format 'http(s)://domain/path'" in error_message


def test_timeout_error():
service = TAPService('http://example.com/tap')

with requests_mock.Mocker() as rm:
rm.register_uri(
'GET',
'http://example.com/tap/capabilities',
exc=requests.Timeout("Request timed out")
)
rm.register_uri(
'GET',
'http://example.com/capabilities',
exc=requests.Timeout("Request timed out")
)

with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Request timed out" in error_message


def test_generic_request_exception():
service = TAPService('http://example.com/tap')

with requests_mock.Mocker() as rm:
rm.register_uri(
'GET',
'http://example.com/tap/capabilities',
exc=requests.RequestException("Some request error")
)
rm.register_uri(
'GET',
'http://example.com/capabilities',
exc=requests.RequestException("Some request error")
)

with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Some request error" in error_message


def test_unexpected_exception():
service = TAPService('http://example.com/tap')

class CustomException(Exception):
pass

with requests_mock.Mocker() as rm:
rm.register_uri(
'GET',
'http://example.com/tap/capabilities',
exc=CustomException("Unexpected error occurred")
)
rm.register_uri(
'GET',
'http://example.com/capabilities',
exc=CustomException("Unexpected error occurred")
)

with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Unexpected error: Unexpected error occurred" in error_message


def test_tap_service_initialization_error():
with requests_mock.Mocker() as rm:
rm.register_uri(
'GET',
'http://example.com/tap/capabilities',
status_code=404
)
rm.register_uri(
'GET',
'http://example.com/capabilities',
status_code=404
)

service = TAPService('http://example.com/tap')
with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Unable to access the capabilities endpoint at:" in error_message
assert "404" in error_message


def test_tap_service_invalid_url_error():
service = TAPService('http://[invalid-url')
with pytest.raises(DALServiceError) as excinfo:
_ = service.capabilities

error_message = str(excinfo.value)
assert "Invalid service URL" in error_message
assert "Please provide a valid URL in the format 'http(s)://domain/path'" in error_message


def test_endpoint_connection_errors():
service = TAPService('http://example.com/tap')

Expand Down

0 comments on commit d8b8983

Please sign in to comment.