askrobots / dbbasic-object-server
Public
Runs live, versioned Python application objects on one VM, with a suite of apps: projects, notes, tasks, files and more.
danq9
signup: the person chooses the password and name on the confirm page
83c7aa6
2 weeks, 5 days ago
History
test_app_notes_package.py · 3.5 KB · 92 lines
| 1 | """Structural tests for packages/app-notes after the Stage-6 retrofit: the |
| 2 | bespoke 152-line site_note_view.py permalink page was replaced by a seeded |
| 3 | 59 detail view (site_view_render) whose `detail` block is owner-aware |
| 4 | (editable/deletable), so there is no per-note page object anymore. This also |
| 5 | fixes a latent gap -- the package previously shipped no site_routes record |
| 6 | for /notes/{note_id}, so permalinks depended on a route nothing seeded. |
| 7 | """ |
| 8 | |
| 9 | import json |
| 10 | from pathlib import Path |
| 11 | |
| 12 | import object_packages |
| 13 | import object_permissions |
| 14 | |
| 15 | PACKAGES_ROOT = Path(__file__).resolve().parents[1] / "packages" |
| 16 | APP_NOTES_DIR = PACKAGES_ROOT / "app-notes" |
| 17 | |
| 18 | |
| 19 | def _seed_rows(name): |
| 20 | import csv |
| 21 | |
| 22 | with open(APP_NOTES_DIR / "seed" / f"{name}.tsv", newline="") as fh: |
| 23 | return list(csv.DictReader(fh, delimiter="\t")) |
| 24 | |
| 25 | |
| 26 | def test_manifest_drops_the_bespoke_view_object_and_seeds_the_detail_view(): |
| 27 | package = object_packages.get_package("app-notes", root=PACKAGES_ROOT) |
| 28 | # Only the list page remains an object -- the permalink page is gone. |
| 29 | # 0.4.0: the bespoke page is gone; notes is now pure data |
| 30 | # (schema + permissions + two seeded view records). |
| 31 | assert package["objects"] == [] |
| 32 | # The detail view + its route are seeded (into app-views'/site-routing's |
| 33 | # own shared collections), alongside the notes seed. |
| 34 | assert {entry["collection"] for entry in package["seed"]} == { |
| 35 | "notes", "views", "site_routes", |
| 36 | } |
| 37 | |
| 38 | |
| 39 | def test_note_view_object_file_is_deleted(): |
| 40 | assert not (APP_NOTES_DIR / "objects" / "site" / "note_view.py").exists() |
| 41 | |
| 42 | |
| 43 | def test_seeded_detail_view_uses_an_owner_aware_editable_detail_block(): |
| 44 | rows = _seed_rows("views") |
| 45 | # 0.4.0 added the index view beside the detail view. |
| 46 | rows = [r for r in rows if r["id"] == "view_notes_detail"] |
| 47 | assert len(rows) == 1 |
| 48 | view = rows[0] |
| 49 | assert view["id"] == "view_notes_detail" |
| 50 | assert view["route"] == "/notes/{note_id}" |
| 51 | blocks = json.loads(view["blocks"]) |
| 52 | assert len(blocks) == 1 |
| 53 | block = blocks[0] |
| 54 | assert block["kind"] == "detail" |
| 55 | assert block["collection"] == "notes" |
| 56 | assert block["record_id"] == "$record_id" |
| 57 | # The retrofit's whole point: read-only for everyone, owner-editable + |
| 58 | # deletable in place -- preserving what the bespoke page did. |
| 59 | assert block["editable"] is True |
| 60 | assert block["deletable"] is True |
| 61 | assert block["delete_redirect"] == "/notes" |
| 62 | |
| 63 | |
| 64 | def test_permalink_route_is_seeded_to_the_view_render_generator(): |
| 65 | rows = _seed_rows("site_routes") |
| 66 | # 0.4.0 added the /notes index route alongside the permalink, so assert |
| 67 | # on the permalink row rather than a total that keeps growing. |
| 68 | rows = [r for r in rows if r["id"] == "route_notes_detail"] |
| 69 | assert len(rows) == 1 |
| 70 | route = rows[0] |
| 71 | assert route["pattern"] == "/notes/{note_id}" |
| 72 | assert route["object_id"] == "site_view_render" |
| 73 | |
| 74 | |
| 75 | def test_permissions_no_longer_reference_the_removed_object(): |
| 76 | payload = json.loads((APP_NOTES_DIR / "permissions" / "rules.json").read_text()) |
| 77 | object_ids = {rule.get("object_id") for rule in payload["rules"]} |
| 78 | assert "site_note_view" not in object_ids |
| 79 | assert "site_notes" in object_ids # the list page is still a public object |
| 80 | |
| 81 | |
| 82 | def test_dry_run_is_safe(tmp_path): |
| 83 | object_root = tmp_path / "objects" |
| 84 | object_root.mkdir() |
| 85 | plan = object_packages.dry_run_package( |
| 86 | "app-notes", |
| 87 | root=PACKAGES_ROOT, |
| 88 | base_dir=tmp_path / "data", |
| 89 | object_roots=[object_root], |
| 90 | ) |
| 91 | assert plan["safe_to_install"] is True |
| 92 | assert plan["warnings"] == [] |