def test_cart_add_merchandise(self): expected_1 = self.cart_item_book expected_1.qty = 10 cart = Cart() cart.add_merchandise(self.book, qty=10) self.assertEqual(cart.items, [expected_1]) cart = Cart() cart.add_merchandise([self.book, self.perfume]) expected_2 = self.cart_item_perfume expected_1 = self.cart_item_book expected_1.qty = 1 self.assertEqual(cart.items, [expected_1, expected_2])
def test_checkout(self): import sys from io import StringIO expected = [ 'Qty - Items - Amount', ' 1 - book - 1.99', ' 1 - perfume - 11.74', 'Sales Tax - 1.55', 'Total(Incl. tax) - 13.73', '' ] original_stdout = sys.stdout sys.stdout = StringIO() cart = Cart([self.cart_item_book, self.cart_item_perfume]) cart.checkout() result = sys.stdout.getvalue() sys.stdout = original_stdout result = result.split('\n') self.assertEqual(result, expected)
def test_merchandise_add_to_cart(self): expected = [ CartItem(item=Merchandise(name='book', price=1.99, category='book', imported=False), total=3.98, tax_amount=0.0, _qty=2) ] cart = Cart() self.book.add_to(cart, 2) self.assertEqual(cart.items, expected)
def test_cart_validity(self): expected = [ CartItem(item=Merchandise(name='book', price=1.99, category='book', imported=False), total=1.99, tax_amount=0.0), CartItem(item=Merchandise(name='perfume', price=10.19, category='accessory', imported=True), total=11.74, tax_amount=1.55) ] items = [self.cart_item_book, self.cart_item_perfume] cart = Cart(items) self.assertEqual(cart.items, expected)
def test_cart_failure(self): with self.assertRaises(InvalidCartItem): Cart(self.book) with self.assertRaises(InvalidCartItem): Cart([self.book, self.music])
def test_cart_total_tax(self): cart = Cart([self.cart_item_book, self.cart_item_perfume]) self.assertEqual(cart.total_tax(), 1.55)
def test_cart_total(self): cart = Cart() cart.add_merchandise([self.book, self.perfume]) self.assertEqual(cart.cart_total(), 13.73)
def test_cart_add_merchandise_failure(self): cart = Cart() with self.assertRaises(InvalidProduct): cart.add_merchandise('Product')