Пример #1
0
    def test_unique_recipe_in_cookbook(self):
        # ask to make the recipe we have one of
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'Pancakes').build()
        req = requester.Request().new().type(
            requester.Types.INTENT).intent(intent).attributes({
                core.STATE_KEY:
                core.States.INITIAL_STATE
            }).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_COOKBOOK)

        #agree to make it
        intent = requester.Intent('AMAZON.YesIntent').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).copy_attributes(response_dict).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)

        intent = requester.Intent('IngredientsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).copy_attributes(response_dict).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
Пример #2
0
    def test_search_one_match_conversation(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        test_util.set_bigoven_username()

        # lauch as new user, check out session attributes afterwards
        # since there are no recipes in our cookbook it should search
        # but we expect "pancakes" to be one of the recipes in the online database
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'pizza').build()
        req = requester.Request().type(
            requester.Types.INTENT).intent(intent).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe_name',
                      response_dict['sessionAttributes'])
        # save current recipe for later in test
        current_recipe_name = response_dict['sessionAttributes'][
            'current_recipe_name']
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_SEARCH)

        # response with "Yes" to search
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('search_recipe_result',
                      response_dict['sessionAttributes'])
        self.assertNotEqual(
            response_dict['sessionAttributes']['search_recipe_result']
            ['Title'], None)
        self.assertEqual(current_recipe_name, 'pizza')
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_ONLINE)

        # response with "Yes" to use the recipe we found
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertNotEqual(
            response_dict['sessionAttributes']['current_recipe'], None)
        self.assertEqual(current_recipe_name, 'pizza')
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)
Пример #3
0
    def test_launch_recipe_conversation(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        test_util.set_bigoven_username()
        test_util.no_firt_time()

        event = requester.Request().type(requester.Types.LAUNCH).new().build()
        response_dict = lambda_function.handle_event(event, None)
        inv_result = lambda_function._skill.db_helper.get('invocations')

        self.assertTrue(responder.is_valid(response_dict))
        self.assertFalse(response_dict['response']['shouldEndSession'])
        self.assertEqual(inv_result.value, 2)

        intent = requester.Intent('RecipeNameIntent').slot(
            'RecipeName', 'southern biscuits').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).new().copy_attributes(response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_COOKBOOK)

        # response with "Yes" to make recipe from cookbook, check that we saved state in db
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertNotEqual(
            response_dict['sessionAttributes']['current_recipe'], None)
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)
        # save current recipe for later in test
        current_recipe = response_dict['sessionAttributes']['current_recipe']

        # ask for ingredients
        intent = requester.Intent('IngredientsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).copy_attributes(
            response_dict).intent(intent).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)
        self.assertEqual(response_dict['sessionAttributes']['current_recipe'],
                         current_recipe)
        self.assertFalse(response_dict['response']['shouldEndSession'])
Пример #4
0
    def test_recipe_conversation(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        test_util.set_bigoven_username()

        # lauch as new user, check out session attributes afterwards
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'chicken pot pie').build()
        req = requester.Request().type(
            requester.Types.INTENT).intent(intent).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_COOKBOOK)

        # response with "Yes" to make recipe from cookbook, check that we saved state in db
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertNotEqual(
            response_dict['sessionAttributes']['current_recipe'], None)
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)
        # save current recipe for later in test
        current_recipe = response_dict['sessionAttributes']['current_recipe']

        # ask for ingredients
        intent = requester.Intent('IngredientsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).copy_attributes(
            response_dict).intent(intent).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)
        self.assertEqual(response_dict['sessionAttributes']['current_recipe'],
                         current_recipe)
Пример #5
0
    def test_recipe_not_in_cookbook(self):
        # ask to make something else
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'pizza').build()
        req = requester.Request().type(
            requester.Types.INTENT).intent(intent).attributes({
                core.STATE_KEY:
                core.States.INITIAL_STATE
            }).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_SEARCH)

        # agree to search online
        intent = requester.Intent('AMAZON.YesIntent').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).copy_attributes(response_dict).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_ONLINE)

        # agree to make the one recipe it found
        intent = requester.Intent('AMAZON.YesIntent').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).copy_attributes(response_dict).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)

        # ask to go right to instructions
        intent = requester.Intent('InstructionsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).intent(
            intent).copy_attributes(response_dict).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
Пример #6
0
    def test_unheard_recipe(self):
        test_util.delete_table(core.LOCAL_DB_URI)

        intent = requester.Intent('StartNewRecipeIntent').build()
        req = requester.Request().type(
            requester.Types.INTENT).intent(intent).new().attributes({
                core.STATE_KEY:
                core.States.INITIAL_STATE
            }).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.NEW_RECIPE)
Пример #7
0
    def test_tutorial_conversation(self):
        test_util.delete_table(core.LOCAL_DB_URI)

        # lauch as new user, check out session attributes are in ASK_TUTORIAL
        req = requester.Request().type(requester.Types.LAUNCH).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_TUTORIAL)

        # response with "Yes" to to tutorial, check that we saved state in db
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("_MAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)
        state_result = lambda_function._skill.db_helper.getState()

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(state_result.value, core.States.INITIAL_STATE)

        # delete user so we are prompted again, this time respond no.
        test_util.delete_table(core.LOCAL_DB_URI)

        # lauch as new user again
        req = requester.Request().type(requester.Types.LAUNCH).new().build()
        response_dict = lambda_function.handle_event(req, None)

        # response with "No" to to tutorial, check that we saved state in db
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.NoIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.PROMPT_FOR_START)
Пример #8
0
    def test_all_new_intents_in_all_states(self):
        for state in core.all_states():
            for intent_name in schema.intents():
                intent = requester.Intent(intent_name).build()
                event = requester.Request().type(
                    requester.Types.INTENT).new().intent(intent).attributes({
                        core.STATE_KEY:
                        state
                    }).build()
                response_dict = lambda_function.handle_event(event, None)

                self.assertTrue(responder.is_valid(response_dict))

                # make sure the end the conversation
                event = requester.Request().type(requester.Types.END).build()
                response_dict = lambda_function.handle_event(event, None)
                self.assertTrue(responder.is_valid(response_dict))
Пример #9
0
    def test_make_link(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'chicken pot pie').build()
        req = requester.Request().new().type(
            requester.Types.INTENT).intent(intent).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))

        #fake the user entering their id
        fake_bigoven_username = '******'
        response = requests.get(
            'http://localhost:5000/link?amazonId=default_user_id&bigoven_username=%s'
            % fake_bigoven_username)
        self.assertTrue(response.ok)

        link_result = lambda_function._skill.db_helper.get('bigoven_username')
        self.assertEqual(link_result.value, fake_bigoven_username)
Пример #10
0
    def test_brownies(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        test_util.set_bigoven_username()

        # search for something not in our cookbook
        intent = requester.Intent('StartNewRecipeIntent').slot(
            'RecipeName', 'brownies').build()
        req = requester.Request().type(
            requester.Types.INTENT).intent(intent).new().build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe_name',
                      response_dict['sessionAttributes'])
        self.assertEqual(
            response_dict['sessionAttributes']['current_recipe_name'],
            'brownies')
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_SEARCH)

        # response with "Yes" to search online
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('search_recipe_result',
                      response_dict['sessionAttributes'])
        self.assertIn(
            'Title',
            response_dict['sessionAttributes']['search_recipe_result'])
        self.assertIn(
            'RecipeID',
            response_dict['sessionAttributes']['search_recipe_result'])
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_MAKE_ONLINE)

        # response with "Yes" to make the recipe it found
        req = requester.Request().type(requester.Types.INTENT).intent(
            requester.Intent("AMAZON.YesIntent").build()).copy_attributes(
                response_dict).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertIn('current_recipe', response_dict['sessionAttributes'])
        self.assertIn('Title',
                      response_dict['sessionAttributes']['current_recipe'])
        self.assertIn('RecipeID',
                      response_dict['sessionAttributes']['current_recipe'])
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)

        # ask for ingredients
        intent = requester.Intent('IngredientsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).copy_attributes(
            response_dict).intent(intent).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)

        # now ask for instructions
        intent = requester.Intent('InstructionsIntent').build()
        req = requester.Request().type(requester.Types.INTENT).copy_attributes(
            response_dict).intent(intent).build()
        response_dict = lambda_function.handle_event(req, None)

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.INGREDIENTS_OR_INSTRUCTIONS)