Exemplo n.º 1
0
 def test_adding_multiple_products(self):
     c = Cart()
     p1 = Product(fake.ean13(), round(random.random(), 2))
     p2 = Product(fake.ean13(), round(random.random(), 2))
     c.add_products([p1, p2])
     assert c.products_count == 2
     assert c.calculate_total() == p1.price + p2.price
Exemplo n.º 2
0
    def test_clearing_cart(self):
        c = Cart()
        p1 = Product(fake.ean13(), round(random.random(), 2))
        p2 = Product(fake.ean13(), round(random.random(), 2))
        c.add_products([p1, p2])
        c.clear()

        assert c.products_count == 0
Exemplo n.º 3
0
    def test_calculate_with_discount(self):
        c = Cart()
        p1 = Product(fake.ean13(), round(random.random(), 2))
        p2 = Product(fake.ean13(), round(random.random(), 2))
        c.add_products([p1, p2])
        c.apply_discount('XYZ123')
        actual_price = c.calculate_total()
        expected_price = (p1.price + p2.price) * 0.8

        assert actual_price == expected_price
Exemplo n.º 4
0
def single_product():
    return Product(fake.ean13(), round(random.random(), 2))
Exemplo n.º 5
0
 def test_adding_more_than_10_products_to_empty_cart(self):
     c = Cart()
     products = [Product(fake.ean13(), round(random.random(), 2)) for _ in range(11)]
     with pytest.raises(NoSpaceInCartError):
         c.add_products(products)
Exemplo n.º 6
0
 def test_adding_10_products_to_empty_cart(self):
     c = Cart()
     products = [Product(fake.ean13(), round(random.random(), 2)) for _ in range(10)]
     c.add_products(products)
     assert c.products_count == 10
Exemplo n.º 7
0
 def test_product_price(self):
     p = Product('Black Dress', 99.99)
     assert p.price == 99.99
Exemplo n.º 8
0
 def test_product_name(self):
     p = Product('Black Dress', 99.99)
     assert p.name == 'Black Dress'