ProfileStore.of_meta resolves a conversation with a guest meta.owner (or a guest-<uid> login) to the new built-in 'guests' profile — no runners, projects or resources; only label/icon/colour/enabled are editable, and off restores the runner rule. /api/profiles adds its members; the selector keeps guest spend on a profile's own seat in that profile's figures and takes guest:<uid> items to narrow the Guests view; the notification feed carries the conversation's owner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.4 KiB
Python
89 lines
3.4 KiB
Python
"""The account stamp on /api/notify-log entries — what the PWA's Perso / Work
|
|
switch scopes a hub-only entry by (``python3 -m unittest test_notify_log_account``
|
|
from ``backend/``, inside the service image)."""
|
|
|
|
import unittest
|
|
from types import SimpleNamespace
|
|
|
|
from notifications.routes import _with_account
|
|
from notifications.service import session_account
|
|
|
|
|
|
class _Meta:
|
|
def __init__(self, by_sid):
|
|
self.by_sid = by_sid
|
|
|
|
def peek(self, sid):
|
|
return self.by_sid.get(sid, {})
|
|
|
|
|
|
class _Profiles:
|
|
"""The runner rule, as ProfileStore.of_meta answers it: the Mac is Work,
|
|
a guest's conversation is Guests'."""
|
|
|
|
def of_meta(self, meta, account=None):
|
|
m = meta or {}
|
|
if m.get("profile"):
|
|
return m["profile"]
|
|
if m.get("owner") not in (None, "", "owner"):
|
|
return "guests"
|
|
return "work" if (m.get("worker") or m.get("workerSource")) == "mac" else "personal"
|
|
|
|
|
|
def _deps(by_sid):
|
|
return SimpleNamespace(meta_store=_Meta(by_sid), profile_store=_Profiles())
|
|
|
|
|
|
class WithAccount(unittest.TestCase):
|
|
def test_spawn_stamp(self):
|
|
e = {"id": "n1", "sessionId": "s1"}
|
|
out = _with_account(_deps({"s1": {"account": "work"}}), e)
|
|
self.assertEqual(out["account"], "work")
|
|
self.assertNotIn("account", e) # the stored entry is never mutated
|
|
|
|
def test_profile_follows_the_runner(self):
|
|
# a lab run on the work seat is a Personal entry; the Mac's are Work
|
|
out = _with_account(_deps({"s1": {"account": "work"},
|
|
"s2": {"accountSource": "work", "workerSource": "mac"}}),
|
|
{"sessionId": "s1"})
|
|
self.assertEqual((out["account"], out["profile"]), ("work", "personal"))
|
|
out = _with_account(_deps({"s2": {"accountSource": "work", "workerSource": "mac"}}),
|
|
{"sessionId": "s2"})
|
|
self.assertEqual(out["profile"], "work")
|
|
|
|
def test_a_guests_entry_is_the_guests_profiles(self):
|
|
out = _with_account(_deps({"s1": {"account": "personal", "owner": "dom"}}),
|
|
{"sessionId": "s1"})
|
|
self.assertEqual((out["account"], out["profile"]), ("personal", "guests"))
|
|
|
|
def test_import_source(self):
|
|
out = _with_account(_deps({"s1": {"accountSource": "work"}}),
|
|
{"sessionId": "s1"})
|
|
self.assertEqual(out["account"], "work")
|
|
|
|
def test_unknown_stays_unstamped(self):
|
|
# no sidecar stamp: never guessed onto the default account
|
|
for deps, e in ((_deps({}), {"sessionId": "s1"}),
|
|
(_deps({"s1": {"account": "nope"}}), {"sessionId": "s1"}),
|
|
(_deps({}), {"id": "n1"})):
|
|
self.assertNotIn("account", _with_account(deps, e))
|
|
|
|
|
|
class SessionAccount(unittest.TestCase):
|
|
"""The same stamp rides the webhook payload of every push and ask, so the
|
|
HA integration can keep work pushes on their own channels."""
|
|
|
|
def test_stamped(self):
|
|
deps = _deps({"s1": {"account": "work"}, "s2": {"accountSource": "personal"}})
|
|
self.assertEqual(session_account(deps, "s1"), "work")
|
|
self.assertEqual(session_account(deps, "s2"), "personal")
|
|
|
|
def test_unstamped_is_empty(self):
|
|
deps = _deps({"s1": {"account": "nope"}})
|
|
for sid in ("", "s1", "s9"):
|
|
self.assertEqual(session_account(deps, sid), "")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|