def test_get_unit_id(): unit = Unit(name='test', symbol='t') db.session.add(unit) db.session.commit() assert db_funcs.get_unit_id('test') == unit.unit_id assert db_funcs.get_unit_id('t') == unit.unit_id conftest.delete(unit)
def test_get_recipe(product, ingredient): recipe = Recipe(product_id=product.product_id, ingredient_id=ingredient.ingredient_id, amount=500) db.session.add(recipe) db.session.commit() assert len(db_funcs.get_recipe(product.product_id)) == 1 conftest.delete(recipe)
def test_get_all_units(): amount = len(Unit.query.all()) unit = Unit(name='test', symbol='t') db.session.add(unit) db.session.commit() units = db_funcs.get_all_units() assert len(units) == amount + 1 assert all(map(lambda x: isinstance(x, str), units)) conftest.delete(unit)
def test_add_recipe(product, ingredient): amount = 500 unit = 1 assert Recipe.query.filter( and_(Recipe.product_id == product.product_id, Recipe.ingredient_id == ingredient.ingredient_id)).first() is None db_funcs.add_recipe(product.product_id, ingredient.name, amount, unit) recipe = Recipe.query.filter( and_(Recipe.product_id == product.product_id, Recipe.ingredient_id == ingredient.ingredient_id)).first() assert recipe is not None conftest.delete(recipe)
def test_product_add_success(client, user): conftest.login(client, user) data = {'name': 'test_product', 'amount': 500, 'unit': 'g', 'public': True} assert (client.post( conftest.ROUTES['new_product'], data=data, follow_redirects=True).status_code == conftest.HTTP_CODES['ok']) product = Product.query.filter( and_(Product.name == data['name'], Product.user_id == user.user_id)).first() assert product is not None conftest.delete(product) conftest.logout(client)
def test_add_ingredient(): ingredient_name = 'aaa_ingredient_test_name_aaa' unit_id = 1 assert Ingredient.query.filter( and_(Ingredient.name == ingredient_name.lower(), Ingredient.unit_id == unit_id)).first() is None ingredient_id = db_funcs.add_ingredient(ingredient_name, unit_id) ingredient = Ingredient.query.get(ingredient_id) assert ingredient is not None ingredient_id = db_funcs.add_ingredient(ingredient_name, unit_id) ingredient = Ingredient.query.get(ingredient_id) assert ingredient is not None conftest.delete(ingredient)
def test_add_user(): user_details = { 'username': '******', 'email': '*****@*****.**', 'password': '******', 'fullname': 'test user' } assert User.query.filter( User.username == user_details['username'].lower()).first() is None user_id = db_funcs.add_user(**user_details) user = User.query.get(user_id) assert user is not None conftest.delete(user)
def test_add_product(user): product_details = { 'name': 'test_product', 'amount': 1, 'unit': 1, 'public': True } assert Product.query.filter( and_(Product.name == product_details['name'].lower(), Product.user_id == user.user_id)).first() is None product_id = db_funcs.add_product(**product_details, user_id=user.user_id) product = Product.query.get(product_id) assert product is not None conftest.delete(product)
def test_get_unit_name(unit_details, name): unit = Unit(**unit_details) db.session.add(unit) db.session.commit() assert db_funcs.get_unit_name(unit.unit_id) == name conftest.delete(unit)