Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply conversation reference in TurnContext.update_activity #358

Merged
merged 2 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libraries/botbuilder-core/botbuilder/core/turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)

Expand Down Expand Up @@ -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
Expand Down
25 changes: 23 additions & 2 deletions libraries/botbuilder-core/tests/test_turn_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Mention,
ResourceResponse,
)
from botbuilder.core import BotAdapter, TurnContext
from botbuilder.core import BotAdapter, MessageFactory, TurnContext

ACTIVITY = Activity(
id="1234",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -225,6 +226,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)

Expand Down