diff --git a/aiogram/api/types/user.py b/aiogram/api/types/user.py index b6500ff6..273bba38 100644 --- a/aiogram/api/types/user.py +++ b/aiogram/api/types/user.py @@ -1,11 +1,15 @@ from __future__ import annotations +import typing from typing import Optional from ...utils import markdown from .base import TelegramObject from .parse_mode import ParseMode +if typing.TYPE_CHECKING: + from ..methods import GetUserProfilePhotos # pragma: no cover + class User(TelegramObject): """ @@ -70,3 +74,19 @@ class User(TelegramObject): if as_html: return markdown.hlink(name, self.url) return markdown.link(name, self.url) + + def get_profile_photos( + self, offset: Optional[int] = None, limit: Optional[int] = None + ) -> GetUserProfilePhotos: + """ + Alias for bot method get_user_profile_photos. + + Source: https://core.telegram.org/bots/api#getuserprofilephotos + + :param offset: Sequential number of the first photo to be returned. By default, all photos are returned. + :param limit: Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100. + :return: GetUserProfilePhotos method object. + """ + from aiogram.api.methods import GetUserProfilePhotos + + return GetUserProfilePhotos(user_id=self.id, offset=offset, limit=limit) diff --git a/tests/test_api/test_types/test_user.py b/tests/test_api/test_types/test_user.py index 9a89b05b..9d18a609 100644 --- a/tests/test_api/test_types/test_user.py +++ b/tests/test_api/test_types/test_user.py @@ -1,9 +1,11 @@ +from asyncio import Future from unittest import mock -from unittest.mock import PropertyMock, _patch +from unittest.mock import PropertyMock, _patch, patch import pytest from aiogram import Bot +from aiogram.api.methods import GetUserProfilePhotos from aiogram.api.types import User @@ -65,3 +67,10 @@ class TestUser: user = User(id=42, is_bot=False, first_name="User", last_name="Name") mock_bot_property.return_value = Bot(token="42:TEST", parse_mode=bot_parse_mode) assert user.get_mention(name, as_html) == expected_mention + + @pytest.mark.parametrize( + "user_id, offset, limit", [[1, 123, 456], [-999, 0, None], [42, None, None]], + ) + def test_get_profile_photos(self, user_id: int, offset: int, limit: int): + user = User(id=user_id, is_bot=False, first_name="User", last_name="Name") + assert isinstance(user.get_profile_photos(offset, limit), GetUserProfilePhotos)