Skip to content

Commit cff6a66

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

3 files changed

Lines changed: 20 additions & 11 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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
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
earlybatch = random_batchref(1)
1111
laterbatch = random_batchref(2)
@@ -14,21 +14,25 @@ def test_happy_path_returns_201_and_allocated_batch():
1414
api_client.post_to_add_batch(earlybatch, sku, 100, '2011-01-01')
1515
api_client.post_to_add_batch(otherbatch, othersku, 100, None)
1616

17-
response = api_client.post_to_allocate(random_orderid(), sku, qty=3)
18-
19-
assert response.status_code == 201
20-
assert response.json()['batchref'] == earlybatch
17+
r = api_client.post_to_allocate(orderid, sku, qty=3)
18+
assert r.status_code == 202
2119

20+
r = api_client.get_allocation(orderid)
21+
assert r.ok
22+
assert r.json() == [
23+
{'sku': sku, 'batchref': earlybatch},
24+
]
2225

2326

2427
@pytest.mark.usefixtures('postgres_db')
2528
@pytest.mark.usefixtures('restart_api')
2629
def test_unhappy_path_returns_400_and_error_message():
2730
unknown_sku, orderid = random_sku(), random_orderid()
28-
29-
response = api_client.post_to_allocate(
31+
r = api_client.post_to_allocate(
3032
orderid, unknown_sku, qty=20, expect_success=False,
3133
)
34+
assert r.status_code == 400
35+
assert r.json()['message'] == f'Invalid sku {unknown_sku}'
3236

33-
assert response.status_code == 400
34-
assert response.json()['message'] == f'Invalid sku {unknown_sku}'
37+
r = api_client.get_allocation(orderid)
38+
assert r.status_code == 404

0 commit comments

Comments
 (0)