def test_completed(os): # ===== CREATING 3 ORDERS ===== order1 = Order() m = Main("burger", b_ingres) order1.add_main(m) os.add_order(order1) order2 = Order() order2.add_main(m) os.add_order(order2) order3 = Order() order3.add_main(m) os.add_order(order3) assert len(os._orders) == 3 # ===== COMPLETING ORDERS ===== os.complete_order(order1._order_id) assert len(os._orders) == 2 assert len(os._completed_orders) == 1 os.complete_order(order3._order_id) assert len(os._orders) == 1 assert len(os._completed_orders) == 2 os.complete_order(order2._order_id) assert len(os._orders) == 0 assert len(os._completed_orders) == 3
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 test_cancel(os): # ===== CREATING 3 ORDERS ===== order1 = Order() m = Main("burger", b_ingres) order1.add_main(m) os.add_order(order1) order2 = Order() order2.add_main(m) os.add_order(order2) order3 = Order() order3.add_main(m) os.add_order(order3) # ==== CANCELLING 3 ORDERS ==== os.cancel_order(order1._order_id) assert len(os._orders) == 2 assert len(os._completed_orders) == 0 os.cancel_order(order3._order_id) assert len(os._orders) == 1 assert len(os._completed_orders) == 0 os.cancel_order(order2._order_id) assert len(os._orders) == 0 assert len(os._completed_orders) == 0
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_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(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_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_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_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_status(os): # ===== CREATING 3 ORDERS ===== order1 = Order() m = Main("burger", b_ingres) order1.add_main(m) os.add_order(order1) order2 = Order() order2.add_main(m) os.add_order(order2) order3 = Order() order3.add_main(m) os.add_order(order3) # ===== COMPLETING ORDERS ===== assert order3._completed == False os.complete_order(order1._order_id) assert len(os._orders) == 2 assert len(os._completed_orders) == 1 assert order1._completed == True assert order3._completed == False os.complete_order(order3._order_id) assert len(os._orders) == 1 assert len(os._completed_orders) == 2 assert order3._completed == True assert order2._completed == False os.complete_order(order2._order_id) assert len(os._orders) == 0 assert len(os._completed_orders) == 3 assert order2._completed == True
def test_get_order_number(): order = Order(1, [['pepperoni', 'medium', ['olives', 'chicken']]], [['pepsi', 'small']]) assert order.get_order_number() == 1 order = Order(2, [['pepperoni', 'medium', ['olives', 'chicken']]], [['pepsi', 'small']]) assert order.get_order_number() == 2
def test_map_department_to_orders(self): dept_to_order = { "16": [Order("2", "1"), Order("3", "1")], "4": [Order("3", "1")] } self.assertEqual( dept_to_order.keys(), map_department_to_orders(self.products, self.order_to_product))
def newOrder(self): if not self._orders: order = Order(0) self._orders.append(order) self._currOrder = order else: order = Order(len(self._orders)) self._orders.append(order) self._currOrder = order return order
def setUp(self): self.orders = [("2", "33120", "1", "1"), ("3", "17668", "1", "1"), ("3", "46667", "2", "1")] self.products = [ ("33120", "Organic Egg Whites", "86", "16"), ("17668", "Unsweetened Chocolate Almond Breeze Almond Milk", "91", "16"), ("46667", "Organic Ginger Root", "83", "4") ] self.order_to_product = { "33120": [Order("2", "1")], "17668": [Order("3", "1")], "46667": [Order("3", "1")] }
def show_order_summary(self): items = {} invalid_character = False for row in range(0, self.max_row_count): if not self.tableWidget.item(row, 2).text().isdigit(): invalid_character = True QMessageBox.information(self, "Error", "Please enter a whole number") break else: qty = int(self.tableWidget.item(row, 2).text()) name = self.entries[row][0] if not qty == 0: if self.order == None: items[name] = qty else: self.order.set_qty(name, qty) elif self.order != None and self.order.items.keys().count( name) == 1: self.order.remove_item(name) if self.order == None: self.order = Order(self.menu, items, self.database.order_number) if not invalid_character: self.hide() self.window = OrderSummary(self.customer, self.database, self.order) self.window.show()
def __init__(self): self._orders = [] self._inventory = inventory() self._menu = Menu() self._current_order = Order() self._base_burger = None self._base_wrap = None
def test_del_main_incorrect_input(): order = Order(1) order.add_main('burger') wrong_main = Main('wrap') with pytest.raises(DevError) as e: order.del_main(wrong_main) assert "main that you're trying to delete doesn't exist in this order" in str(e.value)
def test_add_sidedrink(): order = Order(1) ing = WeightIngredient(2, 'fries', 's', 2000, 60, 100, 140, 2, 2.8, 3.4) order.add_sideDrink(ing, 2, 'l') assert order.sideDrinks[0][0] == ing assert order.sideDrinks[0][1] == 2 assert order.sideDrinks[0][2] == 'l'
def order(self, pizza_data, drinks): """Makes an order using the order class and the given parameters. This order is given an order number and stored in the orders list. This order's order number is returned.""" order = Order(self.num_orders, pizza_data, drinks) self.orders.append(order) self.num_orders += 1 return self.num_orders - 1
def new_order(self, id): new_order = Order() new_order.set_ID(id) self._orders.append(new_order) return new_order
def test_checkout_all(self, restaurant_fixture): order = Order() #adding a burger burger = Burger() bun = restaurant_fixture.menu.get_item("Bun") patty = restaurant_fixture.menu.get_item("Patty") cheese = restaurant_fixture.menu.get_item("Cheese") burger.add_item(bun, 2) burger.add_item(patty, 1) burger.add_item(cheese, 1) order.add_main(burger) #adding sides and drinks coke = restaurant_fixture.menu.get_item("Canned Coke") nugget = restaurant_fixture.menu.get_item("Small Chicken Nugget") order.add_others(coke, 1) order.add_others(nugget, 1) #placing the order and checking out restaurant_fixture.place_order(order) restaurant_fixture.checkout(1) assert restaurant_fixture.inventory.items[0].quantity == 98 assert restaurant_fixture.inventory.items[1].quantity == 99 assert restaurant_fixture.inventory.items[2].quantity == 99 assert restaurant_fixture.inventory.items[3].quantity == 99 assert restaurant_fixture.inventory.items[4].quantity == 94 assert len(restaurant_fixture.orders) == 1
def test_add_one_sides_one_drinks(): o = Order() o.add_others(side, 1) o.add_others(drink, 1) assert len(o) == 2 assert len(o.others) == 2 assert o.total_price == 20
def order_fixture(): o = Order() o.add_main(burger) o.add_others(side, 1) o.add_others(drink, 1) return o
def test_add_main_success(): o = Order() o.add_main(burger) assert len(o) == 1 assert len(o.mains) == 1 assert len(o.others) == 0 assert o.total_price == 44
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_get_discount_when_discount_applies(self): order = Order() products = ['VOUCHER', 'TSHIRT', 'VOUCHER'] for product in products: order.add_product(product) discount = TwoForOneDiscount('VOUCHER') assert discount.get_discount(order) == 5.0
def test_get_discount_when_discount_applies(self): order = Order() products = ['TSHIRT', 'TSHIRT', 'TSHIRT', 'VOUCHER', 'TSHIRT'] for product in products: order.add_product(product) discount = BulkPurchaseDiscount('TSHIRT', 3, 1.00) assert discount.get_discount(order) == 4.0
def setUpClass(self): self.control = BangazonControl() self.order = Order() self.product = Product() self.payment_type = PaymentType() self.product_order = ProductOrder() self.control.set_active_customer(1)