def test_order_drink_can_invalid(os): # ===== ORDERS DRINKS UNTIL NEXT ORDER WILL BE INVALID ===== x = 1 pepsi_q = drink_quantity("pepsi", "can") end = pepsi_q while x <= pepsi_q: orderx = Order() orderx.add_drink(Drink("pepsi", "can", 1)) assert orderx.calculate_price() == 2 assert os.add_order(orderx) == True assert drink_quantity("pepsi", "can") == pepsi_q - x x += 1 assert len(os._orders) == end # ===== MAKES A NEW ORDER ===== invalid_order = Order() invalid_order.add_drink(Drink("pepsi", "can", 1)) assert invalid_order.calculate_price() == 2 # ===== 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) == end
def test_cancel_nuggets(os): # ===== ORDERING 3 NUGGETS ===== order1 = Order() originalq = nuggetq = side_quantity(Nuggets(3)) nuggetq = side_quantity(Nuggets(3)) order1.add_side(Nuggets(3)) assert order1.calculate_price() == 3 assert os.add_order(order1) == True assert side_quantity(Nuggets(3)) == nuggetq - 3 # ===== ORDERING 6 NUGGETS ===== order2 = Order() nuggetq = side_quantity(Nuggets(6)) order2.add_side(Nuggets(6)) assert order2.calculate_price() == 4.50 assert os.add_order(order2) == True assert side_quantity(Nuggets(6)) == nuggetq - 6 assert len(os._orders) == 2 # ===== TESTING CANCEL ORDER UPDATES INVENTORY CORRECTLY ===== os.cancel_order(order1._order_id) assert side_quantity(Nuggets(6)) == nuggetq - 3 os.cancel_order(order2._order_id) assert side_quantity(Nuggets(6)) == originalq
def test_order_drink_bottle_invalid(os): # ===== ORDERS DRINKS UNTIL NEXT ORDER WILL BE INVALID ===== x = 1 sprite_q = drink_quantity("sprite", "bottle") end = sprite_q while x <= sprite_q: orderx = Order() orderx.add_drink(Drink("sprite", "bottle", 1)) assert orderx.calculate_price() == 3 assert os.add_order(orderx) == True assert drink_quantity("sprite", "bottle") == sprite_q - x x += 1 assert len(os._orders) == end # ===== MAKES A NEW ORDER ===== invalid_order = Order() invalid_order.add_drink(Drink("sprite", "bottle", 1)) assert invalid_order.calculate_price() == 3 # ===== 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 LENGTH IS THE SAME assert len(os._orders) == end
def test_order_drinks_invalid(os): # ===== ORDERS DRINKS UNTIL NEXT ORDER WILL BE INVALID ===== orange_q = drink_quantity("orange juice", "") end = orange_q / 640 x = 1 while x < orange_q - 640: orderx = Order() orderx.add_drink(Drink("orange juice", "large", 640)) assert orderx.calculate_price() == 2.95 assert os.add_order(orderx) == True x += 640 assert len(os._orders) == int(end) # ===== MAKES A NEW ORDER ===== invalid_order = Order() invalid_order.add_drink(Drink("orange juice", "large", 640)) assert invalid_order.calculate_price() == 2.95 # ===== 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 LENGTH OF ORDERS IS THE SAME - NO ORDER WAS ADDED assert len(os._orders) == int(end)
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_order_drinks(os): # ===== ORDERING SMALL OJ ===== order1 = Order() ojQ = drink_quantity("orange juice", "") order1.add_drink(Drink("orange juice", "small", 250)) assert order1.calculate_price() == 2 assert os.add_order(order1) == True assert drink_quantity("orange juice", "") == ojQ - 250 # ===== ORDERING MEDIUM OJ ===== order2 = Order() ojQ = drink_quantity("orange juice", "") order2.add_drink(Drink("orange juice", "medium", 500)) assert order2.calculate_price() == 2.50 assert os.add_order(order2) == True assert drink_quantity("orange juice", "") == ojQ - 500 # ===== ORDERING LARGE OJ ===== order3 = Order() ojQ = drink_quantity("orange juice", "") order3.add_drink(Drink("orange juice", "large", 650)) assert order3.calculate_price() == 2.95 assert os.add_order(order3) == True assert drink_quantity("orange juice", "") == ojQ - 650 # ===== 3 ORDERS WERE MADE ===== assert len(os._orders) == 3
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_order_invalid_nuggets(os): # ===== ORDERS NUGGETS UNTIL NEXT ORDER WILL BE INVALID ===== x = 0 nuggetq = side_quantity(Nuggets(6)) end = nuggetq / 6 iterate = nuggetq - 6 if nuggetq % 6 == 0: iterate = nuggetq while x < iterate: orderx = Order() orderx.add_side(Nuggets(6)) assert orderx.calculate_price() == 4.50 assert os.add_order(orderx) == True x += 6 assert len(os._orders) == int(end) # ===== MAKES A NEW ORDER ===== invalid_order = Order() invalid_order.add_side(Nuggets(6)) assert invalid_order.calculate_price() == 4.50 # ===== 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_order_nuggets(os): # ===== ORDERING 3 NUGGETS ===== order1 = Order() nuggetq = side_quantity(Nuggets(3)) order1.add_side(Nuggets(3)) assert order1.calculate_price() == 3 assert os.add_order(order1) == True assert side_quantity(Nuggets(3)) == nuggetq - 3 # ===== ORDERING 6 NUGGETS ===== order2 = Order() nuggetq = side_quantity(Nuggets(6)) order2.add_side(Nuggets(6)) assert order2.calculate_price() == 4.50 assert os.add_order(order2) == True assert side_quantity(Nuggets(6)) == nuggetq - 6 assert len(os._orders) == 2
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_drink_can_bottle(os): #===== ORDERING AN CAN OF PEPSI ===== order1 = Order() pepsi_q = drink_quantity("pepsi", "can") order1.add_drink(Drink("pepsi", "can", 1)) order1.add_drink(Drink("pepsi", "can", 1)) assert order1.calculate_price() == 2 * 2 assert os.add_order(order1) == True assert drink_quantity("pepsi", "can") == pepsi_q - 2 #===== ORDERING AN BOTTLE OF SPRITE ===== order2 = Order() order2.add_drink(Drink("sprite", "bottle", 1)) sprite_q = drink_quantity("sprite", "bottle") assert order2.calculate_price() == 3 assert os.add_order(order2) == True assert drink_quantity("sprite", "bottle") == sprite_q - 1 assert len(os._orders) == 2
def test_cancel_drinks(os): # ===== ORDERING SMALL OJ ===== order1 = Order() ojQ = drink_quantity("orange juice", "") order1.add_drink(Drink("orange juice", "small", 250)) assert order1.calculate_price() == 2 assert os.add_order(order1) == True assert drink_quantity("orange juice", "") == ojQ - 250 os.cancel_order(order1.order_id) assert drink_quantity("orange juice", "") == ojQ
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 test_cancel_main(os): # ===== MAKE LIST OF INGREDIENTS ===== b_ingres = [] x1 = Ingredient("sesame", "bun", "sesame bun", 3, 1.5) x2 = Ingredient("beef", "patty", "beef patty", 2, 3.0) x3 = Ingredient("tomato", "vegetable", "tomato", 2, 0.5) x4 = Ingredient("cheddar", "cheese", "cheddar cheese", 2, 1) x5 = Ingredient("tomato", "sauce", "tomato sauce", 2, 0.5) for x in [x1, x2, x3, x4, x5]: b_ingres.append(x) # ===== STORE CURRENT INVENTORY LEVELS ===== bunQ = ing_quantity("sesame", "bun") pattyQ = ing_quantity("beef", "patty") vegQ = ing_quantity("tomato", "vegetable") cheQ = ing_quantity("cheddar", "cheese") sauQ = ing_quantity("tomato", "sauce") # ===== ORDER A MAIN ===== order1 = Order() m1 = Main("burger", b_ingres) order1.add_main(m1) os.add_order(order1) assert len(os._orders) == 1 assert order1.calculate_price() == 14.5 assert len(order1.mains) == 1 assert len(order1.mains[0]._ingredients) == 5 # ===== MAKE SURE INVENTORY UPDATED CORRECTLY ===== assert ing_quantity("sesame", "bun") == bunQ - 3 assert ing_quantity("beef", "patty") == pattyQ - 2 assert ing_quantity("tomato", "vegetable") == vegQ - 2 assert ing_quantity("cheddar", "cheese") == cheQ - 2 assert ing_quantity("tomato", "sauce") == sauQ - 2 os.cancel_order(order1._order_id) # ===== IF AN ORDER IS CANCELLED MAKE SURE THE INGREDIENTS ARE PUT BACK IN THE INVENTORY SYSTEM ===== assert ing_quantity("sesame", "bun") == bunQ assert ing_quantity("beef", "patty") == pattyQ assert ing_quantity("tomato", "vegetable") == vegQ assert ing_quantity("cheddar", "cheese") == cheQ assert ing_quantity("tomato", "sauce") == sauQ
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)
nuggets = input("Would you like nuggets (y/n)? ") if nuggets.lower() == "y": nuggets = orderNuggets() order1.add_side(nuggets) drink = input("Would you like a drink (y/n)? ") if drink.lower() == "y": drink = orderDrink() order1.add_drink(drink) print("Your order subtotal: ${:0,.2f}".format(order1.calculate_price())) try: os.add_order(order1) except: print( "Could not add your order to queue, not enough ingredients available." ) else: print("Order added to queue.") # When the order has been fuffiled by the chefs os.complete_order(order1)
def test_order_two(os): b_ingres = [] x1 = Ingredient("sesame", "bun", "sesame bun", 3, 1.5) x2 = Ingredient("beef", "patty", "beef patty", 2, 3.0) x3 = Ingredient("tomato", "vegetable", "tomato", 2, 0.5) x4 = Ingredient("cheddar", "cheese", "cheddar cheese", 2, 1) for x in [x1, x2, x3, x4]: b_ingres.append(x) # ===== ORDER 1ST MAIN ===== order1 = Order() m1 = Main("burger", b_ingres) order1.add_main(m1) assert os.add_order(order1) == True assert len(os._orders) == 1 assert order1.calculate_price() == 13.5 # ===== MAKE SURE ONLY 1 MAIN WITH 4 INGREDIENTS ADDED ===== assert len(order1.mains) == 1 assert len(order1.sides) == 0 assert len(order1.drinks) == 0 assert len(order1.mains[0]._ingredients) == 4 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) # ===== STORE CURRENT INVENTORY LEVELS ===== wrapQ = ing_quantity("plain", "wrap") letQ = ing_quantity("lettuce", "vegetable") tomQ = ing_quantity("tomato", "vegetable") cheQ = ing_quantity("cheddar", "cheese") # ===== ORDER 2ND MAIN ===== order2 = Order() m2 = Main("wrap", w_ingres) order2.add_main(m2) assert os.add_order(order2) == True assert len(os._orders) == 2 assert order2.calculate_price() == 9 # ===== MAKE SURE ONLY 1 MAIN WITH 4 INGREDIENTS ADDED ===== assert len(order2.mains) == 1 assert len(order2.sides) == 0 assert len(order2.drinks) == 0 assert len(order2.mains[0]._ingredients) == 4 # ===== MAKE SURE INVENTORY 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