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_catalog_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_catalog_detail_retrofit.py · 5.7 KB · 134 lines
1"""Structural tests for packages/app-catalog after the Stage-6 retrofit: the
2bespoke ~165-line site_product_view.py permalink page was replaced by a
3seeded 59 detail view (site_view_render) whose `detail` block is
4owner-aware (editable/deletable), so there is no per-product page object
5anymore. Products have no public read path -- the row-filtered products
6collection has no public read rule -- so this page only ever served (and
7still only ever serves) the owner; non-owners and anonymous visitors are
8permission-gated at the collection API the same as before.
9"""
10
11import json
12from pathlib import Path
13
14import object_packages
15import object_permissions
16
17PACKAGES_ROOT = Path(__file__).resolve().parents[1] / "packages"
18APP_CATALOG_DIR = PACKAGES_ROOT / "app-catalog"
19
20
21def _seed_rows(name):
22 import csv
23
24 with open(APP_CATALOG_DIR / "seed" / f"{name}.tsv", newline="") as fh:
25 return list(csv.DictReader(fh, delimiter="\t"))
26
27
28def test_manifest_drops_the_bespoke_view_object_and_seeds_the_detail_view():
29 package = object_packages.get_package("app-catalog", root=PACKAGES_ROOT)
30 # The permalink page object is gone; 0.4.0 joined it with the
31 # inventory-adjustments trio (hook/composer/count action). 0.5.0 then
32 # deleted the bespoke products/locations list page objects too -- see
33 # tests/test_app_catalog_package.py. 0.7.0 added the reorder pass and
34 # the two attention providers, none of which is a page.
35 assert {obj["id"] for obj in package["objects"]} == {
36 "site_stock",
37 "hook_stock_moves", "system_stock_books", "action_apply_count",
38 "system_reorder_check", "system_reorder_attention",
39 # 0.10.0: backorders_waiting is a declared count (collection +
40 # where), so its provider object is gone.
41 }
42 # The detail view + its route are seeded (into app-views'/site-routing's
43 # own shared collections), alongside the existing products/locations/
44 # stock_moves seeds and 0.7.0's backorders/reorder_suggestions.
45 assert {entry["collection"] for entry in package["seed"]} == {
46 "products", "locations", "stock_moves", "views", "site_routes",
47 "backorders", "reorder_suggestions",
48 }
49
50
51def test_product_view_object_file_is_deleted():
52 assert not (APP_CATALOG_DIR / "objects" / "site" / "product_view.py").exists()
53
54
55def test_seeded_detail_view_uses_an_owner_aware_editable_detail_block():
56 rows = _seed_rows("views")
57 # 0.5.0 added the /products and /locations index views alongside this
58 # detail view, so assert on the detail row rather than a total that
59 # keeps growing.
60 rows = [r for r in rows if r["id"] == "view_products_detail"]
61 assert len(rows) == 1
62 view = rows[0]
63 assert view["id"] == "view_products_detail"
64 assert view["route"] == "/products/{product_id}"
65 blocks = json.loads(view["blocks"])
66 assert len(blocks) == 1
67 block = blocks[0]
68 assert block["kind"] == "detail"
69 assert block["collection"] == "products"
70 assert block["record_id"] == "$record_id"
71 # The retrofit's whole point: owner-editable + deletable in place --
72 # preserving what the bespoke page did. Non-owners never reach the
73 # record at all (no public read rule on products), so the detail
74 # block's read-only view is moot for them; the owner affordances are
75 # what this page actually existed for.
76 assert block["editable"] is True
77 assert block["deletable"] is True
78 assert block["delete_redirect"] == "/products"
79
80
81def test_permalink_route_is_seeded_to_the_view_render_generator():
82 rows = _seed_rows("site_routes")
83 # 0.5.0 appended the /products and /locations index routes, so assert
84 # on the detail row rather than a total that keeps growing.
85 rows = [r for r in rows if r["id"] == "route_products_detail"]
86 assert len(rows) == 1
87 route = rows[0]
88 assert route["id"] == "route_products_detail"
89 assert route["pattern"] == "/products/{product_id}"
90 assert route["object_id"] == "site_view_render"
91 assert route["priority"] == "10"
92
93
94def test_permissions_no_longer_reference_the_removed_object():
95 payload = json.loads((APP_CATALOG_DIR / "permissions" / "rules.json").read_text())
96 object_ids = {rule.get("object_id") for rule in payload["rules"]}
97 assert "site_product_view" not in object_ids
98 # site_stock is a real page object and keeps its grant; site_products
99 # and site_locations name objects nothing ships any more (seeded views),
100 # and a rule for an id nothing ships makes whatever is later created
101 # under that id public (bug-reports/2026-11-28-06-14-43).
102 assert "site_stock" in object_ids
103 assert "site_products" not in object_ids
104 assert "site_locations" not in object_ids
105
106
107def test_no_public_read_rule_was_added_to_products():
108 """The retrofit must not loosen the owner-only posture: products still
109 has no public read rule -- the seeded view's detail block is
110 read-only-for-everyone in principle, but nobody except the owner can
111 actually fetch the record.
112 """
113 payload = json.loads((APP_CATALOG_DIR / "permissions" / "rules.json").read_text())
114 policy = object_permissions.policy_from_dict(
115 {"access_mode": "role_based", "rules": payload["rules"]}
116 )
117 record = {"owner_id": "7", "name": "Widget", "product_type": "physical"}
118 decision = object_permissions.check_permission(
119 None, object_permissions.READ, policy=policy, collection="products", record=record
120 )
121 assert decision.allowed is False
122
123
124def test_dry_run_is_safe(tmp_path):
125 object_root = tmp_path / "objects"
126 object_root.mkdir()
127 plan = object_packages.dry_run_package(
128 "app-catalog",
129 root=PACKAGES_ROOT,
130 base_dir=tmp_path / "data",
131 object_roots=[object_root],
132 )
133 assert plan["safe_to_install"] is True
134 assert plan["warnings"] == []