def test_order_fries_invalid(os): # ===== ORDERS FRIES UNTIL NEXT ORDER WILL BE INVALID ===== friesQ = side_quantity(Fries("")) end = friesQ / 640 x = 0 iterate = friesQ - 640 if friesQ % 640 == 0: iterate = friesQ while x < iterate: orderx = Order() orderx.add_side(Fries("large")) assert orderx.calculate_price() == 3.50 assert os.add_order(orderx) == True x += 640 assert len(os._orders) == int(end) # ===== MAKES A NEW ORDER ===== invalid_order = Order() invalid_order.add_side(Fries("large")) assert invalid_order.calculate_price() == 3.5 # ===== MAKES SURE THE ERROR IS CATCHED AND THE CORRECT MESSAGE IS DISPLAYED===== try: os.add_order(invalid_order) assert False except Exception as err: assert str(err) == "Not enough ingredients available." assert True # ASSERT THAT LENGTH IS SAME AS BEFORE SHOWING THAT ORDER WASN'T ADDED assert len(os._orders) == int(end)
def test_make_full_order(os): # ===== MAKE A LIST OF INGREDIENTS AND MAKE A MAIN ===== w_ingres = [] x1 = Ingredient("plain", "wrap", "plain wrap", 1, 2) x2 = Ingredient("lettuce", "vegetable", "lettuce", 2, 0.5) x3 = Ingredient("tomato", "vegetable", "tomato", 2, 1) x4 = Ingredient("cheddar", "cheese", "cheddar cheese", 4, 1) for x in [x1, x2, x3, x4]: w_ingres.append(x) m1 = Main("wrap", w_ingres) # ===== STORE INVENTORY LEVELS ===== wrapQ = ing_quantity("plain", "wrap") letQ = ing_quantity("lettuce", "vegetable") tomQ = ing_quantity("tomato", "vegetable") cheQ = ing_quantity("cheddar", "cheese") ojQ = drink_quantity("orange juice", "") pepsi_q = drink_quantity("pepsi", "can") nuggetQ = side_quantity(Nuggets(6)) friesQ = side_quantity(Fries("")) # ===== ADD MAIN, DRINK AND SIDES TO ORDER ===== order1 = Order() order1.add_main(m1) order1.add_drink(Drink("orange juice", "small", 250)) order1.add_drink(Drink("pepsi", "can", 2)) order1.add_side(Fries("large")) order1.add_side(Nuggets(6)) # ===== ADD ORDER TO ORDERING SYSTEM ===== assert os.add_order(order1) == True # ===== ASSERT ORDER WAS LOGGED ===== assert len(os._orders) == 1 # ===== CHECK PRICE ===== assert order1.calculate_price() == 21 # ===== MAKE SURE CORRECT NUMBER OF ITEMS HAVE BEEN PUT INTO THE ORDER ===== assert len(order1.mains) == 1 assert len(order1.sides) == 2 assert len(order1.drinks) == 2 assert len(order1.mains[0]._ingredients) == 4 # ===== MAKE SURE INVENTORY LEVELS WERE UPDATED CORRECTLY ===== assert ing_quantity("plain", "wrap") == wrapQ - 1 assert ing_quantity("lettuce", "vegetable") == letQ - 2 assert ing_quantity("tomato", "vegetable") == tomQ - 2 assert ing_quantity("cheddar", "cheese") == cheQ - 4 assert side_quantity(Nuggets(6)) == nuggetQ - 6 assert side_quantity(Fries("")) == friesQ - 640 assert drink_quantity("orange juice", "") == ojQ - 250 assert drink_quantity("pepsi", "can") == pepsi_q - 2
def test_order_fries(os): # ===== ORDERING SMALL FRIES ===== order1 = Order() friesQ = side_quantity(Fries("")) order1.add_side(Fries("small")) assert order1.calculate_price() == 2 assert os.add_order(order1) == True assert side_quantity(Fries("")) == friesQ - 250 # ===== ORDERING MEDIUM FRIES ===== order2 = Order() friesQ = side_quantity(Fries("")) order2.add_side(Fries("medium")) assert order2.calculate_price() == 3 assert os.add_order(order2) == True assert side_quantity(Fries("")) == friesQ - 400 # ===== ORDERING LARGE FRIES ===== order3 = Order() friesQ = side_quantity(Fries("")) order3.add_side(Fries("large")) assert order3.calculate_price() == 3.5 assert os.add_order(order3) == True assert side_quantity(Fries("")) == friesQ - 640 # ASSERT THAT 3 ORDERS WERE MADE assert len(os._orders) == 3
def test_cancel_fries(os): # ===== ORDERING SMALL FRIES ===== order1 = Order() friesQ = side_quantity(Fries("")) order1.add_side(Fries("small")) assert order1.calculate_price() == 2 assert os.add_order(order1) == True assert side_quantity(Fries("")) == friesQ - 250 os.cancel_order(order1.order_id) assert side_quantity(Fries("")) == friesQ
def bootstrap_system(): system = OrderingSystem() order1 = Order() custom_ingredients = deepcopy(g_ingredients) custom_ingredients = [x for x in custom_ingredients if x.i_type != "wrap"] for i in custom_ingredients: i.amount = 1 main1 = Main("burger", custom_ingredients) order1.add_main(main1) nuggets1 = Nuggets(6) order1.add_side(nuggets1) fries1 = Fries("large") order1.add_side(fries1) drink1 = Drink("pepsi", "can", 2) order1.add_drink(drink1) system.add_order(order1) order2 = Order() order2.add_main(main1) order2.add_side(nuggets1) order2.add_side(fries1) order2.add_drink(drink1) system.add_order(order2) return system
def orderFries(): size = int(input("Size? \n1. Small\n2. Medium \n3. Large\n")) if (size == 1): fries = Fries("small") elif (size == 2): fries = Fries("medium") elif (size == 3): fries = Fries("large") else: fries = None return fries
# create ingredients list with amount left, name and price # customer and ordering_system will access this list for i_gen in ingredients_gen: g_ingredients.append( Ingredient(i_gen[0], i_gen[1], i_gen[2], i_gen[3], i_gen[4])) pickle_ingredients() filename = 'g_sides' try: infile = open(filename, 'rb') g_sides = pickle.load(infile) infile.close() except: g_sides = [Nuggets(342), Fries(amount=18000)] pickle_sides() filename = 'g_drinks' try: infile = open(filename, 'rb') g_drinks = pickle.load(infile) infile.close() except: g_drinks = [ Drink("pepsi", "can", 134), Drink("pepsi", "bottle", 34), Drink("sprite", "can", 134), Drink("sprite", "bottle", 231), Drink("orange juice", "", 65000) ]
def new_order(): # TODO this is gonna be sloppy as f**k, will fix later # first get the type of burger then display the available list of ingredients # for that type of main.. Then just display the rest LOL # validate burger and wrap option if request.method == "GET": if request.args.get('amount') is None: return render_template('new_order_amount.html') else: return render_template('new_order_type.html') else: if request.form.get('first_try') == 'true': return render_template('new_order_main.html', ingredients=g_ingredients, sides=g_sides, drinks=g_drinks) form = OrderForm(request.form) if form.is_valid: order = Order() if int(form.get_raw_data('amount')) > 0: for x in range(int(form.get_raw_data('amount'))): # i_type = 'burger' or 'wrap' i_type = form.get_raw_data('main_' + str(x)) ingredients = deepcopy(g_ingredients) custom_ingredients = [] for ingredient in ingredients: if i_type == 'burger' and ingredient.i_type != 'wrap': ingredient.amount = int( form.get_raw_data('main_' + str(x) + '_' + str(ingredient.inv_id))) custom_ingredients.append(ingredient) elif i_type == 'wrap' and ingredient.i_type != 'bun': ingredient.amount = int( form.get_raw_data('main_' + str(x) + '_' + str(ingredient.inv_id))) custom_ingredients.append(ingredient) else: continue main = Main(i_type, custom_ingredients) order.add_main(main) if int(form.get_raw_data('sundae_small')) > 0: for x in range(int(form.get_raw_data('sundae_small'))): sundae_small = Sundae("chocolate", "small", 1) order.add_sundae(sundae_small) if int(form.get_raw_data('sundae_medium')) > 0: for x in range(int(form.get_raw_data('sundae_medium'))): sundae_small = Sundae("chocolate", "medium", 1) order.add_sundae(sundae_small) if int(form.get_raw_data('sundae_large')) > 0: for x in range(int(form.get_raw_data('sundae_large'))): sundae_small = Sundae("chocolate", "large", 1) order.add_sundae(sundae_small) if int(form.get_raw_data('nuggets_3')) > 0: for x in range(int(form.get_raw_data('nuggets_3'))): nuggets_3 = Nuggets(3) order.add_side(nuggets_3) if int(form.get_raw_data('nuggets_6')) > 0: for x in range(int(form.get_raw_data('nuggets_6'))): nuggets_6 = Nuggets(6) order.add_side(nuggets_6) if int(form.get_raw_data('fries_small')) > 0: for x in range(int(form.get_raw_data('fries_small'))): fries_small = Fries('small') order.add_side(fries_small) if int(form.get_raw_data('fries_medium')) > 0: for x in range(int(form.get_raw_data('fries_medium'))): fries_medium = Fries('medium') order.add_side(fries_medium) if int(form.get_raw_data('fries_large')) > 0: for x in range(int(form.get_raw_data('fries_large'))): fries_large = Fries('large') order.add_side(fries_large) if int(form.get_raw_data('sprite_can')) > 0: for x in range(int(form.get_raw_data('sprite_can'))): sprite_can = Drink('sprite', 'can', 1) order.add_drink(sprite_can) if int(form.get_raw_data('sprite_bottle')) > 0: for x in range(int(form.get_raw_data('sprite_bottle'))): sprite_bottle = Drink('sprite', 'bottle', 1) order.add_drink(sprite_bottle) if int(form.get_raw_data('pepsi_can')) > 0: for x in range(int(form.get_raw_data('pepsi_can'))): pepsi_can = Drink('pepsi', 'can', 1) order.add_drink(pepsi_can) if int(form.get_raw_data('pepsi_bottle')) > 0: for x in range(int(form.get_raw_data('pepsi_bottle'))): pepsi_bottle = Drink('pepsi', 'bottle', 1) order.add_drink(pepsi_bottle) if int(form.get_raw_data('orange_juice_small')) > 0: for x in range(int(form.get_raw_data('orange_juice_small'))): orange_juice_small = Drink('orange juice', 'small', 250) order.add_drink(orange_juice_small) if int(form.get_raw_data('orange_juice_medium')) > 0: for x in range(int(form.get_raw_data('orange_juice_medium'))): orange_juice_medium = Drink('orange juice', 'medium', 450) order.add_drink(orange_juice_medium) if int(form.get_raw_data('orange_juice_large')) > 0: for x in range(int(form.get_raw_data('orange_juice_large'))): orange_juice_large = Drink('orange juice', 'large', 650) order.add_drink(orange_juice_large) if 'confirm' in request.form: system.add_order(order) return redirect(url_for('order', order_id=order.order_id)) else: if order.calculate_price() > 0: return render_template('new_order_main.html', ingredients=g_ingredients, sides=g_sides, drinks=g_drinks, confirm=True, fee='{:0,.2f}'.format( order.calculate_price())) else: return render_template('new_order_main.html', ingredients=g_ingredients, sides=g_sides, drinks=g_drinks, fee=0) else: errors = {} for field in form.fields: errors[field.name] = field.error return render_template('new_order_main.html', ingredients=g_ingredients, sides=g_sides, drinks=g_drinks, errors=errors) return render_template('new_order_main.html', ingredients=g_ingredients, sides=g_sides, drinks=g_drinks)