-
Notifications
You must be signed in to change notification settings - Fork 470
/
Copy pathextension_locust.py
29 lines (23 loc) · 1.58 KB
/
extension_locust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import re
from locustio.common_utils import init_logger, jira_measure, run_as_specific_user # noqa F401
logger = init_logger(app_type='jira')
@jira_measure("locust_app_specific_action")
# @run_as_specific_user(username='admin', password='admin') # run as specific user
def app_specific_action(locust):
r = locust.get('/app/get_endpoint', catch_response=True) # call app-specific GET endpoint
content = r.content.decode('utf-8') # decode response content
token_pattern_example = '"token":"(.+?)"'
id_pattern_example = '"id":"(.+?)"'
token = re.findall(token_pattern_example, content) # get TOKEN from response using regexp
id = re.findall(id_pattern_example, content) # get ID from response using regexp
logger.locust_info(f'token: {token}, id: {id}') # log info for debug when verbose is true in jira.yml file
if 'assertion string' not in content:
logger.error(f"'assertion string' was not found in {content}")
assert 'assertion string' in content # assert specific string in response content
body = {"id": id, "token": token} # include parsed variables to POST request body
headers = {'content-type': 'application/json'}
r = locust.post('/app/post_endpoint', body, headers, catch_response=True) # call app-specific POST endpoint
content = r.content.decode('utf-8')
if 'assertion string after successful POST request' not in content:
logger.error(f"'assertion string after successful POST request' was not found in {content}")
assert 'assertion string after successful POST request' in content # assertion after POST request