Skip to content

Commit 0099601

Browse files
committed
test persistence by double-allocating. [second_api_test]
1 parent 6fe1236 commit 0099601

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

‎test_api.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,27 @@ def test_api_returns_allocation(add_stock):
3131
r = requests.post(f'{url}/allocate', json=data)
3232
assert r.status_code == 201
3333
assert r.json()['batchref'] == batch2
34+
35+
36+
@pytest.mark.usefixtures('restart_api')
37+
def test_allocations_are_persisted(add_stock):
38+
sku = random_sku()
39+
batch1, batch2 = random_batchref(1), random_batchref(2)
40+
order1, order2 = random_orderid(1), random_orderid(2)
41+
add_stock([
42+
(batch1, sku, 10, '2011-01-01'),
43+
(batch2, sku, 10, '2011-01-02'),
44+
])
45+
line1 = {'orderid': order1, 'sku': sku, 'qty': 10}
46+
line2 = {'orderid': order2, 'sku': sku, 'qty': 10}
47+
url = config.get_api_url()
48+
49+
# first order uses up all stock in batch 1
50+
r = requests.post(f'{url}/allocate', json=line1)
51+
assert r.status_code == 201
52+
assert r.json()['batchref'] == batch1
53+
54+
# second order should go to batch 2
55+
r = requests.post(f'{url}/allocate', json=line2)
56+
assert r.status_code == 201
57+
assert r.json()['batchref'] == batch2

0 commit comments

Comments
 (0)