Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a more helpful message when endpoint not found in source. #311

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)