Пример #1
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)
Пример #2
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)
Пример #3
0
    def test_new_user(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        self.db_helper.init_table()
        self.db_helper.user = '******' % random.randint(0, 1000)

        result = self.db_helper.set("test_attr", 1)
        self.assertFalse(result.err)

        result = self.db_helper.get("test_attr")
        self.assertFalse(result.err)
        self.assertEqual(result.value, 1)
        self.assertEqual(self.db_helper.table.item_count, 1)
        self.assertEqual(dbhelper._db_hit_count, 2)
Пример #4
0
    def test_new_user(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        self.db_helper.init_table()
        self.db_helper.user = '******' % random.randint(0, 1000)

        result = self.db_helper.set("test_attr", 1)
        self.assertFalse(result.err)

        result = self.db_helper.get("test_attr")
        self.assertFalse(result.err)
        self.assertEqual(result.value, 1)
        self.assertEqual(self.db_helper.table.item_count, 1)
        self.assertEqual(dbhelper._db_hit_count, 2)
Пример #5
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)
Пример #6
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'])
Пример #7
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)
Пример #8
0
    def test_many_new_users(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        self.db_helper.init_table()
        self.assertEqual(self.db_helper.table.item_count, 0)

        N_USERS = 100
        for i in range(N_USERS):
            self.db_helper.user = '******' % i
            result = self.db_helper.set("test_attr", 1)
            self.assertFalse(result.err)

            result = self.db_helper.get("test_attr")
            self.assertFalse(result.err)
            self.assertEqual(result.value, 1)

        self.assertEqual(self.db_helper.table.item_count, N_USERS)
        self.assertEqual(dbhelper._db_hit_count, 2 * N_USERS)
Пример #9
0
    def test_many_new_users(self):
        test_util.delete_table(core.LOCAL_DB_URI)
        self.db_helper.init_table()
        self.assertEqual(self.db_helper.table.item_count, 0)

        N_USERS = 100
        for i in range(N_USERS):
            self.db_helper.user = '******' % i
            result = self.db_helper.set("test_attr", 1)
            self.assertFalse(result.err)

            result = self.db_helper.get("test_attr")
            self.assertFalse(result.err)
            self.assertEqual(result.value, 1)

        self.assertEqual(self.db_helper.table.item_count, N_USERS)
        self.assertEqual(dbhelper._db_hit_count, 2 * N_USERS)
Пример #10
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)
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #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)
Пример #16
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)
Пример #17
0
 def setUpClass(cls):
     test_util.delete_table(core.LOCAL_DB_URI)
Пример #18
0
 def setUpClass(cls):
     test_util.delete_table(core.LOCAL_DB_URI)
     test_util.set_bigoven_username()
Пример #19
0
 def setUpClass(cls):
     test_util.delete_table(core.LOCAL_DB_URI)
     test_util.set_bigoven_username()
Пример #20
0
 def setUpClass(cls):
     test_util.delete_table(core.LOCAL_DB_URI)