kwork-api/tests/e2e/test_auth.py
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

53 lines
1.4 KiB
Python

"""
E2E тесты аутентификации.
"""
import pytest
from kwork_api import KworkClient
from kwork_api.errors import KworkAuthError
@pytest.mark.e2e
async def test_login_success(require_credentials):
"""E2E: Успешная аутентификация."""
client = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"]
)
try:
assert client.token is not None
assert len(client.token) > 0
finally:
await client.aclose()
@pytest.mark.e2e
async def test_login_invalid_credentials():
"""E2E: Неверные credentials."""
with pytest.raises(KworkAuthError):
await KworkClient.login(
username="invalid_user_12345",
password="invalid_pass_12345"
)
@pytest.mark.e2e
async def test_restore_session(require_credentials):
"""E2E: Восстановление сессии из токена."""
# First login
client1 = await KworkClient.login(
username=require_credentials["username"],
password=require_credentials["password"]
)
token = client1.token
await client1.aclose()
# Restore from token
client2 = KworkClient(token=token)
try:
user = await client2.user.get_info()
assert user.username == require_credentials["username"]
finally:
await client2.aclose()