mirror of
https://github.com/NCBM/plyngent.git
synced 2026-07-25 08:04:57 +08:00
core/tools: serialize domain objects on PersistentDataView commit
This commit is contained in:
@@ -29,7 +29,7 @@ async def test_view_rollback_on_error() -> None:
|
||||
assert await store.load() == {"keep": 1}
|
||||
|
||||
|
||||
async def test_typed_todo_stack() -> None:
|
||||
async def test_typed_todo_stack_commits_raw() -> None:
|
||||
store = MemoryViewStore({})
|
||||
root: PersistentDataView[dict[str, object]] = PersistentDataView(store, bound_type=dict)
|
||||
async with root as data:
|
||||
@@ -38,7 +38,24 @@ async def test_typed_todo_stack() -> None:
|
||||
assert todo.depth == 1
|
||||
loaded = await store.load()
|
||||
assert isinstance(loaded, dict)
|
||||
assert isinstance(loaded.get("todo"), TodoStack)
|
||||
raw_todo = loaded.get("todo")
|
||||
assert isinstance(raw_todo, dict)
|
||||
assert "groups" in raw_todo
|
||||
restored = TodoStack.from_raw(raw_todo)
|
||||
assert restored.depth == 1
|
||||
assert [i.title for i in restored.groups[0].items] == ["A", "B"]
|
||||
|
||||
|
||||
async def test_typed_todo_stack_roundtrip_from_raw() -> None:
|
||||
store = MemoryViewStore({"todo": {"groups": [], "next_id": 1}})
|
||||
root: PersistentDataView[dict[str, object]] = PersistentDataView(store, bound_type=dict)
|
||||
async with root as data:
|
||||
todo = data["todo"].typed(TodoStack)
|
||||
_ = todo.push_group(["only"])
|
||||
loaded = await store.load()
|
||||
assert isinstance(loaded, dict)
|
||||
again = TodoStack.from_raw(loaded["todo"])
|
||||
assert [i.title for i in again.all_items()] == ["only"]
|
||||
|
||||
|
||||
async def test_mutate_outside_txn_errors() -> None:
|
||||
|
||||
Reference in New Issue
Block a user