예제 #1
0
    async def test_should_call_send_on_activities_handler_before_send(self):
        context = BotContext(SimpleAdapter(), ACTIVITY)
        called = False

        async def send_handler(context, activities, next_handler_coroutine):
            nonlocal called
            called = True
            assert activities is not None
            assert context is not None
            assert activities[0].id == '1234'
            await next_handler_coroutine()

        context.on_send_activities(send_handler)
        await context.send_activity(ACTIVITY)
        assert called is True
예제 #2
0
    def test_copy_to_should_copy_all_references(self):
        old_adapter = SimpleAdapter()
        old_activity = Activity(id='2', type='message', text='test copy')
        old_context = BotContext(old_adapter, old_activity)
        old_context.responded = True

        async def send_activities_handler(context, activities, next_handler):
            assert context is not None
            assert activities is not None
            assert next_handler is not None
            await next_handler

        async def delete_activity_handler(context, reference, next_handler):
            assert context is not None
            assert reference is not None
            assert next_handler is not None
            await next_handler

        async def update_activity_handler(context, activity, next_handler):
            assert context is not None
            assert activity is not None
            assert next_handler is not None
            await next_handler

        old_context.on_send_activities(send_activities_handler)
        old_context.on_delete_activity(delete_activity_handler)
        old_context.on_update_activity(update_activity_handler)

        adapter = SimpleAdapter()
        new_context = BotContext(adapter, ACTIVITY)
        assert len(new_context._on_send_activities) == 0
        assert len(new_context._on_update_activity) == 0
        assert len(new_context._on_delete_activity) == 0

        old_context.copy_to(new_context)

        assert new_context.adapter == old_adapter
        assert new_context.activity == old_activity
        assert new_context.responded is True
        assert len(new_context._on_send_activities) == 1
        assert len(new_context._on_update_activity) == 1
        assert len(new_context._on_delete_activity) == 1