Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.

9 downloads

dbbasic-object-server/tests/test_app_forum_detail_retrofit.py
Install on DigitalOcean Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-object-server.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-object-server.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-object-server.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

Daniel Quellhorst Changelog for this batch. 65ef78d 3 hours, 19 minutes ago History
test_app_forum_detail_retrofit.py · 4.8 KB · 116 lines
1"""Stage-6 retrofit of packages/app-forum: the 338-line bespoke
2site_forum_topic.py page is replaced by a seeded 59 detail view composed of
3three GENERIC block renderers -- an editable+deletable `detail` block (the
4topic), a `related` block (FLAT replies by topic_id -- deliberately flat, not
5nested), and a `form` block with a FK locked to the page's topic (reply
6compose). Flat, because nested discussion buries new replies and orphans
7subtrees on delete; a "poll" over flat replies is a rollup, not a new feature.
8"""
9
10import json
11from pathlib import Path
12
13import object_packages
14import object_schemas
15
16PACKAGES_ROOT = Path(__file__).resolve().parents[1] / "packages"
17APP_FORUM_DIR = PACKAGES_ROOT / "app-forum"
18
19
20def _seed_rows(name):
21 import csv
22
23 with open(APP_FORUM_DIR / "seed" / f"{name}.tsv", newline="") as fh:
24 return list(csv.DictReader(fh, delimiter="\t"))
25
26
27def test_manifest_drops_bespoke_topic_page_and_seeds_the_detail_view():
28 package = object_packages.get_package("app-forum", root=PACKAGES_ROOT)
29 assert package["objects"] == [] # the landing page became a view in 0.3.0
30 assert {entry["collection"] for entry in package["seed"]} == {
31 "forum_categories", "forum_topics", "forum_replies", "views", "site_routes",
32 }
33
34
35def test_forum_topic_object_file_is_deleted():
36 assert not (APP_FORUM_DIR / "objects" / "site" / "forum_topic.py").exists()
37
38
39def test_topic_view_composes_detail_flat_related_and_fk_locked_form():
40 rows = _seed_rows("views")
41 assert [r["id"] for r in rows] == ["view_forum_topic", "view_forum"]
42 view = rows[0]
43 assert view["id"] == "view_forum_topic"
44 assert view["route"] == "/forum/topics/{topic_id}"
45 blocks = json.loads(view["blocks"])
46 kinds = [b["kind"] for b in blocks]
47 assert kinds == ["detail", "related", "form"]
48
49 detail, related, form = blocks
50 # 1. editable+deletable topic detail
51 assert detail["collection"] == "forum_topics"
52 assert detail["record_id"] == "$record_id"
53 assert detail["editable"] is True and detail["deletable"] is True
54
55 # 2. FLAT replies (a plain related list by topic_id -- no nesting)
56 assert related["collection"] == "forum_replies"
57 assert related["fk_field"] == "topic_id"
58 assert related["match"] == "$record_id"
59
60 # 3. reply compose with topic_id locked to the page's topic
61 assert form["collection"] == "forum_replies"
62 assert form["fixed"] == {"topic_id": "$record_id"}
63
64
65def test_permalink_route_points_to_view_render():
66 rows = _seed_rows("site_routes")
67 assert [r["pattern"] for r in rows] == ["/forum/topics/{topic_id}", "/forum"]
68 assert {r["object_id"] for r in rows} == {"site_view_render"}
69
70
71def test_ai_summary_is_conditionally_visible_via_visible_when():
72 """The orphaned ai_summary field now shows on the topic detail, but only
73 when is_ai_summarized -- via the field's own visible_when, not page code."""
74 schema = json.loads((APP_FORUM_DIR / "schemas" / "forum_topics.json").read_text())
75 ai = next(f for f in schema["fields"] if f["name"] == "ai_summary")
76 assert ai["visible_when"] == {"field": "is_ai_summarized", "equals": "true"}
77
78
79def test_reply_compose_form_is_flat_no_parent_id():
80 """Flat replies: parent_id is dropped from the compose form's
81 forms.default, so no one composes a nested reply. The field itself stays
82 on the schema (existing data), it is just never offered."""
83 schema = json.loads((APP_FORUM_DIR / "schemas" / "forum_replies.json").read_text())
84 assert schema["forms"]["default"]["fields"] == ["topic_id", "content"]
85 assert "parent_id" in {f["name"] for f in schema["fields"]}
86
87
88def test_permissions_no_longer_reference_the_removed_object():
89 payload = json.loads((APP_FORUM_DIR / "permissions" / "rules.json").read_text())
90 object_ids = {rule.get("object_id") for rule in payload["rules"]}
91 assert "site_forum_topic" not in object_ids
92 assert "site_forum" not in object_ids # the landing page is a view too (0.3.0)
93
94
95def test_dry_run_is_safe(tmp_path):
96 object_root = tmp_path / "objects"
97 object_root.mkdir()
98 plan = object_packages.dry_run_package(
99 "app-forum", root=PACKAGES_ROOT, base_dir=tmp_path / "data", object_roots=[object_root],
100 )
101 assert plan["safe_to_install"] is True
102 assert plan["warnings"] == []
103
104
105def test_visible_when_survives_install(tmp_path):
106 """The condition must survive normalization/install -- else non-summarized
107 topics would show a blank AI Summary row."""
108 data_dir = tmp_path / "data"
109 object_root = tmp_path / "objects"
110 object_root.mkdir()
111 object_packages.install_package(
112 "app-forum", root=PACKAGES_ROOT, base_dir=data_dir, object_roots=[object_root],
113 )
114 schema = object_schemas.get_schema("forum_topics", base_dir=data_dir)
115 ai = next(f for f in schema["fields"] if f["name"] == "ai_summary")
116 assert ai.get("visible_when") == {"field": "is_ai_summarized", "equals": "true"}