AIOG-T-49. User method get_profile_photos()

* method added
 * unit tests added
 * local import used to avoid circular reference

fixup! AIOG-T-49. User method get_profile_photos()
This commit is contained in:
Igor Sereda 2020-05-31 14:05:56 +03:00
parent 7cec70f94f
commit 5ce94e2309
2 changed files with 30 additions and 1 deletions

View file

@ -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)

View file

@ -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)