Skip to content

Commit

Permalink
test: added in open datasoft health test [2024-12-02]
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Dec 2, 2024
1 parent 01522d9 commit ff0c1f5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions tests/open_data_soft/test_ods_endpoint_health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from HerdingCats.session.cat_session import CatSession
from HerdingCats.endpoints.api_endpoints import OpenDataSoftApiPaths
import requests
from loguru import logger

CATALOGUES = [
"https://ukpowernetworks.opendatasoft.com"
]

@pytest.mark.parametrize("catalogue_url", CATALOGUES)
def test_ckan_health_check(catalogue_url):
"""
Check that predefined data catalogues are healthy and available
"""
with CatSession(catalogue_url) as cat_session:
url = cat_session.base_url + OpenDataSoftApiPaths.SHOW_DATASETS
try:
response = cat_session.session.get(url)
print(response)

# Check status code
assert response.status_code == 200, f"Expected status code 200, but got {response.status_code}"

# Check data is not empty
data = response.json()
assert data, f"Received empty data from {catalogue_url}"

# Additional check for 'success' key if your API returns it
if 'success' in data:
assert data['success'], f"OpenDataSoft returned success=False for {catalogue_url}"

logger.info(f"Health check passed for {catalogue_url}")

except requests.RequestException as e:
pytest.fail(f"Failed to connect to OpenDataSoft endpoint for {catalogue_url}: {str(e)}")
except AssertionError as e:
pytest.fail(str(e))

0 comments on commit ff0c1f5

Please sign in to comment.