Initial commit
This commit is contained in:
commit
9795660e1f
43 changed files with 2757 additions and 0 deletions
64
tests/api/conftest.py
Normal file
64
tests/api/conftest.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import logging
|
||||
import allure
|
||||
import pytest
|
||||
from config.session_config import session_config
|
||||
from tests.api.utils.api_client import APIClient
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def api_client(api_base_url):
|
||||
"""Клиент для работы с API"""
|
||||
return APIClient(base_url=api_base_url)
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def admin_credentials():
|
||||
"""Учетные данные администратора"""
|
||||
return session_config.get_admin_credentials()
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def auth_admin(api_client: APIClient, admin_credentials):
|
||||
with allure.step("Admin authentication fixture"):
|
||||
logger.info("Authentificate admin")
|
||||
|
||||
success = api_client.login(
|
||||
admin_credentials["username"],
|
||||
admin_credentials["password"]
|
||||
)
|
||||
|
||||
assert success is True
|
||||
assert api_client.logged_in is True
|
||||
|
||||
logger.info("Admin authenticated")
|
||||
|
||||
yield api_client
|
||||
|
||||
api_client.logout()
|
||||
|
||||
@pytest.fixture(scope="class")
|
||||
def auth_user(api_client: APIClient, auth_admin: APIClient, api_user_auth_data):
|
||||
id = ''
|
||||
|
||||
with allure.step("User auth fixture"):
|
||||
logger.info("Creating new user for auth")
|
||||
|
||||
resp = auth_admin.create_user(api_user_auth_data)
|
||||
assert resp.status_code is 201
|
||||
id = resp.json()['id']
|
||||
|
||||
|
||||
logger.info(f"Auth as user: {api_user_auth_data['username']}")
|
||||
|
||||
resp = api_client.login(
|
||||
api_user_auth_data['username'],
|
||||
api_user_auth_data['password']
|
||||
)
|
||||
|
||||
assert resp
|
||||
assert api_client.logged_in
|
||||
|
||||
yield api_client
|
||||
|
||||
api_client.logout()
|
||||
auth_admin.delete_user(id)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue