def setUp(self) -> None: # Lets create a few items self.item_a = Item(SKU="A") self.item_b = Item(SKU="B") self.item_c = Item(SKU="C") self.item_d = Item(SKU="D") self.customer_c = [self.item_a, self.item_b, self.item_b, self.item_b] self.checkout = Checkout(operative_name="Wood Mackenzie") self.checkout.create_lookup(STORE_ITEMS)
def test_all_discounts(self): pricing_rules = [ TwoForOneDiscount('VOUCHER'), BulkPurchaseDiscount('TSHIRT', 3, 1.00) ] checkout = Checkout(pricing_rules) products = 5 * ['TSHIRT'] + 2 * ['MUG'] + 5 * ['VOUCHER'] for product in products: checkout.scan(product) assert checkout.total == 125
def test_scan(self): code = 'VOUCHER' pricing_rules = [ TwoForOneDiscount('VOUCHER'), BulkPurchaseDiscount('TSHIRT', 3, 1.00) ] checkout = Checkout(pricing_rules) checkout.scan(code) assert code in checkout.order.product_orders assert checkout.order.product_orders[code].quantity == 1
def test_get_total_discount(self): pricing_rules = [ TwoForOneDiscount('VOUCHER'), BulkPurchaseDiscount('TSHIRT', 3, 1.00) ] checkout = Checkout(pricing_rules) products = ['TSHIRT', 'TSHIRT', 'VOUCHER', 'TSHIRT', 'MUG'] for product in products: checkout.scan(product) assert checkout.get_total_discount() == 3.0
def test_total(self): pricing_rules = [ TwoForOneDiscount('VOUCHER'), BulkPurchaseDiscount('TSHIRT', 3, 1.00) ] checkout = Checkout(pricing_rules) products = ['TSHIRT', 'TSHIRT', 'TSHIRT', 'VOUCHER', 'TSHIRT'] for product in products: checkout.scan(product) assert checkout.total == 81.0 assert checkout.get_total_display() == '81.00\N{euro sign}'
class CheckoutTest(unittest.TestCase): def setUp(self) -> None: # Lets create a few items self.item_a = Item(SKU="A") self.item_b = Item(SKU="B") self.item_c = Item(SKU="C") self.item_d = Item(SKU="D") self.customer_c = [self.item_a, self.item_b, self.item_b, self.item_b] self.checkout = Checkout(operative_name="Wood Mackenzie") self.checkout.create_lookup(STORE_ITEMS) def test_basic_subtotal(self): result = self.checkout.basic_sub_total(self.customer_c) self.assertEqual(140, result) def tearDown(self) -> None: pass
#!/usr/bin/env python from src.checkout import Checkout from src.model import Item, Stock STORE_ITEMS = [ Stock("A", 50, True, 130, 3), Stock("B", 30, True, 45, 2), Stock("C", 20, False, None, None), Stock("D", 15, False, None, None), ] if __name__ == "__main__": # Lets create a few items item_a = Item(SKU="A") item_b = Item(SKU="B") item_c = Item(SKU="C") item_d = Item(SKU="D") # Create some customers customer_a = [item_d, item_a] customer_b = [item_c, item_b, item_a] customer_c = [item_a, item_b, item_b, item_b] # Create a checkout checkout = Checkout(operative_name="Wood Mackenzie") checkout.create_lookup(STORE_ITEMS) print(f"Customer A subtotal: {checkout.basic_sub_total(customer_a)}") print(f"Customer B subtotal: {checkout.basic_sub_total(customer_b)}") print(f"Customer C subtotal: {checkout.basic_sub_total(customer_c)}")
def checkout(): checkout = Checkout() return checkout