def setUp(self): self.book = Merchandise(name='book', price=1.99, category='book', imported=False) self.perfume = Merchandise(name='perfume', price='10.19', category='accessory', imported=True) self.music = Merchandise(name='music CD', price='5.29', category='music', imported=False)
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)
class TestMerchandise(unittest.TestCase): def setUp(self): self.book = Merchandise(name='book', price=1.99, category='book', imported=False) def test_valid_merchandise(self): self.assertEqual(self.book.name, 'book') self.assertEqual(self.book.price, 1.99) self.assertEqual(self.book.category, 'book') self.assertEqual(self.book.imported, False) def test_valid_automatic_category(self): book = Merchandise(name='book', price=1.99) self.assertEqual(book.category, 'book') def test_generic_category(self): random = Merchandise(name='Random', price=1.99) self.assertEqual(random.category, 'GENERIC') def test_merchandise_invalid_price(self): with self.assertRaises(InvalidPrice): Merchandise(name='perfume', price="ten dollar") 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_merchandise_add_to_failure(self): cart = CartItem(self.book) with self.assertRaises(InvalidCart): self.book.add_to(cart)
def test_cart_item_validity(self): expected = CartItem(item=Merchandise(name='book', price=1.99, category='book', imported=False), total=1.99, tax_amount=0.0, _qty=1) cart_item = CartItem(self.book) self.assertEqual(cart_item, 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 setUp(self): self.book = Merchandise(name='book', price=1.99, category='book', imported=False)
def test_merchandise_invalid_price(self): with self.assertRaises(InvalidPrice): Merchandise(name='perfume', price="ten dollar")
def test_generic_category(self): random = Merchandise(name='Random', price=1.99) self.assertEqual(random.category, 'GENERIC')
def test_valid_automatic_category(self): book = Merchandise(name='book', price=1.99) self.assertEqual(book.category, 'book')