def test_basket_update_errors(): request = get_request_with_basket() basket = request.basket product = get_default_product() basket_commands.handle_add(request, basket, product_id=product.pk, quantity=1) # Hide product and now updating quantity should give errors shop_product = product.get_shop_instance(request.shop) shop_product.suppliers.clear() line_id = basket.get_lines()[0].line_id basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "2"}) error_messages = messages.get_messages(request) # One warning is added to messages assert len(error_messages) == 1 assert any("not supplied" in msg.message for msg in error_messages) shop_product.visible = False shop_product.save() basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "2"}) error_messages = messages.get_messages(request) # Two warnings is added to messages assert len(error_messages) == 3 assert any("not visible" in msg.message for msg in error_messages) assert all("[" not in msg.message for msg in error_messages)
def test_basket_update(): request = get_request_with_basket() basket = request.basket product = get_default_product() basket_commands.handle_add(request, basket, product_id=product.pk, quantity=1) assert basket.product_count == 1 line_id = basket.get_lines()[0].line_id basket_commands.handle_update(request, basket, **{"q_%s" % line_id: "2"}) assert basket.product_count == 2 basket_commands.handle_update(request, basket, **{"delete_%s" % line_id: "1"}) assert basket.product_count == 0