|
7 | 7 | block_action, |
8 | 8 | action, |
9 | 9 | workflow_step_execute, |
| 10 | + event, |
| 11 | + shortcut, |
10 | 12 | ) |
11 | 13 |
|
12 | 14 |
|
@@ -52,6 +54,7 @@ def test_block_action(self): |
52 | 54 | action({"action_id": re.compile("invalid_.+")}).matches(req, resp) is False |
53 | 55 | ) |
54 | 56 |
|
| 57 | + # block_id + action_id |
55 | 58 | assert ( |
56 | 59 | action({"action_id": "valid_action_id", "block_id": "b"}).matches(req, resp) |
57 | 60 | is True |
@@ -100,6 +103,26 @@ def test_block_action(self): |
100 | 103 | is False |
101 | 104 | ) |
102 | 105 |
|
| 106 | + # with type |
| 107 | + assert ( |
| 108 | + action({"action_id": "valid_action_id", "type": "block_actions"}).matches( |
| 109 | + req, resp |
| 110 | + ) |
| 111 | + is True |
| 112 | + ) |
| 113 | + assert ( |
| 114 | + action( |
| 115 | + {"callback_id": "valid_action_id", "type": "interactive_message"} |
| 116 | + ).matches(req, resp) |
| 117 | + is False |
| 118 | + ) |
| 119 | + assert ( |
| 120 | + action( |
| 121 | + {"callback_id": "valid_action_id", "type": "workflow_step_edit"} |
| 122 | + ).matches(req, resp) |
| 123 | + is False |
| 124 | + ) |
| 125 | + |
103 | 126 | def test_workflow_step_execute(self): |
104 | 127 | payload = { |
105 | 128 | "team_id": "T111", |
@@ -135,3 +158,137 @@ def test_workflow_step_execute(self): |
135 | 158 |
|
136 | 159 | m = workflow_step_execute(re.compile("copy_.+")) |
137 | 160 | assert m.matches(request, None) == True |
| 161 | + |
| 162 | + def test_events(self): |
| 163 | + request = BoltRequest(body=json.dumps(event_payload)) |
| 164 | + |
| 165 | + m = event("app_mention") |
| 166 | + assert m.matches(request, None) |
| 167 | + m = event({"type": "app_mention"}) |
| 168 | + assert m.matches(request, None) |
| 169 | + m = event("message") |
| 170 | + assert not m.matches(request, None) |
| 171 | + m = event({"type": "message"}) |
| 172 | + assert not m.matches(request, None) |
| 173 | + |
| 174 | + request = BoltRequest(body=f"payload={quote(json.dumps(shortcut_payload))}") |
| 175 | + |
| 176 | + m = event("app_mention") |
| 177 | + assert not m.matches(request, None) |
| 178 | + m = event({"type": "app_mention"}) |
| 179 | + assert not m.matches(request, None) |
| 180 | + |
| 181 | + def test_global_shortcuts(self): |
| 182 | + request = BoltRequest(body=f"payload={quote(json.dumps(shortcut_payload))}") |
| 183 | + |
| 184 | + m = shortcut("test-shortcut") |
| 185 | + assert m.matches(request, None) |
| 186 | + m = shortcut({"callback_id": "test-shortcut", "type": "shortcut"}) |
| 187 | + assert m.matches(request, None) |
| 188 | + |
| 189 | + m = shortcut("test-shortcut!!!") |
| 190 | + assert not m.matches(request, None) |
| 191 | + m = shortcut({"callback_id": "test-shortcut", "type": "message_action"}) |
| 192 | + assert not m.matches(request, None) |
| 193 | + m = shortcut({"callback_id": "test-shortcut!!!", "type": "shortcut"}) |
| 194 | + assert not m.matches(request, None) |
| 195 | + |
| 196 | + def test_message_shortcuts(self): |
| 197 | + request = BoltRequest( |
| 198 | + body=f"payload={quote(json.dumps(message_shortcut_payload))}" |
| 199 | + ) |
| 200 | + |
| 201 | + m = shortcut("test-shortcut") |
| 202 | + assert m.matches(request, None) |
| 203 | + m = shortcut({"callback_id": "test-shortcut", "type": "message_action"}) |
| 204 | + assert m.matches(request, None) |
| 205 | + |
| 206 | + m = shortcut("test-shortcut!!!") |
| 207 | + assert not m.matches(request, None) |
| 208 | + m = shortcut({"callback_id": "test-shortcut", "type": "shortcut"}) |
| 209 | + assert not m.matches(request, None) |
| 210 | + m = shortcut({"callback_id": "test-shortcut!!!", "type": "message_action"}) |
| 211 | + assert not m.matches(request, None) |
| 212 | + |
| 213 | + |
| 214 | +event_payload = { |
| 215 | + "team_id": "T111", |
| 216 | + "enterprise_id": "E111", |
| 217 | + "api_app_id": "A111", |
| 218 | + "event": { |
| 219 | + "type": "app_mention", |
| 220 | + "text": "<@W111> Hi there!", |
| 221 | + "user": "W222", |
| 222 | + "ts": "1595926230.009600", |
| 223 | + "event_ts": "1595926230.009600", |
| 224 | + }, |
| 225 | + "type": "event_callback", |
| 226 | + "event_id": "Ev111", |
| 227 | + "event_time": 1595926230, |
| 228 | + "authorizations": [ |
| 229 | + { |
| 230 | + "enterprise_id": "E111", |
| 231 | + "team_id": "T111", |
| 232 | + "user_id": "W111", |
| 233 | + "is_bot": True, |
| 234 | + "is_enterprise_install": True, |
| 235 | + } |
| 236 | + ], |
| 237 | +} |
| 238 | + |
| 239 | +shortcut_payload = { |
| 240 | + "type": "shortcut", |
| 241 | + "token": "verification_token", |
| 242 | + "action_ts": "111.111", |
| 243 | + "team": { |
| 244 | + "id": "T111", |
| 245 | + "domain": "workspace-domain", |
| 246 | + "enterprise_id": "E111", |
| 247 | + "enterprise_name": "Org Name", |
| 248 | + }, |
| 249 | + "user": {"id": "W111", "username": "primary-owner", "team_id": "T111"}, |
| 250 | + "callback_id": "test-shortcut", |
| 251 | + "trigger_id": "111.111.xxxxxx", |
| 252 | +} |
| 253 | + |
| 254 | + |
| 255 | +message_shortcut_payload = { |
| 256 | + "type": "message_action", |
| 257 | + "token": "verification_token", |
| 258 | + "action_ts": "1583637157.207593", |
| 259 | + "team": { |
| 260 | + "id": "T111", |
| 261 | + "domain": "test-test", |
| 262 | + "enterprise_id": "E111", |
| 263 | + "enterprise_name": "Org Name", |
| 264 | + }, |
| 265 | + "user": {"id": "W111", "name": "test-test"}, |
| 266 | + "channel": {"id": "C111", "name": "dev"}, |
| 267 | + "callback_id": "test-shortcut", |
| 268 | + "trigger_id": "111.222.xxx", |
| 269 | + "message_ts": "1583636382.000300", |
| 270 | + "message": { |
| 271 | + "client_msg_id": "zzzz-111-222-xxx-yyy", |
| 272 | + "type": "message", |
| 273 | + "text": "<@W222> test", |
| 274 | + "user": "W111", |
| 275 | + "ts": "1583636382.000300", |
| 276 | + "team": "T111", |
| 277 | + "blocks": [ |
| 278 | + { |
| 279 | + "type": "rich_text", |
| 280 | + "block_id": "d7eJ", |
| 281 | + "elements": [ |
| 282 | + { |
| 283 | + "type": "rich_text_section", |
| 284 | + "elements": [ |
| 285 | + {"type": "user", "user_id": "U222"}, |
| 286 | + {"type": "text", "text": " test"}, |
| 287 | + ], |
| 288 | + } |
| 289 | + ], |
| 290 | + } |
| 291 | + ], |
| 292 | + }, |
| 293 | + "response_url": "https://hooks.slack.com/app/T111/111/xxx", |
| 294 | +} |
0 commit comments