From 653af722535d5e175e51d7514e4046b7beb01866 Mon Sep 17 00:00:00 2001 From: christophercarlon Date: Fri, 27 Sep 2024 13:21:52 +0100 Subject: [PATCH] Open Data Soft Catalogue Prep --- README.md | 13 +++++++------ tests/test_endpoint_health.py | 4 ++-- tests/test_package_list.py | 16 ++++++++-------- tests/test_session_creation.py | 17 ++++++++++++----- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1c9a3fd..0f4242d 100644 --- a/README.md +++ b/README.md @@ -51,14 +51,15 @@ This will improve and speed up how people: **Herding-CATs supports the following catalogues by default** -**CKAN** +**Default** | Catalogue Name | Website | Catalogue API Endpoint Definition | |----------------|---------|-------------------| -| London Datastore | https://data.london.gov.uk | CKAN | -| Subak Data Catalogue | https://data.subak.org | CKAN | -| Gov Open Data | https://www.data.gov.uk | CKAN | -| Humanitarian Data Exchange | https://data.humdata.org | CKAN | - +| London Datastore | https://data.london.gov.uk | CKAN |✅ +| Subak Data Catalogue | https://data.subak.org | CKAN |✅ +| Gov Open Data | https://www.data.gov.uk | CKAN |✅ +| Humanitarian Data Exchange | https://data.humdata.org | CKAN |✅ +| UK Power Networks | https://ukpowernetworks.opendatasoft.com | Open Datasoft |🚧 +| Infrabel | https://opendata.infrabel.be | Open Datasoft |🚧 **TBC** | Catalogue Name | Website | Catalogue API Endpoint Definition | diff --git a/tests/test_endpoint_health.py b/tests/test_endpoint_health.py index 79b508b..1f82d72 100644 --- a/tests/test_endpoint_health.py +++ b/tests/test_endpoint_health.py @@ -1,5 +1,5 @@ import pytest -from HerdingCats.session.cat_session import CkanCatSession +from HerdingCats.session.cat_session import CatSession from HerdingCats.endpoints.api_endpoints import CkanApiPaths import requests from loguru import logger @@ -12,7 +12,7 @@ def test_site_read(catalogue_url): """ Check that predefined data cataloues return True - means they can be used """ - with CkanCatSession(catalogue_url) as cat_session: + with CatSession(catalogue_url) as cat_session: url = cat_session.base_url + CkanApiPaths.SITE_READ try: response = cat_session.session.get(url) diff --git a/tests/test_package_list.py b/tests/test_package_list.py index 02cf2f5..c64a34e 100644 --- a/tests/test_package_list.py +++ b/tests/test_package_list.py @@ -1,23 +1,20 @@ import pytest -from HerdingCats.session.cat_session import CkanCatSession +from HerdingCats.session.cat_session import CatSession from HerdingCats.explorer.cat_explore import CkanCatExplorer import requests from loguru import logger -CATALOGUES = [ - "https://data.london.gov.uk", - "https://data.humdata.org" -] +CATALOGUES = ["https://data.london.gov.uk", "https://data.humdata.org"] + @pytest.mark.parametrize("catalogue_url", CATALOGUES) def test_package_list_dictionary(catalogue_url): """ Test the package list functionality for predefined data catalogues """ - with CkanCatSession(catalogue_url) as cat_session: + with CatSession(catalogue_url) as cat_session: explorer = CkanCatExplorer(cat_session) try: - results = explorer.package_list_dictionary() # Assert that we got a result @@ -28,10 +25,13 @@ def test_package_list_dictionary(catalogue_url): logger.info(f"Package search test passed for {catalogue_url}") except requests.RequestException as e: - pytest.fail(f"Failed to perform package search for {catalogue_url}: {str(e)}") + pytest.fail( + f"Failed to perform package search for {catalogue_url}: {str(e)}" + ) except AssertionError as e: pytest.fail(str(e)) + # COULD ADD IN TESTS FOR DATAFRAME PACKAGE LIST BUT DON'T WANT TO CALL THE ENDPOINTS TOO MUCH # THIS WOULD CALL THEM ALL 12 TIMES - TEST ABOVE SHOULD DO FOR NOW # @pytest.mark.parametrize("catalogue_url", CATALOGUES) diff --git a/tests/test_session_creation.py b/tests/test_session_creation.py index 8c13c57..5aa0337 100644 --- a/tests/test_session_creation.py +++ b/tests/test_session_creation.py @@ -1,25 +1,32 @@ import pytest -from HerdingCats.session.cat_session import CkanCatSession +from HerdingCats.session.cat_session import CatSession + @pytest.fixture def domain(): return "data.london.gov.uk" + def test_cat_session_creation(domain): """ Check that a valid Ckan session can be created """ try: - session = CkanCatSession(domain) - assert isinstance(session, CkanCatSession), "CkanCatSession object should be created" + session = CatSession(domain) + assert isinstance( + session, CatSession + ), "CkanCatSession object should be created" assert session.domain == domain, "CkanCatSession should have the correct domain" - assert session.base_url == f"https://{domain}", "CkanCatSession should have the correct base URL" + assert ( + session.base_url == f"https://{domain}" + ), "CkanCatSession should have the correct base URL" except Exception as e: pytest.fail(f"Failed to create CkanCatSession: {str(e)}") + def test_cat_session_start(domain): try: - with CkanCatSession(domain) as session: + with CatSession(domain) as session: assert session.session is not None, "Session object should be created" except Exception as e: pytest.fail(f"Failed to start CkanCatSession: {str(e)}")