-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_main.py
More file actions
151 lines (120 loc) · 4.46 KB
/
Copy pathtest_main.py
File metadata and controls
151 lines (120 loc) · 4.46 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import os
import unittest
from unittest.mock import patch
import main
class CommandWrapperTest(unittest.TestCase):
def capture_run(self):
calls = []
def fake_run(*args, **kwargs):
calls.append((args, kwargs))
return {"ok": True}
return calls, fake_run
def test_postings_include_pagination_flags(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.list_postings("imbox", limit=25, fetch_all=True)
self.assertEqual(calls[0][0], ("box", "imbox", "--limit", "25", "--all"))
def test_compose_defaults_to_send_without_draft_flag(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.compose_email(
to="alice@example.com",
subject="Hello",
message="Hi there",
)
self.assertEqual(
calls[0][0],
(
"compose",
"--subject",
"Hello",
"--message",
"Hi there",
"--to",
"alice@example.com",
),
)
def test_compose_can_save_draft(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.compose_email(
to="alice@example.com",
subject="Hello",
message="Hi there",
draft=True,
)
self.assertEqual(calls[0][0][-1], "--draft")
def test_reply_defaults_to_send_without_draft_flag(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.reply_to_thread("123", "Thanks")
self.assertEqual(calls[0][0], ("reply", "123", "--message", "Thanks"))
def test_reply_can_save_draft(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.reply_to_thread("123", "Thanks", draft=True)
self.assertEqual(calls[0][0], ("reply", "123", "--message", "Thanks", "--draft"))
def test_event_create_supports_reminders_and_invitees(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.create_event(
calendar_id="1",
title="Project review",
starts_at="2026-01-20",
start_time="09:00",
end_time="09:30",
timezone="America/New_York",
reminders=["15m"],
invitees=["alice@example.com", "bob@example.org"],
)
self.assertEqual(
calls[0][0],
(
"event",
"create",
"--title",
"Project review",
"--calendar-id",
"1",
"--starts-at",
"2026-01-20",
"--start-time",
"09:00",
"--end-time",
"09:30",
"--timezone",
"America/New_York",
"--reminder",
"15m",
"--invitee",
"alice@example.com",
"--invitee",
"bob@example.org",
),
)
def test_event_update_can_set_all_day_false_and_replace_invitees(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.update_event(event_id="123", all_day=False, invitees=["carol@example.com"])
self.assertEqual(
calls[0][0],
(
"event",
"update",
"123",
"--all-day=false",
"--invitee",
"carol@example.com",
),
)
def test_attachment_download_expands_output_path(self):
calls, fake_run = self.capture_run()
with patch.object(main, "run_hey", fake_run):
main.download_attachments("123", output="~/Downloads", entry_id="456", index=1)
args, kwargs = calls[0]
self.assertEqual(args[:4], ("attachments", "download", "123", "--output"))
self.assertEqual(args[4], os.path.expanduser("~/Downloads"))
self.assertEqual(args[5:], ("--entry", "456", "--index", "1"))
self.assertGreaterEqual(kwargs["timeout_seconds"], 120)
if __name__ == "__main__":
unittest.main()