From c87c435a65fb067f21af7f345dff65c5a14a1bc2 Mon Sep 17 00:00:00 2001 From: Chris Carlon Date: Tue, 26 Nov 2024 20:15:08 +0000 Subject: [PATCH] test(tests and docs): added new test for open datasoft session start and ammended documentation [2024-11-26] --- documentation/overview.md | 23 +++++++------- .../test_ods_session_creation.py | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 tests/open_data_soft/test_ods_session_creation.py diff --git a/documentation/overview.md b/documentation/overview.md index 7bed431..4c04e68 100644 --- a/documentation/overview.md +++ b/documentation/overview.md @@ -43,11 +43,14 @@ if __name__ == "__main__": #### Initialisation ```python -from cat_session import CatSession -from cat_explorer import OpenDataSoftCatExplorer +import HerdingCats as hc + +def main(): + with hc.CatSession(hc.OpenDataSoftDataCatalogues.UK_POWER_NETWORKS) as session: + explore = hc.OpenDataSoftCatExplorer(session) -with CatSession("ukpowernetworks.opendatasoft.com") as session: - explorer = OpenDataSoftCatExplorer(session) +if __name__ == "__main__": + main() ``` #### Methods @@ -131,10 +134,10 @@ def main(): polars_df = loader.polars_data_loader(resource_list) pandas_df = loader.pandas_data_loader(resource_list) - # Load into in-memory DuckDB + # Load into in-memory DuckDB and specify db name and table name loader.duckdb_data_loader(resource_list, "cycle_hire_db", "daily_hires") - # Load into S3 as Parquet + # Load into S3 as Parquet - AWS creds need to be configured with something like AWS vault for this loader.aws_s3_data_loader( resource_list, "my-data-bucket", @@ -146,9 +149,9 @@ if __name__ == "__main__": main() ``` -## Supported Data Formats for Resource Loader +## Supported File Types for Resource Loader -The library currently supports the following data formats: +The Resource Loader currently supports the following data formats: - Excel (.xlsx) ✅ - CSV ✅ - JSON (partial support) ✅ @@ -159,9 +162,9 @@ Future format support planned for: - Shapefile - GeoJSON -## Storage Solutions +## Data Formats and Storage Solutions -Current storage solutions supported: +Current data formats and storage solutions supported: - Polars DataFrame ✅ - Pandas DataFrame ✅ - DuckDB (local) ✅ diff --git a/tests/open_data_soft/test_ods_session_creation.py b/tests/open_data_soft/test_ods_session_creation.py new file mode 100644 index 0000000..77ae068 --- /dev/null +++ b/tests/open_data_soft/test_ods_session_creation.py @@ -0,0 +1,30 @@ +import pytest +from HerdingCats.session.cat_session import CatSession + +@pytest.fixture +def domain(): + return "ukpowernetworks.opendatasoft.com" + +def test_cat_session_creation(domain): + """ + Check that a valid Ckan session can be created + """ + try: + session = CatSession(domain) + assert isinstance( + session, CatSession + ), "OpenDataSoftCatSession object should be created" + assert session.domain == domain, "OpenDataSoftCatSession should have the correct domain" + assert ( + session.base_url == f"https://{domain}" + ), "OpenDataSoftCatSession should have the correct base URL" + except Exception as e: + pytest.fail(f"Failed to create OpenDataSoftCatSession: {str(e)}") + + +def test_cat_session_start(domain): + try: + 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)}")