Пример #1
0
def test_order_discount(sale, order, request_cart_with_item):
    cart = request_cart_with_item
    group = models.DeliveryGroup.objects.create(order=order)
    fill_group_with_partition(
        group, cart.lines.all(), discounts=cart.discounts)
    line = group.lines.first()
    assert line.get_price_per_item() == Price(currency="USD", net=5)
Пример #2
0
def test_stock_allocation(billing_address, product_in_stock):
    variant = product_in_stock.variants.get()
    cart = Cart()
    cart.save()
    cart.add(variant, quantity=2)
    order = models.Order.objects.create(billing_address=billing_address)
    delivery_group = models.DeliveryGroup.objects.create(order=order)
    fill_group_with_partition(delivery_group, cart.lines.all())
    order_line = delivery_group.items.get()
    stock = order_line.stock
    assert stock.quantity_allocated == 2
Пример #3
0
def test_dashboard_change_quantity_form(request_cart_with_item, order):
    cart = request_cart_with_item
    group = DeliveryGroup.objects.create(order=order)
    fill_group_with_partition(group, cart.lines.all())
    order_line = group.items.get()

    # Check max quantity validation
    form = ChangeQuantityForm({'quantity': 9999}, instance=order_line)
    assert not form.is_valid()
    assert form.errors['quantity'] == [
        'Ensure this value is less than or equal to 50.'
    ]

    # Check minimum quantity validation
    form = ChangeQuantityForm({'quantity': 0}, instance=order_line)
    assert not form.is_valid()
    assert group.items.get().stock.quantity_allocated == 1

    # Check available quantity validation
    form = ChangeQuantityForm({'quantity': 20}, instance=order_line)
    assert not form.is_valid()
    assert group.items.get().stock.quantity_allocated == 1
    assert form.errors['quantity'] == ['Only 5 remaining in stock.']

    # Save same quantity
    form = ChangeQuantityForm({'quantity': 1}, instance=order_line)
    assert form.is_valid()
    form.save()
    order_line.stock.refresh_from_db()
    assert group.items.get().stock.quantity_allocated == 1

    # Increase quantity
    form = ChangeQuantityForm({'quantity': 2}, instance=order_line)
    assert form.is_valid()
    form.save()
    order_line.stock.refresh_from_db()
    assert group.items.get().stock.quantity_allocated == 2

    # Decrease quantity
    form = ChangeQuantityForm({'quantity': 1}, instance=order_line)
    assert form.is_valid()
    form.save()
    assert group.items.get().stock.quantity_allocated == 1