mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-11 18:01:04 +00:00
Add token validation util, fix deepcopy of sessions and make bot hashable and comparable
This commit is contained in:
parent
9adc2f91bd
commit
c674b5547b
11 changed files with 223 additions and 41 deletions
|
|
@ -1,3 +1,5 @@
|
|||
import copy
|
||||
|
||||
import pytest
|
||||
from asynctest import CoroutineMock, patch
|
||||
|
||||
|
|
@ -9,12 +11,21 @@ from aiogram.api.methods import GetMe
|
|||
|
||||
class TestBaseBot:
|
||||
def test_init(self):
|
||||
base_bot = BaseBot("TOKEN")
|
||||
base_bot = BaseBot("42:TEST")
|
||||
assert isinstance(base_bot.session, AiohttpSession)
|
||||
assert base_bot.id == 42
|
||||
|
||||
def test_hashable(self):
|
||||
base_bot = BaseBot("42:TEST")
|
||||
assert hash(base_bot) == hash("42:TEST")
|
||||
|
||||
def test_equals(self):
|
||||
base_bot = BaseBot("42:TEST")
|
||||
assert base_bot == BaseBot("42:TEST")
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_emit(self):
|
||||
base_bot = BaseBot("TOKEN")
|
||||
base_bot = BaseBot("42:TEST")
|
||||
|
||||
method = GetMe()
|
||||
|
||||
|
|
@ -23,11 +34,11 @@ class TestBaseBot:
|
|||
new_callable=CoroutineMock,
|
||||
) as mocked_make_request:
|
||||
await base_bot.emit(method)
|
||||
mocked_make_request.assert_awaited_with("TOKEN", method)
|
||||
mocked_make_request.assert_awaited_with("42:TEST", method)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close(self):
|
||||
base_bot = BaseBot("TOKEN", session=AiohttpSession())
|
||||
base_bot = BaseBot("42:TEST", session=AiohttpSession())
|
||||
await base_bot.session.create_session()
|
||||
|
||||
with patch(
|
||||
|
|
@ -41,6 +52,6 @@ class TestBaseBot:
|
|||
with patch(
|
||||
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
|
||||
) as mocked_close:
|
||||
async with BaseBot("TOKEN", session=AiohttpSession()) as bot:
|
||||
async with BaseBot("42:TEST", session=AiohttpSession()) as bot:
|
||||
assert isinstance(bot, BaseBot)
|
||||
mocked_close.assert_awaited()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue