feat: тесты
This commit is contained in:
@@ -164,7 +164,7 @@ class Postgres(DatabaseBase):
|
||||
await self.session.execute(stmt)
|
||||
await self.session.flush()
|
||||
|
||||
async def get_creative(self, creative_id: uuid.UUID, user_id: uuid.UUID) -> domain.Creative | None:
|
||||
async def get_creative(self, user_id: uuid.UUID, creative_id: uuid.UUID) -> domain.Creative | None:
|
||||
stmt = (
|
||||
select(domain.Creative)
|
||||
.options(selectinload(domain.Creative.target_channel))
|
||||
|
||||
@@ -62,12 +62,10 @@ async def update_creative(
|
||||
@creatives_router.post('/{creative_id}/archive')
|
||||
async def archive_creative(
|
||||
creative_id: uuid.UUID,
|
||||
request: dto.ArchiveCreativeInput,
|
||||
current_user: Annotated[JWTPayload, Depends(dependencies.get_current_user)],
|
||||
) -> dto.CreativeOutput:
|
||||
return await dependencies.get_usecase().archive_creative(
|
||||
creative_id=creative_id,
|
||||
input=request,
|
||||
user_id=current_user.user_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ async def on_bot_added_to_chat(event: ChatMemberUpdated) -> None:
|
||||
if bot_removed:
|
||||
disconnect_input = dto.DisconnectTargetChanByTgIdInput(
|
||||
telegram_id=event.chat.id,
|
||||
user_telegram_id=event.from_user.id,
|
||||
)
|
||||
try:
|
||||
await usecase.disconnect_target_chan_by_tg_id(input=disconnect_input)
|
||||
|
||||
@@ -43,6 +43,11 @@ class UpdateCreativeInput(pydantic.BaseModel):
|
||||
text: str | None = None
|
||||
|
||||
|
||||
class ArchiveCreativeInput(pydantic.BaseModel):
|
||||
creative_id: uuid.UUID
|
||||
user_id: uuid.UUID
|
||||
|
||||
|
||||
class DeleteCreativeInput(pydantic.BaseModel):
|
||||
creative_id: uuid.UUID
|
||||
user_id: uuid.UUID
|
||||
|
||||
@@ -46,7 +46,7 @@ class DisconnectTargetChanInput(pydantic.BaseModel):
|
||||
|
||||
class DisconnectTargetChanByTgIdInput(pydantic.BaseModel):
|
||||
telegram_id: int
|
||||
user_id: uuid.UUID
|
||||
user_telegram_id: int
|
||||
|
||||
|
||||
class UpdateTargetChanPermissionsInput(pydantic.BaseModel):
|
||||
|
||||
@@ -10,8 +10,14 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def disconnect_target_chan_by_tg_id(self: 'Usecase', input: dto.DisconnectTargetChanByTgIdInput) -> None:
|
||||
# Получаем user_id по telegram_id
|
||||
user = await self.database.get_user(telegram_id=input.user_telegram_id)
|
||||
if not user:
|
||||
log.warning(f'User with telegram_id {input.user_telegram_id} not found when disconnecting channel')
|
||||
return
|
||||
|
||||
async with self.database.transaction():
|
||||
channel = await self.database.get_target_channel(input.user_id, telegram_id=input.telegram_id)
|
||||
channel = await self.database.get_target_channel(user.id, telegram_id=input.telegram_id)
|
||||
if not channel:
|
||||
log.warning(f'Target channel {input.telegram_id} not found')
|
||||
raise domain.TargetChannelNotFound()
|
||||
|
||||
@@ -16,8 +16,14 @@ async def update_target_chan_permissions(self: 'Usecase', input: dto.UpdateTarge
|
||||
if not input.permissions.can_restrict_members:
|
||||
missing_permissions.append('Управление пользователями')
|
||||
|
||||
# Получаем user_id по telegram_id
|
||||
user = await self.database.get_user(telegram_id=input.user_telegram_id)
|
||||
if not user:
|
||||
log.warning(f'User with telegram_id {input.user_telegram_id} not found when updating channel permissions')
|
||||
return
|
||||
|
||||
async with self.database.transaction():
|
||||
channel = await self.database.get_target_channel(user_id, telegram_id=input.telegram_id)
|
||||
channel = await self.database.get_target_channel(user.id, telegram_id=input.telegram_id)
|
||||
if not channel:
|
||||
log.warning(f'Target channel {input.telegram_id} not found when permissions changed')
|
||||
raise domain.TargetChannelNotFound()
|
||||
|
||||
Reference in New Issue
Block a user