feat(notion-writer): markdown endpoint helpers + version-aware client
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Tests for markdown transport helpers — run with `python test_engine_routing.py`."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
|
||||
import _notion_compat as compat
|
||||
|
||||
|
||||
def _fake_client():
|
||||
c = mock.MagicMock()
|
||||
c.request.return_value = {"object": "page", "id": "p1"}
|
||||
return c
|
||||
|
||||
|
||||
def test_create_page_markdown():
|
||||
c = _fake_client()
|
||||
parent = {"type": "data_source_id", "data_source_id": "ds1"}
|
||||
compat.create_page_markdown(c, parent, {"Name": {"title": []}}, "# Hi")
|
||||
_, kwargs = c.request.call_args
|
||||
assert kwargs["path"] == "pages"
|
||||
assert kwargs["method"] == "POST"
|
||||
assert kwargs["body"]["markdown"] == "# Hi"
|
||||
assert kwargs["body"]["parent"] == parent
|
||||
|
||||
|
||||
def test_append_markdown():
|
||||
c = _fake_client()
|
||||
compat.append_markdown(c, "page-123", "## More")
|
||||
_, kwargs = c.request.call_args
|
||||
assert kwargs["path"] == "pages/page-123/markdown"
|
||||
assert kwargs["method"] == "PATCH"
|
||||
assert kwargs["body"]["type"] == "insert_content"
|
||||
assert kwargs["body"]["insert_content"]["content"] == "## More"
|
||||
assert kwargs["body"]["insert_content"]["position"] == {"type": "end"}
|
||||
|
||||
|
||||
def test_replace_markdown():
|
||||
c = _fake_client()
|
||||
compat.replace_markdown(c, "page-123", "# Fresh", allow_deleting=True)
|
||||
_, kwargs = c.request.call_args
|
||||
assert kwargs["path"] == "pages/page-123/markdown"
|
||||
assert kwargs["body"]["type"] == "replace_content"
|
||||
assert kwargs["body"]["replace_content"]["new_str"] == "# Fresh"
|
||||
assert kwargs["body"]["replace_content"]["allow_deleting_content"] is True
|
||||
|
||||
|
||||
def run_all():
|
||||
tests = [
|
||||
test_create_page_markdown,
|
||||
test_append_markdown,
|
||||
test_replace_markdown,
|
||||
]
|
||||
for t in tests:
|
||||
print(f"\n{t.__name__}")
|
||||
t()
|
||||
print("\n" + "=" * 50)
|
||||
print(f"✅ All {len(tests)} tests passed")
|
||||
print("=" * 50)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_all()
|
||||
Reference in New Issue
Block a user