22from ..random_refs import random_batchref , random_orderid , random_sku
33from . 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' )
2629def 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