feat: catalog Record model and validation
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import pytest
|
||||
|
||||
from hef.catalog import Record, validate, CatalogError
|
||||
|
||||
|
||||
def make_record(**overrides):
|
||||
base = dict(
|
||||
id="nasa-apollo-earthrise",
|
||||
title="Earthrise",
|
||||
source_url="https://archive.org/details/earthrise",
|
||||
source_archive="internet_archive",
|
||||
license="public_domain",
|
||||
mode="video",
|
||||
left=1,
|
||||
right=4,
|
||||
dark=1,
|
||||
light=3,
|
||||
duration_s=600,
|
||||
file_path="/media/earthrise.mp4",
|
||||
)
|
||||
base.update(overrides)
|
||||
return Record(**base)
|
||||
|
||||
|
||||
def test_valid_record_passes():
|
||||
validate(make_record()) # must not raise
|
||||
|
||||
|
||||
def test_defaults_are_set():
|
||||
record = make_record()
|
||||
assert record.review_status == "proposed"
|
||||
assert record.attribution == ""
|
||||
assert record.reviewed_at is None
|
||||
|
||||
|
||||
def test_invalid_mode_raises():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(mode="hologram"))
|
||||
|
||||
|
||||
def test_invalid_license_raises():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(license="all_rights_reserved"))
|
||||
|
||||
|
||||
def test_coordinate_out_of_range_raises():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(left=5))
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(dark=-1))
|
||||
|
||||
|
||||
def test_boolean_coordinate_rejected():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(right=True))
|
||||
|
||||
|
||||
def test_cc_by_requires_attribution():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(license="cc_by", attribution=""))
|
||||
validate(make_record(license="cc_by", attribution="Jane Doe, CC BY 4.0"))
|
||||
|
||||
|
||||
def test_empty_id_raises():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(id=""))
|
||||
|
||||
|
||||
def test_negative_duration_raises():
|
||||
with pytest.raises(CatalogError):
|
||||
validate(make_record(duration_s=-1))
|
||||
Reference in New Issue
Block a user