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_auto_fill_happy_path_validation(kwik_e_mart_app, qa_kwik_e_mart): """Tests a happy path for the app with gazetter validation.""" convo = Conversation(app=kwik_e_mart_app) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") convo.process("the store on elm street") assert_target_dialogue_state(convo, None)
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)
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_auto_fill_exit_flow(kwik_e_mart_app, qa_kwik_e_mart): """Tests slot-fill exit flow logic.""" convo = Conversation(app=kwik_e_mart_app) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") directives = convo.process("exit").directives assert_reply(directives, "Sorry I cannot help you. Please try again.") assert_target_dialogue_state(convo, None)
def test_intent_handler_and_exit_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") directives = convo.process("exit").directives assert_target_dialogue_state(convo, None) assert_reply(directives, templates=["Bye", "Goodbye", "Have a nice day."])
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_auto_fill_happy_path(kwik_e_mart_app, kwik_e_mart_app_path, qa_kwik_e_mart): """Tests that the params are cleared in one trip from app to mm.""" convo = Conversation( app=kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True ) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") directives = convo.process("elm street").directives assert_target_dialogue_state(convo, None)
def test_auto_fill_exit_flow(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=kwik_e_mart_app, app_path=kwik_e_mart_app_path, force_sync=True ) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") directives = convo.process("exit").directives assert_reply(directives, "Sorry I cannot help you. Please try again.") assert_target_dialogue_state(convo, None)
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(DucklingRecognizer, "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_auto_fill_validation_missing_entities(kwik_e_mart_app, qa_kwik_e_mart): """Tests default validation when user input has no entities. Check is to see that flow doesn't break.""" convo = Conversation(app=kwik_e_mart_app) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") directives = convo.process("123").directives assert_reply( directives, "Sorry, I did not get you. " "Which store would you like to know about?", )
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('are there any stores near me?').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?')
def test_auto_fill_switch_flow(kwik_e_mart_app, qa_kwik_e_mart): """Tests flow switching from inside slot filling to another intent when the number of retry attempts are exceeded.""" convo = Conversation(app=kwik_e_mart_app) directives = convo.process("What's the store phone number?").directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") directives = convo.process("goodbye").directives assert_reply( directives, "Sorry, I did not get you. " "Which store would you like to know about?", ) directives = convo.process("goodbye").directives assert_reply(directives, ["Bye", "Goodbye", "Have a nice day."])
async def test_auto_fill_validation_async(async_kwik_e_mart_app, qa_kwik_e_mart): """Tests a happy path for the async app with gazetter validation.""" convo = Conversation(app=async_kwik_e_mart_app) response = await convo.process("What's the store phone number?") directives = response.directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") await convo.process("elm street") assert_target_dialogue_state(convo, None)
async def test_auto_exit_flow_async(async_kwik_e_mart_app, qa_kwik_e_mart): """Tests auto fill for async apps.""" convo = Conversation(app=async_kwik_e_mart_app) response = await convo.process("What's the store phone number?") directives = response.directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") response = await convo.process("exit") directives = response.directives assert_reply(directives, "Sorry I cannot help you. Please try again.") assert_target_dialogue_state(convo, None)
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(DucklingRecognizer, "get_response", return_value=({}, 400)) try: 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 except ValidationError as error: if isinstance(error.messages, dict): if language == 'INVALID_LANG_CODE': assert 'Invalid language param: invalid_lang_code is not a valid ' \ 'ISO 639-1 or ISO 639-2 language code.' in str(error.messages) elif locale == 'INVALID_LOCALE_CODE': assert 'Invalid locale param: invalid_locale_code is not a valid ' \ 'ISO 639-1 or ISO 639-2 language code.' in str(error.messages) else: assert error.messages[0] == "Invalid locale_code param: %s is " \ "not a valid locale." % locale
async def test_auto_fill_retry_async(async_kwik_e_mart_app, qa_kwik_e_mart): """Tests that the retry logic for slots/entities in async app.""" convo = Conversation(app=async_kwik_e_mart_app) response = await convo.process("What's the store phone number?") directives = response.directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply(directives, "Which store would you like to know about?") response = await convo.process("Some store") directives = response.directives assert_target_dialogue_state(convo, "send_store_phone") assert_reply( directives, "Sorry, I did not get you. " "Which store would you like to know about?", ) await convo.process("elm street") assert_target_dialogue_state(convo, None)
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)