Remnawave_python-sdk/tests/test_auth.py
Artem 3f0b5af2cf
Refactor tests for HWID, subscriptions, system, and users; add subscription request history functionality
- Restructured HWID tests into classes for better organization and clarity.
- Enhanced subscription tests to cover additional scenarios and improved assertions.
- Introduced new tests for system statistics and monitoring.
- Implemented CRUD operations for user management with comprehensive test coverage.
- Added new controllers and models for handling subscription request history.
- Created tests for subscription request history, including pagination and statistics.
- Improved error handling in tests to skip when exceptions occur.
2025-10-02 01:46:17 +02:00

43 lines
No EOL
1.8 KiB
Python
Raw Permalink 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.

import pytest
from remnawave.models import (
LoginRequestDto,
LoginResponseDto,
LoginTelegramRequestDto,
TelegramCallbackRequestDto,
)
from remnawave.exceptions import ForbiddenError, ApiError
from tests.conftest import REMNAWAVE_ADMIN_PASSWORD, REMNAWAVE_ADMIN_USERNAME
class TestAuthentication:
"""Тесты для проверки функциональности аутентификации"""
@pytest.mark.asyncio
async def test_login_with_credentials(self, remnawave):
"""Тест базовой аутентификации по имени пользователя и паролю"""
login = await remnawave.auth.login(
LoginRequestDto(
username=REMNAWAVE_ADMIN_USERNAME,
password=REMNAWAVE_ADMIN_PASSWORD,
)
)
assert isinstance(login, LoginResponseDto)
assert login.access_token is not None
# Проверяем наличие токена, но не обращаемся к полю user,
# так как в текущей версии API это поле не возвращается
assert login.access_token.startswith("eyJ") # JWT token всегда начинается с eyJ
@pytest.mark.asyncio
async def test_login_with_invalid_credentials(self, remnawave):
"""Тест аутентификации с неверными учетными данными"""
try:
await remnawave.auth.login(
LoginRequestDto(
username="invalid_username",
password="invalid_password",
)
)
pytest.fail("Expected authentication error for invalid credentials")
except ApiError as e:
assert e.status_code in [401, 403], f"Expected 401 or 403, got {e.status_code}"