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] 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( 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)