Skip to content
Open
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
48 changes: 48 additions & 0 deletions packages/zeeker/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,4 +731,52 @@ def test_schema_conflict_error_message(self):
assert "Schema conflict detected" in error_msg
assert "Added columns: age, email" in error_msg
assert "migrate_schema() function" in error_msg


class TestZeekerProjectToDatasette:
"""Tests for ZeekerProject.to_datasette_metadata() table-level field pass-through."""

def test_per_resource_license_fields_in_table_metadata(self):
"""Per-resource license and license_url must appear in the generated table metadata."""
from zeeker.core.types import ZeekerProject

project = ZeekerProject(
name="test",
database="test.db",
resources={
"decisions": {
"description": "Enforcement decisions",
"license": "All rights reserved",
"license_url": "https://www.example.gov.sg/terms-of-use/",
"source": "Example Agency",
"source_url": "https://www.example.gov.sg/decisions/",
}
},
)

metadata = project.to_datasette_metadata()
table = metadata["databases"]["test"]["tables"]["decisions"]

assert table["license"] == "All rights reserved"
assert table["license_url"] == "https://www.example.gov.sg/terms-of-use/"
assert table["source"] == "Example Agency"
assert table["source_url"] == "https://www.example.gov.sg/decisions/"

def test_per_resource_license_fields_optional(self):
"""Resources without license fields should produce table metadata without them."""
from zeeker.core.types import ZeekerProject

project = ZeekerProject(
name="test",
database="test.db",
resources={"items": {"description": "Some items"}},
)

metadata = project.to_datasette_metadata()
table = metadata["databases"]["test"]["tables"]["items"]

assert "license" not in table
assert "license_url" not in table
assert "source" not in table
assert "source_url" not in table
assert "--force-schema-reset" in error_msg
4 changes: 4 additions & 0 deletions packages/zeeker/zeeker/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def to_datasette_metadata(self) -> dict[str, Any]:
"label_column",
"columns",
"units",
"license",
"license_url",
"source",
"source_url",
]

for field_name in datasette_fields:
Expand Down
Loading