fix missing auth header in locust tests

This commit is contained in:
Sergey Chubaryan 2024-08-25 20:05:41 +03:00
parent 3e999f8b60
commit 64759c2227

View File

@ -1,36 +1,22 @@
import random import random
import string import string
from locust import FastHttpUser, task from locust import HttpUser, FastHttpUser, task
class DummyRoute(FastHttpUser): class DummyRoute(FastHttpUser):
@task @task
def dummy_test(self): def dummy_test(self):
self.client.get("/dummy") self.client.get("/dummy", headers=self.headers)
# @task
# def user_create_test(self):
# randEmail = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
# randPassword = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
# randName = ''.join(random.choices(string.ascii_letters, k=10))
# self.client.post(
# "/user/create",
# json={
# "email":randEmail,
# "password":randPassword,
# "name": randName,
# },
# )
def on_start(self): def on_start(self):
randEmail = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test' randEmail = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
randPassword = ''.join(random.choices(string.ascii_letters + string.digits, k=10))
randName = ''.join(random.choices(string.ascii_letters, k=10)) randName = ''.join(random.choices(string.ascii_letters, k=10))
password = 'Abcdef1!!1'
response = self.client.post( response = self.client.post(
"/user/create", "/user/create",
json={ json={
"email": randEmail, "email": randEmail,
"password":randPassword, "password": password,
"name": randName, "name": randName,
}, },
) )
@ -41,7 +27,7 @@ class DummyRoute(FastHttpUser):
"/user/login", "/user/login",
json={ json={
"email": randEmail, "email": randEmail,
"password":randPassword, "password": password,
}, },
) )
if response.status_code != 200: if response.status_code != 200:
@ -51,4 +37,4 @@ class DummyRoute(FastHttpUser):
if token == '': if token == '':
raise AssertionError('empty user token') raise AssertionError('empty user token')
self.client.headers = {"X-Auth": token} self.headers = {"X-Auth": token}