@@ -22,7 +22,7 @@ def random_orderid(name=""):
22
22
23
23
24
24
@pytest .mark .usefixtures ("restart_api" )
25
- def test_api_returns_allocation (add_stock ):
25
+ def test_happy_path_returns_201_and_allocated_batch (add_stock ):
26
26
sku , othersku = random_sku (), random_sku ("other" )
27
27
earlybatch = random_batchref (1 )
28
28
laterbatch = random_batchref (2 )
@@ -44,43 +44,7 @@ def test_api_returns_allocation(add_stock):
44
44
45
45
46
46
@pytest .mark .usefixtures ("restart_api" )
47
- def test_allocations_are_persisted (add_stock ):
48
- sku = random_sku ()
49
- batch1 , batch2 = random_batchref (1 ), random_batchref (2 )
50
- order1 , order2 = random_orderid (1 ), random_orderid (2 )
51
- add_stock (
52
- [(batch1 , sku , 10 , "2011-01-01" ), (batch2 , sku , 10 , "2011-01-02" ),]
53
- )
54
- line1 = {"orderid" : order1 , "sku" : sku , "qty" : 10 }
55
- line2 = {"orderid" : order2 , "sku" : sku , "qty" : 10 }
56
- url = config .get_api_url ()
57
-
58
- # first order uses up all stock in batch 1
59
- r = requests .post (f"{ url } /allocate" , json = line1 )
60
- assert r .status_code == 201
61
- assert r .json ()["batchref" ] == batch1
62
-
63
- # second order should go to batch 2
64
- r = requests .post (f"{ url } /allocate" , json = line2 )
65
- assert r .status_code == 201
66
- assert r .json ()["batchref" ] == batch2
67
-
68
-
69
- @pytest .mark .usefixtures ("restart_api" )
70
- def test_400_message_for_out_of_stock (add_stock ):
71
- sku , smalL_batch , large_order = random_sku (), random_batchref (), random_orderid ()
72
- add_stock (
73
- [(smalL_batch , sku , 10 , "2011-01-01" ),]
74
- )
75
- data = {"orderid" : large_order , "sku" : sku , "qty" : 20 }
76
- url = config .get_api_url ()
77
- r = requests .post (f"{ url } /allocate" , json = data )
78
- assert r .status_code == 400
79
- assert r .json ()["message" ] == f"Out of stock for sku { sku } "
80
-
81
-
82
- @pytest .mark .usefixtures ("restart_api" )
83
- def test_400_message_for_invalid_sku ():
47
+ def test_unhappy_path_returns_400_and_error_message ():
84
48
unknown_sku , orderid = random_sku (), random_orderid ()
85
49
data = {"orderid" : orderid , "sku" : unknown_sku , "qty" : 20 }
86
50
url = config .get_api_url ()
0 commit comments