kwork-api/tests/e2e/README.md
root 8cb0a59063 test: add E2E testing framework
- 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
2026-03-29 01:35:57 +00:00

137 lines
3.2 KiB
Markdown
Raw 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.

# End-to-End (E2E) Testing
E2E тесты требуют реальных credentials Kwork.ru и запускаются **только локально** (не в CI).
## ⚠️ Предупреждение
- **Не запускай в CI** — требуются реальные credentials
- **Используй тестовый аккаунт** — не основной аккаунт Kwork
- **Rate limiting** — добавляй задержки между запросами
---
## 🔧 Настройка
### 1. Создай файл окружения
```bash
cd /root/kwork-api
cp tests/e2e/.env.example tests/e2e/.env
```
### 2. Заполни credentials
```bash
# tests/e2e/.env
KWORK_USERNAME=your_test_username
KWORK_PASSWORD=your_test_password
```
### 3. Установи зависимости
```bash
uv sync --group dev
```
---
## 🚀 Запуск тестов
### Все E2E тесты
```bash
uv run pytest tests/e2e/ -v
```
### Конкретный тест
```bash
uv run pytest tests/e2e/test_auth.py -v
uv run pytest tests/e2e/test_catalog.py::test_get_catalog_list -v
```
### С задержками (rate limiting)
```bash
uv run pytest tests/e2e/ -v --slowmo=1
```
---
## 📁 Структура тестов
```
tests/e2e/
├── README.md # Этот файл
├── .env.example # Шаблон для credentials
├── conftest.py # Фикстуры и setup
├── test_auth.py # Аутентификация
├── test_catalog.py # Каталог кворков
├── test_projects.py # Биржа проектов
└── test_user.py # Пользовательские данные
```
---
## 🧪 Пример теста
```python
import pytest
from kwork_api import KworkClient
@pytest.mark.e2e
async def test_get_user_info():
"""E2E тест: получение информации о пользователе."""
async with await KworkClient.login(
username="test_user",
password="test_pass"
) as client:
user = await client.user.get_info()
assert user.username == "test_user"
assert user.balance >= 0
```
---
## 🏷️ Маркировка тестов
E2E тесты маркируются `@pytest.mark.e2e` для изоляции:
```bash
# Запустить только unit тесты (исключить e2e)
uv run pytest tests/ -v -m "not e2e"
# Запустить только e2e тесты
uv run pytest tests/ -v -m e2e
```
---
## 🔒 Безопасность
1. **Никогда не коммить `.env`** — добавлен в `.gitignore`
2. **Используй тестовый аккаунт** — не основной
3. **Не сохраняй токены в коде** — только через env vars
---
## 🐛 Troubleshooting
### Ошибка аутентификации
```
KworkAuthError: Invalid credentials
```
**Решение:** Проверь credentials в `.env`
### Rate limit
```
KworkApiError: Too many requests
```
**Решение:** Запусти с задержкой: `pytest --slowmo=2`
### Session expired
```
KworkAuthError: Session expired
```
**Решение:** Перезапусти тесты (session создаётся заново)