@@ -17,22 +17,31 @@ def random_orderid(name=''):
1717 return f'order-{ name } -{ random_suffix ()} '
1818
1919
20+ def post_to_add_batch (ref , sku , qty , eta ):
21+ url = config .get_api_url ()
22+ r = requests .post (
23+ f'{ url } /add_batch' ,
24+ json = {'ref' : ref , 'sku' : sku , 'qty' : qty , 'eta' : eta }
25+ )
26+ assert r .status_code == 201
27+
28+
29+ @pytest .mark .usefixtures ('postgres_db' )
2030@pytest .mark .usefixtures ('restart_api' )
21- def test_happy_path_returns_201_and_allocated_batch (add_stock ):
31+ def test_happy_path_returns_201_and_allocated_batch ():
2232 sku , othersku = random_sku (), random_sku ('other' )
2333 batch1 , batch2 , batch3 = random_batchref (1 ), random_batchref (2 ), random_batchref (3 )
24- add_stock ([
25- (batch1 , sku , 100 , '2011-01-02' ),
26- (batch2 , sku , 100 , '2011-01-01' ),
27- (batch3 , othersku , 100 , None ),
28- ])
34+ post_to_add_batch (batch1 , sku , 100 , '2011-01-02' )
35+ post_to_add_batch (batch2 , sku , 100 , '2011-01-01' )
36+ post_to_add_batch (batch3 , othersku , 100 , None )
2937 data = {'orderid' : random_orderid (), 'sku' : sku , 'qty' : 3 }
3038 url = config .get_api_url ()
3139 r = requests .post (f'{ url } /allocate' , json = data )
3240 assert r .status_code == 201
3341 assert r .json ()['batchref' ] == batch2
3442
3543
44+ @pytest .mark .usefixtures ('postgres_db' )
3645@pytest .mark .usefixtures ('restart_api' )
3746def test_unhappy_path_returns_400_and_error_message ():
3847 unknown_sku , orderid = random_sku (), random_orderid ()
0 commit comments