kwork-api/tests/e2e/conftest.py
root e985e03ddb feat: Kwork API client with full CI/CD and E2E tests
Core Features:
- Async API client for Kwork.ru (45+ endpoints)
- Pydantic models for type-safe responses
- Comprehensive error handling (KworkAuthError, KworkApiError, etc.)
- 93% test coverage (57 unit tests)

CI/CD Pipeline:
- 3 parallel jobs: lint, test, security
- Ruff for linting/formatting (150x faster than flake8)
- MyPy for static type checking
- pip-audit for security scanning
- Pre-commit hooks for code quality

E2E Testing:
- Login/logout authentication
- Session restoration
- All endpoints tested against real API

Documentation:
- API reference with examples
- Usage guide
- Contributing guidelines

Based on HAR analysis (mitmproxy + har-analyzer skill):
- Correct endpoints: api.kwork.ru
- Proper authentication: Basic auth + cookies
- Form-urlencoded login payload
2026-03-29 23:31:28 +00:00

57 lines
1.6 KiB
Python

"""
E2E тесты для Kwork API.
Требуют реальных credentials и запускаются только локально.
"""
import os
from pathlib import Path
import pytest
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)"
)