예제 #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
예제 #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
예제 #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
예제 #4
0
def test_wrong_datetime_raise_valueerror():
    with pytest.raises(ValueError):
        Delivery(
            name="Andines",
            order_before=now(),
            to_date=now(),
            from_date="pouet",
            contact="*****@*****.**",
        )
예제 #5
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
예제 #6
0
def test_can_create_delivery_with_products():
    delivery = Delivery(
        name="Andines",
        from_date=now(),
        to_date=now(),
        order_before=now(),
        products=[Product(name="Lait", ref="123", price=1.5)],
        contact="*****@*****.**",
    )
    assert len(delivery.products) == 1
    assert delivery.products[0].ref == "123"
예제 #7
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
예제 #8
0
def test_can_create_delivery():
    delivery = Delivery(
        name="Andines",
        from_date=now(),
        to_date=now(),
        order_before=now(),
        contact="*****@*****.**",
    )
    assert delivery.name == "Andines"
    assert delivery.where == "Marché de la Briche"
    assert delivery.from_date.year == now().year
    assert not delivery.id
예제 #9
0
async def test_create_delivery(client):
    assert not list(Delivery.all())
    body = {
        "name": "Andines",
        "where": "Marché de la Briche",
        "date": "2019-02-23",
        "from_time": "18:30:00",
        "to_time": "20:00:00",
        "order_before": "2019-02-12",
        "contact": "*****@*****.**",
    }
    resp = await client.post("/distribution", body=body)
    assert resp.status == 302
    assert len(list(Delivery.all())) == 1
    delivery = list(Delivery.all())[0]
    assert delivery.name == "Andines"
    assert delivery.from_date.year == 2019
    assert delivery.from_date.hour == 18
    assert delivery.from_date.minute == 30
    assert delivery.to_date.year == 2019
    assert delivery.to_date.hour == 20
    assert delivery.to_date.minute == 0
예제 #10
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
예제 #11
0
파일: conftest.py 프로젝트: vinyll/copanier
def delivery():
    return Delivery(
        name="CRAC d'automne",
        contact="*****@*****.**",
        from_date=datetime.now() + timedelta(days=10),
        to_date=datetime.now() + timedelta(days=10),
        order_before=datetime.now() + timedelta(days=7),
        products=[
            Product(
                name="Lait",
                producer="ferme-du-coin",
                ref="lait",
                price=1.5,
            )
        ],
        producers={
            "ferme-du-coin": Producer(name="Ferme du coin", id="ferme-du-coin")
        },
    )
예제 #12
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
예제 #13
0
파일: conftest.py 프로젝트: vinyll/copanier
def pytest_runtest_setup(item):
    for path in Delivery.get_root().glob("*.yml"):
        path.unlink()
예제 #14
0
def test_can_load_delivery(delivery):
    delivery.name = "Corto"
    delivery.persist()
    loaded = Delivery.load(delivery.id)
    assert loaded.name == "Corto"