def test_add_sidedrink(): order = Order(1) ing = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) order.add_sideDrink(ing, 2, 'l') assert order.sideDrinks[0][0] == ing assert order.sideDrinks[0][1] == 2 assert order.sideDrinks[0][2] == 'l'
def addWeightIngredient(self, name, kind, stock, sWeight, mWeight, lWeight, sPrice, mPrice, lPrice): if not isinstance(name, str): raise UserError('Name of ingredient must be in alphabets') if kind != 'm' and kind != 'd' and kind != 's': raise DevError('kind must be either "m"/"s"/"d"') if not isinstance(stock, int): raise UserError('Stock of ingredient must be in number') if int(stock) < 0: raise UserError( 'Stock of ingredient must be equal to or larger than 0') if not isinstance(sWeight, int) or not isinstance( mWeight, int) or not isinstance(lWeight, int): raise UserError('All weights of ingredient must be in number') if int(sWeight) <= 0 or int(mWeight) <= 0 or int(lWeight) <= 0: raise UserError( 'All weights of ingredient must be larger than zero') if isinstance(sPrice, str) or isinstance(mPrice, str) or isinstance( lPrice, str): raise UserError('All prices of ingredient must be in number') if not isinstance(float(sPrice), float) or not isinstance( float(mPrice), float) or not isinstance(float(lPrice), float): raise UserError('All prices of ingredient must be in number') if float(sPrice) < 0 or float(mPrice) < 0 or float(lWeight) < 0: raise UserError('All prices of ingredient must be positive') global newID newID += 1 new = WeightIngredient(newID, name, kind, stock, sWeight, mWeight, lWeight, sPrice, mPrice, lPrice) self._ingredients.append(new)
def test_addIngredient_weightIngredient_to_burger(): main = Main('wrap') lettuce = WeightIngredient(1, 'lettuce', 'm', 2000, 50, 100, 150, .50, 1, 1.5) main.addIngredient(lettuce, 1, 's') assert main.ingredients[0][0] == lettuce assert main.ingredients[0][1] == 1 assert main.ingredients[0][2] == 's' assert main.price == 4
def test_del_sideDrinks_incorrect_input(): order = Order(1) ing = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) order.add_sideDrink(ing, 2, 'l') ing2 = QuantityIngredient(1, 'can of coke', 'd', 40, 3) with pytest.raises(UserError) as e: order.del_sideDrink(ing2, 1, 's') assert "You don't have any can of coke in your order to remove." in str(e.value)
def test_calc_price(): order = Order(1) main = order.add_main('burger') ing1 = QuantityIngredient(1, 'sesame bun', 'm', 20, 1.00) main.addIngredient(ing1, 2, None) ing2 = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) order.add_sideDrink(ing2, 1, None) assert order.calc_price() == 5.0
def test_new_weight_ingredient(): food = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) assert food.id == 2 assert food.name == 'fries' assert food.kind == 's' assert food.stock == 2000 assert food.sWeight == 60 assert food.mWeight == 100 assert food.lWeight == 140 assert food.sPrice == 2.00 assert food.mPrice == 2.80 assert food.lPrice == 3.4
def test_del_sideDrinks_correct_input(): order = Order(1) ing = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) order.add_sideDrink(ing, 2, 'l') order.del_sideDrink(ing, 2, 'l') assert not order.sideDrinks