Esempio n. 1
0
import re
from locustio.common_utils import init_logger, jira_measure

logger = init_logger(app_type='jira')


@jira_measure
def app_specific_action(locust):
    r = locust.client.get('/plugin/report')  # navigate to page

    content = r.content.decode('utf-8')  # parse page content
    token_pattern_example = '"token":"(.+?)"'
    id_pattern_example = '"id":"(.+?)"'
    token = re.findall(token_pattern_example,
                       content)  # parse variables from response using regexp
    id = re.findall(id_pattern_example, content)
    logger.locust_info(
        f'token: {token}, id: {id}'
    )  # logger 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  # assertion after GET request

    body = {"id": id, "token": token}  # include parsed variables to POST body
    headers = {'content-type': 'application/json'}
    r = locust.client.post('/plugin/post/endpoint', body,
                           headers)  # send some POST request
    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}"
import re
from locustio.common_utils import init_logger, jsm_agent_measure, run_as_specific_user  # noqa F401

logger = init_logger(app_type='jsm')


@jsm_agent_measure('locust_agent_app_specific_action')
# @run_as_specific_user(username='******', password='******')  # 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 jsm.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
import re
from locustio.common_utils import init_logger, confluence_measure

logger = init_logger(app_type='confluence')


@confluence_measure("locust_app_specific_action")
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 confluence.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'}
Esempio n. 4
0
import random
import time

from locustio.bamboo.requests_params import bamboo_datasets
from locustio.common_utils import init_logger, JSON_HEADERS
from util.api.bamboo_clients import BambooClient
from locust import events

from util.conf import BAMBOO_SETTINGS

logger = init_logger(app_type='bamboo')
bamboo_dataset = bamboo_datasets()
url = BAMBOO_SETTINGS.server_url
api_client = BambooClient(url,
                          BAMBOO_SETTINGS.admin_login,
                          BAMBOO_SETTINGS.admin_password,
                          verify=BAMBOO_SETTINGS.secure)
action_time = BAMBOO_SETTINGS.default_dataset_plan_duration
PLAN_STARTED_TIMEOUT = BAMBOO_SETTINGS.start_plan_timeout  # seconds
PLAN_STATUS_REQUEST_TIMEOUT = 10
DEFAULT_DATASET_JOB_KEY = 'JB1'


def run_build_plans(locust):
    start = time.time()
    user_auth = tuple(random.choice(bamboo_dataset['users']))
    build_plan = random.choice(bamboo_dataset['build_plans'])
    build_plan_id = build_plan[1]
    r = locust.get(f'/rest/api/latest/plan/{build_plan_id}',
                   auth=user_auth,
                   catch_response=True,