Skip to content

Commit bd080f2

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

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

tests/conftest.py

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

17+
pytest.register_assert_rewrite("tests.e2e.api_client")
18+
1719

1820
@pytest.fixture
1921
def in_memory_db():

tests/e2e/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,10 @@ def post_to_allocate(orderid, sku, qty, expect_success=True):
2121
},
2222
)
2323
if expect_success:
24-
assert r.status_code == 201
24+
assert r.status_code == 202
2525
return r
26+
27+
28+
def get_allocation(orderid):
29+
url = config.get_api_url()
30+
return requests.get(f"{url}/allocations/{orderid}")

tests/e2e/test_api.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
@pytest.mark.usefixtures("postgres_db")
77
@pytest.mark.usefixtures("restart_api")
8-
def test_happy_path_returns_201_and_allocated_batch():
8+
def test_happy_path_returns_202_and_batch_is_allocated():
9+
orderid = random_orderid()
910
sku, othersku = random_sku(), random_sku("other")
1011
earlybatch = random_batchref(1)
1112
laterbatch = random_batchref(2)
@@ -14,23 +15,25 @@ def test_happy_path_returns_201_and_allocated_batch():
1415
api_client.post_to_add_batch(earlybatch, sku, 100, "2011-01-01")
1516
api_client.post_to_add_batch(otherbatch, othersku, 100, None)
1617

17-
response = api_client.post_to_allocate(random_orderid(), sku, qty=3)
18+
r = api_client.post_to_allocate(orderid, sku, qty=3)
19+
assert r.status_code == 202
1820

19-
assert response.status_code == 201
20-
assert response.json()["batchref"] == earlybatch
21+
r = api_client.get_allocation(orderid)
22+
assert r.ok
23+
assert r.json() == [
24+
{"sku": sku, "batchref": earlybatch},
25+
]
2126

2227

2328
@pytest.mark.usefixtures("postgres_db")
2429
@pytest.mark.usefixtures("restart_api")
2530
def test_unhappy_path_returns_400_and_error_message():
2631
unknown_sku, orderid = random_sku(), random_orderid()
27-
28-
response = api_client.post_to_allocate(
29-
orderid,
30-
unknown_sku,
31-
qty=20,
32-
expect_success=False,
32+
r = api_client.post_to_allocate(
33+
orderid, unknown_sku, qty=20, expect_success=False
3334
)
35+
assert r.status_code == 400
36+
assert r.json()["message"] == f"Invalid sku {unknown_sku}"
3437

35-
assert response.status_code == 400
36-
assert response.json()["message"] == f"Invalid sku {unknown_sku}"
38+
r = api_client.get_allocation(orderid)
39+
assert r.status_code == 404

0 commit comments

Comments
 (0)