add integration tests
This commit is contained in:
parent
64bb402ad1
commit
1126ff1321
@ -9,6 +9,7 @@ class Auth():
|
|||||||
self.token = token
|
self.token = token
|
||||||
|
|
||||||
class User():
|
class User():
|
||||||
|
id: string
|
||||||
email: string
|
email: string
|
||||||
name: string
|
name: string
|
||||||
password: string
|
password: string
|
||||||
@ -21,18 +22,16 @@ class User():
|
|||||||
|
|
||||||
|
|
||||||
class BackendApi():
|
class BackendApi():
|
||||||
http: FastHttpUser
|
def __init__(self, httpClient):
|
||||||
|
self.httpClient = httpClient
|
||||||
def __init__(self, http: FastHttpUser):
|
|
||||||
self.http = http
|
|
||||||
|
|
||||||
def user_create(self) -> User:
|
def user_create(self) -> User:
|
||||||
email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
|
email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10)) + '@test.test'
|
||||||
name = ''.join(random.choices(string.ascii_letters, k=10))
|
name = ''.join(random.choices(string.ascii_letters, k=10))
|
||||||
password = 'Abcdef1!!1'
|
password = 'Abcdef1!!1'
|
||||||
|
|
||||||
response = self.http.client.post(
|
response = self.httpClient.post(
|
||||||
"/user/create",
|
"/v1/user/create",
|
||||||
json={
|
json={
|
||||||
"email": email,
|
"email": email,
|
||||||
"password": password,
|
"password": password,
|
||||||
@ -45,8 +44,8 @@ class BackendApi():
|
|||||||
return User(email, password, name)
|
return User(email, password, name)
|
||||||
|
|
||||||
def user_login(self, user: User) -> Auth:
|
def user_login(self, user: User) -> Auth:
|
||||||
response = self.http.client.post(
|
response = self.httpClient.post(
|
||||||
"/user/login",
|
"/v1/user/login",
|
||||||
json={
|
json={
|
||||||
"email": user.email,
|
"email": user.email,
|
||||||
"password": user.password,
|
"password": user.password,
|
||||||
@ -63,22 +62,11 @@ class BackendApi():
|
|||||||
|
|
||||||
def dummy_get(self, auth: Auth):
|
def dummy_get(self, auth: Auth):
|
||||||
headers = {"X-Auth": auth.token}
|
headers = {"X-Auth": auth.token}
|
||||||
response = self.http.client.get("/dummy", headers=headers)
|
response = self.httpClient.get("/v1/dummy", headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise AssertionError('something wrong')
|
raise AssertionError('something wrong')
|
||||||
|
|
||||||
def health_get(self):
|
def health_get(self):
|
||||||
response = self.http.client.get("/health")
|
response = self.httpClient.get("/health")
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise AssertionError('something wrong')
|
raise AssertionError('something wrong')
|
||||||
|
|
||||||
def shortlink_create(self, url: string) -> string:
|
|
||||||
response = self.http.client.post("/s/new?url=" + url)
|
|
||||||
if response.status_code != 200:
|
|
||||||
raise AssertionError('can not login user')
|
|
||||||
|
|
||||||
link = response.json()['link']
|
|
||||||
if link == '':
|
|
||||||
raise AssertionError('empty user token')
|
|
||||||
|
|
||||||
return link
|
|
||||||
12
tests/integration/test_user.py
Normal file
12
tests/integration/test_user.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
from api import BackendApi
|
||||||
|
import requests
|
||||||
|
|
||||||
|
class TestUser:
|
||||||
|
def test_create_user(self):
|
||||||
|
api = BackendApi(requests)
|
||||||
|
api.user_create()
|
||||||
|
|
||||||
|
def test_login_user(self):
|
||||||
|
api = BackendApi(requests)
|
||||||
|
user = api.user_create()
|
||||||
|
api.user_login(user)
|
||||||
@ -16,6 +16,6 @@ requirements:
|
|||||||
pip freeze > requirements.txt
|
pip freeze > requirements.txt
|
||||||
|
|
||||||
run-web:
|
run-web:
|
||||||
locust -f tests,loads --class-picker --host http://localhost:8080 --processes 16
|
locust -f performance --class-picker --host http://localhost:8080 --processes 16
|
||||||
|
|
||||||
|
|
||||||
@ -3,15 +3,13 @@ from locust import FastHttpUser, task
|
|||||||
from api import BackendApi, Auth
|
from api import BackendApi, Auth
|
||||||
|
|
||||||
class DummyGet(FastHttpUser):
|
class DummyGet(FastHttpUser):
|
||||||
api: BackendApi
|
def on_start(self):
|
||||||
auth: Auth
|
self.api = BackendApi(self.client)
|
||||||
|
user = self.api.user_create()
|
||||||
|
self.auth = self.api.user_login(user)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def dummy_test(self):
|
def dummy_test(self):
|
||||||
self.api.dummy_get(self.auth)
|
self.api.dummy_get(self.auth)
|
||||||
|
|
||||||
def on_start(self):
|
|
||||||
self.api = BackendApi(self)
|
|
||||||
|
|
||||||
user = self.api.user_create()
|
|
||||||
self.auth = self.api.user_login(user)
|
|
||||||
@ -3,11 +3,9 @@ from locust import FastHttpUser, task
|
|||||||
from api import BackendApi
|
from api import BackendApi
|
||||||
|
|
||||||
class HealthGet(FastHttpUser):
|
class HealthGet(FastHttpUser):
|
||||||
api: BackendApi
|
def on_start(self):
|
||||||
|
self.api = BackendApi(self.client)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def user_create_test(self):
|
def user_create_test(self):
|
||||||
self.api.health_get()
|
self.api.health_get()
|
||||||
|
|
||||||
def on_start(self):
|
|
||||||
self.api = BackendApi(self)
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
from locust import LoadTestShape
|
from locust import LoadTestShape
|
||||||
|
|
||||||
class LowLoad(LoadTestShape):
|
class LowLoad(LoadTestShape):
|
||||||
time_limit = 600
|
time_limit = 60
|
||||||
spawn_rate = 5
|
spawn_rate = 2
|
||||||
max_users = 100
|
max_users = 10
|
||||||
|
|
||||||
def tick(self) -> (tuple[float, int] | None):
|
def tick(self) -> (tuple[float, int] | None):
|
||||||
user_count = self.spawn_rate * self.get_run_time()
|
user_count = self.spawn_rate * self.get_run_time()
|
||||||
@ -3,11 +3,9 @@ from locust import FastHttpUser, task
|
|||||||
from api import BackendApi
|
from api import BackendApi
|
||||||
|
|
||||||
class ShortlinkCreate(FastHttpUser):
|
class ShortlinkCreate(FastHttpUser):
|
||||||
api: BackendApi
|
def on_start(self):
|
||||||
|
self.api = BackendApi(self.client)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def user_create_test(self):
|
def user_create_test(self):
|
||||||
self.api.shortlink_create("https://ya.ru")
|
self.api.shortlink_create("https://example.com")
|
||||||
|
|
||||||
def on_start(self):
|
|
||||||
self.api = BackendApi(self)
|
|
||||||
@ -3,23 +3,18 @@ from locust import FastHttpUser, task
|
|||||||
from api import BackendApi, User
|
from api import BackendApi, User
|
||||||
|
|
||||||
class UserCreate(FastHttpUser):
|
class UserCreate(FastHttpUser):
|
||||||
api: BackendApi
|
def on_start(self):
|
||||||
|
self.api = BackendApi(self.client)
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def user_create_test(self):
|
def user_create_test(self):
|
||||||
self.api.user_create()
|
self.api.user_create()
|
||||||
|
|
||||||
|
class UserLogin(FastHttpUser):
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
self.api = BackendApi(self)
|
self.api = BackendApi(self)
|
||||||
|
self.user = self.api.user_create()
|
||||||
class UserLogin(FastHttpUser):
|
|
||||||
api: BackendApi
|
|
||||||
user: User
|
|
||||||
|
|
||||||
@task
|
@task
|
||||||
def user_create_test(self):
|
def user_create_test(self):
|
||||||
self.api.user_login(self.user)
|
self.api.user_login(self.user)
|
||||||
|
|
||||||
def on_start(self):
|
|
||||||
self.api = BackendApi(self)
|
|
||||||
self.user = self.api.user_create()
|
|
||||||
@ -4,6 +4,7 @@ certifi==2024.7.4
|
|||||||
charset-normalizer==3.3.2
|
charset-normalizer==3.3.2
|
||||||
click==8.1.7
|
click==8.1.7
|
||||||
ConfigArgParse==1.7
|
ConfigArgParse==1.7
|
||||||
|
exceptiongroup==1.2.2
|
||||||
Flask==3.0.3
|
Flask==3.0.3
|
||||||
Flask-Cors==4.0.1
|
Flask-Cors==4.0.1
|
||||||
Flask-Login==0.6.3
|
Flask-Login==0.6.3
|
||||||
@ -11,12 +12,16 @@ gevent==24.2.1
|
|||||||
geventhttpclient==2.3.1
|
geventhttpclient==2.3.1
|
||||||
greenlet==3.0.3
|
greenlet==3.0.3
|
||||||
idna==3.7
|
idna==3.7
|
||||||
|
iniconfig==2.0.0
|
||||||
itsdangerous==2.2.0
|
itsdangerous==2.2.0
|
||||||
Jinja2==3.1.4
|
Jinja2==3.1.4
|
||||||
locust==2.31.3
|
locust==2.31.3
|
||||||
MarkupSafe==2.1.5
|
MarkupSafe==2.1.5
|
||||||
msgpack==1.0.8
|
msgpack==1.0.8
|
||||||
|
packaging==24.2
|
||||||
|
pluggy==1.5.0
|
||||||
psutil==6.0.0
|
psutil==6.0.0
|
||||||
|
pytest==8.3.4
|
||||||
pyzmq==26.1.0
|
pyzmq==26.1.0
|
||||||
requests==2.32.3
|
requests==2.32.3
|
||||||
tomli==2.0.1
|
tomli==2.0.1
|
||||||
Loading…
x
Reference in New Issue
Block a user