use idomatic locust for chained requests for applications.
@@ -84,27 +84,21 @@ class LoggedInUser(HttpUser):
@task(1)
def post_applications(self):
- get_app_req = self.client.get(
+ with self.client.get(
"/applications/request/",
allow_redirects=False,
- # catch_response=True,
+ catch_response=True,
+ ) as get_app_req:
+ if get_app_req.status_code != 200:
+ get_app_req.failure(
+ "get_app_req status code: " + str(get_app_req.status_code)
)
- # if get_app_req.status_code != 200:
- # get_app_req.failure('Redirected to login page')
- # print(get_app_req.url)
- # print(get_app_req.status_code)
- # print(get_app_req.headers)
- # print(self.client.cookies)
- # print(get_app_req.cookies)
- # csrfMiddlewareToken = response.cookies['csrfMiddlewareToken']
match = reCsrfMiddlewareToken.search(get_app_req.text)
if match:
csrfMiddlewareToken = match.group(1)
if csrfMiddlewareToken:
- # print(csrfMiddlewareToken)
- # print(get_app_req.url)
- post_app_req = self.client.post(
- "/applications/request/",
+ with self.client.post(
+ get_app_req.url,
{
"csrfmiddlewaretoken": csrfMiddlewareToken,
"partner_24": "on",
@@ -162,16 +156,15 @@ class LoggedInUser(HttpUser):
"partner_19": "on",
"partner_83": "on",
},
- # cookies = self.client.cookies,
catch_response=True,
- # headers = {"Content-Type": "application/x-www-form-urlencoded"},
+ ) as post_app_req:
+ if post_app_req.status_code != 200:
+ post_app_req.failure(
+ "post_app_req status code: "
+ + str(post_app_req.status_code)
)
- # print(post_app_req.text)
-
- # def post_applications_apply(self):
- # get_apps_apply = self.client.get("/applications/apply/")
- post_apps_apply = self.client.post(
- "/applications/apply/",
+ with self.client.post(
+ post_app_req.url,
{
"csrfmiddlewaretoken": csrfMiddlewareToken,
"real_name": "Test",
@@ -316,4 +309,9 @@ class LoggedInUser(HttpUser):
"submit": "Apply",
},
catch_response=True,
+ ) as post_app_apply:
+ if post_app_apply.status_code != 200:
+ post_app_apply.failure(
+ "post_app_apply status code: "
+ + str(post_app_apply.status_code)
)
