Skip to content

Commit 32e33a7

Browse files
committed
ongoing simplification
1 parent 6bf7716 commit 32e33a7

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

tests/performance/locustfiles/webserver_services.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
import faker
1010
import locust
11+
from common.base_user import OsparcWebUserBase
1112
from dotenv import load_dotenv
12-
from locust.contrib.fasthttp import FastHttpUser
1313

1414
logging.basicConfig(level=logging.INFO)
1515

@@ -18,19 +18,19 @@
1818
load_dotenv() # take environment variables from .env
1919

2020

21-
class WebApiUser(FastHttpUser):
21+
class WebApiUser(OsparcWebUserBase):
2222
def __init__(self, *args, **kwargs):
2323
super().__init__(*args, **kwargs)
24-
2524
self.email = fake.email()
25+
self.password = "testtesttest" # noqa: S105
2626

2727
@locust.task
2828
def list_latest_services(self):
2929
base_url = "/v0/catalog/services/-/latest"
3030
params = {"offset": 20, "limit": 20}
3131

3232
while True:
33-
response = self.client.get(base_url, params=params)
33+
response = self.authenticated_get(base_url, params=params)
3434
response.raise_for_status()
3535

3636
page = response.json()
@@ -46,25 +46,31 @@ def list_latest_services(self):
4646
params = dict(urllib.parse.parse_qsl(parsed_next.query))
4747

4848
def on_start(self):
49-
print("Created User ", self.email)
50-
password = "testtesttest" # noqa: S105
49+
logging.info("Creating user with email: %s", self.email)
5150

52-
self.client.post(
51+
# Register user
52+
self.authenticated_post(
5353
"/v0/auth/register",
5454
json={
5555
"email": self.email,
56-
"password": password,
57-
"confirm": password,
56+
"password": self.password,
57+
"confirm": self.password,
5858
},
5959
)
60-
self.client.post(
60+
61+
# Login using the custom user credentials instead of the default ones
62+
logging.info("Logging in user with email: %s", self.email)
63+
response = self.authenticated_post(
6164
"/v0/auth/login",
6265
json={
6366
"email": self.email,
64-
"password": password,
67+
"password": self.password,
6568
},
6669
)
70+
response.raise_for_status()
71+
logging.info("Logged in user with email: %s", self.email)
6772

6873
def on_stop(self):
69-
self.client.post("/v0/auth/logout")
70-
print("Stopping", self.email)
74+
# Logout
75+
self.authenticated_post("/v0/auth/logout")
76+
logging.info("Logged out user with email: %s", self.email)

0 commit comments

Comments
 (0)