-
-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example performance test written with Locust
- 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
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("/") |