@@ -29,10 +29,14 @@ class APITasks(TaskSet):
2929 @task
3030 def purchaseItem (self ):
3131 self .createCustomer ()
32+ self .createCard ()
33+ self .createAddress ()
3234 self .login ()
3335 self .addItemToCart ()
3436 self .buy ()
3537 self .deleteCustomer ()
38+ self .deleteCard ()
39+ self .deleteAddress ()
3640
3741 # @task
3842 # def addRemoveFromCart(self):
@@ -68,27 +72,31 @@ def login(self):
6872 # self.cust_id = login.cookies["logged_in"]
6973
7074 def createCustomer (self ):
71- # TODO just use same address/card for all generated customers?
72- address = self .client .post ("/addresses" , json = {"street" : "my road" , "number" : "3" , "country" : "UK" , "city" : "London" })
73-
74- self .address_id = address .json ()["_links" ]["self" ]["href" ][26 :]
75- card = self .client .post ("/cards" , json = {"longNum" : "5429804235432" , "expires" : "04/16" , "ccv" : "432" })
76-
77- self .card_id = card .json ()["_links" ]["self" ]["href" ][22 :]
7875 global counter
7976 counter += 1
8077 self .username = "test_user_" + str (uuid .uuid4 ())
8178
8279 self .password = "test_password"
83- customer = self .client .post ("/customers" , json = {"firstName" : "testUser_" + str (counter ), "lastName" : "Last_Name" , "username" : self .username , "addresses" : [ "http://accounts/addresses/" + self . address_id ], "cards" : [ "http://accounts/cards/" + self . card_id ] })
80+ customer = self .client .post ("/customers" , json = {"firstName" : "testUser_" + str (counter ), "lastName" : "Last_Name" , "username" : self .username })
8481
85- self .cust_id = customer .json ()["_links" ]["self" ]["href" ][27 :]
86- self .client .get ("/register?username=" + self .username + "&password=" + self .password )
82+ self .cust_id = customer .json ()["id" ]
83+
84+ def createCard (self ):
85+ self .client .post ("/cards" , json = {"longNum" : "5429804235432" , "expires" : "04/16" , "ccv" : "432" })
86+ card = self .client .post ("/cards" , json = {"longNum" : "5429804235432" , "expires" : "04/16" , "ccv" : "432" , "userId" : self .cust_id })
87+ self .card_id = card .json ()["id" ]
88+
89+ def createAddress (self ):
90+ self .client .post ("/addresses" , json = {"street" : "my road" , "number" : "3" , "country" : "UK" , "city" : "London" })
91+ addr = self .client .post ("/addresses" , json = {"street" : "my road" , "number" : "3" , "country" : "UK" , "city" : "London" , "userId" :self .cust_id })
92+ self .addr_id = addr .json ()["id" ]
8793
8894 def deleteCustomer (self ):
8995 self .client .delete ("/customers/" + self .cust_id )
90- self . client . delete ( "/addresses/" + self . address_id )
96+ def deleteCard ( self ):
9197 self .client .delete ("/cards/" + self .card_id )
98+ def deleteAddress (self ):
99+ self .client .delete ("/addresses/" + self .addr_id )
92100
93101class ErrorTasks (TaskSet ):
94102
@@ -130,4 +138,4 @@ class UnknownUser(HttpLocust):
130138class ErrorUser (HttpLocust ):
131139 task_set = ErrorTasks
132140 min_wait = 2000
133- max_wait = 5000
141+ max_wait = 5000
0 commit comments