def test_invalid_order_main(os): # ===== ORDERS A BURGER WITH TOO MANY BUNS ===== b_ingres = [] x1 = Ingredient("sesame", "bun", "sesame bun", 1000, 1.5) x2 = Ingredient("lettuce", "vegetable", 2, 0.5) b_ingres.append(x1) b_ingres.append(x2) order1 = Order() bunQ = ing_quantity("sesame", "bun") m1 = Main("Burger", b_ingres) order1.add_main(m1) # ===== MAKES SURE THE ERROR IS CATCHED AND THE CORRECT MESSAGE IS DISPLAYED ===== try: os.add_order(order1) assert False except Exception as err: assert str(err) == "Not enough ingredients available." assert True # ===== MAKE SURE INVENTORY WASN'T UPDATED ===== assert ing_quantity("sesame", "bun") == bunQ # ASSERT NO ORDER LOGGED assert len(os._orders) == 0
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_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
ingredients_gen = [["sesame", "bun", "Sesame Bun", 52, 1.5], ["plain", "wrap", "Plain Wrap", 42, 2.0], ["vegetarian", "patty", "Vegetarian Patty", 35, 3.0], ["beef", "patty", "Beef Patty", 84, 3.0], ["lettuce", "vegetable", "Lettuce", 84, 0.5], ["tomato", "vegetable", "Tomato", 84, 1.0], ["tomato", "sauce", "Tomato Sauce", 84, 0.5], ["cheddar", "cheese", "Cheddar Cheese", 84, 1.0]] g_ingredients = [] # 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')
# ===== FUNCTION THAT RETURNS THE AMOUNT OF INVENTORY LEFT FOR A DRINK ===== def drink_quantity(name, dtype): find = [x for x in g_drinks if x.name == name and x.drink_type == dtype] return find[0].amount # ===== FUNCTION THAT RETURNS THE AMOUNT OF INVENTORY LEFT FOR AN INGREDIENT ===== def ing_quantity(name, itype): find = [x for x in g_ingredients if x.name == name and itype == itype] return find[0].amount # ===== CREATING LIST OF BURGER INGREDIENTS ===== b_ingres = [] x1 = Ingredient("sesame", "bun", 3, 1.5) x2 = Ingredient("beef", "patty", 2, 3.0) x3 = Ingredient("tomato", "vegetable", 2, 0.5) x4 = Ingredient("cheddar", "cheese", 2, 1) x5 = Ingredient("tomato", "sauce", 2, 0.5) for x in [x1, x2, x3, x4, x5]: b_ingres.append(x) def test_completed(os): # ===== CREATING 3 ORDERS ===== order1 = Order() m = Main("burger", b_ingres) order1.add_main(m)
def test_many_invalid_order_main(os): ingres1 = [] x1 = Ingredient("sesame", "bun", "sesame bun", 3, 1.5) x2 = Ingredient("beef", "patty", "beef patty", 40, 3.0) x3 = Ingredient("tomato", "vegetable", "tomato", 15, 0.5) x4 = Ingredient("cheddar", "cheese", "cheddar cheese", 2, 1) for x in [x1, x2, x3, x4]: ingres1.append(x) # ===== ORDERING 1 BURGER ===== order1 = Order() m1 = Main("Burger", ingres1) order1.add_main(m1) assert os.add_order(order1) == True assert len(os._orders) == 1 ingres2 = [] x1 = Ingredient("plain", "wrap", "plain wrap", 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]: ingres2.append(x) # ===== ORDERING A WRAP ===== order2 = Order() m2 = Main("wrap", ingres2) order2.add_main(m2) assert os.add_order(order2) == True assert len(os._orders) == 2 # ===== ORDERING ANOTHER BURGER - INVALID ===== ingres3 = [] x1 = Ingredient("plain", "wrap", "plain wrap", 30, 1.5) x2 = Ingredient("beef", "patty", "beef patty", 4000, 3.0) x3 = Ingredient("tomato", "vegetable", "tomato", 20, 0.5) x4 = Ingredient("cheddar", "cheese", "cheddar cheese", 200, 1) for x in [x1, x2, x3, x4]: ingres3.append(x) m3 = Main("burger", ingres3) order3 = Order() order3.add_main(m3) # ===== MAKES SURE THE ERROR IS CATCHED AND THE CORRECT MESSAGE IS DISPLAYED===== try: os.add_order(order3) print(ing_quantity("beef", "patty")) assert False except Exception as err: assert str(err) == "Not enough ingredients available." assert True # ASSERT ONLY 2 ORDERS HAVE BEEN LOGGED assert len(os._orders) == 2
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