def test_product_constructor_should_raise_exception():
    """This test will raise error if you pass empty string to product constructor"""
    with pytest.raises(ValueError):
        Product('  ', 89)
    """This test will raise error if you pass price of product less than 0"""
    with pytest.raises(ValueError):
        Product('Dove', -9)
    """This test will raise error if you pass price of product as a string"""
    with pytest.raises(ValueError):
        Product('Dove', 'trge')
Esempio n. 2
0
def test_cart_total_cost_should_be_roundup_by_2_decimal(cart):
    product = Product('Test 1', 39.99)
    item = Item(product, 5)
    cart.add_item_in_cart(item)
    expected_no_of_items = 1
    expected_total_cost_cart = 199.95
    assert len(cart.get_all_items_in_cart()) == expected_no_of_items
    assert cart.get_subtotal_of_cart() == expected_total_cost_cart
Esempio n. 3
0
def main():
    try:
        print("Started")
        """Let create Dove product"""
        product = Product('Dove Soap', 39.99)
        """create second product"""
        product2 = Product('Axe Deo', 99.99)
        """Create empty Cart for the user"""
        cart = Cart()
        """Add items to the cart"""
        item = Item(product, 2)
        cart.add_item_in_cart(item)
        print("Added first item to the cart")
        """ Add second item to the cart"""
        item2 = Item(product2, 2)
        cart.add_item_in_cart(item2)
        print("Added first item to the cart")
        """Print the Bill"""
        print("===============================================")
        print("Item_no  Product_name  Quantity")

        for count, item in enumerate(cart.get_all_items_in_cart(), 1):
            print("{0:8d}   {1:12}   {2}".format(count,
                                                 item.get_product().get_name(),
                                                 item.get_quantity()))
        print("================================================")
        print("Subtotal of bill {0}".format(cart.get_subtotal_of_cart()))
        print("Sales tax on the bill {0}".format(cart.get_total_tax_of_cart()))
        print("Total bill {0}".format(cart.get_total_cart_cost()))

    except ValueError as err:
        print("Value Error : {0}".format(err))
    except TypeError as err:
        print("Type Error : {0}".format(err))
    except Exception as err:
        print("Exception : {0}".format(err))
    finally:
        print("Finished")
Esempio n. 4
0
def test_cart_decrease_quantity_item_to_zero(cart):
    """Create product"""
    product = Product('Dove Soap', 39.99)
    """create an item """
    item = Item(product, 5)
    cart.add_item_in_cart(item)
    """Initial checks"""
    assert len(cart.get_all_items_in_cart()) == 1
    cart_item = cart.get_all_items_in_cart()[0]
    assert cart_item.get_quantity() == 5
    assert cart.get_subtotal_of_cart() == 199.95
    assert cart.get_total_tax_of_cart() == 25.0
    assert cart.get_total_cart_cost() == 224.95
    """update the item quantity to zero"""
    quantity = cart.get_all_items_in_cart()[0].get_quantity()
    cart.decrease_quantity_of_item(item, quantity)
    assert len(cart.get_all_items_in_cart()) == 0
    assert cart.get_subtotal_of_cart() == 0
    assert cart.get_total_tax_of_cart() == 0
    assert cart.get_total_cart_cost() == 0
Esempio n. 5
0
def test_cart_increase_item_quantity(cart):
    """Create product"""
    product = Product('Dove Soap', 39.99)
    """create an item """
    item = Item(product, 5)
    cart.add_item_in_cart(item)
    """Initial checks"""
    assert len(cart.get_all_items_in_cart()) == 1
    cart_item = cart.get_all_items_in_cart()[0]
    assert cart_item.get_quantity() == 5
    assert cart.get_subtotal_of_cart() == 199.95
    assert cart.get_total_tax_of_cart() == 25.0
    assert cart.get_total_cart_cost() == 224.95
    """increase the item quantity by 5 """
    cart.increase_quantity_of_item(item, 3)
    assert len(cart.get_all_items_in_cart()) == 1
    cart_item = cart.get_all_items_in_cart()[0]
    assert cart_item.get_quantity() == 8
    assert cart.get_subtotal_of_cart() == 319.92
    assert cart.get_total_tax_of_cart() == 39.99
    assert cart.get_total_cart_cost() == 359.91
def product():
    return Product('Dove Soap', 39.99)
Esempio n. 7
0
def product():
    return Product('Dove Soap', 19)
def test_item_sub_total_should_round_value_by_2_decimal():
    product = Product('Test 1', 19.499)
    item = Item(product, 9)
    assert item.get_sub_total() == 175.5