@@ -18,7 +18,7 @@ def random_orderid(name=''):
1818
1919
2020@pytest.mark.usefixtures('restart_api')
21- def test_api_returns_allocation (add_stock):
21+ def test_happy_path_returns_201_and_allocated_batch (add_stock):
2222 sku, othersku = random_sku(), random_sku('other')
2323 batch1, batch2, batch3 = random_batchref(1), random_batchref(2), random_batchref(3)
2424 add_stock([
@@ -34,44 +34,7 @@ def test_api_returns_allocation(add_stock):
3434
3535
3636@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
58-
59-
60- @pytest.mark.usefixtures('restart_api')
61- def test_400_message_for_out_of_stock(add_stock):
62- sku, smalL_batch, large_order = random_sku(), random_batchref(), random_orderid()
63- add_stock([
64- (smalL_batch, sku, 10, '2011-01-01'),
65- ])
66- data = {'orderid': large_order, 'sku': sku, 'qty': 20}
67- url = config.get_api_url()
68- r = requests.post(f'{url}/allocate', json=data)
69- assert r.status_code == 400
70- assert r.json()['message'] == f'Out of stock for sku {sku}'
71-
72-
73- @pytest.mark.usefixtures('restart_api')
74- def test_400_message_for_invalid_sku():
37+ def test_unhappy_path_returns_400_and_error_message():
7538 unknown_sku, orderid = random_sku(), random_orderid()
7639 data = {'orderid': orderid, 'sku': unknown_sku, 'qty': 20}
7740 url = config.get_api_url()
0 commit comments