Files
coruna-lab/channel-builder/tools/tests/test_channel_layout.py
T
2026-08-09 21:57:08 +08:00

51 lines
1.8 KiB
Python

import tempfile
import unittest
from pathlib import Path
import sys
TOOLS = Path(__file__).resolve().parents[1]
if str(TOOLS) not in sys.path:
sys.path.insert(0, str(TOOLS))
import _common
from new_project import release_files
class ChannelLayoutTest(unittest.TestCase):
def test_shared_layout_web_under_channel(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
channel = "a" * 32
_common.set_tree_root(root, channel=channel, shared_layout=True)
self.assertEqual(_common.CAMPAIGN_DIR, root.resolve() / "web" / channel)
self.assertEqual(_common.SYNC_DIR, root.resolve() / "sync")
def test_legacy_layout_web_flat(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
_common.set_tree_root(root, channel="a" * 32, shared_layout=False)
self.assertEqual(_common.CAMPAIGN_DIR, root.resolve() / "web")
self.assertEqual(_common.SYNC_DIR, root.resolve() / "sync")
def test_release_manifest_files_are_relative_and_hashed(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
channel = "b" * 32
(root / "web" / channel).mkdir(parents=True)
(root / "sync").mkdir()
(root / "web" / channel / "support.html").write_bytes(b"support")
(root / "sync" / "daily.html").write_bytes(b"daily")
files = release_files(root, channel)
self.assertEqual(
sorted(item["path"] for item in files),
sorted([f"web/{channel}/support.html", "sync/daily.html"]),
)
self.assertTrue(all(len(str(item["sha256"])) == 64 for item in files))
if __name__ == "__main__":
unittest.main()