python101 lines · 2.5 KB
1from broadcast import Broadcast, BroadcastError, kickoff_for, render
2from mapping import Work
3
4FULL = """*North Star launch*
5`north-star` · active
6
7Jordan Lee owns it
8Ada Chen is on it
9
10> Default to the single, then the pair, then the set.
11> — Jordan Lee
12
13Reply in this thread. One status is enough.
14"""
15
16
17def test_kickoff_is_a_card_not_a_dump():
18 text = render(
19 Broadcast(
20 kind="kickoff",
21 work_id="north-star",
22 title="North Star launch",
23 state="active",
24 owner="Jordan Lee",
25 assignee="Ada Chen",
26 quote="Default to the single, then the pair, then the set.",
27 quote_from="Jordan Lee",
28 )
29 )
30 assert text == FULL
31 for banned in ("broadcast:", "state:", "owner:", "in flight:", "context:"):
32 assert banned not in text
33
34
35def test_empty_fields_are_omitted():
36 text = render(
37 Broadcast(
38 kind="nudge",
39 work_id="beta-waitlist",
40 title="Beta waitlist",
41 state="active",
42 )
43 )
44 assert "owns it" not in text
45 assert "is on it" not in text
46 assert ">" not in text
47 assert text.endswith("Still open. Reply in this thread.\n")
48
49
50def test_discord_bolds_with_two_stars():
51 text = render(
52 Broadcast(
53 kind="done",
54 work_id="north-star",
55 title="North Star launch",
56 state="closed",
57 platform="discord",
58 )
59 )
60 assert text.startswith("**North Star launch**\n")
61 assert text.endswith("Closed.\n")
62
63
64def test_kind_must_match_state():
65 try:
66 render(
67 Broadcast(
68 kind="kickoff",
69 work_id="north-star",
70 title="North Star launch",
71 state="blocked",
72 )
73 )
74 raise AssertionError("kickoff accepted a blocked row")
75 except BroadcastError:
76 pass
77
78
79def test_kickoff_for_uses_the_work_row():
80 w = Work(
81 id="north-star",
82 name="North Star launch",
83 room="C0OPS03",
84 state="active",
85 anchor="",
86 owner="Jordan Lee",
87 )
88 text = kickoff_for(w, assignee="Ada Chen")
89 assert "Jordan Lee owns it" in text
90 assert "Ada Chen is on it" in text
91 assert text.startswith("*North Star launch*\n")
92
93
94if __name__ == "__main__":
95 test_kickoff_is_a_card_not_a_dump()
96 test_empty_fields_are_omitted()
97 test_discord_bolds_with_two_stars()
98 test_kind_must_match_state()
99 test_kickoff_for_uses_the_work_row()
100 print("ok")
101