mirror of
https://github.com/almet/copanier.git
synced 2025-04-28 19:42:37 +02:00
Deal with empty quantities in place order
A user may add a value in place of the "0" and then delete it, so it will send an empty string to the server.
This commit is contained in:
parent
69b5b6cf0b
commit
db08ef7a68
2 changed files with 14 additions and 2 deletions
|
@ -5,7 +5,7 @@ from time import perf_counter
|
|||
import ujson as json
|
||||
import minicli
|
||||
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||
from roll import Roll, Response
|
||||
from roll import Roll, Response, HttpError
|
||||
from roll.extensions import cors, options, traceback, simple_server, static
|
||||
|
||||
from . import config, reports, session, utils, emails, loggers
|
||||
|
@ -222,7 +222,10 @@ async def place_order(request, response, id):
|
|||
form = request.form
|
||||
order = Order(paid=form.bool("paid", False))
|
||||
for product in delivery.products:
|
||||
quantity = form.int(product.ref, 0)
|
||||
try:
|
||||
quantity = form.int(product.ref, 0)
|
||||
except HttpError:
|
||||
continue
|
||||
if quantity:
|
||||
order.products[product.ref] = ProductOrder(wanted=quantity)
|
||||
if not delivery.orders:
|
||||
|
|
|
@ -76,6 +76,15 @@ async def test_place_empty_order_should_delete_previous(client, delivery):
|
|||
assert not delivery.orders
|
||||
|
||||
|
||||
async def test_place_order_with_empty_string(client, delivery):
|
||||
delivery.persist()
|
||||
body = {"123": ""} # User deleted the field value.
|
||||
resp = await client.post(f"/livraison/{delivery.id}/commander", body=body)
|
||||
assert resp.status == 302
|
||||
delivery = Delivery.load(id=delivery.id)
|
||||
assert not delivery.orders
|
||||
|
||||
|
||||
async def test_change_paid_status_when_placing_order(client, delivery):
|
||||
delivery.persist()
|
||||
body = {
|
||||
|
|
Loading…
Reference in a new issue