forked from slackapi/bolt-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ack.py
More file actions
189 lines (171 loc) · 7.07 KB
/
test_ack.py
File metadata and controls
189 lines (171 loc) · 7.07 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from slack_sdk.models.blocks import PlainTextObject, DividerBlock
from slack_sdk.models.views import View
from slack_bolt import Ack, BoltResponse
class TestAck:
def setup_method(self):
pass
def teardown_method(self):
pass
def test_text(self):
ack = Ack()
response: BoltResponse = ack(text="foo")
assert (response.status, response.body) == (200, "foo")
sample_attachments = [
{
"fallback": "Plain-text summary of the attachment.",
"color": "#2eb886",
"pretext": "Optional text that appears above the attachment block",
"author_name": "Bobby Tables",
"author_link": "http://flickr.com/bobby/",
"author_icon": "http://flickr.com/icons/bobby.jpg",
"title": "Slack API Documentation",
"title_link": "https://api.slack.com/",
"text": "Optional text that appears within the attachment",
"fields": [{"title": "Priority", "value": "High", "short": False}],
"image_url": "http://my-website.com/path/to/image.jpg",
"thumb_url": "http://example.com/path/to/thumb.png",
"footer": "Slack API",
"footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png",
"ts": 123456789,
}
]
def test_attachments(self):
ack = Ack()
response: BoltResponse = ack(text="foo", attachments=self.sample_attachments)
assert (response.status, response.body) == (
200,
'{"text": "foo", '
'"attachments": [{"fallback": "Plain-text summary of the attachment.", "color": "#2eb886", "pretext": "Optional text that appears above the attachment block", "author_name": "Bobby Tables", "author_link": "http://flickr.com/bobby/", "author_icon": "http://flickr.com/icons/bobby.jpg", "title": "Slack API Documentation", "title_link": "https://api.slack.com/", "text": "Optional text that appears within the attachment", "fields": [{"title": "Priority", "value": "High", "short": false}], "image_url": "http://my-website.com/path/to/image.jpg", "thumb_url": "http://example.com/path/to/thumb.png", "footer": "Slack API", "footer_icon": "https://platform.slack-edge.com/img/default_application_icon.png", "ts": 123456789}]'
"}",
)
def test_blocks(self):
ack = Ack()
response: BoltResponse = ack(text="foo", blocks=[{"type": "divider"}])
assert (response.status, response.body) == (
200,
'{"text": "foo", "blocks": [{"type": "divider"}]}',
)
sample_options = [{"text": {"type": "plain_text", "text": "Maru"}, "value": "maru"}]
def test_options(self):
ack = Ack()
response: BoltResponse = ack(text="foo", options=self.sample_options)
assert response.status == 200
assert (
response.body
== '{"options": [{"text": {"type": "plain_text", "text": "Maru"}, "value": "maru"}]}'
)
sample_option_groups = [
{
"label": {"type": "plain_text", "text": "Group 1"},
"options": [
{"text": {"type": "plain_text", "text": "Option 1"}, "value": "1-1"},
{"text": {"type": "plain_text", "text": "Option 2"}, "value": "1-2"},
],
},
{
"label": {"type": "plain_text", "text": "Group 2"},
"options": [
{"text": {"type": "plain_text", "text": "Option 1"}, "value": "2-1"},
],
},
]
def test_option_groups(self):
ack = Ack()
response: BoltResponse = ack(
text="foo", option_groups=self.sample_option_groups
)
assert response.status == 200
assert response.body.startswith('{"option_groups":')
def test_response_type(self):
ack = Ack()
response: BoltResponse = ack(text="foo", response_type="in_channel")
assert (response.status, response.body) == (
200,
'{"text": "foo", "response_type": "in_channel"}',
)
def test_dialog_errors(self):
expected_body = '{"errors": [{"name": "loc_origin", "error": "Pickup Location must be longer than 3 characters"}]}'
errors = [
{
"name": "loc_origin",
"error": "Pickup Location must be longer than 3 characters",
}
]
ack = Ack()
response: BoltResponse = ack(errors=errors)
assert (response.status, response.body) == (200, expected_body)
response: BoltResponse = ack({"errors": errors})
assert (response.status, response.body) == (200, expected_body)
def test_view_errors(self):
ack = Ack()
response: BoltResponse = ack(
response_action="errors",
errors={
"block_title": "Title is required",
"block_description": "Description must be longer than 10 characters",
},
)
assert (response.status, response.body) == (
200,
'{"response_action": "errors", '
'"errors": {'
'"block_title": "Title is required", '
'"block_description": "Description must be longer than 10 characters"'
"}"
"}",
)
def test_view_update(self):
ack = Ack()
response: BoltResponse = ack(
response_action="update",
view={
"type": "modal",
"callback_id": "view-id",
"title": {
"type": "plain_text",
"text": "My App",
},
"close": {
"type": "plain_text",
"text": "Cancel",
},
"blocks": [{"type": "divider", "block_id": "b"}],
},
)
assert (response.status, response.body) == (
200,
'{"response_action": "update", '
'"view": {'
'"type": "modal", '
'"callback_id": "view-id", '
'"title": {"type": "plain_text", "text": "My App"}, '
'"close": {"type": "plain_text", "text": "Cancel"}, '
'"blocks": [{"type": "divider", "block_id": "b"}]'
"}"
"}",
)
def test_view_update_2(self):
ack = Ack()
response: BoltResponse = ack(
response_action="update",
view=View(
type="modal",
callback_id="view-id",
title=PlainTextObject(text="My App"),
close=PlainTextObject(text="Cancel"),
blocks=[DividerBlock(block_id="b")],
),
)
assert (response.status, response.body) == (
200,
""
'{"response_action": "update", '
'"view": {'
'"blocks": [{"block_id": "b", "type": "divider"}], '
'"callback_id": "view-id", '
'"close": {"text": "Cancel", "type": "plain_text"}, '
'"title": {"text": "My App", "type": "plain_text"}, '
'"type": "modal"'
"}"
"}",
)