コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
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)
コード例 #4
0
 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)
コード例 #5
0
 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)
コード例 #6
0
 def setUp(self):
     self.book = Merchandise(name='book',
                             price=1.99,
                             category='book',
                             imported=False)
コード例 #7
0
 def test_merchandise_invalid_price(self):
     with self.assertRaises(InvalidPrice):
         Merchandise(name='perfume', price="ten dollar")
コード例 #8
0
 def test_generic_category(self):
     random = Merchandise(name='Random', price=1.99)
     self.assertEqual(random.category, 'GENERIC')
コード例 #9
0
 def test_valid_automatic_category(self):
     book = Merchandise(name='book', price=1.99)
     self.assertEqual(book.category, 'book')