shard-wiki/tests/test_writable_adapter.py

42 lines
1.5 KiB
Python
Raw Normal View History

"""Tests for the writable FolderAdapter + positive write conformance (SHARD-WP-0008 T1)."""
import pytest
from shard_wiki.adapters import FolderAdapter, assert_conformant, run_conformance
from shard_wiki.model import NotSupported, Verb
def test_writable_round_trip(tmp_path):
shard = FolderAdapter("w", tmp_path, writable=True)
rev_before = shard.current_rev("New")
assert rev_before is None
page = shard.write("New", "hello")
assert page.body == "hello"
assert shard.read("New").body == "hello"
assert shard.current_rev("New") is not None
def test_writable_profile_supports_write(tmp_path):
prof = FolderAdapter("w", tmp_path, writable=True).profile()
assert prof.supports(Verb.WRITE)
def test_read_only_still_rejects_write(tmp_path):
(tmp_path / "Home.md").write_text("x", encoding="utf-8")
with pytest.raises(NotSupported):
FolderAdapter("ro", tmp_path).write("Home", "y")
def test_conformance_passes_for_writable(tmp_path):
(tmp_path / "Home.md").write_text("body", encoding="utf-8")
report = assert_conformant(FolderAdapter("w", tmp_path, writable=True))
assert report.ok
assert any(c.name == "write-round-trips" and c.ok for c in report.checks)
def test_conformance_write_probe_is_content_preserving(tmp_path):
(tmp_path / "Home.md").write_text("keep me", encoding="utf-8")
shard = FolderAdapter("w", tmp_path, writable=True)
run_conformance(shard)
assert shard.read("Home").body == "keep me" # probe did not alter content