1- import uuid
2-
31import pytest
42import requests
53
64pytestmark = pytest .mark .e2e
75
86
9- def random_suffix ():
10- return uuid .uuid4 ().hex [:6 ]
11-
12-
13- def random_sku (name = "" ):
14- return f"sku-{ name } -{ random_suffix ()} "
15-
16-
17- def random_batchref (name = "" ):
18- return f"batch-{ name } -{ random_suffix ()} "
19-
20-
21- def random_orderid (name = "" ):
22- return f"order-{ name } -{ random_suffix ()} "
23-
24-
257@pytest .mark .usefixtures ("postgres_db" )
268@pytest .mark .usefixtures ("restart_api" )
27- def test_add_batch (url ):
9+ def test_add_batch (url , random_sku , random_batchref ):
2810 sku , othersku = random_sku (), random_sku ("other" )
2911 earlybatch = random_batchref (1 )
3012 laterbatch = random_batchref (2 )
@@ -53,7 +35,9 @@ def test_add_batch(url):
5335
5436
5537@pytest .mark .usefixtures ("restart_api" )
56- def test_returns_200_and_allocated_batch (url , post_to_add_stock ):
38+ def test_returns_200_and_allocated_batch (
39+ url , post_to_add_stock , random_sku , random_batchref , random_orderid
40+ ):
5741 sku , othersku = random_sku (), random_sku ("other" )
5842 earlybatch = random_batchref (1 )
5943 laterbatch = random_batchref (2 )
@@ -71,7 +55,9 @@ def test_returns_200_and_allocated_batch(url, post_to_add_stock):
7155
7256
7357@pytest .mark .usefixtures ("restart_api" )
74- def test_retuns_400_and_out_of_stock_message (url , post_to_add_stock ):
58+ def test_retuns_400_and_out_of_stock_message (
59+ url , post_to_add_stock , random_sku , random_batchref , random_orderid
60+ ):
7561 sku , small_batch , large_order = (
7662 random_sku (),
7763 random_batchref (),
@@ -87,7 +73,7 @@ def test_retuns_400_and_out_of_stock_message(url, post_to_add_stock):
8773
8874
8975@pytest .mark .usefixtures ("restart_api" )
90- def test_returns_400_invalid_sku_message (url ):
76+ def test_returns_400_invalid_sku_message (url , random_sku , random_orderid ):
9177 unknown_sku , orderid = random_sku (), random_orderid ()
9278
9379 data = {"orderid" : orderid , "sku" : unknown_sku , "qty" : 20 }
@@ -98,7 +84,9 @@ def test_returns_400_invalid_sku_message(url):
9884
9985
10086@pytest .mark .usefixtures ("restart_api" )
101- def test_deallocate (url , post_to_add_stock ):
87+ def test_deallocate (
88+ url , post_to_add_stock , random_sku , random_batchref , random_orderid
89+ ):
10290 sku , order1 , order2 = random_sku (), random_orderid (), random_orderid ()
10391 batch = random_batchref ()
10492 post_to_add_stock (batch , sku , 100 , "2011-01-01" )
0 commit comments