Skip to content

Commit 158e760

Browse files
committed
test persistence by double-allocating. [second_api_test]
1 parent 8fc086e commit 158e760

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

test_api.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,26 @@ def test_api_returns_allocation(add_stock):
4141

4242
assert r.status_code == 201
4343
assert r.json()["batchref"] == earlybatch
44+
45+
46+
@pytest.mark.usefixtures("restart_api")
47+
def test_allocations_are_persisted(add_stock):
48+
sku = random_sku()
49+
batch1, batch2 = random_batchref(1), random_batchref(2)
50+
order1, order2 = random_orderid(1), random_orderid(2)
51+
add_stock(
52+
[(batch1, sku, 10, "2011-01-01"), (batch2, sku, 10, "2011-01-02"),]
53+
)
54+
line1 = {"orderid": order1, "sku": sku, "qty": 10}
55+
line2 = {"orderid": order2, "sku": sku, "qty": 10}
56+
url = config.get_api_url()
57+
58+
# first order uses up all stock in batch 1
59+
r = requests.post(f"{url}/allocate", json=line1)
60+
assert r.status_code == 201
61+
assert r.json()["batchref"] == batch1
62+
63+
# second order should go to batch 2
64+
r = requests.post(f"{url}/allocate", json=line2)
65+
assert r.status_code == 201
66+
assert r.json()["batchref"] == batch2

0 commit comments

Comments
 (0)