From 1a7309f924e3368e6cfaca890e3d17206b8ea1b5 Mon Sep 17 00:00:00 2001 From: Christopher Johns Date: Fri, 3 Jan 2025 13:30:29 +0000 Subject: [PATCH 1/3] Give a more helpful message when endpoint not found in source. --- digital_land/collection.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/digital_land/collection.py b/digital_land/collection.py index adf85947..b0e875d6 100644 --- a/digital_land/collection.py +++ b/digital_land/collection.py @@ -168,6 +168,11 @@ def load( organisations = set() datasets = set() for endpoint in resource["endpoints"]: + if endpoint not in source.records: + raise RuntimeError( + f"Endpoint '{endpoint}' not found in source. Check the endpoint.csv and source.csv files." + ) + for entry in source.records[endpoint]: organisations.add(entry["organisation"]) datasets = set( From 6a18a4dd035e37885c9ad8688f2b6e94399e18ff Mon Sep 17 00:00:00 2001 From: Christopher Johns Date: Mon, 6 Jan 2025 08:42:01 +0000 Subject: [PATCH 2/3] Added test. --- tests/unit/test_collection.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_collection.py b/tests/unit/test_collection.py index b22aba1f..7c9f7c5a 100644 --- a/tests/unit/test_collection.py +++ b/tests/unit/test_collection.py @@ -1,5 +1,6 @@ +import pytest from digital_land.register import hash_value, Item -from digital_land.collection import Collection, LogStore +from digital_land.collection import Collection, LogStore, ResourceLogStore, CSVStore from digital_land.schema import Schema from datetime import datetime @@ -90,3 +91,30 @@ def test_format_date(): for date in dates: print(date) assert Collection.format_date(date) == check + + +def test_endpoint_source_mismatch(): + log = LogStore(Schema("log")) + log.add_entry( + { + "endpoint": "abc123", + "entry-date": "2025-01-06", + "resource": "aaa", + "bytes": "1024", + } + ) + + # This one matches + source = CSVStore(Schema("source")) + source.add_entry({"endpoint": "abc123", "organisation": "test-org"}) + + resource = ResourceLogStore(Schema("resource")) + resource.load(log, source) + + # This one doesn't + source = CSVStore(Schema("source")) + source.add_entry({"endpoint": "abc124", "organisation": "test-org"}) + + resource = ResourceLogStore(Schema("resource")) + with pytest.raises(RuntimeError): + resource.load(log, source) From 9884364d3df7be55e8764ce2912aedc26358a142 Mon Sep 17 00:00:00 2001 From: Christopher Johns Date: Mon, 6 Jan 2025 15:45:57 +0000 Subject: [PATCH 3/3] Use ubuntu 22.04 for CI --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 9dd4cc5e..b71df115 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -6,7 +6,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 strategy: matrix: python-version: [3.8, 3.9]