Ejemplo n.º 1
0
def test_new_quantity_ingredient():
    food = QuantityIngredient(1, 'sesame bun', 'm', 20, 5.00)
    assert food.id == 1
    assert food.name == 'sesame bun'
    assert food.kind == 'm'
    assert food.stock == 20
    assert food.price == 5.00
Ejemplo n.º 2
0
def test_check_burger_invalid():
    main = Main('burger')
    bun = QuantityIngredient(1, 'bun','m', 10, 1.5)
    main.addIngredient(bun, 1, None)
    with pytest.raises(UserError) as err:
        main.checkBurger()
    assert  "You must finish your burger before moving on. It needs at least 2 buns to be finished." in str(err.value)
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def test_add_patty_to_burger_within_range():
    main=Main('burger')
    patty=QuantityIngredient(1, 'patty', 'm', 25, 5)
    main.addIngredient(patty, 3, None)
    assert main.ingredients[0][0] == patty
    assert main.ingredients[0][1] == 3
    assert main.price == 18 
    assert main.nBun == 0
    assert main.nPatty == 3
    assert main.type == 'burger'
Ejemplo n.º 6
0
def test_add_bun_to_burger_within_range():
    main = Main('burger')
    bun = QuantityIngredient(1, 'bun', 'm', 10, 1.5)
    main.addIngredient(bun, 3, None)
    assert main.ingredients[0][0] == bun 
    assert main.ingredients[0][1] == 3
    assert main.price == 7.5 
    assert main.nBun == 3
    assert main.nPatty == 0
    assert main.type == 'burger'
Ejemplo n.º 7
0
def test_addIngredient_tomato_to_burger_enough_stock():
    main = Main('burger')
    tomato = QuantityIngredient(1, 'tomato', 'm', 20, 1)
    main.addIngredient(tomato, 5, None)
    assert main.ingredients[0][0] == tomato  
    assert main.ingredients[0][1] == 5
    assert main.price == 8
    assert main.nBun == 0
    assert main.nPatty == 0
    assert main.type == 'burger'
Ejemplo n.º 8
0
    def addQuantityIngredient(self, name, kind, stock, price):
        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 float(stock) < 0:
            raise UserError('Stock of ingredient must be positive')
        if not isinstance(price, float) and not isinstance(price, int):
            raise UserError('Price of ingredient must be a number')
        if float(price) < 0:
            raise UserError('Price of ingredient must be positive')

        global newID
        newID += 1
        new = QuantityIngredient(newID, name, kind, stock, price)
        self._ingredients.append(new)
Ejemplo n.º 9
0
def test_add_bun_to_burger_too_many_buns():
    main = Main('burger')
    bun = QuantityIngredient(1, 'bun', 'm', 10, 1.5)
    with pytest.raises(UserError) as error: 
        main.addIngredient(bun, 4, None)
    assert "You can't add more than 3 buns to your order" in str(error.value)
Ejemplo n.º 10
0
def test_addIngredient_tomato_to_burger_not_enough_stock():
    main = Main('burger')
    tomato = QuantityIngredient(1, 'tomato', 'm', 4, 0.2)
    with pytest.raises(StockError) as error: 
        main.addIngredient(tomato, 5, None)
    assert "Not enough tomato in stock: 4 left." in str(error.value)
Ejemplo n.º 11
0
def test_check_burger_valid():
    main = Main('burger')
    bun = QuantityIngredient(1, 'bun','m', 10, 1.5)
    main.addIngredient(bun, 2, None)
    assert main.checkBurger() == True
Ejemplo n.º 12
0
def test_addIngredient_add_bun_to_wrap():
    main = Main('wrap')
    bun = QuantityIngredient(0, 'bun', 'm', 20, .50)
    with pytest.raises(UserError) as error:
        main.addIngredient(bun, 2, None)
    assert "You can't add a bun to a wrap" in str(error.value)
Ejemplo n.º 13
0
def test_add_Patty_to_Burger_too_many_patties():
    main=Main('burger')
    patty=QuantityIngredient(1, 'patty', 'm', 25, 5)
    with pytest.raises(UserError) as error: 
        main.addIngredient(patty, 5, None)
    assert "You can't add more than 4 patties to your order" in str(error.value)
Ejemplo n.º 14
0
def test_updateStock_string():
    food = QuantityIngredient(1, 'sesame bun', 'm', 20, 5.00)
    with pytest.raises(IngUserError) as error:
        food.updateStock('ten')
    assert 'Entry must be an integer' in str(error.value)
Ejemplo n.º 15
0
def test_updateStock_negative_num():
    food = QuantityIngredient(1, 'sesame bun', 'm', 20, 5.00)
    with pytest.raises(IngUserError) as error:
        food.updateStock(-35)
    assert 'Entry must be a positive number' in str(error.value)
Ejemplo n.º 16
0
def test_updateStock_valid_input():
    food = QuantityIngredient(1, 'sesame bun', 'm', 20, 5.00)
    food.updateStock(1000)
    assert food.stock == 1000