Merge pull request #297 from aiogram/feature/bot_id

#296 Get bot's user_id without get_me
This commit is contained in:
Alex Root Junior 2020-04-26 00:24:50 +03:00 committed by GitHub
commit 61cfb8e99a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View file

@ -61,6 +61,7 @@ class BaseBot:
api.check_token(token)
self._token = None
self.__token = token
self.id = int(token.split(sep=':')[0])
self.proxy = proxy
self.proxy_auth = proxy_auth

View file

@ -2,7 +2,8 @@ import aresponses
from aiogram import Bot
TOKEN = '123456789:AABBCCDDEEFFaabbccddeeff-1234567890'
BOT_ID = 123456789
TOKEN = f'{BOT_ID}:AABBCCDDEEFFaabbccddeeff-1234567890'
class FakeTelegram(aresponses.ResponsesMockServer):

View file

@ -1,7 +1,7 @@
import pytest
from aiogram import Bot, types
from . import FakeTelegram, TOKEN
from . import FakeTelegram, TOKEN, BOT_ID
pytestmark = pytest.mark.asyncio
@ -525,3 +525,9 @@ async def test_set_sticker_set_thumb(bot: Bot, event_loop):
result = await bot.set_sticker_set_thumb(name='test', user_id=123456789, thumb='file_id')
assert isinstance(result, bool)
assert result is True
async def test_bot_id(bot: Bot):
""" Check getting id from token. """
bot = Bot(TOKEN)
assert bot.id == BOT_ID # BOT_ID is a correct id from TOKEN