示例#1
0
def test_raises_out_of_stock_exception_if_cannot_add():
    product = Product("pref", "WHEAT-1-GALLON", 11, 11, 'CHAKRI ATTA', 2)
    cart = Cart(sku="WHEAT-1-GALLON", products=[product])
    cart.add(CartItem("item1", "WHEAT-1-GALLON", 11))

    with pytest.raises(OutOfStock, match="WHEAT-1-GALLON"):
        cart.add(CartItem("item2", "WHEAT-1-GALLON", 1))
示例#2
0
def test_increments_version_number():
    item = CartItem("iref", "RICE-1-GALLON", 4)
    cart = Cart(sku="RICE-1-GALLON",
                products=[
                    Product("p1", "RICE-1-GALLON", 10, 11, 'SONAMASURI RICE',
                            2)
                ])
    cart.version_number = 7
    cart.add(item)
    assert cart.version_number == 8
示例#3
0
def test_returns_added_product_ref():
    more_quantity_product = Product("pref", "RICE-1-GALLON", 11, 5,
                                    'SONA MASURI', 2)
    less_quantity_product = Product("pref", "RICE-1-GALLON", 3, 3, 'NIRAPARA',
                                    2)
    item = CartItem("iref", "RICE-1-GALLON", 4)
    cart = Cart(sku="RICE-1-GALLON",
                products=[more_quantity_product, less_quantity_product])
    adds = cart.add(item)
    assert adds == more_quantity_product.reference
示例#4
0
def test_prefers_more_maxAllowedPurchaseQty_products():
    more_maxAllowed_product = Product("pref", "RICE-1-GALLON", 11, 5,
                                      'SONA MASURI', 2)
    less_maxAllowed_product = Product("pref", "RICE-1-GALLON", 3, 1,
                                      'NIRAPARA', 2)

    cart = Cart(sku="RICE-1-GALLON",
                products=[more_maxAllowed_product, less_maxAllowed_product])
    item = CartItem("iref", "RICE-1-GALLON", 4)
    cart.add(item)

    assert more_maxAllowed_product.available_quantity == 7
    assert less_maxAllowed_product.available_quantity == 3
示例#5
0
def add(itemid: str, sku: str, qty: int,uow: unit_of_work.AbstractUnitOfWork) -> str:
    item = CartItem(itemid, sku, qty)
    with uow:
        print(sku)

        cart = uow.carts.get(sku=item.sku)
        print('IN GET')
        print(cart)
        if cart is None:
            raise InvalidSku(f"Invalid sku {item.sku}")
        productref = cart.add(item)
        uow.commit()
    return productref
示例#6
0
def test_adding_to_a_product_reduces_the_available_quantity():
    product = Product("oref", "WHEAT-1-GALLON", 10, 5, 'CHAKRI ATTA' , 16)
    item = CartItem("iref", "WHEAT-1-GALLON", 2)
    product.add(item)
    assert product.available_quantity == 8
示例#7
0
def test_cannot_add_if_skus_do_not_match():
    product = Product("product-001", "WHEAT-1-GALLON", 10, 5, 'CHAKRI ATTA' , 16)
    different_sku_item = CartItem("item-123", "RICE-1-GALLON", 2)
    assert product.can_add(different_sku_item) is False
示例#8
0
def make_product_and_item(sku, product_qty, product_max_allowed_qty, product_brand, product_price, item_qty):
    return (
        Product("product-001", sku, product_qty, product_max_allowed_qty, product_brand, product_price ),
        CartItem("item-123", sku, item_qty),
    )