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" )
2530def 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