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_install_order_after_upgrade.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_install_order_after_upgrade.py · 3.6 KB · 93 lines
1"""Reinstalling every package after an upgrade works in any order.
2
3app-nav owns the `attention_sources` schema. 2026.11v3 required `object_id`; the
4current tree makes it optional, because a declared count has no provider
5object. Packages that declare such a count write a row there at install. On a
6box upgraded from 2026.11v3 whose app-nav has not been reinstalled yet, the
7installed schema still demands `object_id`, and alphabetical order installs
8app-nav last: seven packages answered 400 on the first pass and succeeded on a
9second. An install must not fail on another package's stale schema.
10"""
11
12from __future__ import annotations
13
14import io
15import json
16import subprocess
17import tarfile
18from pathlib import Path
19
20import pytest
21
22import object_package_baselines
23import object_packages
24import object_records
25
26ROOT = Path(__file__).resolve().parents[1]
27PREVIOUS = "2026.11v3"
28DECLARES_COUNTS = "app-finance" # one of the packages that declares a count
29
30
31@pytest.fixture
32def old_nav_box(tmp_path):
33 """A data dir whose app-nav is the previous release's."""
34 archive = subprocess.run(
35 ["git", "archive", PREVIOUS, "packages/app-nav"], cwd=ROOT, capture_output=True)
36 if archive.returncode != 0:
37 pytest.skip(f"{PREVIOUS} is not in this checkout")
38 old = tmp_path / "old"
39 old.mkdir()
40 with tarfile.open(fileobj=io.BytesIO(archive.stdout)) as tar:
41 tar.extractall(old, filter="data")
42 data = tmp_path / "data"
43 result = object_packages.install_package(
44 "app-nav", root=old / "packages", base_dir=data, allow_replace=True,
45 object_roots=[data / "objects"])
46 assert result["mode"] == "install"
47 schema = json.loads((data / "schemas" / "attention_sources.json").read_text())
48 object_field = next(f for f in schema["fields"] if f["name"] == "object_id")
49 assert object_field.get("required") is True # the old box really is old
50 return data
51
52
53def install(name, data):
54 return object_packages.install_package(
55 name, root=ROOT / "packages", base_dir=data, allow_replace=True,
56 object_roots=[data / "objects"])
57
58
59def test_a_package_installs_before_app_nav_is_refreshed(old_nav_box):
60 result = install(DECLARES_COUNTS, old_nav_box)
61 assert result["mode"] == "install"
62 assert any("attention" in w and "app-nav" in w for w in result["warnings"])
63
64
65def test_app_nav_then_registers_what_the_earlier_install_deferred(old_nav_box):
66 install(DECLARES_COUNTS, old_nav_box)
67 rows = {r["id"] for r in object_records.read_collection_records(
68 "attention_sources", base_dir=old_nav_box)}
69 declared = {e["id"] for e in object_package_baselines.load_baseline(
70 DECLARES_COUNTS, base_dir=old_nav_box)["attention"]}
71 assert declared and not (declared & rows)
72
73 registered = install("app-nav", old_nav_box)["registered_for_others"]
74 rows = {r["id"] for r in object_records.read_collection_records(
75 "attention_sources", base_dir=old_nav_box)}
76 assert declared <= rows
77 assert any(item["package"] == DECLARES_COUNTS for item in registered)
78
79
80def test_a_second_install_after_app_nav_needs_no_warning(old_nav_box):
81 install(DECLARES_COUNTS, old_nav_box)
82 install("app-nav", old_nav_box)
83 again = install(DECLARES_COUNTS, old_nav_box)
84 assert not [w for w in again["warnings"] if "attention" in w]
85
86
87def test_a_real_validation_error_is_still_refused_when_the_schema_is_current(tmp_path):
88 data = tmp_path / "data"
89 install("app-nav", data)
90 with pytest.raises(Exception):
91 object_records.create_collection_record(
92 "attention_sources", {"id": "bad", "label": "x", "severity": "no-such-level"},
93 base_dir=data, actor="package:test")