Exemplo n.º 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))
Exemplo n.º 2
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))
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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'])
Exemplo n.º 6
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))
Exemplo n.º 7
0
    def test_multiple_end(self):
        request = requester.Request().type(requester.Types.END).new()

        for i in range(5):
            event = request.build()
            response_dict = lambda_function.handle_event(event, None)
            self.assertTrue(responder.is_valid(response_dict))
Exemplo n.º 8
0
    def test_multiple_end(self):
        request = requester.Request().type(requester.Types.END).new()

        for i in range(5):
            event = request.build()
            response_dict = lambda_function.handle_event(event, None)
            self.assertTrue(responder.is_valid(response_dict))
Exemplo n.º 9
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))
Exemplo n.º 10
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)
Exemplo n.º 11
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))
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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))
Exemplo n.º 15
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)
Exemplo n.º 16
0
    def test_returning_user(self):
        test_util.delete_table(core.LOCAL_DB_URI)

        # first launch on new user should result in a table entry with state set
        # as well as session attributes set correctly
        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.assertEqual(inv_result.value, 1)

        # end the session and make sure database state is good
        event = requester.Request().type(
            requester.Types.END).copy_attributes(response_dict).build()
        response_dict = lambda_function.handle_event(event, None)
        inv_result = lambda_function._skill.db_helper.get('invocations')
        state_result = lambda_function._skill.db_helper.getState()

        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(inv_result.value, 1)
        self.assertEqual(state_result.value, core.States.INITIAL_STATE)
        self.assertEqual(lambda_function._skill.db_helper.table.item_count, 1)

        # on the next request we expect the have the right state
        # last response was a tell, so we don't need to call copy_attributes
        r = requester.Request()
        event = r.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.assertEqual(inv_result.value, 2)
        self.assertFalse(response_dict['response']['shouldEndSession'])
        self.assertEqual(response_dict['sessionAttributes']['STATE'],
                         core.States.NEW_RECIPE)
        self.assertEqual(lambda_function._skill.db_helper.table.item_count, 1)
Exemplo n.º 17
0
    def test_first_time(self):
        test_util.delete_table(core.LOCAL_DB_URI)

        event = requester.Request().type(requester.Types.LAUNCH).new().build()
        response_dict = lambda_function.handle_event(event, None)

        # first launch on new user should result in a table entry with state set
        # as well as session attributes set correctly
        self.assertTrue(responder.is_valid(response_dict))
        self.assertEqual(response_dict['sessionAttributes'][core.STATE_KEY],
                         core.States.ASK_TUTORIAL)

        # since it was an ask, we expect sessionAttributes of response to be ASK_TUTORIAL
        # but we have no need to save to database, so state there should still be INITIAL_STATE
        state_result = lambda_function._skill.db_helper.getState()
        self.assertEqual(state_result.value, core.States.INITIAL_STATE)
        self.assertEqual(lambda_function._skill.db_helper.table.item_count, 1)
Exemplo n.º 18
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)
Exemplo n.º 19
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)
Exemplo n.º 20
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)
Exemplo n.º 21
0
    def test_single_end(self):
        r = requester.Request()
        event = r.type(requester.Types.END).new().build()
        response_dict = lambda_function.handle_event(event, None)

        self.assertTrue(responder.is_valid(response_dict))
Exemplo n.º 22
0
    def test_single_end(self):
        r = requester.Request()
        event = r.type(requester.Types.END).new().build()
        response_dict = lambda_function.handle_event(event, None)

        self.assertTrue(responder.is_valid(response_dict))