Remnawave_python-sdk/tests/test_subscriptions_template.py
Artem 9e2822774a
feat: Enhance subscription and external squad management
- Updated NodeUsageDto to include node_uuid and changed date to datetime.
- Changed total fields in subscription and subscription request history models from float to int.
- Introduced response rules and conditions for subscription settings, including new models for response modifications.
- Added external squads management with CRUD operations and associated models.
- Implemented passkey management with registration and verification endpoints.
- Enhanced snippets management with full CRUD operations and validation.
- Added OAuth2 provider enum for better authentication handling.
2025-10-28 00:44:15 +01:00

91 lines
No EOL
3.4 KiB
Python

import pytest
from remnawave.enums import TemplateType
from remnawave.models import (
CreateSubscriptionTemplateRequestDto,
CreateSubscriptionTemplateResponseDto,
DeleteSubscriptionTemplateResponseDto,
GetTemplateResponseDto,
GetTemplatesResponseDto,
UpdateTemplateRequestDto,
UpdateTemplateResponseDto,
)
def random_string(length=10):
import random
import string
return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
@pytest.mark.asyncio
async def test_get_all_templates(remnawave):
"""Проверка получения всех шаблонов"""
templates = await remnawave.subscriptions_template.get_all_templates()
assert isinstance(templates, GetTemplatesResponseDto)
@pytest.mark.asyncio
async def test_create_template(remnawave):
"""Проверка создания шаблона"""
rand_name = random_string()
create_request = CreateSubscriptionTemplateRequestDto(
name=rand_name,
template_type=TemplateType.SINGBOX,
)
created_template = await remnawave.subscriptions_template.create_template(create_request)
assert isinstance(created_template, CreateSubscriptionTemplateResponseDto)
assert created_template.name == rand_name
assert created_template.template_type == TemplateType.SINGBOX
# Удаляем после проверки
await remnawave.subscriptions_template.delete_template(str(created_template.uuid))
@pytest.fixture
async def created_template(remnawave):
"""Фикстура: создать временный шаблон и удалить после теста"""
create_request = CreateSubscriptionTemplateRequestDto(
name="Temp Template",
template_type=TemplateType.SINGBOX,
)
template = await remnawave.subscriptions_template.create_template(create_request)
yield template
await remnawave.subscriptions_template.delete_template(str(template.uuid))
@pytest.mark.asyncio
async def test_get_template_by_uuid(remnawave, created_template):
"""Проверка получения шаблона по UUID"""
template = await remnawave.subscriptions_template.get_template_by_uuid(
str(created_template.uuid)
)
assert isinstance(template, GetTemplateResponseDto)
assert template.uuid == created_template.uuid
@pytest.mark.asyncio
async def test_update_template(remnawave, created_template):
"""Проверка обновления шаблона"""
update_request = UpdateTemplateRequestDto(
uuid=created_template.uuid,
name="Updated Template Name",
)
updated_template = await remnawave.subscriptions_template.update_template(update_request)
assert isinstance(updated_template, UpdateTemplateResponseDto)
assert updated_template.name == "Updated Template Name"
@pytest.mark.asyncio
async def test_delete_template(remnawave):
"""Проверка удаления шаблона"""
# Сначала создаем
create_request = CreateSubscriptionTemplateRequestDto(
name="Temp Delete Template",
template_type=TemplateType.SINGBOX,
)
created = await remnawave.subscriptions_template.create_template(create_request)
# Теперь удаляем
delete_response = await remnawave.subscriptions_template.delete_template(
str(created.uuid)
)
assert isinstance(delete_response, DeleteSubscriptionTemplateResponseDto)
assert delete_response.is_deleted is True