Esempio n. 1
0
    def test_edit_recipe_endpoint(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        editTitle = 'pao de queijo'
        editIngredients = 'agua, polvilho, 100ml leite, fermento'
        editDirections = 'na mão, assar'

        test_recipe_edit_data = {
            "id": 1,
            "title": editTitle,
            "ingredients": editIngredients,
            "directions": editDirections,
            "text": None,
            "time": None,
            "image": None
        }

        with self.client:
            test_user_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_user_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)

            response = self.client.post('/edit_recipe',
                                        data=json.dumps(test_recipe_edit_data),
                                        headers=get_headers(
                                            'application/json', token))
            self.assert200(response)

            result = get_recipe_by_id(1)
            self.assertEqual(result['titulo'], editTitle)
            self.assertEqual(result['ingredientes'], editIngredients)
            self.assertEqual(result['modo_preparo'], editDirections)
Esempio n. 2
0
 def test_save_favorite(self):
     newTitle = 'bolo de chocolate'
     newIngredients = '2 ovos, 100ml leite, fermento'
     newDirections = 'batedeira tudo e assar'
     with self.client:
         test_data = save_test_user()
         newAuthor, token = self.login_id_and_token(test_data)
         save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
         save_new_favorite(1, newAuthor)
         self.assertEqual(check_exists_favorite(1, newAuthor), True)
Esempio n. 3
0
 def test_unfavorite(self):
     newTitle = 'bolo de chocolate'
     newIngredients = '2 ovos, 100ml leite, fermento'
     newDirections = 'batedeira tudo e assar'
     with self.client:
         test_data = save_test_user()
         newAuthor, token = self.login_id_and_token(test_data)
         save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
         save_new_favorite(1, newAuthor)
         unfavorite_recipe(1, newAuthor)
         result = get_favorite_relation(1, newAuthor)
         self.assertEqual(result.is_active(), False)
Esempio n. 4
0
    def test_average_stars_endpoint(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'
        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            submit_new_review(1, newAuthor, 5)

            response = self.client.get('/average_stars?id=1',
                                       headers=get_headers('html/text', token))
            self.assert200(response)
Esempio n. 5
0
    def test_get_recipe_by_id(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            result = get_recipe_by_id(1)
            self.assertEqual(result['titulo'], newTitle)
            self.assertEqual(result['ingredientes'], newIngredients)
            self.assertEqual(result['modo_preparo'], newDirections)
Esempio n. 6
0
    def test_endpoint_get_recipe_with_search_filter(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)

            response = self.client.get('/receitas?search=bolo',
                                       headers=get_headers('html/text', token))
            self.assert200(response)
Esempio n. 7
0
    def test_save_new_recipe(self):
        newTitle = 'bolo'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            savedRecipe = Recipe.query.filter_by(titulo=newTitle).first()
            self.assertEqual(newAuthor, savedRecipe.autor)
            self.assertEqual(newTitle, savedRecipe.titulo)
            self.assertEqual(newIngredients, savedRecipe.ingredientes)
            self.assertEqual(newDirections, savedRecipe.modo_preparo)
Esempio n. 8
0
    def test_get_all_user_recipes(self):
        newTitle = 'bolo'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'
        newTitle2 = 'bolo2'
        newIngredients2 = '23 ovos, 1000ml leite, 2 fermento'
        newDirections2 = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            save_new_recipe(newTitle2, newIngredients2, newDirections2,
                            newAuthor)
            savedRecipes = get_user_recipes_as_dict(newAuthor)
            self.assertEqual(len(savedRecipes), 2)
Esempio n. 9
0
    def test_submit_review_endpoint(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'
        test_submit_data = {
            "id": 1,
            "stars": 5,
        }
        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)

            response = self.client.post('/submit_review',
                                        data=json.dumps(test_submit_data),
                                        headers=get_headers(
                                            'application/json', token))
            self.assert200(response)
Esempio n. 10
0
    def test_get_recipe_when_logged_returns_favorite_status_as_well(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            save_new_favorite(1, newAuthor)
            response = self.client.get('/receitas/1?token=' + token,
                                       headers=get_headers(
                                           'application/json', token))

            data = json.loads(response.get_data())

            self.assert200(response)
            self.assertEqual(data['titulo'], newTitle)
            self.assertEqual(data['ingredientes'], newIngredients)
            self.assertEqual(data['modo_preparo'], newDirections)
            self.assertEqual(data['favorite_status'], True)
Esempio n. 11
0
    def test_delete_recipe(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        test_recipe_data = {
            "id": 1,
        }

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)

            response = self.client.post('/delete_recipe',
                                        data=json.dumps(test_recipe_data),
                                        headers=get_headers(
                                            'application/json', token))
            result = get_recipe_by_id(1)

            self.assert200(response)
            self.assertEqual(result, None)
Esempio n. 12
0
    def test_favorite_unfavorite_favorite_route(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        test_submit_data = {
            "id": 1,
        }

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)

            response = self.client.post('/favorite',
                                        data=json.dumps(test_submit_data),
                                        headers=get_headers(
                                            'application/json', token))
            self.assert200(response)
            result = get_favorite_relation(1, newAuthor)
            self.assertEqual(result.is_active(), True)

            response = self.client.post('/favorite',
                                        data=json.dumps(test_submit_data),
                                        headers=get_headers(
                                            'application/json', token))
            self.assert200(response)
            result = get_favorite_relation(1, newAuthor)
            self.assertEqual(result.is_active(), False)

            response = self.client.post('/favorite',
                                        data=json.dumps(test_submit_data),
                                        headers=get_headers(
                                            'application/jason', token))
            self.assert200(response)
            result = get_favorite_relation(1, newAuthor)
            self.assertEqual(result.is_active(), True)
Esempio n. 13
0
    def test_get_recipe_by_filters(self):
        newTitle = 'bolo de chocolate'
        newIngredients = '2 ovos, 100ml leite, fermento'
        newDirections = 'batedeira tudo e assar'

        newTitle2 = 'cake'
        newIngredients2 = '2 ovos, 100ml leite, fermento'
        newDirections2 = 'batedeira tudo e assar'

        newTitle3 = 'bolo'
        newIngredients3 = '2 ovos, 100ml leite, fermento'
        newDirections3 = 'batedeira tudo e assar'

        with self.client:
            test_data = save_test_user()
            newAuthor, token = self.login_id_and_token(test_data)
            save_new_recipe(newTitle, newIngredients, newDirections, newAuthor)
            save_new_recipe(newTitle2, newIngredients2, newDirections2,
                            newAuthor)
            save_new_recipe(newTitle3, newIngredients3, newDirections3,
                            newAuthor)
            result = get_recipe_by_filters('bolo', 'titulo', None)
            self.assertEqual(len(result), 2)