Beispiel #1
0
 def test_add_three_other(self):
     wrap = Wrap()
     wrap.add_item(other1, 3)
     assert wrap._num_others == 3
     assert len(wrap) == 3
     assert len(wrap.components) == 1
     assert wrap.price == 36
Beispiel #2
0
 def test_add_six_others(self):
     wrap = Wrap()
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(other1, 6)
     assert len(wrap.components) == 0
     assert len(wrap) == 0
     assert wrap.price == 0
Beispiel #3
0
 def test_add_two_buns(self):
     wrap = Wrap()
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(bun1, 2)
     assert len(wrap.components) == 0
     assert len(wrap) == 0
     assert wrap.price == 0
Beispiel #4
0
 def test_add_one_bun_success(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     assert wrap._num_buns == 1
     assert len(wrap) == 1
     assert len(wrap.components) == 1
     assert wrap.price == 11
Beispiel #5
0
 def test_add_one_other_success(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     assert wrap._num_others == 1
     assert len(wrap) == 1
     assert len(wrap.components) == 1
     assert wrap.price == 12
Beispiel #6
0
def test_wrap():
    w = Wrap()
    w.add_item(patty1, 1)
    w.add_item(bun1, 1)
    w.add_item(other1, 1)

    return w
Beispiel #7
0
 def test_update_patty(self):
     wrap = Wrap()
     wrap.add_item(patty1, 1)
     wrap.update_qty(patty1, 2)
     assert wrap.num_patties == 2
     assert wrap.price == 20
     assert len(wrap) == 2
Beispiel #8
0
 def test_update_other(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     wrap.update_qty(other1, 2)
     assert wrap.num_others == 2
     assert wrap.price == 24
     assert len(wrap) == 2
Beispiel #9
0
 def test_add_different_patties(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     wrap.add_item(patty1, 2)
     assert wrap.num_patties == 2
     assert len(wrap) == 3
     assert wrap.price == 31
Beispiel #10
0
 def test_update_invalid_others(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     with pytest.raises(ValueError):
         wrap.update_qty(other2, 1)
     assert wrap.num_others == 1
     assert len(wrap) == 1
Beispiel #11
0
 def test_update_patties_out_of_range(self):
     wrap = Wrap()
     wrap.add_item(patty1, 2)
     with pytest.raises(InvalidQuantityException):
         wrap.update_qty(patty1, 6)
     assert wrap.num_patties == 2
     assert wrap.price == 20
     assert len(wrap) == 2
Beispiel #12
0
 def test_add_zero_patty(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(patty2, 0)
     assert wrap.num_patties == 0
     assert len(wrap) == 1
     assert wrap.price == 11
Beispiel #13
0
 def test_add_too_many_patties_in_one_go(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(patty1, 3)
     assert wrap.num_patties == 0
     assert len(wrap) == 1
     assert wrap.price == 11
Beispiel #14
0
 def test_add_one_patty(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     wrap.add_item(patty1, 1)
     assert wrap._num_patties == 1
     assert len(wrap) == 2
     assert len(wrap.components) == 2
     assert wrap.price == 21
Beispiel #15
0
 def test_update_bun_zero(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.update_qty(bun1, 0)
     assert wrap.num_buns == 1
     assert wrap.price == 11
     assert len(wrap) == 1
Beispiel #16
0
 def test_update_patty_zero(self):
     wrap = Wrap()
     wrap.add_item(patty1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.update_qty(patty1, 0)
     assert wrap.num_patties == 1
     assert wrap.price == 10
     assert len(wrap) == 1
Beispiel #17
0
 def test_update_other_out_of_stock(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.update_qty(other1, 101)
     assert wrap.num_others == 1
     assert len(wrap) == 1
     assert wrap.price == 12
Beispiel #18
0
 def test_update_other_exceeding_limit(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     with pytest.raises(InvalidQuantityException):
         wrap.update_qty(other1, 5)
     assert wrap.num_others == 1
     assert wrap.price == 12
     assert len(wrap) == 1
Beispiel #19
0
def custom_wrap():
    errors = None
    form = None
    if request.method == 'POST':
        errors = {}
        form = request.form
        wrap = Wrap()
        items = form_handler(request.form)
        for name, qty in items.items():
            item = system.menu.get_item(name)
            try:
                wrap.add_item(item, qty)
            except InvalidQuantityException as e:
                errors[name] = e.__str__()

        try:
            wrap.check_min_buns()
        except ValueError as e:
            errors['min_buns'] = e.__str__()

        try:
            wrap.check_min_patties()
        except ValueError as e:
            errors['min_patties'] = e.__str__()

        if len(errors) == 0:
            system.current_order.add_main(wrap)
            return redirect(
                url_for(
                    'index',
                    msg='the customised wrap has been added to your order'))

    return render_template('main_customisation.html',
                           menu=system.menu,
                           errors=errors,
                           form=form)
def initialise_system():
    restaurant = Restaurant()
    names = ("Sesame Bun",
                "Gluten Free Bun",
                "Beef Patty", 
                "Chicken Patty",
                "Vegie Patty",
                "Chedder Cheese",
                "Tasty Cheese",
                "Coke", 
                "Chicken Nugget",
                "Chips")
    for name in names:
        restaurant.inventory.add_stock(name, 100)

    sesame_bun_inv = restaurant.inventory.get_item("Sesame Bun")
    gf_bun_inv = restaurant.inventory.get_item("Gluten Free Bun")
    bf_patty_inv = restaurant.inventory.get_item("Beef Patty")
    ck_patty_inv = restaurant.inventory.get_item("Chicken Patty")
    c_cheese_inv = restaurant.inventory.get_item("Chedder Cheese")
    t_cheese_inv = restaurant.inventory.get_item("Tasty Cheese")
    coke_inv = restaurant.inventory.get_item("Coke")
    chick_inv = restaurant.inventory.get_item("Chicken Nugget")
    chip_inv = restaurant.inventory.get_item("Chips")
    restaurant.menu.add_bun("Sesame Bun", 10, sesame_bun_inv, 1)
    restaurant.menu.add_bun("Gluten Free Bun", 10, gf_bun_inv, 1)
    restaurant.menu.add_patty("Beef Patty", 10, bf_patty_inv, 1)
    restaurant.menu.add_patty("Chicken Patty", 10, ck_patty_inv, 1)
    restaurant.menu.add_other("Chedder Cheese", 10, c_cheese_inv, 1)
    restaurant.menu.add_other("Tasty Cheese", 10, t_cheese_inv, 1)
    restaurant.menu.add_drink("Canned Coke", 10, coke_inv, 1)
    restaurant.menu.add_side("Small Chicken Nugget", 10, chick_inv, 6)
    restaurant.menu.add_side("Medium Chicken Nugget", 11, chick_inv, 8)
    restaurant.menu.add_side("Large Chicken Nugget", 12, chick_inv,10)
    restaurant.menu.add_side("Small Chips", 10, chip_inv, 20)
    restaurant.menu.add_side("Medium Chips", 10, chip_inv, 25)
    restaurant.menu.add_side("Large Chips", 10, chip_inv, 30)
    
    sesame_bun = restaurant.menu.get_item("Sesame Bun")
    beef_patty = restaurant.menu.get_item("Beef Patty")
    tasty_cheese = restaurant.menu.get_item("Tasty Cheese")

    base_burger = Burger()
    base_wrap = Wrap()

    base_burger.add_item(sesame_bun, 2)
    base_burger.add_item(beef_patty,1)
    base_burger.add_item(tasty_cheese, 1)

    base_wrap.add_item(sesame_bun, 1)
    base_wrap.add_item(beef_patty, 1)
    base_wrap.add_item(tasty_cheese, 1)

    restaurant.base_burger = base_burger
    restaurant.base_wrap = base_wrap
    if ((os.path.exists('inv.dat') and os.path.getsize('inv.dat') > 0) 
        and (os.path.exists('order.dat') and os.path.getsize('order.dat') > 0)):
        print('loading dumped data...')
        restaurant.load_data()
    print("Done")

    return restaurant
Beispiel #21
0
 def test_add_existing_bun(self):
     wrap = Wrap()
     wrap.add_item(bun1, 1)
     with pytest.raises(ValueError):
         wrap.add_item(bun1, 1)
Beispiel #22
0
 def test_insufficient_patties(self):
     wrap = Wrap()
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(patty1, 101)
Beispiel #23
0
 def test_add_existing_others(self):
     wrap = Wrap()
     wrap.add_item(other1, 1)
     with pytest.raises(ValueError):
         wrap.add_item(other1, 1)
Beispiel #24
0
 def test_insufficient_others(self):
     wrap = Wrap()
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(other1, 101)
Beispiel #25
0
 def test_add_zero_others(self):
     wrap = Wrap()
     with pytest.raises(InvalidQuantityException):
         wrap.add_item(other1, 0)
Beispiel #26
0
 def test_add_existing_patty(self):
     wrap = Wrap()
     wrap.add_item(patty1, 1)
     with pytest.raises(ValueError):
         wrap.add_item(patty1, 1)
Beispiel #27
0
 def test_empty_wrap(self):
     wrap = Wrap()
     assert len(wrap.components) == 0
     assert wrap.price == 0