Ejemplo n.º 1
0
    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])
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def test_cart_failure(self):
        with self.assertRaises(InvalidCartItem):
            Cart(self.book)

        with self.assertRaises(InvalidCartItem):
            Cart([self.book, self.music])
Ejemplo n.º 6
0
 def test_cart_total_tax(self):
     cart = Cart([self.cart_item_book, self.cart_item_perfume])
     self.assertEqual(cart.total_tax(), 1.55)
Ejemplo n.º 7
0
 def test_cart_total(self):
     cart = Cart()
     cart.add_merchandise([self.book, self.perfume])
     self.assertEqual(cart.cart_total(), 13.73)
Ejemplo n.º 8
0
 def test_cart_add_merchandise_failure(self):
     cart = Cart()
     with self.assertRaises(InvalidProduct):
         cart.add_merchandise('Product')