Skip to content

Commit

Permalink
Add an example performance test written with Locust
Browse files Browse the repository at this point in the history
- a base class which can login into Kiwi TCMS (keeps cookies) and
  provides a helper method for JSON-RPC API calls

- an example test case which GETs the Dashboard page and
  calls the User.filter API method!
  • Loading branch information
atodorov committed Jan 16, 2025
1 parent c911ef0 commit 53e6c19
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements/devel.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ doc8
isort==5.13.2
colorama
black==24.10.0
locust
parameterized
robotframework
robotframework-seleniumlibrary
Expand Down
50 changes: 50 additions & 0 deletions tests/performance/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Copyright (c) 2025 Alexander Todorov <[email protected]>
#
# Licensed under GNU Affero General Public License v3 or later (AGPLv3+)
# https://www.gnu.org/licenses/agpl-3.0.html

from locust import FastHttpUser, task, between
from requests.utils import dict_from_cookiejar


class LoggedInTestCase(FastHttpUser):
abstract = True

username = "testadmin"
password = "password"
login_url = "/accounts/login/"

def on_start(self):
with self.client.get(self.login_url, catch_response=True) as response:
cookies = dict_from_cookiejar(self.client.cookiejar)
csrf_middleware_token = cookies["csrftoken"]

self.client.post(
self.login_url,
data={
"username": self.username,
"password": self.password,
"csrfmiddlewaretoken": csrf_middleware_token,
},
)

def json_rpc(self, rpc_method, rpc_args, **kwargs):
payload = {
"jsonrpc": "2.0",
"method": rpc_method,
"params": rpc_args,
"id": "jsonrpc",
}
return self.client.post("/json-rpc/", json=payload, **kwargs)


class ExampleTestCase(LoggedInTestCase):
wait_time = between(1, 5)

@task
def rpc_user_filter(self):
self.json_rpc("User.filter", {})

@task
def visit_dashboard_page(self):
self.client.get("/")

0 comments on commit 53e6c19

Please sign in to comment.