|
2 | 2 | from ..random_refs import random_batchref, random_orderid, random_sku |
3 | 3 | from . import api_client |
4 | 4 |
|
5 | | - |
6 | 5 | @pytest.mark.usefixtures('postgres_db') |
7 | 6 | @pytest.mark.usefixtures('restart_api') |
8 | | -def test_happy_path_returns_201_and_allocated_batch(): |
| 7 | +def test_happy_path_returns_202_and_batch_is_allocated(): |
| 8 | + orderid = random_orderid() |
9 | 9 | sku, othersku = random_sku(), random_sku('other') |
10 | 10 | batch1, batch2, batch3 = random_batchref(1), random_batchref(2), random_batchref(3) |
11 | 11 | api_client.post_to_add_batch(batch1, sku, 100, '2011-01-02') |
12 | 12 | api_client.post_to_add_batch(batch2, sku, 100, '2011-01-01') |
13 | 13 | api_client.post_to_add_batch(batch3, othersku, 100, None) |
14 | 14 |
|
15 | | - response = api_client.post_to_allocate(random_orderid(), sku, qty=3) |
| 15 | + r = api_client.post_to_allocate(orderid, sku, qty=3) |
| 16 | + assert r.status_code == 202 |
16 | 17 |
|
17 | | - assert response.json()['batchref'] == batch2 |
| 18 | + r = api_client.get_allocation(orderid) |
| 19 | + assert r.ok |
| 20 | + assert r.json() == [ |
| 21 | + {'sku': sku, 'batchref': batch2}, |
| 22 | + ] |
18 | 23 |
|
19 | 24 |
|
20 | 25 | @pytest.mark.usefixtures('postgres_db') |
21 | 26 | @pytest.mark.usefixtures('restart_api') |
22 | 27 | def test_unhappy_path_returns_400_and_error_message(): |
23 | 28 | unknown_sku, orderid = random_sku(), random_orderid() |
24 | | - |
25 | | - response = api_client.post_to_allocate( |
| 29 | + r = api_client.post_to_allocate( |
26 | 30 | orderid, unknown_sku, qty=20, expect_success=False, |
27 | 31 | ) |
| 32 | + assert r.status_code == 400 |
| 33 | + assert r.json()['message'] == f'Invalid sku {unknown_sku}' |
28 | 34 |
|
29 | | - assert response.status_code == 400 |
30 | | - assert response.json()['message'] == f'Invalid sku {unknown_sku}' |
| 35 | + r = api_client.get_allocation(orderid) |
| 36 | + assert r.status_code == 404 |
0 commit comments