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

0 downloads

dbbasic-object-server/tests/test_object_feature_flags.py
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.

danq9 signup: the person chooses the password and name on the confirm page 83c7aa6 2 weeks, 5 days ago History
test_object_feature_flags.py · 3.0 KB · 64 lines
1"""The shared opt-in and kill-switch gates (object_feature_flags).
2
3These were six copies before; the tests pin the posture every copy had,
4so the extraction cannot quietly change what an operator's flag means.
5"""
6
7import object_email
8import object_feature_flags
9import object_records
10
11
12def _flags(tmp_path, rows):
13 data_dir = tmp_path / "data"
14 schema_dir = data_dir / "schemas"
15 schema_dir.mkdir(parents=True)
16 (schema_dir / "feature_flags.json").write_text(
17 '{"name": "feature_flags", "fields": [{"name": "id"}, {"name": "flag"}, {"name": "value"}]}')
18 for index, (flag, value) in enumerate(rows):
19 object_records.create_collection_record(
20 "feature_flags", {"id": f"f{index}", "flag": flag, "value": value},
21 base_dir=data_dir, actor="test")
22 return data_dir
23
24
25def test_env_opt_in_is_off_unless_the_operator_wrote_it():
26 """Adoption gate: a fresh box talks to nobody."""
27 assert object_feature_flags.env_opt_in("X", {}) is False
28 assert object_feature_flags.env_opt_in("X", {"X": ""}) is False
29 assert object_feature_flags.env_opt_in("X", {"X": "false"}) is False
30 assert object_feature_flags.env_opt_in("X", {"X": " TRUE "}) is True
31 assert object_feature_flags.env_opt_in("X", {"X": "1"}) is True
32
33
34def test_kill_switch_is_on_without_a_table_a_row_or_a_value(tmp_path):
35 """Brownout lever: only an explicit off turns a pass off. A switch that
36 failed closed on a missing table would turn every fresh box's passes
37 off for a reason nobody chose."""
38 missing = tmp_path / "nothing"
39 assert object_feature_flags.kill_switch_on("mail_sync_enabled", base_dir=missing) is True
40 data_dir = _flags(tmp_path, [("other_enabled", "off"), ("mail_sync_enabled", "")])
41 assert object_feature_flags.kill_switch_on("mail_sync_enabled", base_dir=data_dir) is True
42 assert object_feature_flags.kill_switch_on("other_enabled", base_dir=data_dir) is False
43
44
45def test_the_existing_switches_now_read_through_the_shared_gate(tmp_path):
46 """email_pass_enabled keeps its name and its meaning."""
47 data_dir = _flags(tmp_path, [("email_enabled", "no")])
48 assert object_email.email_pass_enabled(base_dir=data_dir) is False
49
50
51def test_refusal_names_what_to_set(tmp_path):
52 """A refusal that does not name the variable is a refusal nobody can act on."""
53 data_dir = _flags(tmp_path, [("mail_sync_enabled", "off")])
54 off_env = object_feature_flags.refusal(
55 env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled",
56 base_dir=data_dir, env={})
57 assert "DBBASIC_ENABLE_MAIL_SYNC" in off_env
58 off_flag = object_feature_flags.refusal(
59 env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled",
60 base_dir=data_dir, env={"DBBASIC_ENABLE_MAIL_SYNC": "true"})
61 assert "mail_sync_enabled" in off_flag
62 assert object_feature_flags.refusal(
63 env_name="DBBASIC_ENABLE_MAIL_SYNC", flag="mail_sync_enabled",
64 base_dir=tmp_path / "nothing", env={"DBBASIC_ENABLE_MAIL_SYNC": "yes"}) is None