From 2d5e8d80698c7af65e45665cd4cf869d5d91c853 Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 24 Oct 2019 12:12:00 -0700 Subject: [PATCH 1/2] Create test_update_activity_should_apply_conversation_reference --- .../tests/test_turn_context.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-core/tests/test_turn_context.py b/libraries/botbuilder-core/tests/test_turn_context.py index 8e7c6f407..12615bff4 100644 --- a/libraries/botbuilder-core/tests/test_turn_context.py +++ b/libraries/botbuilder-core/tests/test_turn_context.py @@ -10,7 +10,7 @@ Mention, ResourceResponse, ) -from botbuilder.core import BotAdapter, TurnContext +from botbuilder.core import BotAdapter, MessageFactory, TurnContext ACTIVITY = Activity( id="1234", @@ -225,6 +225,26 @@ async def update_handler(context, activity, next_handler_coroutine): await context.update_activity(ACTIVITY) assert called is True + async def test_update_activity_should_apply_conversation_reference(self): + activity_id = "activity ID" + context = TurnContext(SimpleAdapter(), ACTIVITY) + called = False + + async def update_handler(context, activity, next_handler_coroutine): + nonlocal called + called = True + assert context is not None + assert activity.id == activity_id + assert activity.conversation.id == ACTIVITY.conversation.id + await next_handler_coroutine() + + context.on_update_activity(update_handler) + new_activity = MessageFactory.text("test text") + new_activity.id = activity_id + update_result = await context.update_activity(new_activity) + assert called is True + assert update_result.id == activity_id + def test_get_conversation_reference_should_return_valid_reference(self): reference = TurnContext.get_conversation_reference(ACTIVITY) From 4cdfce20a168b61c16e0977cba58c4391c5eca0f Mon Sep 17 00:00:00 2001 From: Kyle Delaney Date: Thu, 24 Oct 2019 13:21:50 -0700 Subject: [PATCH 2/2] Apply conversation reference in TurnContext.update_activity --- libraries/botbuilder-core/botbuilder/core/turn_context.py | 6 ++++-- libraries/botbuilder-core/tests/test_turn_context.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder-core/botbuilder/core/turn_context.py b/libraries/botbuilder-core/botbuilder/core/turn_context.py index 99d53996a..0155a992b 100644 --- a/libraries/botbuilder-core/botbuilder/core/turn_context.py +++ b/libraries/botbuilder-core/botbuilder/core/turn_context.py @@ -173,9 +173,11 @@ async def update_activity(self, activity: Activity): :param activity: :return: """ + reference = TurnContext.get_conversation_reference(self.activity) + return await self._emit( self._on_update_activity, - activity, + TurnContext.apply_conversation_reference(activity, reference), self.adapter.update_activity(self, activity), ) @@ -240,7 +242,7 @@ async def next_handler(): raise error await emit_next(0) - # This should be changed to `return await logic()` + # logic does not use parentheses because it's a coroutine return await logic @staticmethod diff --git a/libraries/botbuilder-core/tests/test_turn_context.py b/libraries/botbuilder-core/tests/test_turn_context.py index 12615bff4..2fe6bdcc5 100644 --- a/libraries/botbuilder-core/tests/test_turn_context.py +++ b/libraries/botbuilder-core/tests/test_turn_context.py @@ -40,11 +40,12 @@ async def send_activities(self, context, activities): async def update_activity(self, context, activity): assert context is not None assert activity is not None + return ResourceResponse(id=activity.id) async def delete_activity(self, context, reference): assert context is not None assert reference is not None - assert reference.activity_id == "1234" + assert reference.activity_id == ACTIVITY.id class TestBotContext(aiounittest.AsyncTestCase):