"""The store: vocabulary enforced, the story kept in order.""" import pytest from store import DEFAULT_STATE, STATE_KEYS, Store @pytest.fixture def store(): s = Store(":memory:") yield s s.close() def test_add_and_get(store): a = store.add("alice", name="Alice", roles="Apache Foo PMC member") assert a.asf_id == "alice" assert a.state == DEFAULT_STATE assert a.tags == [] assert store.get("alice").name == "Alice" def test_unknown_values_are_refused(store): with pytest.raises(ValueError): _ = store.add("bob", state="nope") with pytest.raises(ValueError): _ = store.add("bob", shoe_size=9) _ = store.add("bob") with pytest.raises(ValueError): store.set_tags("bob", ["nope"]) with pytest.raises(ValueError): _ = store.add_event("bob", "nope", "text") def test_state_change_is_an_event(store): _ = store.add("carol") store.set_state("carol", "approved", by="admin", note="program said so") assert store.get("carol").state == "approved" events = store.events("carol") assert len(events) == 1 assert events[0].kind == "state" assert events[0].text == "applied -> approved: program said so" assert events[0].source == "admin" # The same state again, with nothing to say, is not an event. store.set_state("carol", "approved") assert len(store.events("carol")) == 1 def test_tags_and_priority_order(store): _ = store.add("dave", name="Dave") _ = store.add("erin", name="Erin") store.set_tags("erin", ["priority", "wrong_repo"]) assert store.get("erin").tags == ["priority", "wrong_repo"] assert [a.asf_id for a in store.list()] == ["erin", "dave"] store.set_tags("erin", []) assert [a.asf_id for a in store.list()] == ["dave", "erin"] def test_counts_cover_every_state(store): _ = store.add("frank", state="held") counts = store.counts() assert set(counts) == set(STATE_KEYS) assert counts["held"] == 1 assert counts["applied"] == 0 assert [a.asf_id for a in store.list("held")] == ["frank"] def test_events_keep_their_order(store): _ = store.add("grace") _ = store.add_event("grace", "applicant_wrote", "I applied.", at="2026-09-01") _ = store.add_event("grace", "program_said", "No record.") kinds = [(e.kind, e.at) for e in store.events("grace")] assert kinds == [("applicant_wrote", "2026-09-01"), ("program_said", None)]