"""Unit tests for the MuseHub JSON-LD structured data helpers.
Covers — jsonld_repo and jsonld_release produce valid
schema.org/MusicComposition and schema.org/MusicRecording dicts.
render_jsonld_script produces a safe, well-formed ")
def test_render_jsonld_script_contains_valid_json() -> None:
"""The content inside the script tag is valid JSON matching the input dict."""
data: dict[str, object] = {
"@context": "https://schema.org",
"@type": "MusicComposition",
"name": "Blue in Green",
}
script = render_jsonld_script(data)
inner = script.removeprefix('")
parsed = json.loads(inner)
assert parsed["name"] == "Blue in Green"
assert parsed["@type"] == "MusicComposition"
def test_render_jsonld_script_escapes_closing_tag_xss() -> None:
""" sequences inside JSON values are escaped to prevent XSS."""
data: dict[str, object] = {
"@context": "https://schema.org",
"name": "Attack")
# The closing tag sequence must not appear verbatim inside the JSON payload.
assert "" not in inner
def test_render_jsonld_script_preserves_unicode() -> None:
"""Non-ASCII characters (e.g. accented, CJK) are preserved without escaping."""
data: dict[str, object] = {
"@context": "https://schema.org",
"name": "Caf\u00e9 M\u00fasica \u3084\u307e\u3068",
}
script = render_jsonld_script(data)
assert "Caf\u00e9" in script
assert "\u3084\u307e\u3068" in script