-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: added in open datasoft health test [2024-12-02]
- Loading branch information
1 parent
01522d9
commit ff0c1f5
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |