def test_dashboard_change_quantity_form(request_cart_with_item, order): cart = request_cart_with_item group = models.DeliveryGroup.objects.create(order=order) add_items_to_delivery_group(group, cart.lines.all()) order_line = group.items.get() # Check available quantity validation form = ChangeQuantityForm({'quantity': 9999}, instance=order_line) assert not form.is_valid() assert group.items.get().stock.quantity_allocated == 1 # Save same quantity form = ChangeQuantityForm({'quantity': 1}, instance=order_line) assert form.is_valid() form.save() assert group.items.get().stock.quantity_allocated == 1 # Increase quantity form = ChangeQuantityForm({'quantity': 2}, instance=order_line) assert form.is_valid() form.save() 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
def test_dashboard_change_quantity_form(request_cart_with_item, order): cart = request_cart_with_item group = models.DeliveryGroup.objects.create(order=order) add_items_to_delivery_group(group, cart.lines.all()) order_line = group.items.get() # Check available quantity validation form = ChangeQuantityForm({'quantity': 9999}, instance=order_line) assert not form.is_valid() assert group.items.get().stock.quantity_allocated == 1 # Save same quantity form = ChangeQuantityForm({'quantity': 1}, instance=order_line) assert form.is_valid() form.save() assert group.items.get().stock.quantity_allocated == 1 # Increase quantity form = ChangeQuantityForm({'quantity': 2}, instance=order_line) assert form.is_valid() form.save() 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
def test_dashboard_change_quantity_form(request_cart_with_item, order): cart = request_cart_with_item group = DeliveryGroup.objects.create(order=order) add_items_to_delivery_group(group, cart.lines.all()) order_line = group.items.get() variant = ProductVariant.objects.get(sku=order_line.product_sku) # Check max quantity validation form = ChangeQuantityForm( {'quantity': 9999}, instance=order_line, variant=variant) 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, variant=variant) assert not form.is_valid() assert group.items.get().stock.quantity_allocated == 1 # Check available quantity validation form = ChangeQuantityForm( {'quantity': 20}, instance=order_line, variant=variant) assert not form.is_valid() assert group.items.get().stock.quantity_allocated == 1 assert form.errors['quantity'] == ['Only 4 remaining in stock.'] # Save same quantity form = ChangeQuantityForm( {'quantity': 1}, instance=order_line, variant=variant) assert form.is_valid() form.save() assert group.items.get().stock.quantity_allocated == 1 # Increase quantity form = ChangeQuantityForm( {'quantity': 2}, instance=order_line, variant = variant) assert form.is_valid() form.save() assert group.items.get().stock.quantity_allocated == 2 # Decrease quantity form = ChangeQuantityForm( {'quantity': 1}, instance=order_line, variant=variant) assert form.is_valid() form.save() assert group.items.get().stock.quantity_allocated == 1
def test_dashboard_change_quantity_form(request_cart_with_item, order): cart = request_cart_with_item for line in cart.lines.all(): add_variant_to_order(order, line.variant, line.quantity) order_line = order.lines.get() quantity_before = order_line.variant.quantity_allocated # 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 order.lines.get().variant.quantity_allocated == quantity_before assert 'quantity' in form.errors # Check available quantity validation form = ChangeQuantityForm({'quantity': 20}, instance=order_line) assert not form.is_valid() assert order.lines.get().variant.quantity_allocated == quantity_before assert 'quantity' in form.errors # Save same quantity form = ChangeQuantityForm( {'quantity': 1}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before # Increase quantity form = ChangeQuantityForm( {'quantity': 2}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before + 1 # Decrease quantity form = ChangeQuantityForm({'quantity': 1}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before
def test_dashboard_change_quantity_form(request_cart_with_item, order): for line in request_cart_with_item: add_variant_to_order(order, line.variant, line.quantity) order_line = order.lines.get() quantity_before = order_line.variant.quantity_allocated # 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 order.lines.get().variant.quantity_allocated == quantity_before assert 'quantity' in form.errors # Check available quantity validation form = ChangeQuantityForm({'quantity': 20}, instance=order_line) assert not form.is_valid() assert order.lines.get().variant.quantity_allocated == quantity_before assert 'quantity' in form.errors # Save same quantity form = ChangeQuantityForm( {'quantity': 1}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before # Increase quantity form = ChangeQuantityForm( {'quantity': 2}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before + 1 # Decrease quantity form = ChangeQuantityForm({'quantity': 1}, instance=order_line) assert form.is_valid() form.save() order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before
def test_dashboard_change_quantity_form(request_cart_with_item, order): cart = request_cart_with_item for line in cart.lines.all(): add_variant_to_order(order, line.variant, line.quantity) order_line = order.lines.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 order.lines.get().stock.quantity_allocated == 1 # Check available quantity validation form = ChangeQuantityForm({'quantity': 20}, instance=order_line) assert not form.is_valid() assert order.lines.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 order.lines.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 order.lines.get().stock.quantity_allocated == 2 # Decrease quantity form = ChangeQuantityForm({'quantity': 1}, instance=order_line) assert form.is_valid() form.save() assert order.lines.get().stock.quantity_allocated == 1
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
def test_dashboard_change_quantity_form(request_checkout_with_item, order): for line in request_checkout_with_item: add_variant_to_order(order, line.variant, line.quantity) order_line = order.lines.get() quantity_before = order_line.variant.quantity_allocated # 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 order.lines.get().variant.quantity_allocated == quantity_before assert "quantity" in form.errors # Check available quantity validation form = ChangeQuantityForm({"quantity": 20}, instance=order_line) assert not form.is_valid() assert order.lines.get().variant.quantity_allocated == quantity_before assert "quantity" in form.errors # Save same quantity form = ChangeQuantityForm({"quantity": 1}, instance=order_line) assert form.is_valid() form.save(None) order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before # Increase quantity form = ChangeQuantityForm({"quantity": 2}, instance=order_line) assert form.is_valid() form.save(None) order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before + 1 # Decrease quantity form = ChangeQuantityForm({"quantity": 1}, instance=order_line) assert form.is_valid() form.save(None) order_line.variant.refresh_from_db() assert order_line.variant.quantity_allocated == quantity_before