From 2ede1685183926cb1dfbddf23b690aab4244ea3a Mon Sep 17 00:00:00 2001 From: Sergey Chubaryan Date: Fri, 7 Feb 2025 18:22:41 +0300 Subject: [PATCH] fix tests --- tests/api.py | 20 ++++++++++++++++---- tests/integration/test_user.py | 8 +++++--- tests/makefile | 5 ++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/api.py b/tests/api.py index c945007..338e043 100644 --- a/tests/api.py +++ b/tests/api.py @@ -1,6 +1,13 @@ import random import string -from locust import HttpUser, FastHttpUser +import requests + +class Requests(): + def __init__(self, baseUrl): + self.baseUrl = baseUrl + + def post(self, path, json = {}): + return requests.post(self.baseUrl + path, json=json) class Auth(): token: string @@ -47,14 +54,19 @@ class BackendApi(): response = self.httpClient.post( "/v1/user/login", json={ - "email": user.email, + "email": user.email+"a", "password": user.password, }, ) + + status = response.json()['status'] + if status == 'error': + raise AssertionError(response.json()['error']['message']) + if response.status_code != 200: raise AssertionError('can not login user') - - token = response.json()['token'] + + token = response.json()['result']['token'] if token == '': raise AssertionError('empty user token') diff --git a/tests/integration/test_user.py b/tests/integration/test_user.py index 9c69bc6..0614b82 100644 --- a/tests/integration/test_user.py +++ b/tests/integration/test_user.py @@ -1,12 +1,14 @@ -from api import BackendApi +from api import BackendApi, Requests import requests +backendUrl = "http://localhost:8080" + class TestUser: def test_create_user(self): - api = BackendApi(requests) + api = BackendApi(Requests(backendUrl)) api.user_create() def test_login_user(self): - api = BackendApi(requests) + api = BackendApi(Requests(backendUrl)) user = api.user_create() api.user_login(user) \ No newline at end of file diff --git a/tests/makefile b/tests/makefile index b349abd..36f1721 100644 --- a/tests/makefile +++ b/tests/makefile @@ -15,7 +15,10 @@ install: requirements: pip freeze > requirements.txt -run-web: +run-integration: + python3 -m pytest integration/ + +run-performance-web: locust -f performance --class-picker --host http://localhost:8080 --processes 16