@@ -21,28 +21,34 @@ def random_orderid(name=""):
2121 return f"order-{ name } -{ random_suffix ()} "
2222
2323
24+ def post_to_add_batch (ref , sku , qty , eta ):
25+ url = config .get_api_url ()
26+ r = requests .post (
27+ f"{ url } /add_batch" , json = {"ref" : ref , "sku" : sku , "qty" : qty , "eta" : eta }
28+ )
29+ assert r .status_code == 201
30+
31+
32+ @pytest .mark .usefixtures ("postgres_db" )
2433@pytest .mark .usefixtures ("restart_api" )
25- def test_happy_path_returns_201_and_allocated_batch (add_stock ):
34+ def test_happy_path_returns_201_and_allocated_batch ():
2635 sku , othersku = random_sku (), random_sku ("other" )
2736 earlybatch = random_batchref (1 )
2837 laterbatch = random_batchref (2 )
2938 otherbatch = random_batchref (3 )
30- add_stock (
31- [
32- (laterbatch , sku , 100 , "2011-01-02" ),
33- (earlybatch , sku , 100 , "2011-01-01" ),
34- (otherbatch , othersku , 100 , None ),
35- ]
36- )
39+ post_to_add_batch (laterbatch , sku , 100 , "2011-01-02" )
40+ post_to_add_batch (earlybatch , sku , 100 , "2011-01-01" )
41+ post_to_add_batch (otherbatch , othersku , 100 , None )
3742 data = {"orderid" : random_orderid (), "sku" : sku , "qty" : 3 }
38- url = config .get_api_url ()
3943
44+ url = config .get_api_url ()
4045 r = requests .post (f"{ url } /allocate" , json = data )
4146
4247 assert r .status_code == 201
4348 assert r .json ()["batchref" ] == earlybatch
4449
4550
51+ @pytest .mark .usefixtures ("postgres_db" )
4652@pytest .mark .usefixtures ("restart_api" )
4753def test_unhappy_path_returns_400_and_error_message ():
4854 unknown_sku , orderid = random_sku (), random_orderid ()
0 commit comments