- Add E2E test structure (tests/e2e/) - Add conftest.py with fixtures and credentials loading - Add test_auth.py with authentication tests - Add .env.example template - Add README.md with usage instructions - Mark tests with @pytest.mark.e2e - Add --slowmo option for rate limiting
60 lines
1.6 KiB
Python
60 lines
1.6 KiB
Python
"""
|
|
E2E тесты для Kwork API.
|
|
|
|
Требуют реальных credentials и запускаются только локально.
|
|
"""
|
|
|
|
import os
|
|
import pytest
|
|
from pathlib import Path
|
|
from dotenv import load_dotenv
|
|
|
|
# Загружаем .env
|
|
load_dotenv(Path(__file__).parent / ".env")
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def kwork_credentials():
|
|
"""Credentials для тестового аккаунта."""
|
|
return {
|
|
"username": os.getenv("KWORK_USERNAME"),
|
|
"password": os.getenv("KWORK_PASSWORD"),
|
|
}
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def require_credentials(kwork_credentials):
|
|
"""Пропускает тест если нет credentials."""
|
|
if not kwork_credentials["username"] or not kwork_credentials["password"]:
|
|
pytest.skip(
|
|
"E2E credentials not set. "
|
|
"Copy tests/e2e/.env.example to tests/e2e/.env and fill in credentials."
|
|
)
|
|
return kwork_credentials
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def slowmo(request):
|
|
"""Задержка между тестами для rate limiting."""
|
|
slowmo = request.config.getoption("--slowmo", default=0)
|
|
if slowmo > 0:
|
|
import time
|
|
time.sleep(slowmo)
|
|
|
|
|
|
def pytest_configure(config):
|
|
"""Регистрация маркера e2e."""
|
|
config.addinivalue_line(
|
|
"markers", "e2e: mark test as end-to-end (requires credentials)"
|
|
)
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
"""Добавляет опцию --slowmo."""
|
|
parser.addoption(
|
|
"--slowmo",
|
|
type=float,
|
|
default=0,
|
|
help="Delay between tests in seconds (for rate limiting)"
|
|
)
|