예제 #1
0
 def test_should_not_be_able_to_set_responded_to_False(self):
     context = BotContext(SimpleAdapter(), ACTIVITY)
     try:
         context.responded = False
     except ValueError:
         pass
     except Exception as e:
         raise e
예제 #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
예제 #3
0
 def test_should_be_able_to_set_responded_to_True(self):
     context = BotContext(SimpleAdapter(), ACTIVITY)
     assert context.responded is False
     context.responded = True
     assert context.responded