Python Locust Performance test: Locust Association---Extract the returned data and use

Source: Internet
Author: User
Tags assert ukey

From locust import httplocust, TaskSet, task
Import JSON
From common import Readconfig


Class Userbehavior (TaskSet): # define user behavior

def on_start (self): # The On_Start method is called when the impersonated user starts executing the Taskset class
Pass

def get_headers (self):
"" Member Login "" "
headers = {
"Content-type": "Application/json",
"Channel": "Shop"
}
BODY = {
"Unionid": Readconfig.unionid # Such use will be error, no common ...
}
res = self.client.post ('/customers/login ', headers=headers, Data=json.dumps (body)). Text
Assert ' success ' in Res # assertion to determine if interface return succeeded
res = json.loads (res)
UID = res[' data ' [' UID ']
Ukey = res[' data ' [' Ukey ']
return [UID, Ukey] # member Login return UID and Ukey

@task (1) # @task () decorate the method as a task; 1 indicates that a locust instance is selected to perform the weights, the higher the value, the higher the execution frequency;
def members_can_withdraw_account_information (self): # a behavior
"" "to enable members to obtain membership status" "
res = Self.get_headers ()
headers = {
"Channel": "Shop",
"UID": Str (res[0]),
"Ukey": res[1]
}
Response = Self.client.put ("/customers/customer_state",
headers=headers). Text # Client.get () is used to refer to the requested path, which can be added headers,params,body parameters;
Assert ' success ' in response

@task (1)
def get_member_account_withdrawal_details (self):
"" "to obtain the member account withdrawal details" "
res = Self.get_headers ()
headers = {
"Channel": "Shop",
"UID": Str (res[0]),
"Ukey": res[1]
}
params = {
"Page": "10",
"Size": "10"
}
Response = Self.client.get ("/customers/account/withdraw/log", Headers=headers, params=params). Text
Assert ' success ' in response


Class Websiteuser (Httplocust): # Set performance test;
Host = "Http://dev.sign.lixiaofeng.com"
Task_set = Userbehavior # points to a defined user behavior class;
min_wait = 3000 # The lower bound of the wait time between tasks performed by the user: milliseconds;
max_wait = 6000 # The upper bound of the wait time between tasks performed by the user: milliseconds;

Python Locust Performance test: Locust Association---Extract the returned data and use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.