Guest state: provisioned-but-not-set-up reads 'invited', never 'active'
A guest invitation provisions immediately, but the Cloudron account is not ACCEPTED until the guest clicks the setup link (inviteAccepted=false, no username) — until then they cannot log in, so no surface may read them as active. guest_invite_pending() derives it from the same Cloudron signal the overview's activated flag uses; unseen-record (users fetch failed) is never pending, so the state falls back instead of asserting what the data does not show. /admin/overview: guest rows report state='invited' with an 'awaiting setup' reason (invite date named when the ledger has it); /broker/guests trail entries carry state='invited' the same way, status stays the ledger record of record. Display/state semantics only — access rules, the $2 cap and the expiry box are unchanged. Tests: new test_guest_invited_state.py (derivation, overview flip, fetch-failure fallback, member rows untouched, trail state); test_guest_requests.py gains the trail invited/accepted assertions and a constructible-but-loud fake client so the stubbed users fetch runs.
This commit is contained in:
1 parent
f592e5b7b5
commit
88ca8bfe18
3 files changed
+414
-10
No files matched your search
@@ -77,7 +77,42 @@ class _NoNetwork:
|
||||
raise AssertionError("live network attempted during fixture test")
|
||||
|
||||
|
||||
m.httpx.AsyncClient = _NoNetwork
|
||||
# The trail now derives each guest's invited/active state from the Cloudron
|
||||
# user record, so it opens an httpx client around a STUBBED users fetch: the
|
||||
# client is constructible but every real HTTP attempt still raises — the
|
||||
# guard, kept.
|
||||
class _FakeClient(_NoNetwork):
|
||||
def __init__(self, *a, **k):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *a):
|
||||
return False
|
||||
|
||||
async def get(self, *a, **k):
|
||||
raise AssertionError("live network attempted during fixture test")
|
||||
|
||||
async def post(self, *a, **k):
|
||||
raise AssertionError("live network attempted during fixture test")
|
||||
|
||||
|
||||
m.httpx.AsyncClient = _FakeClient
|
||||
|
||||
# Cloudron users fixture for the invited-state derivation: the fixture guest's
|
||||
# Cloudron user id is 'uid-fixture' (fake_user_create below) with the invite
|
||||
# NOT yet accepted. Tests flip `inviteAccepted` to simulate acceptance.
|
||||
CLOUDRON_USERS = {"uid-fixture": {"inviteAccepted": False, "username": None}}
|
||||
|
||||
|
||||
async def fake_fetch_users(client):
|
||||
return [{"id": uid, "username": v.get("username"),
|
||||
"inviteAccepted": v.get("inviteAccepted", False)}
|
||||
for uid, v in CLOUDRON_USERS.items()]
|
||||
|
||||
|
||||
m.cloudron_fetch_all_users = fake_fetch_users
|
||||
|
||||
# --- recorders (same contract as test_guest_lifecycle) ---------------------- #
|
||||
calls = {"group": [], "budget": [], "email": [], "listmonk": [], "loomio": 0,
|
||||
@@ -266,6 +301,13 @@ def main():
|
||||
check("trail: the new guest visible to the member as active",
|
||||
len(guests) == 1 and guests[0]["recipient"] == "friend@x.org"
|
||||
and guests[0]["status"] == "active", str(view["trail"]))
|
||||
check("trail: un-accepted invite shows state='invited' (never reads active)",
|
||||
guests and guests[0]["state"] == "invited", str(guests))
|
||||
CLOUDRON_USERS["uid-fixture"]["inviteAccepted"] = True # simulate acceptance
|
||||
view = asyncio.run(m.broker_guest_list(make_request("GET")))
|
||||
guests = [t for t in view["trail"] if t.get("kind") == "guest"]
|
||||
check("trail: after acceptance the state follows the ledger (active)",
|
||||
guests and guests[0]["state"] == "active", str(guests))
|
||||
check("trail: no pending entries in the member's trail",
|
||||
not any(t.get("status") == "pending" for t in view["trail"]),
|
||||
str(view["trail"]))
|
||||
|
||||
Reference in new issue
Block a user