예제 #1
0
    def test_add_existing_pantry_ingredients(self):

        dbrb = json_to_ingredient(self.rootbeer, access_db=True)
        dbic = json_to_ingredient(self.icecream, access_db=True)
        user = json_to_user(self.user_obj, access_db=True)
        db.session.commit()

        i = Ingredient.query.filter(Ingredient.name == 'rootbeer').first()
        u = User.query.filter(User.username == 'Frank').first()
        pantry_ingredient = PantryIngredient(ingredient=i, user=u, value=11.0)
        db.session.add(pantry_ingredient)

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())
            ingredients_to_quantity = {'rootbeer': 7.0, 'icecream': 3.0}
            response = req_add_ingredient_to_pantry(self,
                                                    ingredients_to_quantity,
                                                    user_data)
            data = json.loads(response.data.decode())
            self.assertEqual(data['status'], 'success')
            ing = Ingredient.query.filter(
                Ingredient.name == 'rootbeer').first()
            use = User.query.filter(User.username == 'Frank').first()
            pan = PantryIngredient.query.filter(
                (PantryIngredient.user_id == use.id)
                & (PantryIngredient.ingredient_id == ing.id)).first()
            self.assertEqual(pan.value, 7.0)
예제 #2
0
 def test_non_registered_user_login(self):
     """ Test for login of non-registered user """
     with self.client:
         response = req_user_login(self, 'Dennis', 'magicword')
         data = json.loads(response.data.decode())
         self.assertEqual(data['status'], 'fail')
         self.assertEqual(data['message'], 'User does not exist.')
         self.assertEqual(response.content_type, 'application/json')
         self.assertEqual(response.status_code, 404)
예제 #3
0
    def test_prepare_recipe(self):
        """ Test user cooking a recipe """
        meat = {'name': 'Meat', 'measurement': 'MASS', 'value': 5.0}

        water = {'name': 'Dirty Water', 'measurement': 'VOLUME', 'value': 5.0}

        dog_food = {'name': 'Dog Food', 'measurement': 'MASS', 'value': 5.0}

        meat_water = {
            'name': 'Meat Water',
            'ingredients': [meat, water],
            'description': 'Watery meat',
            'steps': ['Place meat in bowl', 'Add water'],
            'rating': 1.0
        }

        dog_food_recipe = {
            'name': 'Dog Food Recipe',
            'ingredients': [dog_food],
            'description': 'This is for dogs. Do not eat.',
            'steps': ['Place in dog bowl.', 'Consume.'],
            'rating': 3.0
        }

        user_obj = {
            'email': '*****@*****.**',
            'username': '******',
            'password': '******',
            'ingredients': [meat, water]
        }

        dbmeat = json_to_ingredient(meat, access_db=True)
        dbwater = json_to_ingredient(water, access_db=True)
        dbdog_food = json_to_ingredient(dog_food, access_db=True)
        user = json_to_user(user_obj, access_db=True)

        db.session.commit()

        recipe = json_to_recipe(meat_water, access_db=True)
        df_recipe = json_to_recipe(dog_food_recipe, access_db=True)
        db.session.commit()

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())

            response = req_prepare_recipe(self, user_data, recipe)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(data['has_all_ingredients'], True)

            response = req_prepare_recipe(self, user_data, recipe)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'fail')
예제 #4
0
    def test_registered_user_login(self):
        """ Test login for a registered user """

        user = User(email='*****@*****.**',
                    username='******',
                    password='******')

        db.session.add(user)
        db.session.commit()

        with self.client:
            response = req_user_login(self, 'John', 'welcometojp')
            data = json.loads(response.data.decode())
            self.assertEqual(data['status'], 'success')
            self.assertEqual(data['message'], 'Successfully logged in.')
            self.assertTrue(data['auth_token'])
            self.assertEqual(response.content_type, 'application/json')
            self.assertEqual(response.status_code, 200)
예제 #5
0
    def test_create_recipe(self):
        """ Test user creating a recipe """

        meat = {'name': 'Meat', 'measurement': 'MASS', 'value': 5.0}

        water = {'name': 'Dirty Water', 'measurement': 'VOLUME', 'value': 5.0}

        meat_water = {
            'name': 'Meat Water',
            'ingredients': [meat, water],
            'description': 'Watery meat',
            'steps': ['Place meat in bowl', 'Add water'],
        }

        user_obj = {
            'email': '*****@*****.**',
            'username': '******',
            'password': '******',
            'ingredients': [meat, water]
        }

        dbmeat = json_to_ingredient(meat, access_db=True)
        dbwater = json_to_ingredient(water, access_db=True)
        user = json_to_user(user_obj, access_db=True)

        db.session.commit()

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())

            response = req_create_recipe(self, user_data, meat_water)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')

            response = req_create_recipe(self, user_data, meat_water)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'fail')
예제 #6
0
    def test_get_ingredients(self):
        dbrb = json_to_ingredient(self.rootbeer, access_db=True)
        dbic = json_to_ingredient(self.icecream, access_db=True)
        user = json_to_user(self.user_obj, access_db=True)
        db.session.commit()

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())
            ingredients_to_quantity = {'rootbeer': 7.0, 'icecream': 3.0}
            response = req_add_ingredient_to_pantry(self,
                                                    ingredients_to_quantity,
                                                    user_data)
            data = json.loads(response.data.decode())
            self.assertEqual(data['status'], 'success')
            response = get_ingredients_from_pantry(self, user_data)
            data = json.loads(response.data.decode())
            self.assertEqual(data['status'], 'success')
            for entry in data['data']['ingredients']:
                if entry['name'] == 'rootbeer':
                    self.assertEqual(entry['value'], 7.0)
                elif entry['name'] == 'icecream':
                    self.assertEqual(entry['value'], 3.0)
예제 #7
0
    def test_search_recipes(self):
        """ Test searching for recipes """

        meat = {'name': 'Meat', 'measurement': 'MASS', 'value': 5.0}

        water = {'name': 'Dirty Water', 'measurement': 'VOLUME', 'value': 5.0}

        dog_food = {'name': 'Dog Food', 'measurement': 'MASS', 'value': 5.0}

        meat_water = {
            'name': 'Meat Water',
            'ingredients': [meat, water],
            'description': 'Watery meat',
            'steps': ['Place meat in bowl', 'Add water'],
            'rating': 1.0
        }

        dog_food_recipe = {
            'name': 'Dog Food Recipe',
            'ingredients': [dog_food],
            'description': 'This is for dogs. Do not eat.',
            'steps': ['Place in dog bowl.', 'Consume.'],
            'rating': 3.0
        }

        user_obj = {
            'email': '*****@*****.**',
            'username': '******',
            'password': '******',
            'ingredients': [meat, water]
        }

        dbmeat = json_to_ingredient(meat, access_db=True)
        dbwater = json_to_ingredient(water, access_db=True)
        dbdog_food = json_to_ingredient(dog_food, access_db=True)
        user = json_to_user(user_obj, access_db=True)

        db.session.commit()

        recipe = json_to_recipe(meat_water, access_db=True)
        df_recipe = json_to_recipe(dog_food_recipe, access_db=True)
        db.session.commit()

        meat_water_simple = {
            'name': 'Meat Water',
            'description': 'Watery meat',
            'rating': 1.0
        }

        dog_food_simple = {
            'name': 'Dog Food Recipe',
            'description': 'This is for dogs. Do not eat.',
            'rating': 3.0
        }

        meat_water_simple['recipe_id'] = str(uuid.UUID(hex=recipe.id.hex))

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())

            response = req_search_recipe(self, user_data, filter_='true')
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(data['data']['recipes'], [meat_water_simple])

            response = req_search_recipe(self,
                                         user_data,
                                         'meat water',
                                         filter_='true')
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(data['data']['recipes'], [meat_water_simple])

            response = req_search_recipe(self,
                                         user_data,
                                         'random query',
                                         filter_='true')
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(data['data']['recipes'], [])

            response = req_search_recipe(self, user_data)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            # print(data['data']['recipes'])
            self.assertEqual(len(data['data']['recipes']), 2)
예제 #8
0
    def test_rate_recipe(self):
        """ Test rating a recipe """
        meat = {'name': 'Meat', 'measurement': 'MASS', 'value': 5.0}

        water = {'name': 'Dirty Water', 'measurement': 'VOLUME', 'value': 5.0}

        dog_food = {'name': 'Dog Food', 'measurement': 'MASS', 'value': 5.0}

        meat_water = {
            'name': 'Meat Water',
            'ingredients': [meat, water],
            'description': 'Watery meat',
            'steps': ['Place meat in bowl', 'Add water'],
        }

        frank_obj = {
            'email': '*****@*****.**',
            'username': '******',
            'password': '******',
            'ingredients': [meat, water]
        }

        dennis_obj = {
            'email': '*****@*****.**',
            'username': '******',
            'password': '******',
            'ingredients': [meat, water]
        }

        dbmeat = json_to_ingredient(meat, access_db=True)
        dbwater = json_to_ingredient(water, access_db=True)
        frank = json_to_user(frank_obj, access_db=True)
        dennis = json_to_user(dennis_obj, access_db=True)

        db.session.commit()

        recipe = json_to_recipe(meat_water, access_db=True)
        db.session.commit()

        with self.client:
            response = req_user_login(self, 'Frank', 'magnum')
            user_data = json.loads(response.data.decode())

            response = req_rate_recipe(self, user_data, recipe, 5.0)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(recipe.rating, 5.0)

            response = req_rate_recipe(self, user_data, recipe, 1.0)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(recipe.rating, 1.0)

            response = req_user_login(self, 'Dennis', 'mistertibbs')
            user_data = json.loads(response.data.decode())

            response = req_rate_recipe(self, user_data, recipe, 5.0)
            data = json.loads(response.data.decode())

            self.assertEqual(data['status'], 'success')
            self.assertEqual(recipe.rating, 3.0)