Skip to content

Commit

Permalink
Give a more helpful message when endpoint not found in source. (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjohns-scottlogic authored Jan 6, 2025
1 parent ce5e228 commit af5714d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
jobs:
build:

runs-on: ubuntu-latest
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: [3.8, 3.9]
Expand Down
5 changes: 5 additions & 0 deletions digital_land/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
30 changes: 29 additions & 1 deletion tests/unit/test_collection.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)

0 comments on commit af5714d

Please sign in to comment.