aboutsummaryrefslogtreecommitdiff
path: root/scripts/test_changelog.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/test_changelog.py')
-rw-r--r--scripts/test_changelog.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/scripts/test_changelog.py b/scripts/test_changelog.py
index 5778b6ac..5d9fd506 100644
--- a/scripts/test_changelog.py
+++ b/scripts/test_changelog.py
@@ -1,16 +1,20 @@
from __future__ import annotations
import json
+import tempfile
import unittest
+from pathlib import Path
from scripts.changelog import (
ChangelogError,
build_latest_json,
canonicalize_manifest,
+ DEFAULT_PRODUCT_ANNOUNCEMENT_PATH,
default_release_assets,
ensure_manifest_is_outdated,
ensure_manifest_matches_expected,
extract_section_body,
+ load_product_announcement,
manifest_from_release_payload,
prepare_release,
read_protocol_version,
@@ -76,6 +80,80 @@ class ChangelogScriptTests(unittest.TestCase):
},
)
+ def test_build_latest_json_embeds_product_announcement(self) -> None:
+ manifest = json.loads(
+ build_latest_json(
+ "0.1.1",
+ "### Fixed\n- One",
+ default_release_assets("0.1.1"),
+ announcement={"id": "keybinding-v2", "title": "Keybind Refactor", "body": "body"},
+ )
+ )
+
+ self.assertEqual(
+ manifest["announcement"],
+ {"id": "keybinding-v2", "title": "Keybind Refactor", "body": "body"},
+ )
+
+ def write_temp_json(self, content: str) -> Path:
+ tmp = tempfile.NamedTemporaryFile("w", delete=False, encoding="utf-8")
+ with tmp:
+ tmp.write(content)
+ return Path(tmp.name)
+
+ def test_checked_in_product_announcement_is_valid_or_null(self) -> None:
+ self.assertTrue(DEFAULT_PRODUCT_ANNOUNCEMENT_PATH.is_file())
+ load_product_announcement(DEFAULT_PRODUCT_ANNOUNCEMENT_PATH)
+
+ def test_load_product_announcement_accepts_null(self) -> None:
+ path = self.write_temp_json("null\n")
+ try:
+ self.assertIsNone(load_product_announcement(path))
+ finally:
+ path.unlink(missing_ok=True)
+
+ def test_load_product_announcement_accepts_valid_object(self) -> None:
+ path = self.write_temp_json(
+ json.dumps({"id": "keybinding-v2", "title": "Keybind Refactor", "body": "Body"})
+ )
+ try:
+ self.assertEqual(
+ load_product_announcement(path),
+ {"id": "keybinding-v2", "title": "Keybind Refactor", "body": "Body"},
+ )
+ finally:
+ path.unlink(missing_ok=True)
+
+ def test_load_product_announcement_rejects_missing_file(self) -> None:
+ path = Path(tempfile.gettempdir()) / "herdr-missing-product-announcement.json"
+ path.unlink(missing_ok=True)
+ with self.assertRaisesRegex(ChangelogError, "file not found"):
+ load_product_announcement(path)
+
+ def test_load_product_announcement_rejects_missing_empty_or_extra_fields(self) -> None:
+ cases = [
+ ({"id": "keybinding-v2", "title": "Keybind Refactor"}, "body"),
+ ({"id": "", "title": "Keybind Refactor", "body": "Body"}, "id"),
+ ({"id": "keybinding-v2", "title": "Keybind Refactor", "body": "Body", "cta": "x"}, "unsupported"),
+ ]
+ for payload, expected in cases:
+ path = self.write_temp_json(json.dumps(payload))
+ try:
+ with self.assertRaisesRegex(ChangelogError, expected):
+ load_product_announcement(path)
+ finally:
+ path.unlink(missing_ok=True)
+
+ def test_load_product_announcement_rejects_invalid_id(self) -> None:
+ path = self.write_temp_json(
+ json.dumps({"id": "Keybinding V2", "title": "Keybind Refactor", "body": "Body"})
+ )
+ try:
+ with self.assertRaisesRegex(ChangelogError, "invalid id"):
+ load_product_announcement(path)
+ finally:
+ path.unlink(missing_ok=True)
+
def test_manifest_from_release_payload_uses_release_body_and_asset_urls(self) -> None:
manifest = manifest_from_release_payload(
{