From f7ae543d2bc602aaef33cd8cbbd60f79e0c8f67c Mon Sep 17 00:00:00 2001 From: Santiago Grangetto Date: Fri, 30 Apr 2021 14:16:44 -0300 Subject: [PATCH 1/4] Remove input hint set in attachment prompts --- .../botbuilder/dialogs/prompts/attachment_prompt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py index ab2cf1736..45b4784a9 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py @@ -39,10 +39,8 @@ async def on_prompt( ) if is_retry and options.retry_prompt: - options.retry_prompt.input_hint = InputHints.expecting_input await turn_context.send_activity(options.retry_prompt) elif options.prompt: - options.prompt.input_hint = InputHints.expecting_input await turn_context.send_activity(options.prompt) async def on_recognize( From ee62de8df576097b4d633cfdc9dd9c1dc7732588 Mon Sep 17 00:00:00 2001 From: Santiago Grangetto Date: Tue, 4 May 2021 10:48:05 -0300 Subject: [PATCH 2/4] Add attachment prompt input hint test --- .../tests/test_attachment_prompt.py | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py index 19ae1e429..7997fe56e 100644 --- a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py +++ b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py @@ -7,7 +7,7 @@ PromptOptions, PromptValidatorContext, ) -from botbuilder.schema import Activity, ActivityTypes, Attachment +from botbuilder.schema import Activity, ActivityTypes, Attachment, InputHints from botbuilder.core import ( TurnContext, @@ -18,6 +18,8 @@ from botbuilder.core.adapters import TestAdapter from botbuilder.dialogs import DialogSet, DialogTurnStatus +import copy + class AttachmentPromptTests(aiounittest.AsyncTestCase): def test_attachment_prompt_with_empty_id_should_fail(self): @@ -71,6 +73,44 @@ async def exec_test(turn_context: TurnContext): step3 = await step2.send(attachment_activity) await step3.assert_reply("some content") + async def test_attachment_prompt_with_input_hint(self): + prompt_activity = Activity( + type=ActivityTypes.message, + text="please add an attachment.", + input_hint=InputHints.accepting_input + ) + + async def exec_test(turn_context: TurnContext): + dialog_context = await dialogs.create_context(turn_context) + + results = await dialog_context.continue_dialog() + + if results.status == DialogTurnStatus.Empty: + options = PromptOptions( + prompt=copy.copy(prompt_activity) + ) + await dialog_context.prompt("AttachmentPrompt", options) + elif results.status == DialogTurnStatus.Complete: + attachment = results.result[0] + content = MessageFactory.text(attachment.content) + await turn_context.send_activity(content) + + await convo_state.save_changes(turn_context) + + # Initialize TestAdapter. + adapter = TestAdapter(exec_test) + + # Create ConversationState with MemoryStorage and register the state as middleware. + convo_state = ConversationState(MemoryStorage()) + + # Create a DialogState property, DialogSet and AttachmentPrompt. + dialog_state = convo_state.create_property("dialog_state") + dialogs = DialogSet(dialog_state) + dialogs.add(AttachmentPrompt("AttachmentPrompt")) + + step1 = await adapter.send("hello") + await step1.assert_reply(prompt_activity) + async def test_attachment_prompt_with_validator(self): async def exec_test(turn_context: TurnContext): dialog_context = await dialogs.create_context(turn_context) From 1e302ea3cc422c54f255823d4e97a72713d3d3b9 Mon Sep 17 00:00:00 2001 From: Santiago Grangetto Date: Tue, 4 May 2021 11:12:50 -0300 Subject: [PATCH 3/4] Apply black styling --- .../botbuilder-dialogs/tests/test_attachment_prompt.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py index 7997fe56e..f94c66bf3 100644 --- a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py +++ b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py @@ -77,7 +77,7 @@ async def test_attachment_prompt_with_input_hint(self): prompt_activity = Activity( type=ActivityTypes.message, text="please add an attachment.", - input_hint=InputHints.accepting_input + input_hint=InputHints.accepting_input, ) async def exec_test(turn_context: TurnContext): @@ -86,9 +86,7 @@ async def exec_test(turn_context: TurnContext): results = await dialog_context.continue_dialog() if results.status == DialogTurnStatus.Empty: - options = PromptOptions( - prompt=copy.copy(prompt_activity) - ) + options = PromptOptions(prompt=copy.copy(prompt_activity)) await dialog_context.prompt("AttachmentPrompt", options) elif results.status == DialogTurnStatus.Complete: attachment = results.result[0] From 33f345b6652e59097cc73463a931741da850c546 Mon Sep 17 00:00:00 2001 From: Santiago Grangetto Date: Tue, 4 May 2021 11:21:04 -0300 Subject: [PATCH 4/4] Apply pylint --- .../botbuilder/dialogs/prompts/attachment_prompt.py | 2 +- libraries/botbuilder-dialogs/tests/test_attachment_prompt.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py index 45b4784a9..3f157fb4a 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/attachment_prompt.py @@ -3,7 +3,7 @@ from typing import Callable, Dict -from botbuilder.schema import ActivityTypes, InputHints +from botbuilder.schema import ActivityTypes from botbuilder.core import TurnContext from .prompt import Prompt, PromptValidatorContext diff --git a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py index f94c66bf3..62b0c8905 100644 --- a/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py +++ b/libraries/botbuilder-dialogs/tests/test_attachment_prompt.py @@ -1,6 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import copy import aiounittest from botbuilder.dialogs.prompts import ( AttachmentPrompt, @@ -18,8 +19,6 @@ from botbuilder.core.adapters import TestAdapter from botbuilder.dialogs import DialogSet, DialogTurnStatus -import copy - class AttachmentPromptTests(aiounittest.AsyncTestCase): def test_attachment_prompt_with_empty_id_should_fail(self):