Beispiel #1
0
async def test_place_order_with_empty_string(client, delivery):
    delivery.persist()
    body = {"wanted:lait": ""}  # User deleted the field value.
    resp = await client.post(f"/distribution/{delivery.id}/commander", body=body)
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert not delivery.orders
Beispiel #2
0
async def test_place_order_with_session(client, delivery):
    delivery.persist()
    body = {"wanted:lait": "3"}
    resp = await client.post(f"/distribution/{delivery.id}/commander", body=body)
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert "fractal-brocolis" in delivery.orders.keys()
    assert delivery.orders["fractal-brocolis"].products["lait"].wanted == 3
Beispiel #3
0
async def test_place_empty_order_should_delete_previous(client, delivery):
    delivery.orders["fractal-brocolis"] = Order(
        products={"lait": ProductOrder(wanted=1)}
    )
    delivery.persist()
    resp = await client.post(f"/distribution/{delivery.id}/commander", body={})
    assert resp.status == 302
    delivery = Delivery.load(delivery.id)
    assert not delivery.orders
Beispiel #4
0
async def test_cannot_place_order_on_closed_delivery(client, delivery, monkeypatch):
    monkeypatch.setattr("copanier.config.STAFF", ["*****@*****.**"])
    delivery.order_before = datetime.now() - timedelta(days=1)
    delivery.persist()
    body = {"wanted:lait": "3"}
    resp = await client.post(f"/distribution/{delivery.id}/commander", body=body)
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert not delivery.orders
Beispiel #5
0
async def test_post_adjust_product(client, delivery):
    delivery.order_before = datetime.now() - timedelta(days=1)
    delivery.products[0].packing = 6
    delivery.orders["fractal-brocolis"] = Order(products={"lait": ProductOrder(wanted=2)})
    delivery.persist()
    assert delivery.status == delivery.ADJUSTMENT
    body = {"fractal-brocolis": "1"}
    resp = await client.post(f"/distribution/{delivery.id}/ajuster/lait", body=body)
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert delivery.orders["fractal-brocolis"].products["lait"].wanted == 2
    assert delivery.orders["fractal-brocolis"].products["lait"].adjustment == 1
Beispiel #6
0
async def test_only_staff_can_adjust_product(client, delivery, monkeypatch):
    delivery.order_before = datetime.now() - timedelta(days=1)
    delivery.products[0].packing = 6
    delivery.orders["fractal-brocolis"] = Order(products={"lait": ProductOrder(wanted=2)})
    delivery.persist()
    monkeypatch.setattr("copanier.config.STAFF", ["*****@*****.**"])
    resp = await client.get(f"/distribution/{delivery.id}/ajuster/lait")
    assert resp.status == 302
    body = {"fractal-brocolis": "1"}
    resp = await client.post(f"/distribution/{delivery.id}/ajuster/lait", body=body)
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert delivery.orders["fractal-brocolis"].products["lait"].wanted == 2
    assert delivery.orders["fractal-brocolis"].products["lait"].adjustment == 0
Beispiel #7
0
async def test_place_empty_order(client, delivery):
    delivery.persist()
    resp = await client.post(f"/distribution/{delivery.id}/commander", body={})
    assert resp.status == 302
    delivery = Delivery.load(id=delivery.id)
    assert not delivery.orders
Beispiel #8
0
def test_can_load_delivery(delivery):
    delivery.name = "Corto"
    delivery.persist()
    loaded = Delivery.load(delivery.id)
    assert loaded.name == "Corto"