示例#1
0
class TestBasket(unittest.TestCase):
    def setUp(self):
        self.basket = Basket()
    def tearDown(self):
        self.basket = None
    def testBasketAppear(self):
        assert self.basket, "Basket must be defined."
    def testBasketCanAddProduct(self):
        self.basket.add(Product())

    def testBsketRemoveProduct(self):
        product = Product()
        self.basket.add(product)
        self.basket.remove(product)
        assert len(self.basket.products) == 0, "Basket must be empty on all products deleted"
        self.basket.add(product)
        self.basket.add(product)
        self.basket.add(product)
        self.basket.remove(product)
        assert self.basket.quantity_for(product) == 2, "Basket mst actually remove product from"
    def testBasketStoresQuantity(self):
        product = Product(1)
        product2 = Product(2)
        self.basket.add(product,5)
        self.basket.add(product2,3)
        assert self.basket.quantity_for(product2) == 3
        assert self.basket.quantity_for(product) == 5