62 lines
2.0 KiB
Python
62 lines
2.0 KiB
Python
from locust import Locust, TaskSequence, task, HttpLocust, seq_task
|
|
import os
|
|
import json
|
|
import random
|
|
|
|
#HOST_NAME = os.environ['HOST']
|
|
|
|
|
|
class VikunjaTaskSet(TaskSequence):
|
|
def on_start(self):
|
|
# Called everytime when a simulated user starts executing TaskSet class
|
|
self.headers = {
|
|
'accept': "application/json",
|
|
'content-type': "application/json",
|
|
'Authorization': ""
|
|
}
|
|
# Append your login or authentication keys to header
|
|
self.get_authentication_keys()
|
|
self.listIDs = []
|
|
self.namespaces = {}
|
|
|
|
def get_authentication_keys(self):
|
|
response = self.client.post("/login", {"username":"testuser" + str(random.randint(1, 100)), "password":"1234"})
|
|
data = json.loads(response.text)
|
|
self.headers["Authorization"] = 'Bearer ' + data["token"]
|
|
|
|
@task
|
|
@seq_task(1)
|
|
def dashboard(self):
|
|
self.client.get("/tasks/all", headers=self.headers)
|
|
response = self.client.get("/namespaces", headers=self.headers)
|
|
self.namespaces = json.loads(response.text)
|
|
|
|
@seq_task(2)
|
|
@task(10) # 10 new lists
|
|
def new_list(self):
|
|
response = self.client.put("/namespaces/" + str(self.namespaces[0]["id"]) + "/lists",
|
|
data=json.dumps({"title": "created by locust"}),
|
|
headers=self.headers)
|
|
data = json.loads(response.text)
|
|
self.listIDs.append(data["id"])
|
|
|
|
@seq_task(3)
|
|
@task(500)
|
|
def add_task(self):
|
|
self.client.put("/lists/" + str(random.choice(self.listIDs)),
|
|
data=json.dumps({"text": "task created by locust"}),
|
|
headers=self.headers)
|
|
|
|
@seq_task(4)
|
|
@task(2000)
|
|
def get_list(self):
|
|
self.client.get("/lists/" + str(random.choice(self.listIDs)),
|
|
headers=self.headers)
|
|
|
|
|
|
|
|
class VikunjaLocust(HttpLocust):
|
|
task_set = VikunjaTaskSet
|
|
min_wait = 100
|
|
max_wait = 1500
|