async def test_register(activity_registry, session_service, message_sent): # call on_message_sent a first time await activity_registry.on_message_sent(V4Initiator(), message_sent) session_service.get_session.assert_called_once() session_service.get_session.reset_mock() # call on_message_sent a second time, get_session() is not performed twice await activity_registry.on_message_sent(V4Initiator(), message_sent) session_service.get_session.assert_not_called()
def fixture_bot_message_sent_event(): initiator = V4Initiator(user=V4User(user_id=BOT_USER_ID)) payload = V4Payload(message_sent=V4MessageSent(message=V4Message( message="message"))) return V4Event(type=RealTimeEvent.MESSAGESENT.name, payload=payload, initiator=initiator)
def test_command_context(message_sent): initiator = V4Initiator() context = CommandContext(initiator, message_sent, BOT_NAME) assert context.initiator == initiator assert context.source_event == message_sent assert context.bot_display_name == BOT_NAME assert context.text_content == HELLO_WORLD_MESSAGE assert context.message_id == MESSAGE_ID assert context.stream_id == STREAM_ID
async def test_on_symphony_elements_action_false_match(activity_registry, elements_action, form): form.on_activity = AsyncMock() form.matches.return_value = False activity_registry.register(form) await activity_registry.on_symphony_elements_action(V4Initiator(), elements_action) form.before_matcher.assert_called_once() form.matches.assert_called_once() form.on_activity.assert_not_called()
async def test_on_user_joined_room_false_match(activity_registry, user_joined_room, user): user.on_activity = AsyncMock() user.matches.return_value = False activity_registry.register(user) await activity_registry.on_user_joined_room(V4Initiator(), user_joined_room) user.before_matcher.assert_called_once() user.matches.assert_called_once() user.on_activity.assert_not_called()
async def test_on_symphony_elements_action(activity_registry, elements_action, form): form.on_activity = AsyncMock() activity_registry.register(form) await activity_registry.on_symphony_elements_action(V4Initiator(), elements_action) assert len(activity_registry._activity_list) == 1 form.before_matcher.assert_called_once() form.matches.assert_called_once() form.on_activity.assert_called_once()
async def test_on_message_sent_false_match(activity_registry, message_sent, command): command.on_activity = AsyncMock() command.matches.return_value = False activity_registry.register(command) await activity_registry.on_message_sent(V4Initiator(), message_sent) command.before_matcher.assert_called_once() command.matches.assert_called_once() command.on_activity.assert_not_called()
async def test_on_message_sent(activity_registry, message_sent, command): command.on_activity = AsyncMock() activity_registry.register(command) await activity_registry.on_message_sent(V4Initiator(), message_sent) assert len(activity_registry._activity_list) == 1 command.before_matcher.assert_called_once() command.matches.assert_called_once() command.on_activity.assert_called_once()
async def test_register_different_activities_instance(activity_registry, command, form, user, message_sent, elements_action, user_joined_room): command.on_activity = AsyncMock() form.on_activity = AsyncMock() user.on_activity = AsyncMock() activity_registry.register(command) activity_registry.register(form) activity_registry.register(user) assert len(activity_registry._activity_list) == 3 await activity_registry.on_message_sent(V4Initiator(), message_sent) command.before_matcher.assert_called_once() form.before_matcher.assert_not_called() user.before_matcher.assert_not_called() command.reset_mock() form.reset_mock() user.reset_mock() await activity_registry.on_symphony_elements_action(V4Initiator(), elements_action) form.before_matcher.assert_called_once() command.before_matcher.assert_not_called() user.before_matcher.assert_not_called() command.reset_mock() form.reset_mock() user.reset_mock() await activity_registry.on_user_joined_room(V4Initiator(), user_joined_room) user.before_matcher.assert_called_once() form.before_matcher.assert_not_called() command.before_matcher.assert_not_called()
def create_command_context(message_sent): return CommandContext(V4Initiator(), message_sent, BOT_NAME)
def fixture_context(): return UserJoinedRoomContext( V4Initiator(), V4UserJoinedRoom(stream=V4Stream(stream_id="12345678"), affected_user=V4User(user_id=0)))
def fixture_initiator(): return V4Initiator(user=V4User(username="******"))
def fixture_message_sent(): initiator = V4Initiator(user=V4User(username="******")) return V4Event(type=RealTimeEvent.MESSAGESENT.name, payload=V4Payload(message_sent=V4MessageSent()), initiator=initiator)
def fixture_context(): return FormReplyContext(V4Initiator(), V4SymphonyElementsAction(form_id="test_form", form_message_id="message_id", form_values={"key": "value"}))
def fixture_initiator(): return V4Initiator(user=V4User(user_id=67890))