Esempio n. 1
0
    def test_own_rate_recipe(self):
        with server.app_context():
            user_data_1 = {
                'email': '*****@*****.**',
                'first_name': 'Ethan',
                'last_name': 'Hunt',
                'password': '******'
            }

            reg_user_1 = register_user(user_data_1)

            login({
                'email': user_data_1['email'],
                'password': user_data_1['password']
            })

            recipe_info = {
                'name': 'Pork',
                'preparation': 'Everybodys favorite dish',
                'ingredients': ['Pork', 'Oil', 'Seasoning', 'Beer'],
                'user_id': reg_user_1.id
            }

            recipe = add_recipe(recipe_info)

            self.assertRaises(BadRequest, rate_recipe, {
                'rating': 5,
                'user_id': reg_user_1.id
            }, recipe.id)
Esempio n. 2
0
    def test_invalid_login(self):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'test',
                'last_name': 'Jones',
                'password': '******'
            }
            register_user(user_data)

            self.assertRaises(BadRequest, login, {
                'password': user_data['password']
            })
Esempio n. 3
0
    def test_wrong_pass_login(self):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'test',
                'last_name': 'Jones',
                'password': '******'
            }
            register_user(user_data)

            self.assertRaises(Forbidden, login, {
                'email': user_data['email'],
                'password': '******'
            })
Esempio n. 4
0
    def test_valid_rate_recipe(self):
        with server.app_context():
            user_data_1 = {
                'email': '*****@*****.**',
                'first_name': 'Ethan',
                'last_name': 'Hunt',
                'password': '******'
            }

            user_data_2 = {
                'email': '*****@*****.**',
                'first_name': 'Natasha',
                'last_name': 'Romanov',
                'password': '******'
            }

            reg_user_1 = register_user(user_data_1)
            reg_user_2 = register_user(user_data_2)

            login({
                'email': user_data_1['email'],
                'password': user_data_1['password']
            })

            login({
                'email': user_data_2['email'],
                'password': user_data_2['password']
            })

            recipe_info = {
                'name': 'Pork',
                'preparation': 'Everybodys favorite dish',
                'ingredients': ['Pork', 'Oil', 'Seasoning', 'Beer'],
                'user_id': reg_user_1.id
            }

            recipe = add_recipe(recipe_info)

            self.assertEqual(0, recipe.rating)
            self.assertEqual(0, recipe.num_of_ratings)

            res = rate_recipe({
                'rating': 5,
                'user_id': reg_user_2.id
            }, recipe.id)

            self.assertEqual(recipe.name, res.name)
            self.assertEqual(5, res.rating)
            self.assertEqual(1, res.num_of_ratings)
Esempio n. 5
0
    def test_unknown_user_login(self):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'test',
                'last_name': 'Jones',
                'password': '******'
            }

            register_user(user_data)

            self.assertRaises(Unauthorized, login, {
                'email': '*****@*****.**',
                'password': user_data['password']
            })
Esempio n. 6
0
    def test_valid_login(self):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'test',
                'last_name': 'Jones',
                'password': '******'
            }
            register_user(user_data)

            resp = login({
                'email': user_data['email'],
                'password': user_data['password']
            })

            self.assertEqual(
                list(resp.keys()), ['access_token', 'refresh_token'])
Esempio n. 7
0
    def test_get_invalid_user_recipes(self):
        with server.app_context():
            user_data_1 = {
                'email': '*****@*****.**',
                'first_name': 'Ethan',
                'last_name': 'Hunt',
                'password': '******'
            }

            register_user(user_data_1)

            login({
                'email': user_data_1['email'],
                'password': user_data_1['password']
            })

            self.assertRaises(BadRequest, get_user_recipes,
                              'this aint valid id')
Esempio n. 8
0
    def test_valid_logout(self, mock_jwt_required, mock_jwt_identity):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'Marc',
                'last_name': 'Feldman',
                'password': '******'
            }

            user = register_user(user_data)
            mock_jwt_identity.return_value = str(user.id)

            resp_1 = login({
                'email': '*****@*****.**',
                'password': '******'
            })

            logout_creds = 'Bearer ' + str(resp_1['access_token'])
            resp_2 = logout(logout_creds)

            self.assertEqual(resp_2, 'Logout successful')
Esempio n. 9
0
    def test_invalid_add_recipe(self):
        with server.app_context():
            user_data = {
                'email': '*****@*****.**',
                'first_name': 'test',
                'last_name': 'Jones',
                'password': '******'
            }

            register_user(user_data)

            login({
                'email': user_data['email'],
                'password': user_data['password']
            })

            self.assertRaises(
                BadRequest, add_recipe, {
                    'name': 'Pork',
                    'preparation': 'Everybodys favorite dish',
                    'ingredients': ['Pork', 'Oil', 'Seasoning', 'Beer'],
                    'user_id': 'this aint my id'
                })
Esempio n. 10
0
    def test_get_all_recipe(self):
        with server.app_context():
            resp = get_all_recipes()

            self.assertEqual(type(resp), type([]))
Esempio n. 11
0
 def test_rate_recipe_invalid_request(self):
     with server.app_context():
         self.assertRaises(BadRequest, rate_recipe, {
             'rating': 5,
             'user_id': 'some id'
         }, None)
Esempio n. 12
0
 def test_valid_add_ingredient(self):
     with server.app_context():
         ing = add_ingredient('Onion')
         self.assertEqual(ing.name, 'Onion')
Esempio n. 13
0
 def test_invalid_add_ingredient(self):
     with server.app_context():
         self.assertRaises(BadRequest, add_ingredient, '')
         self.assertRaises(BadRequest, add_ingredient, None)