async def test_should_call_multiple_on_delete_activity_handlers_in_order( self): context = TurnContext(SimpleAdapter(), ACTIVITY) called_first = False called_second = False async def first_delete_handler(context, reference, next_handler_coroutine): nonlocal called_first, called_second assert called_first is False, 'called_first should not be True before first_delete_handler is called.' called_first = True assert called_second is False, 'Second on_delete_activity handler was called before first.' assert reference is not None assert context is not None assert reference.activity_id == '1234' await next_handler_coroutine() async def second_delete_handler(context, reference, next_handler_coroutine): nonlocal called_first, called_second assert called_first assert called_second is False, 'called_second was set to True before second handler was called.' called_second = True assert reference is not None assert context is not None assert reference.activity_id == '1234' await next_handler_coroutine() context.on_delete_activity(first_delete_handler) context.on_delete_activity(second_delete_handler) await context.delete_activity(ACTIVITY.id) assert called_first is True assert called_second is True
def test_copy_to_should_copy_all_references(self): # pylint: disable=protected-access old_adapter = SimpleAdapter() old_activity = Activity(id="2", type="message", text="test copy") old_context = TurnContext(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 = TurnContext(adapter, ACTIVITY) assert not new_context._on_send_activities # pylint: disable=protected-access assert not new_context._on_update_activity # pylint: disable=protected-access assert not new_context._on_delete_activity # pylint: disable=protected-access 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 ) # pylint: disable=protected-access assert ( len(new_context._on_update_activity) == 1 ) # pylint: disable=protected-access assert ( len(new_context._on_delete_activity) == 1 ) # pylint: disable=protected-access
async def test_should_call_on_delete_activity_handlers_before_deletion(self): context = TurnContext(SimpleAdapter(), ACTIVITY) called = False async def delete_handler(context, reference, next_handler_coroutine): nonlocal called called = True assert reference is not None assert context is not None assert reference.activity_id == "1234" await next_handler_coroutine() context.on_delete_activity(delete_handler) await context.delete_activity(ACTIVITY.id) assert called is True
def test_copy_to_should_copy_all_references(self): old_adapter = SimpleAdapter() old_activity = Activity(id='2', type='message', text='test copy') old_context = TurnContext(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 = TurnContext(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