kwork-api/tests/e2e/test_catalog.py

198 lines
6.2 KiB
Python
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.

"""
E2E тесты для каталога и проектов.
Все тесты read-only - ничего не изменяют на сервере.
Endpoints основаны на HAR анализе (mitmproxy + har-analyzer skill).
"""
import pytest
from kwork_api import KworkClient
@pytest.mark.e2e
async def test_get_catalog_list(require_credentials):
"""E2E: Получить список кворков из каталога.
HAR: POST https://api.kwork.ru/catalogMainv2
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
# Первая страница каталога
catalog = await client.catalog.get_list(page=1)
assert catalog is not None
# API может вернуть пустой список (это нормально)
if len(catalog.kworks) > 0:
# Проверка структуры первого кворка
first_kwork = catalog.kworks[0]
assert first_kwork.id is not None
assert first_kwork.title is not None
assert first_kwork.price is not None
# Пагинация
if catalog.pagination:
assert catalog.pagination.current_page >= 1
finally:
await client.close()
@pytest.mark.e2e
async def test_get_kwork_details(require_credentials):
"""E2E: Получить детали кворка.
HAR: POST https://api.kwork.ru/getKworkDetails
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
# Сначала получаем каталог чтобы найти реальный ID
catalog = await client.catalog.get_list(page=1)
# Если каталог пустой - пропускаем тест
if len(catalog.kworks) == 0:
pytest.skip("Catalog is empty")
kwork_id = catalog.kworks[0].id
# Получаем детали
details = await client.catalog.get_details(kwork_id)
assert details is not None
assert details.id == kwork_id
assert details.title is not None
assert details.price is not None
finally:
await client.close()
@pytest.mark.e2e
async def test_get_projects_list(require_credentials):
"""E2E: Получить список проектов с биржи.
HAR: POST https://api.kwork.ru/projects
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
projects = await client.projects.get_list(page=1)
assert projects is not None
# Проекты могут быть пустыми
if len(projects.projects) > 0:
first_project = projects.projects[0]
assert first_project.id is not None
assert first_project.title is not None
finally:
await client.close()
@pytest.mark.e2e
async def test_get_user_info(require_credentials):
"""E2E: Получить информацию о текущем пользователе.
HAR: POST https://api.kwork.ru/user
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
user = await client.user.get_info()
assert user is not None
# API возвращает dict с данными пользователя
assert isinstance(user, dict)
finally:
await client.close()
@pytest.mark.e2e
async def test_get_reference_data(require_credentials):
"""E2E: Получить справочные данные (города, страны, фичи).
HAR endpoints:
- POST https://api.kwork.ru/cities
- POST https://api.kwork.ru/countries
- POST https://api.kwork.ru/getAvailableFeatures
- POST https://api.kwork.ru/getBadgesInfo
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
# Города
cities = await client.reference.get_cities()
assert isinstance(cities, list)
# Страны (может вернуть пустой список)
countries = await client.reference.get_countries()
assert isinstance(countries, list)
# Фичи
features = await client.reference.get_features()
assert isinstance(features, list)
# Бейджи
badges = await client.reference.get_badges_info()
assert isinstance(badges, list)
finally:
await client.close()
@pytest.mark.e2e
async def test_get_notifications(require_credentials):
"""E2E: Получить уведомления.
HAR: POST https://api.kwork.ru/notifications
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
notifications = await client.notifications.get_list()
assert notifications is not None
# Уведомления могут быть пустыми
assert hasattr(notifications, 'notifications')
finally:
await client.close()
@pytest.mark.e2e
async def test_get_user_orders(require_credentials):
"""E2E: Получить заказы пользователя.
HAR endpoints:
- POST https://api.kwork.ru/payerOrders
- POST https://api.kwork.ru/workerOrders
"""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"],
)
try:
# Заказы как заказчик
payer_orders = await client.projects.get_payer_orders()
assert isinstance(payer_orders, list)
# Заказы как исполнитель
worker_orders = await client.projects.get_worker_orders()
assert isinstance(worker_orders, list)
finally:
await client.close()