Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
minor fixes and simplification
  • Loading branch information
WilliamBergamin committed Mar 16, 2026
commit 5a753038c2c998ec0f885e611093a5387f0792e1
13 changes: 6 additions & 7 deletions tests/scenario_tests/test_events_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from tests.utils import remove_os_env_temporarily, restore_os_env


def assert_target_called(called: dict, expected: bool = True, timeout: float = 0.5):
def assert_target_called(called: dict, timeout: float = 0.5):
deadline = time.time() + timeout
while called["value"] is not expected and time.time() < deadline:
while called["value"] is not True and time.time() < deadline:
time.sleep(0.1)
assert called["value"] is expected
assert called["value"] is True


class TestEventsAssistant:
Expand Down Expand Up @@ -142,8 +142,7 @@ def handle_bot_message():
request = BoltRequest(body=message_changed_event_body, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 200
assert_target_called(called, key="user_message", expected=False)
assert_target_called(called, key="bot_message", expected=False)
assert called["value"] is False

def test_channel_user_message_ignored(self):
app = App(client=self.web_client)
Expand All @@ -163,7 +162,7 @@ def handle_bot_message():
request = BoltRequest(body=channel_user_message_event_body, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 404
assert_target_called(called, expected=False)
assert called["value"] is False

def test_channel_message_changed_ignored(self):
app = App(client=self.web_client)
Expand All @@ -183,7 +182,7 @@ def handle_bot_message():
request = BoltRequest(body=channel_message_changed_event_body, mode="socket_mode")
response = app.dispatch(request)
assert response.status == 404
assert_target_called(called, expected=False)
assert called["value"] is False


def build_payload(event: dict) -> dict:
Expand Down
38 changes: 19 additions & 19 deletions tests/scenario_tests/test_events_assistant_without_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
cleanup_mock_web_api_server,
)
from tests.scenario_tests.test_events_assistant import (
assert_target_called,
channel_message_changed_event_body,
channel_user_message_event_body,
message_changed_event_body,
Expand All @@ -16,7 +17,6 @@
user_message_event_body,
user_message_event_body_with_assistant_thread,
)
from tests.scenario_tests.test_events_assistant import assert_target_called
from tests.utils import remove_os_env_temporarily, restore_os_env


Expand Down Expand Up @@ -178,13 +178,13 @@ def handle_message_event(
save_thread_context: SaveThreadContext,
context: BoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = BoltRequest(body=message_changed_event_body, mode="socket_mode")
Expand All @@ -206,13 +206,13 @@ def handle_message_event(
save_thread_context: SaveThreadContext,
context: BoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = BoltRequest(body=channel_user_message_event_body, mode="socket_mode")
Expand All @@ -234,13 +234,13 @@ def handle_message_event(
save_thread_context: SaveThreadContext,
context: BoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = BoltRequest(body=channel_message_changed_event_body, mode="socket_mode")
Expand Down
12 changes: 6 additions & 6 deletions tests/scenario_tests_async/test_events_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
from tests.utils import remove_os_env_temporarily, restore_os_env


async def assert_target_called(called: dict, expected: bool = True, timeout: float = 0.5):
async def assert_target_called(called: dict, timeout: float = 0.5):
deadline = time.time() + timeout
while called["value"] is not expected and time.time() < deadline:
while called["value"] is not True and time.time() < deadline:
await asyncio.sleep(0.1)
assert called["value"] is expected
assert called["value"] is True


class TestAsyncEventsAssistant:
Expand Down Expand Up @@ -166,7 +166,7 @@ async def handle_bot_message():
request = AsyncBoltRequest(body=message_changed_event_body, mode="socket_mode")
response = await app.async_dispatch(request)
assert response.status == 200
await assert_target_called(called, expected=False)
assert called["value"] is False

@pytest.mark.asyncio
async def test_channel_user_message_ignored(self):
Expand All @@ -187,7 +187,7 @@ async def handle_bot_message():
request = AsyncBoltRequest(body=channel_user_message_event_body, mode="socket_mode")
response = await app.async_dispatch(request)
assert response.status == 404
await assert_target_called(called, expected=False)
assert called["value"] is False

@pytest.mark.asyncio
async def test_channel_message_changed_ignored(self):
Expand All @@ -208,7 +208,7 @@ async def handle_bot_message():
request = AsyncBoltRequest(body=channel_message_changed_event_body, mode="socket_mode")
response = await app.async_dispatch(request)
assert response.status == 404
await assert_target_called(called, expected=False)
assert called["value"] is False


def build_payload(event: dict) -> dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
setup_mock_web_api_server_async,
)
from tests.scenario_tests_async.test_events_assistant import (
assert_target_called,
channel_message_changed_event_body,
channel_user_message_event_body,
message_changed_event_body,
Expand All @@ -23,7 +24,6 @@
user_message_event_body,
user_message_event_body_with_assistant_thread,
)
from tests.scenario_tests_async.test_events_assistant import assert_target_called
from tests.utils import remove_os_env_temporarily, restore_os_env


Expand Down Expand Up @@ -195,13 +195,13 @@ async def handle_message_event(
save_thread_context: AsyncSaveThreadContext,
context: AsyncBoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = AsyncBoltRequest(body=message_changed_event_body, mode="socket_mode")
Expand All @@ -224,13 +224,13 @@ async def handle_message_event(
save_thread_context: AsyncSaveThreadContext,
context: AsyncBoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = AsyncBoltRequest(body=channel_user_message_event_body, mode="socket_mode")
Expand All @@ -253,13 +253,13 @@ async def handle_message_event(
save_thread_context: AsyncSaveThreadContext,
context: AsyncBoltContext,
):
assert context.thread_ts is not None
assert context.thread_ts is None
assert say.thread_ts == context.thread_ts
assert set_status is not None
assert set_title is not None
assert set_suggested_prompts is not None
assert get_thread_context is not None
assert save_thread_context is not None
assert set_status is None
assert set_title is None
assert set_suggested_prompts is None
assert get_thread_context is None
assert save_thread_context is None
called["value"] = True

request = AsyncBoltRequest(body=channel_message_changed_event_body, mode="socket_mode")
Expand Down
Loading