Tests/tests/api/conftest.py
2026-01-19 23:32:11 +04:00

64 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)