forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_conversation_first_open_dispatch.py
More file actions
70 lines (57 loc) · 2.51 KB
/
Copy pathtest_conversation_first_open_dispatch.py
File metadata and controls
70 lines (57 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import annotations
from routers import conversations
def test_detail_dispatch_runs_claimed_work_and_completes(monkeypatch) -> None:
calls: list[tuple[object, ...]] = []
monkeypatch.setattr(
conversations.conversations_db, "claim_authorized_first_open_work", lambda _uid, _cid, _source: "lease"
)
monkeypatch.setattr(
conversations.conversations_db,
"get_conversation",
lambda _uid, _cid: {"id": "conversation", "jit_first_open": {"state": "in_flight"}},
)
monkeypatch.setattr(
conversations.conversations_db,
"finish_first_open_work",
lambda _uid, _cid, token, *, succeeded: calls.append((token, succeeded)),
)
monkeypatch.setattr(
conversations,
"run_first_open_derived_work",
lambda uid, row, token: calls.append((uid, row["id"], token)),
)
monkeypatch.setattr(
conversations,
"submit_with_context",
lambda _executor, operation, *args: operation(*args),
)
conversations._dispatch_first_open_work(
"owner", {"id": "conversation", "source": "desktop", "jit_first_open": {"state": "pending"}}
)
assert calls == [("owner", "conversation", "lease"), ("lease", True)]
def test_detail_dispatch_does_not_run_without_claim(monkeypatch) -> None:
monkeypatch.setattr(
conversations.conversations_db, "claim_authorized_first_open_work", lambda _uid, _cid, _source: None
)
monkeypatch.setattr(
conversations,
"submit_with_context",
lambda *_args: (_ for _ in ()).throw(AssertionError("must not dispatch")),
)
conversations._dispatch_first_open_work("owner", {"id": "conversation", "jit_first_open": {"state": "in_flight"}})
def test_kill_or_unknown_suspends_outstanding_obligation_without_claim(monkeypatch) -> None:
observed: list[dict[str, object]] = []
monkeypatch.setattr(
conversations.conversations_db,
"claim_authorized_first_open_work",
lambda uid, cid, source: observed.append({"uid": uid, "conversation_id": cid, "source": source}) or None,
)
monkeypatch.setattr(
conversations,
"submit_with_context",
lambda *_args: (_ for _ in ()).throw(AssertionError("disabled outstanding work must not dispatch")),
)
conversations._dispatch_first_open_work(
"owner", {"id": "conversation", "source": "desktop", "jit_first_open": {"state": "pending"}}
)
assert observed == [{"uid": "owner", "conversation_id": "conversation", "source": "desktop"}]