Skip to content

Commit afe12a3

Browse files
committed
modify api tests to try and do a get after a post [get_after_post]
1 parent b62ad70 commit afe12a3

3 files changed

Lines changed: 20 additions & 9 deletions

File tree

‎tests/conftest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from allocation.adapters.orm import metadata, start_mappers
1515
from allocation import config
1616

17+
pytest.register_assert_rewrite('tests.e2e.api_client')
1718

1819
@pytest.fixture
1920
def in_memory_db():

‎tests/e2e/api_client.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ def post_to_allocate(orderid, sku, qty, expect_success=True):
1717
'orderid': orderid, 'sku': sku, 'qty': qty,
1818
})
1919
if expect_success:
20-
assert r.status_code == 201
20+
assert r.status_code == 202
2121
return r
22+
23+
def get_allocation(orderid):
24+
url = config.get_api_url()
25+
return requests.get(f'{url}/allocations/{orderid}')

‎tests/e2e/test_api.py‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@
22
from ..random_refs import random_batchref, random_orderid, random_sku
33
from . import api_client
44

5-
65
@pytest.mark.usefixtures('postgres_db')
76
@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()
99
sku, othersku = random_sku(), random_sku('other')
1010
batch1, batch2, batch3 = random_batchref(1), random_batchref(2), random_batchref(3)
1111
api_client.post_to_add_batch(batch1, sku, 100, '2011-01-02')
1212
api_client.post_to_add_batch(batch2, sku, 100, '2011-01-01')
1313
api_client.post_to_add_batch(batch3, othersku, 100, None)
1414

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
1617

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+
]
1823

1924

2025
@pytest.mark.usefixtures('postgres_db')
2126
@pytest.mark.usefixtures('restart_api')
2227
def test_unhappy_path_returns_400_and_error_message():
2328
unknown_sku, orderid = random_sku(), random_orderid()
24-
25-
response = api_client.post_to_allocate(
29+
r = api_client.post_to_allocate(
2630
orderid, unknown_sku, qty=20, expect_success=False,
2731
)
32+
assert r.status_code == 400
33+
assert r.json()['message'] == f'Invalid sku {unknown_sku}'
2834

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

Comments
 (0)