coulomb-social/tests/test_pageops.py
tegwick affed64839 Land CSOC-WP-0006 PageOps: member space/page CRUD, copy, transfer
Thin CONTENT_ROOT content plane (ADR-0003/0004) with space visual field,
product UI for Title/Abstract/Visual, page list sidebar, and tests. Update
capability model and smoke checklist; mark WP-0006 finished.
2026-08-13 12:46:39 +02:00

87 lines
2.8 KiB
Python

"""PageOps content-plane unit tests (ADR-0003 / ADR-0004)."""
from pathlib import Path
import pytest
from coulomb_social.apps.spaces import pageops
@pytest.fixture
def content_root(tmp_path, settings):
root = tmp_path / "content"
settings.CONTENT_ROOT = str(root)
return root
def test_write_read_list_page(content_root):
pageops.init_space_content("lab", title="Lab", abstractor="Research", visual="assets/c.jpg")
doc = pageops.write_page(
"lab",
"notes",
title="Notes",
abstractor="Scratch",
visual="assets/n.jpg",
body="# Notes\n\nHello.\n",
)
assert doc.exists
assert doc.title == "Notes"
assert doc.abstractor == "Scratch"
assert "Hello" in doc.body
pages = pageops.list_pages("lab")
slugs = [p.slug for p in pages]
assert slugs[0] == "index"
assert "notes" in slugs
path = Path(doc.path)
assert path.is_file()
text = path.read_text(encoding="utf-8")
assert text.startswith("---\n")
assert 'title: "Notes"' in text or "title: Notes" in text or 'title: "Notes"' in text
def test_copy_page_same_space(content_root):
pageops.init_space_content("lab", title="Lab")
pageops.write_page("lab", "alpha", title="Alpha", body="Body A\n")
copy = pageops.copy_page("lab", "alpha", "lab", "alpha-copy")
assert copy.slug == "alpha-copy"
assert copy.title == "Alpha (copy)"
assert "Body A" in copy.body
assert pageops.read_page("lab", "alpha").exists
def test_transfer_page(content_root):
pageops.init_space_content("src", title="Src")
pageops.init_space_content("dst", title="Dst")
pageops.write_page("src", "moved", title="Moved", abstractor="A", body="X\n")
doc = pageops.transfer_page("src", "moved", "dst", "moved")
assert doc.exists
assert doc.title == "Moved"
assert not pageops.read_page("src", "moved").exists
assert pageops.read_page("dst", "moved").exists
def test_cannot_delete_or_transfer_index(content_root):
pageops.init_space_content("lab", title="Lab")
with pytest.raises(pageops.PageOpsError):
pageops.delete_page("lab", "index")
with pytest.raises(pageops.PageOpsError):
pageops.transfer_page("lab", "index", "other")
def test_copy_relative_visual_asset(content_root):
pageops.init_space_content("lab", title="Lab")
assets = pageops.assets_dir("lab")
assets.mkdir(parents=True, exist_ok=True)
(assets / "cover.png").write_bytes(b"\x89PNG\r\n")
pageops.write_page(
"lab",
"with-pic",
title="Pic",
visual="assets/cover.png",
body="pic\n",
)
copy = pageops.copy_page("lab", "with-pic", "lab", "with-pic-copy")
assert copy.visual.startswith("assets/")
assert (pageops.space_dir("lab") / copy.visual).is_file()