mirror of
https://github.com/remnawave/python-sdk.git
synced 2026-05-13 20:26:50 +00:00
fix: исправить алиасы в эндпоинтах и удалить неиспользуемые DTO
This commit is contained in:
parent
38a57b3e31
commit
f1503b2fda
7 changed files with 22 additions and 28 deletions
|
|
@ -135,7 +135,8 @@ class UsersController(BaseController):
|
|||
"""Get user subscription request history, recent 24 records"""
|
||||
...
|
||||
|
||||
@get("/users/by-short-uuid/{short_uuid}", response_class=GetUserByShortUuidResponseDto)
|
||||
# ИСПРАВЛЕНО: убран alias, используется short_uuid
|
||||
@get("/users/by-short-uuid/{shortUuid}", response_class=GetUserByShortUuidResponseDto)
|
||||
async def get_user_by_short_uuid(
|
||||
self,
|
||||
short_uuid: Annotated[str, Path(description="Short UUID of the user", alias="shortUuid")],
|
||||
|
|
@ -151,7 +152,6 @@ class UsersController(BaseController):
|
|||
"""Get user by username"""
|
||||
...
|
||||
|
||||
# НОВЫЙ ЭНДПОИНТ
|
||||
@get("/users/by-id/{id}", response_class=GetUserByIdResponseDto)
|
||||
async def get_user_by_id(
|
||||
self,
|
||||
|
|
@ -160,8 +160,9 @@ class UsersController(BaseController):
|
|||
"""Get user by ID"""
|
||||
...
|
||||
|
||||
# ИСПРАВЛЕНО: убран alias, используется telegram_id
|
||||
@get(
|
||||
"/users/by-telegram-id/{telegram_id}",
|
||||
"/users/by-telegram-id/{telegramId}",
|
||||
response_class=TelegramUserResponseDto,
|
||||
)
|
||||
async def get_users_by_telegram_id(
|
||||
|
|
|
|||
|
|
@ -263,7 +263,6 @@ from .users import (
|
|||
# Response DTOs - Collections
|
||||
GetAllUsersResponseDto,
|
||||
GetAllTagsResponseDto,
|
||||
GetUserAccessibleNodesResponseDto,
|
||||
GetUserSubscriptionRequestHistoryResponseDto,
|
||||
|
||||
# Response DTOs - Arrays (RootModel)
|
||||
|
|
@ -590,7 +589,6 @@ __all__ = [
|
|||
"ActivateAllInboundsResponseDto",
|
||||
"GetAllUsersResponseDto",
|
||||
"GetAllTagsResponseDto",
|
||||
"GetUserAccessibleNodesResponseDto",
|
||||
"GetUserSubscriptionRequestHistoryResponseDto",
|
||||
"TelegramUserResponseDto",
|
||||
"EmailUserResponseDto",
|
||||
|
|
|
|||
|
|
@ -125,8 +125,6 @@ class NodeResponseDto(BaseModel):
|
|||
is_connected: bool = Field(alias="isConnected")
|
||||
is_disabled: bool = Field(alias="isDisabled")
|
||||
is_connecting: bool = Field(alias="isConnecting")
|
||||
is_node_online: bool = Field(alias="isNodeOnline")
|
||||
is_xray_running: bool = Field(alias="isXrayRunning")
|
||||
last_status_change: Optional[datetime] = Field(None, alias="lastStatusChange")
|
||||
last_status_message: Optional[str] = Field(None, alias="lastStatusMessage")
|
||||
xray_version: Optional[str] = Field(None, alias="xrayVersion")
|
||||
|
|
|
|||
|
|
@ -4,11 +4,17 @@ from uuid import UUID
|
|||
|
||||
from pydantic import BaseModel, Field, RootModel
|
||||
|
||||
class NodeActiveSquadDto(BaseModel):
|
||||
squad_name: str = Field(alias="squadName")
|
||||
active_inbounds: list[str] = Field(alias="activeInbounds")
|
||||
|
||||
class NodeInfoDto(BaseModel):
|
||||
uuid: UUID
|
||||
name: str
|
||||
country_code: str = Field(alias="countryCode")
|
||||
config_profile_name: str = Field(alias="configProfileName")
|
||||
config_profile_uuid: UUID = Field(alias="configProfileUuid")
|
||||
active_squads: List[NodeActiveSquadDto] = Field(alias="activeSquads")
|
||||
|
||||
class GetUserAccessibleNodesResponse(BaseModel):
|
||||
user_uuid: UUID = Field(alias="userUuid")
|
||||
|
|
|
|||
|
|
@ -320,14 +320,5 @@ class TelegramUserResponseDto(RootModel[list[UserResponseDto]]):
|
|||
def __iter__(self):
|
||||
return iter(self.root)
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.root[item]
|
||||
|
||||
|
||||
class GetUserAccessibleNodesResponseDto(RootModel[list[UUID]]):
|
||||
"""Response for get user accessible nodes"""
|
||||
def __iter__(self):
|
||||
return iter(self.root)
|
||||
|
||||
def __getitem__(self, item):
|
||||
return self.root[item]
|
||||
|
|
@ -19,6 +19,7 @@ from remnawave.models import (
|
|||
RevokeUserRequestDto,
|
||||
GetSubscriptionRequestsResponseDto
|
||||
)
|
||||
from remnawave.models.users import GetUserSubscriptionRequestHistoryResponseDto
|
||||
from tests.utils import generate_email, generate_random_string
|
||||
|
||||
|
||||
|
|
@ -110,7 +111,7 @@ class TestUsersFetch:
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_all_users(self, remnawave):
|
||||
all_users = await remnawave.users.get_all_users_v2()
|
||||
all_users = await remnawave.users.get_all_users()
|
||||
assert isinstance(all_users, UsersResponseDto)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -173,12 +174,10 @@ class TestUsersFetch:
|
|||
"""Test fetching user subscription request history"""
|
||||
string_uuid = str(test_user.uuid)
|
||||
try:
|
||||
subscription_requests = await remnawave.users.get_subscription_requests(uuid=string_uuid)
|
||||
assert isinstance(subscription_requests, GetSubscriptionRequestsResponseDto)
|
||||
subscription_requests = await remnawave.users.get_user_subscription_request_history(uuid=string_uuid)
|
||||
assert isinstance(subscription_requests, GetUserSubscriptionRequestHistoryResponseDto)
|
||||
assert hasattr(subscription_requests, 'total')
|
||||
assert hasattr(subscription_requests, 'records')
|
||||
# Даже если записей нет, модель должна быть правильно сформирована
|
||||
# с пустым списком records и total=0
|
||||
except ApiError as e:
|
||||
# Этот блок должен срабатывать только если API вернуло ошибку
|
||||
# (404, 403 и т.д.), но не когда просто нет записей
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from typing import List
|
|||
import pytest
|
||||
import pytz
|
||||
|
||||
from remnawave.models import BulkResponseDto, UpdateUserFields
|
||||
from remnawave.models import BulkResponseDto, UpdateUserFields, BulkUpdateUsersRequestDto
|
||||
from tests.conftest import REMNAWAVE_USER_UUID
|
||||
|
||||
|
||||
|
|
@ -12,14 +12,15 @@ from tests.conftest import REMNAWAVE_USER_UUID
|
|||
async def test_users_bulk_actions(remnawave):
|
||||
expire_at = datetime.now(tz=pytz.utc) + timedelta(days=14)
|
||||
description = "TEST_DESCRIPTION"
|
||||
uuids: List[str] = [REMNAWAVE_USER_UUID]
|
||||
|
||||
bulk_update_users = await remnawave.users_bulk_actions.bulk_update_users(
|
||||
uuids=uuids,
|
||||
fields=UpdateUserFields(
|
||||
description=description,
|
||||
expire_at=expire_at,
|
||||
body=BulkUpdateUsersRequestDto(
|
||||
uuids=[REMNAWAVE_USER_UUID],
|
||||
fields=UpdateUserFields(
|
||||
expire_at=expire_at,
|
||||
description=description,
|
||||
),
|
||||
),
|
||||
)
|
||||
assert isinstance(bulk_update_users, BulkResponseDto)
|
||||
assert bulk_update_users.affected_rows == len(uuids)
|
||||
assert bulk_update_users.affected_rows > 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue