|
1 | 1 | from slack_bolt.request.payload_utils import ( |
2 | | - is_event, |
3 | 2 | is_message_event, |
4 | 3 | is_any_im_message_event, |
5 | 4 | is_im_message_event, |
6 | | - is_user_message_event_in_assistant_thread, |
7 | | - is_bot_message_event_in_assistant_thread, |
8 | | - is_other_message_sub_event_in_assistant_thread, |
9 | | - is_assistant_event, |
10 | | - is_assistant_thread_started_event, |
11 | | - is_assistant_thread_context_changed_event, |
12 | 5 | ) |
13 | 6 | from tests.scenario_tests.test_events_assistant import ( |
14 | 7 | build_payload, |
|
114 | 107 |
|
115 | 108 |
|
116 | 109 | class TestPayloadUtils: |
117 | | - def test_is_event(self): |
118 | | - positives = { |
119 | | - "thread_started": thread_started_event_body, |
120 | | - "thread_context_changed": thread_context_changed_event_body, |
121 | | - "user_message_im": user_message_event_body, |
122 | | - "user_message_im_with_assistant_thread": user_message_event_body_with_assistant_thread, |
123 | | - "message_changed_im": message_changed_event_body, |
124 | | - "channel_user_message": channel_user_message_event_body, |
125 | | - "channel_message_changed": channel_message_changed_event_body, |
126 | | - "bot_message_channel": bot_message_event_payload, |
127 | | - "classic_bot_message_channel": classic_bot_message_event_payload, |
128 | | - "message_deleted_channel": message_deleted_channel_body, |
129 | | - "reaction_added": reaction_added_event_body, |
130 | | - "file_share_im": file_share_im_message_body, |
131 | | - "bot_im_thread": bot_im_thread_message_body, |
132 | | - "im_no_thread_ts": im_message_no_thread_ts_body, |
133 | | - } |
134 | | - negatives = { |
135 | | - "block_actions": block_actions_body, |
136 | | - "slash_command": slash_command_body, |
137 | | - "empty_dict": {}, |
138 | | - } |
139 | | - for key, body in positives.items(): |
140 | | - assert is_event(body), f"{key} should be recognized as an event" |
141 | | - for key, body in negatives.items(): |
142 | | - assert not is_event(body), f"{key} should NOT be recognized as an event" |
143 | | - |
144 | 110 | def test_is_message_event(self): |
145 | 111 | positives = { |
146 | 112 | "user_message_im": user_message_event_body, |
@@ -219,151 +185,3 @@ def test_is_im_message_event(self): |
219 | 185 | assert is_im_message_event(body), f"{key} should pass {is_im_message_event.__name__}" |
220 | 186 | for key, body in negatives.items(): |
221 | 187 | assert not is_im_message_event(body), f"{key} should NOT pass {is_im_message_event.__name__}" |
222 | | - |
223 | | - def test_is_user_message_event_in_assistant_thread(self): |
224 | | - # Requires: is_im_message_event + thread_ts present + bot_id absent |
225 | | - positives = { |
226 | | - "user_message_im": user_message_event_body, |
227 | | - "user_message_im_with_assistant_thread": user_message_event_body_with_assistant_thread, |
228 | | - "file_share_im": file_share_im_message_body, |
229 | | - } |
230 | | - negatives = { |
231 | | - "bot_im_thread": bot_im_thread_message_body, |
232 | | - "im_no_thread_ts": im_message_no_thread_ts_body, |
233 | | - "message_changed_im": message_changed_event_body, |
234 | | - "channel_user_message": channel_user_message_event_body, |
235 | | - "channel_message_changed": channel_message_changed_event_body, |
236 | | - "bot_message_channel": bot_message_event_payload, |
237 | | - "thread_started": thread_started_event_body, |
238 | | - "thread_context_changed": thread_context_changed_event_body, |
239 | | - "reaction_added": reaction_added_event_body, |
240 | | - "block_actions": block_actions_body, |
241 | | - } |
242 | | - for key, body in positives.items(): |
243 | | - assert is_user_message_event_in_assistant_thread( |
244 | | - body |
245 | | - ), f"{key} should pass {is_user_message_event_in_assistant_thread.__name__}" |
246 | | - for key, body in negatives.items(): |
247 | | - assert not is_user_message_event_in_assistant_thread( |
248 | | - body |
249 | | - ), f"{key} should NOT pass {is_user_message_event_in_assistant_thread.__name__}" |
250 | | - |
251 | | - def test_is_bot_message_event_in_assistant_thread(self): |
252 | | - # Requires: is_any_im_message_event + subtype is None + thread_ts present + bot_id present |
253 | | - positives = { |
254 | | - "bot_im_thread": bot_im_thread_message_body, |
255 | | - } |
256 | | - negatives = { |
257 | | - "user_message_im": user_message_event_body, |
258 | | - # file_share_im has subtype="file_share" -- the key user/bot asymmetry |
259 | | - "file_share_im": file_share_im_message_body, |
260 | | - "im_no_thread_ts": im_message_no_thread_ts_body, |
261 | | - "message_changed_im": message_changed_event_body, |
262 | | - "channel_user_message": channel_user_message_event_body, |
263 | | - "bot_message_channel": bot_message_event_payload, |
264 | | - "classic_bot_message_channel": classic_bot_message_event_payload, |
265 | | - "thread_started": thread_started_event_body, |
266 | | - "thread_context_changed": thread_context_changed_event_body, |
267 | | - "reaction_added": reaction_added_event_body, |
268 | | - "block_actions": block_actions_body, |
269 | | - } |
270 | | - for key, body in positives.items(): |
271 | | - assert is_bot_message_event_in_assistant_thread( |
272 | | - body |
273 | | - ), f"{key} should pass {is_bot_message_event_in_assistant_thread.__name__}" |
274 | | - for key, body in negatives.items(): |
275 | | - assert not is_bot_message_event_in_assistant_thread( |
276 | | - body |
277 | | - ), f"{key} should NOT pass {is_bot_message_event_in_assistant_thread.__name__}" |
278 | | - |
279 | | - def test_is_bot_message_user_message_asymmetry(self): |
280 | | - # file_share in IM thread: user predicate accepts it, bot predicate rejects it |
281 | | - assert is_user_message_event_in_assistant_thread(file_share_im_message_body) |
282 | | - assert not is_bot_message_event_in_assistant_thread(file_share_im_message_body) |
283 | | - |
284 | | - # bot message in IM thread: bot predicate accepts it, user predicate rejects it |
285 | | - assert is_bot_message_event_in_assistant_thread(bot_im_thread_message_body) |
286 | | - assert not is_user_message_event_in_assistant_thread(bot_im_thread_message_body) |
287 | | - |
288 | | - def test_is_other_message_sub_event_in_assistant_thread(self): |
289 | | - positives = { |
290 | | - "message_changed_im": message_changed_event_body, |
291 | | - } |
292 | | - negatives = { |
293 | | - "user_message_im": user_message_event_body, |
294 | | - "bot_im_thread": bot_im_thread_message_body, |
295 | | - "im_no_thread_ts": im_message_no_thread_ts_body, |
296 | | - "channel_message_changed": channel_message_changed_event_body, |
297 | | - "channel_user_message": channel_user_message_event_body, |
298 | | - "message_deleted_channel": message_deleted_channel_body, |
299 | | - "thread_started": thread_started_event_body, |
300 | | - "reaction_added": reaction_added_event_body, |
301 | | - "block_actions": block_actions_body, |
302 | | - } |
303 | | - for key, body in positives.items(): |
304 | | - assert is_other_message_sub_event_in_assistant_thread( |
305 | | - body |
306 | | - ), f"{key} should pass {is_other_message_sub_event_in_assistant_thread.__name__}" |
307 | | - for key, body in negatives.items(): |
308 | | - assert not is_other_message_sub_event_in_assistant_thread( |
309 | | - body |
310 | | - ), f"{key} should NOT pass {is_other_message_sub_event_in_assistant_thread.__name__}" |
311 | | - |
312 | | - def test_is_assistant_event(self): |
313 | | - positives = { |
314 | | - "thread_started": thread_started_event_body, |
315 | | - "thread_context_changed": thread_context_changed_event_body, |
316 | | - "user_message_im": user_message_event_body, |
317 | | - "user_message_im_with_assistant_thread": user_message_event_body_with_assistant_thread, |
318 | | - "file_share_im": file_share_im_message_body, |
319 | | - "bot_im_thread": bot_im_thread_message_body, |
320 | | - } |
321 | | - negatives = { |
322 | | - "message_changed_im": message_changed_event_body, |
323 | | - "im_no_thread_ts": im_message_no_thread_ts_body, |
324 | | - "channel_user_message": channel_user_message_event_body, |
325 | | - "channel_message_changed": channel_message_changed_event_body, |
326 | | - "bot_message_channel": bot_message_event_payload, |
327 | | - "classic_bot_message_channel": classic_bot_message_event_payload, |
328 | | - "message_deleted_channel": message_deleted_channel_body, |
329 | | - "reaction_added": reaction_added_event_body, |
330 | | - "block_actions": block_actions_body, |
331 | | - } |
332 | | - for key, body in positives.items(): |
333 | | - assert is_assistant_event(body), f"{key} should pass {is_assistant_event.__name__}" |
334 | | - for key, body in negatives.items(): |
335 | | - assert not is_assistant_event(body), f"{key} should NOT pass {is_assistant_event.__name__}" |
336 | | - |
337 | | - def test_is_assistant_thread_started_event(self): |
338 | | - assert is_assistant_thread_started_event(thread_started_event_body) |
339 | | - |
340 | | - negatives = { |
341 | | - "thread_context_changed": thread_context_changed_event_body, |
342 | | - "user_message_im": user_message_event_body, |
343 | | - "message_changed_im": message_changed_event_body, |
344 | | - "bot_im_thread": bot_im_thread_message_body, |
345 | | - "channel_user_message": channel_user_message_event_body, |
346 | | - "reaction_added": reaction_added_event_body, |
347 | | - "block_actions": block_actions_body, |
348 | | - } |
349 | | - for key, body in negatives.items(): |
350 | | - assert not is_assistant_thread_started_event( |
351 | | - body |
352 | | - ), f"{key} should NOT pass {is_assistant_thread_started_event.__name__}" |
353 | | - |
354 | | - def test_is_assistant_thread_context_changed_event(self): |
355 | | - assert is_assistant_thread_context_changed_event(thread_context_changed_event_body) |
356 | | - |
357 | | - negatives = { |
358 | | - "thread_started": thread_started_event_body, |
359 | | - "user_message_im": user_message_event_body, |
360 | | - "message_changed_im": message_changed_event_body, |
361 | | - "bot_im_thread": bot_im_thread_message_body, |
362 | | - "channel_user_message": channel_user_message_event_body, |
363 | | - "reaction_added": reaction_added_event_body, |
364 | | - "block_actions": block_actions_body, |
365 | | - } |
366 | | - for key, body in negatives.items(): |
367 | | - assert not is_assistant_thread_context_changed_event( |
368 | | - body |
369 | | - ), f"{key} should NOT pass {is_assistant_thread_context_changed_event.__name__}" |
0 commit comments