polish-dynaword / src /test_europeana_contract.py
kacperwikiel's picture
Release v0.3.1 Europeana preview shard (#4)
264ccc9
Raw History Blame
1.34 kB
"""TDD contract for the direct Europeana ingestion path."""
import sys
import unittest
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent))
from fetch_europeana import normalize_europeana_row
class EuropeanaContractTest(unittest.TestCase):
def test_open_record_keeps_rights_and_canonical_schema(self):
item = {
"id": "/123/item-1", "rights": ["https://creativecommons.org/licenses/by/4.0/"],
"dcDescription": ["Polski opis wystarczająco długi do testu." * 10],
"dcCreator": ["Autor Testowy"], "year": ["1912"], "title": ["Tytuł"],
}
row = normalize_europeana_row(item, item)
self.assertEqual(set(row), {"id", "text", "source_url", "title", "license", "rights_url", "author", "created", "provider", "raw_metadata"})
self.assertEqual(row["license"], "CC-BY-4.0")
self.assertEqual(row["author"], "Autor Testowy")
self.assertEqual(row["created"], "1912")
self.assertTrue(row["rights_url"].startswith("https://creativecommons.org/licenses/by/"))
def test_restricted_rights_are_not_normalized(self):
item = {"id": "/x", "rights": ["https://creativecommons.org/licenses/by-nc/4.0/"]}
self.assertIsNone(normalize_europeana_row(item, item))
if __name__ == "__main__":
unittest.main()