Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit ab31ca2

Browse files
committed
Added missing tests for activity prompt
1 parent 6f8d6f2 commit ab31ca2

File tree

1 file changed

+107
-1
lines changed

1 file changed

+107
-1
lines changed

libraries/botbuilder-dialogs/tests/test_activity_prompt.py

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from botbuilder.core import ConversationState, MemoryStorage, TurnContext, MessageFactory
1313
from botbuilder.core.adapters import TestAdapter
14-
from botbuilder.dialogs import DialogSet, DialogTurnStatus
14+
from botbuilder.dialogs import DialogSet, DialogTurnStatus, DialogReason
1515

1616

1717
async def validator(prompt_context: PromptValidatorContext):
@@ -96,3 +96,109 @@ async def exec_test(turn_context: TurnContext):
9696
step2 = await step1.assert_reply('please send an event.')
9797
step3 = await step2.send(event_activity)
9898
await step3.assert_reply('2')
99+
100+
async def test_retry_activity_prompt(self):
101+
async def exec_test(turn_context: TurnContext):
102+
dc = await dialogs.create_context(turn_context)
103+
104+
results = await dc.continue_dialog()
105+
if results.status == DialogTurnStatus.Empty:
106+
options = PromptOptions(prompt=Activity(type=ActivityTypes.message, text='please send an event.'))
107+
await dc.prompt('EventActivityPrompt', options)
108+
elif results.status == DialogTurnStatus.Complete:
109+
await turn_context.send_activity(results.result)
110+
111+
await convo_state.save_changes(turn_context)
112+
113+
# Initialize TestAdapter.
114+
adapter = TestAdapter(exec_test)
115+
116+
# Create ConversationState with MemoryStorage and register the state as middleware.
117+
convo_state = ConversationState(MemoryStorage())
118+
119+
# Create a DialogState property, DialogSet and AttachmentPrompt.
120+
dialog_state = convo_state.create_property('dialog_state')
121+
dialogs = DialogSet(dialog_state)
122+
dialogs.add(SimpleActivityPrompt('EventActivityPrompt', validator))
123+
124+
event_activity = Activity(type=ActivityTypes.event, value=2)
125+
126+
step1 = await adapter.send('hello')
127+
step2 = await step1.assert_reply('please send an event.')
128+
step3 = await step2.send('hello again')
129+
step4 = await step3.assert_reply("Please send an 'event'-type Activity with a value of 2.")
130+
step5 = await step4.send(event_activity)
131+
await step5.assert_reply('2')
132+
133+
async def test_activity_prompt_should_return_dialog_end_if_validation_failed(self):
134+
async def exec_test(turn_context: TurnContext):
135+
dc = await dialogs.create_context(turn_context)
136+
137+
results = await dc.continue_dialog()
138+
if results.status == DialogTurnStatus.Empty:
139+
options = PromptOptions(
140+
prompt=Activity(type=ActivityTypes.message, text='please send an event.'),
141+
retry_prompt=Activity(type=ActivityTypes.message, text='event not received.')
142+
)
143+
await dc.prompt('EventActivityPrompt', options)
144+
elif results.status == DialogTurnStatus.Complete:
145+
await turn_context.send_activity(results.result)
146+
147+
await convo_state.save_changes(turn_context)
148+
149+
async def aux_validator(prompt_context: PromptValidatorContext):
150+
assert prompt_context, 'Validator missing prompt_context'
151+
return False
152+
153+
# Initialize TestAdapter.
154+
adapter = TestAdapter(exec_test)
155+
156+
157+
158+
# Create ConversationState with MemoryStorage and register the state as middleware.
159+
convo_state = ConversationState(MemoryStorage())
160+
161+
# Create a DialogState property, DialogSet and AttachmentPrompt.
162+
dialog_state = convo_state.create_property('dialog_state')
163+
dialogs = DialogSet(dialog_state)
164+
dialogs.add(SimpleActivityPrompt('EventActivityPrompt', aux_validator))
165+
166+
step1 = await adapter.send('hello')
167+
step2 = await step1.assert_reply('please send an event.')
168+
step3 = await step2.send('test')
169+
await step3.assert_reply('event not received.')
170+
171+
async def test_activity_prompt_resume_dialog_should_return_dialog_end(self):
172+
async def exec_test(turn_context: TurnContext):
173+
dc = await dialogs.create_context(turn_context)
174+
175+
results = await dc.continue_dialog()
176+
if results.status == DialogTurnStatus.Empty:
177+
options = PromptOptions(prompt=Activity(type=ActivityTypes.message, text='please send an event.'))
178+
await dc.prompt('EventActivityPrompt', options)
179+
180+
second_results = await event_prompt.resume_dialog(dc, DialogReason.NextCalled)
181+
182+
assert second_results.status == DialogTurnStatus.Waiting, 'resume_dialog did not returned Dialog.EndOfTurn'
183+
184+
await convo_state.save_changes(turn_context)
185+
186+
async def aux_validator(prompt_context: PromptValidatorContext):
187+
assert prompt_context, 'Validator missing prompt_context'
188+
return False
189+
190+
# Initialize TestAdapter.
191+
adapter = TestAdapter(exec_test)
192+
193+
# Create ConversationState with MemoryStorage and register the state as middleware.
194+
convo_state = ConversationState(MemoryStorage())
195+
196+
# Create a DialogState property, DialogSet and AttachmentPrompt.
197+
dialog_state = convo_state.create_property('dialog_state')
198+
dialogs = DialogSet(dialog_state)
199+
event_prompt = SimpleActivityPrompt('EventActivityPrompt', aux_validator)
200+
dialogs.add(event_prompt)
201+
202+
step1 = await adapter.send('hello')
203+
step2 = await step1.assert_reply('please send an event.')
204+
await step2.assert_reply('please send an event.')

0 commit comments

Comments
 (0)