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_articles_detail_retrofit.py · 4.0 KB · 99 lines
| 1 | """Structural tests for packages/app-articles after the Stage-6 retrofit: the |
| 2 | bespoke ~150-line site_article_view.py permalink page was replaced by a |
| 3 | seeded 59 detail view (site_view_render) whose `detail` block is |
| 4 | owner-aware (editable/deletable), so there is no per-article page object |
| 5 | anymore. The one-click Publish/Unpublish toggle collapses into the owner |
| 6 | editing `is_public` (and `published_on`) through the generator's ordinary |
| 7 | edit form -- same fields, one fewer bespoke action, matching how notes' |
| 8 | share-toggle became an is_public edit. |
| 9 | """ |
| 10 | |
| 11 | import json |
| 12 | from pathlib import Path |
| 13 | |
| 14 | import object_packages |
| 15 | import object_permissions |
| 16 | |
| 17 | PACKAGES_ROOT = Path(__file__).resolve().parents[1] / "packages" |
| 18 | APP_ARTICLES_DIR = PACKAGES_ROOT / "app-articles" |
| 19 | |
| 20 | |
| 21 | def _seed_rows(name): |
| 22 | import csv |
| 23 | |
| 24 | with open(APP_ARTICLES_DIR / "seed" / f"{name}.tsv", newline="") as fh: |
| 25 | return list(csv.DictReader(fh, delimiter="\t")) |
| 26 | |
| 27 | |
| 28 | def test_manifest_drops_the_bespoke_view_object_and_seeds_the_detail_view(): |
| 29 | package = object_packages.get_package("app-articles", root=PACKAGES_ROOT) |
| 30 | # The permalink page object was gone first; 0.3.0 deletes the bespoke |
| 31 | # /articles list page object too -- both held no business logic and are |
| 32 | # now seeded VIEW records over the generic `list`/`detail` blocks. |
| 33 | assert package["objects"] == [] |
| 34 | # The detail view + its route are seeded (into app-views'/site-routing's |
| 35 | # own shared collections), alongside the articles seed. |
| 36 | assert {entry["collection"] for entry in package["seed"]} == { |
| 37 | "articles", "views", "site_routes", |
| 38 | } |
| 39 | |
| 40 | |
| 41 | def test_article_view_object_file_is_deleted(): |
| 42 | assert not (APP_ARTICLES_DIR / "objects" / "site" / "article_view.py").exists() |
| 43 | |
| 44 | |
| 45 | def test_seeded_detail_view_uses_an_owner_aware_editable_detail_block(): |
| 46 | rows = _seed_rows("views") |
| 47 | # 0.3.0 added the /articles index view alongside this detail view, so |
| 48 | # assert on the detail row rather than a total that keeps growing. |
| 49 | rows = [r for r in rows if r["id"] == "view_articles_detail"] |
| 50 | assert len(rows) == 1 |
| 51 | view = rows[0] |
| 52 | assert view["id"] == "view_articles_detail" |
| 53 | assert view["route"] == "/articles/{article_id}" |
| 54 | blocks = json.loads(view["blocks"]) |
| 55 | assert len(blocks) == 1 |
| 56 | block = blocks[0] |
| 57 | assert block["kind"] == "detail" |
| 58 | assert block["collection"] == "articles" |
| 59 | assert block["record_id"] == "$record_id" |
| 60 | # The retrofit's whole point: read-only for everyone, owner-editable + |
| 61 | # deletable in place -- preserving what the bespoke page did (minus the |
| 62 | # dedicated Publish button, which becomes an is_public/published_on edit). |
| 63 | assert block["editable"] is True |
| 64 | assert block["deletable"] is True |
| 65 | assert block["delete_redirect"] == "/articles" |
| 66 | |
| 67 | |
| 68 | def test_permalink_route_is_seeded_to_the_view_render_generator(): |
| 69 | rows = _seed_rows("site_routes") |
| 70 | # 0.3.0 appended the /articles index route, so assert on the detail |
| 71 | # row rather than a total that keeps growing. |
| 72 | rows = [r for r in rows if r["id"] == "route_articles_detail"] |
| 73 | assert len(rows) == 1 |
| 74 | route = rows[0] |
| 75 | assert route["pattern"] == "/articles/{article_id}" |
| 76 | assert route["object_id"] == "site_view_render" |
| 77 | |
| 78 | |
| 79 | def test_permissions_no_longer_reference_the_removed_object(): |
| 80 | payload = json.loads((APP_ARTICLES_DIR / "permissions" / "rules.json").read_text()) |
| 81 | object_ids = {rule.get("object_id") for rule in payload["rules"]} |
| 82 | assert "site_article_view" not in object_ids |
| 83 | # site_articles' own public-execute rule is left in place even though |
| 84 | # the object was deleted in 0.3.0 -- same precedent as app-notes' |
| 85 | # site_notes rule (see tests/test_app_notes_package.py). |
| 86 | assert "site_articles" in object_ids |
| 87 | |
| 88 | |
| 89 | def test_dry_run_is_safe(tmp_path): |
| 90 | object_root = tmp_path / "objects" |
| 91 | object_root.mkdir() |
| 92 | plan = object_packages.dry_run_package( |
| 93 | "app-articles", |
| 94 | root=PACKAGES_ROOT, |
| 95 | base_dir=tmp_path / "data", |
| 96 | object_roots=[object_root], |
| 97 | ) |
| 98 | assert plan["safe_to_install"] is True |
| 99 | assert plan["warnings"] == [] |