Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test_action_default_ask_affirmation(
default_channel, default_nlg, default_tracker, default_domain
):
events = await ActionDefaultAskAffirmation().run(
default_channel, default_nlg, default_tracker, default_domain
)
assert events == [
BotUttered(
"Did you mean 'None'?",
{
"buttons": [
{"title": "Yes", "payload": "/None"},
{"title": "No", "payload": "/out_of_scope"},
]
"metadata": {},
},
"active_form": {},
"latest_action_name": None,
"sender_id": "my-sender",
"paused": False,
"followup_action": "action_listen",
"latest_event_time": None,
"slots": {"name": None},
"events": [],
"latest_input_channel": None,
},
}
assert len(events) == 3 # first two events are bot utterances
assert events[0] == BotUttered(
"test text", {"buttons": [{"title": "cheap", "payload": "cheap"}]}
)
assert events[1] == BotUttered("hey there None!")
assert events[2] == SlotSet("name", "rasa")
async def test_action_back(
default_channel, template_nlg, template_sender_tracker, default_domain
):
events = await ActionBack().run(
default_channel, template_nlg, template_sender_tracker, default_domain
)
assert events == [
BotUttered("backing up..."),
UserUtteranceReverted(),
UserUtteranceReverted(),
]
def create_tracker_with_partially_saved_events(
tracker_store: TrackerStore,
) -> Tuple[List[Event], DialogueStateTracker]:
# creates a tracker with two events and saved it to the tracker store
# following that, it adds three more events that are not saved to the tracker store
sender_id = uuid.uuid4().hex
# create tracker with two events and save it
events = [UserUttered("hello"), BotUttered("what")]
tracker = DialogueStateTracker.from_events(sender_id, events)
tracker_store.save(tracker)
# add more events to the tracker, do not yet save it
events = [ActionExecuted(ACTION_LISTEN_NAME), UserUttered("123"), BotUttered("yes")]
for event in events:
tracker.update(event)
return events, tracker
{
"title": "quick_reply1",
"buttons": [{"title": "button3", "payload": "/button3"}],
},
{
"title": "quick_reply2",
"buttons": [{"title": "button4", "payload": "/button4"}],
},
],
},
}
from rasa.core.events import Event
bot_event = Event.from_parameters(message)
assert isinstance(bot_event, BotUttered)
formatted = interactive.format_bot_output(bot_event)
assert formatted == (
"Hello!\n"
"Image: http://example.com/myimage.png\n"
{
"title": "quick_reply1",
"buttons": [{"title": "button3", "payload": "/button3"}],
},
{
"title": "quick_reply2",
"buttons": [{"title": "button4", "payload": "/button4"}],
},
],
},
}
from rasa.core.events import Event
bot_event = Event.from_parameters(message)
assert isinstance(bot_event, BotUttered)
formatted = interactive.format_bot_output(bot_event)
assert formatted == (
"Hello!\n"
"Image: http://example.com/myimage.png\n"
async def test_action_default_ask_rephrase(
default_channel, template_nlg, template_sender_tracker, default_domain
):
events = await ActionDefaultAskRephrase().run(
default_channel, template_nlg, template_sender_tracker, default_domain
)
assert events == [BotUttered("can you rephrase that?")]
UserUttered("/greet", {"name": "greet", "confidence": 1.0}, []),
UserUttered("/goodbye", {"name": "goodbye", "confidence": 1.0}, []),
),
(SlotSet("my_slot", "value"), SlotSet("my__other_slot", "value")),
(Restarted(), None),
(AllSlotsReset(), None),
(ConversationPaused(), None),
(ConversationResumed(), None),
(StoryExported(), None),
(ActionReverted(), None),
(UserUtteranceReverted(), None),
(ActionExecuted("my_action"), ActionExecuted("my_other_action")),
(FollowupAction("my_action"), FollowupAction("my_other_action")),
(
BotUttered("my_text", {"my_data": 1}),
BotUttered("my_other_test", {"my_other_data": 1}),
),
(
AgentUttered("my_text", "my_data"),
AgentUttered("my_other_test", "my_other_data"),
),
(
ReminderScheduled("my_action", datetime.now()),
ReminderScheduled("my_other_action", datetime.now()),
),
],
)
def test_event_has_proper_implementation(one_event, another_event):
# equals tests
assert (
one_event != another_event
), "Same events with different values need to be different"
def _reset(self) -> None:
"""Reset tracker to initial state - doesn't delete events though!."""
self._reset_slots()
self._paused = False
self.latest_action_name = None
self.latest_message = UserUttered.empty()
self.latest_bot_utterance = BotUttered.empty()
self.followup_action = ACTION_LISTEN_NAME
self.active_form = {}