From cd359f135eee19bb09fd7c679f8cccde9d9537e1 Mon Sep 17 00:00:00 2001 From: Ashley Ho <35248895+Zerryth@users.noreply.github.com> Date: Thu, 15 Aug 2019 14:20:19 -0700 Subject: [PATCH 1/2] Fixed retry prompting in NumberPrompt by adding await --- .../dialogs/prompts/number_prompt.py | 2 +- .../tests/test_number_prompt.py | 27 +++++++------------ 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/number_prompt.py b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/number_prompt.py index cddb174c9..ed757c391 100644 --- a/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/number_prompt.py +++ b/libraries/botbuilder-dialogs/botbuilder/dialogs/prompts/number_prompt.py @@ -40,7 +40,7 @@ async def on_prompt( raise TypeError("NumberPrompt.on_prompt(): options cannot be None.") if is_retry and options.retry_prompt is not None: - turn_context.send_activity(options.retry_prompt) + await turn_context.send_activity(options.retry_prompt) elif options.prompt is not None: await turn_context.send_activity(options.prompt) diff --git a/libraries/botbuilder-dialogs/tests/test_number_prompt.py b/libraries/botbuilder-dialogs/tests/test_number_prompt.py index a095bf339..b2d270101 100644 --- a/libraries/botbuilder-dialogs/tests/test_number_prompt.py +++ b/libraries/botbuilder-dialogs/tests/test_number_prompt.py @@ -125,9 +125,6 @@ async def exec_test(turn_context: TurnContext) -> None: test_flow4 = await test_flow3.send("Give me twenty meters of cable") await test_flow4.assert_reply("You asked me for '20' meters of cable.") - # TODO: retry_prompt in NumberPrompt appears to be broken - # It when NumberPrompt fails to receive a number, it retries, prompting - # with the prompt and not retry prompt in options async def test_number_prompt_retry(self): async def exec_test(turn_context: TurnContext) -> None: dialog_context: DialogContext = await dialogs.create_context(turn_context) @@ -161,14 +158,11 @@ async def exec_test(turn_context: TurnContext) -> None: dialogs.add(number_prompt) step1 = await adapter.send("hello") - await step1.assert_reply("Enter a number.") - # TODO: something is breaking in the validators or retry prompt - # where it does not accept the 2nd answer after reprompting the user - # for another value - # step3 = await step2.send("hello") - # step4 = await step3.assert_reply("You must enter a number.") - # step5 = await step4.send("64") - # await step5.assert_reply("Bot received the number '64'.") + step2 = await step1.assert_reply("Enter a number.") + step3 = await step2.send("hello") + step4 = await step3.assert_reply("You must enter a number.") + step5 = await step4.send("64") + await step5.assert_reply("Bot received the number '64'.") async def test_number_uses_locale_specified_in_constructor(self): # Create new ConversationState with MemoryStorage and register the state as middleware. @@ -272,13 +266,10 @@ async def validator(prompt_context: PromptValidatorContext): step1 = await adapter.send("hello") step2 = await step1.assert_reply("Enter a number.") - await step2.send("150") - # TODO: something is breaking in the validators or retry prompt - # where it does not accept the 2nd answer after reprompting the user - # for another value - # step4 = await step3.assert_reply("You must enter a positive number less than 100.") - # step5 = await step4.send("64") - # await step5.assert_reply("Bot received the number '64'.") + step3 = await step2.send("150") + step4 = await step3.assert_reply("You must enter a positive number less than 100.") + step5 = await step4.send("64") + await step5.assert_reply("Bot received the number '64'.") async def test_float_number_prompt(self): async def exec_test(turn_context: TurnContext) -> None: From 693c83c9e25e5369b7849c0054308be86ffff118 Mon Sep 17 00:00:00 2001 From: Ashley Ho <35248895+Zerryth@users.noreply.github.com> Date: Thu, 15 Aug 2019 14:40:55 -0700 Subject: [PATCH 2/2] ran black on libraries --- libraries/botbuilder-dialogs/tests/test_number_prompt.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/botbuilder-dialogs/tests/test_number_prompt.py b/libraries/botbuilder-dialogs/tests/test_number_prompt.py index b2d270101..1b9510017 100644 --- a/libraries/botbuilder-dialogs/tests/test_number_prompt.py +++ b/libraries/botbuilder-dialogs/tests/test_number_prompt.py @@ -267,7 +267,9 @@ async def validator(prompt_context: PromptValidatorContext): step1 = await adapter.send("hello") step2 = await step1.assert_reply("Enter a number.") step3 = await step2.send("150") - step4 = await step3.assert_reply("You must enter a positive number less than 100.") + step4 = await step3.assert_reply( + "You must enter a positive number less than 100." + ) step5 = await step4.send("64") await step5.assert_reply("Bot received the number '64'.")