Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_default_handler(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(
app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True
)
convo.process("When does that open?")
assert_target_dialogue_state(convo, "send_store_hours_flow")
directives = convo.process("Howdy!").directives
assert_target_dialogue_state(convo, "send_store_hours_flow")
assert_reply(
directives,
templates="Sorry, I did not get you. Which store would you like to know about?",
)
async def test_convo_params_are_cleared(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path)
convo.params = Params(
allowed_intents=["store_info.find_nearest_store"],
target_dialogue_state="welcome",
)
await convo.say("close door")
assert convo.params == Params()
def test_reprocess_handler(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(
app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True
)
convo.process("When does that open?")
assert_target_dialogue_state(convo, "send_store_hours_flow")
directives = convo.process("are there any stores near me?").directives
assert_target_dialogue_state(convo, "send_store_hours_flow")
assert_reply(
directives, templates="I'm not sure. You haven't told me where you are!"
)
def test_convo_language_and_locales(
mocker, kwik_e_mart_nlp, kwik_e_mart_app_path, language, locale, expected_ser_call
):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(nlp=kwik_e_mart_nlp, app_path=kwik_e_mart_app_path)
convo.params = Params(language=language, locale=locale)
mock1 = mocker.patch.object(
SystemEntityRecognizer, "get_response", return_value=({}, 400)
)
convo.say("set alarm for 4pm tomorrow")
mock1.call_args_list[0][0][0].pop("text")
assert mock1.call_args_list[0][0][0] == expected_ser_call
def test_convo_params_are_cleared(kwik_e_mart_nlp, kwik_e_mart_app_path):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(nlp=kwik_e_mart_nlp, app_path=kwik_e_mart_app_path)
convo.params = Params(
allowed_intents=["store_info.find_nearest_store"],
target_dialogue_state="greeting",
)
convo.say("close door")
assert convo.params == Params()
def test_convo_force_sync_invocation(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that force sync kwarg works correctly when passed to convo
at invocation.
"""
convo = Conversation(app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path)
response = convo.process("close door", force_sync=True)
assert isinstance(response, DialogueResponder)
def test_convo_force_sync_creation(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that force sync kwarg works correctly when passed to convo
at creation.
"""
convo = Conversation(
app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True
)
response = convo.process("close door")
assert isinstance(response, DialogueResponder)
def test_repeated_flow(async_kwik_e_mart_app, kwik_e_mart_app_path):
"""Tests that the params are cleared in one trip from app to mm."""
convo = Conversation(
app=async_kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True
)
convo.process("When does that open?")
assert_target_dialogue_state(convo, "send_store_hours_flow")
for i in range(2):
directives = convo.process("When does that open?").directives
assert_reply(directives, "Which store would you like to know about?")
assert_target_dialogue_state(convo, "send_store_hours_flow")
directives = convo.process("When does that open?").directives
assert_reply(directives, "Sorry I cannot help you. Please try again.")
assert_target_dialogue_state(convo, None)
context = json.loads(context)
if app is None:
raise ValueError(
"No app was given. Run 'python app.py converse' from your app"
" folder."
)
# make sure num parser is running
ctx.invoke(num_parser, start=True)
if app.async_mode:
loop = asyncio.get_event_loop()
loop.run_until_complete(_converse_async(app, context))
return
convo = Conversation(app=app, context=context)
while True:
message = click.prompt("You")
responses = convo.say(message)
for index, response in enumerate(responses):
prefix = "App: " if index == 0 else "... "
click.secho(prefix + response, fg="blue", bg="white")
except MindMeldError as ex:
logger.error(ex.message)
ctx.exit(1)
async def _converse_async(app, context):
convo = Conversation(app=app, context=context)
while True:
message = click.prompt("You")
responses = await convo.say(message)
for index, response in enumerate(responses):
prefix = "App: " if index == 0 else "... "
click.secho(prefix + response, fg="blue", bg="white")