From locust import httplocust, TaskSet, task
Import Pymysql
Import Random
Class Userbehavior (TaskSet):
def on_start (self):
db = Pymysql.connect ("IP Address", "username", "password", "database")
cursor = Db.cursor ()
Cursor.execute ("Select Id,code from Zj_class WHERE name like '% test create class% ' limit 20001")
Self.data = Cursor.fetchall ()
Db.close ()
Self.bindstudents ()
def login_user (self):
Zhi=random.randint (0,20000)
CLASSID=SELF.DATA[ZHI][0]
CODE=SELF.DATA[ZHI][1]
Print (Classid,code)
Return (ClassID, code)
@task
def bindstudents (self):
Classid,code=self.login_user ()
Self.client.post ("/wx/bind/add/mq/openid", {"class_id": ClassID,
"Stuname": "Lilifang 22",
"Code": Code,
"Isverify": "N"
})
# @task (1)
# def Baidu (self):
# Self.client.get ("/")
Class Websiteuser (Httplocust):
Host= ""
Task_set = Userbehavior
min_wait = 0
max_wait = 0
Locust performance test connect MySQL, randomly remove class, bind student