Rework polling and start covering

This commit is contained in:
Alex Root Junior 2019-12-10 01:14:58 +02:00
parent 38c725db46
commit db397e3a05
6 changed files with 84 additions and 12 deletions

View file

@ -48,10 +48,16 @@ class TestBaseBot:
mocked_close.assert_awaited()
@pytest.mark.asyncio
async def test_context_manager(self):
@pytest.mark.parametrize("close", [True, False])
async def test_context_manager(self, close: bool):
with patch(
"aiogram.api.client.session.aiohttp.AiohttpSession.close", new_callable=CoroutineMock
) as mocked_close:
async with BaseBot("42:TEST", session=AiohttpSession()) as bot:
async with BaseBot("42:TEST", session=AiohttpSession()).context(
auto_close=close
) as bot:
assert isinstance(bot, BaseBot)
mocked_close.assert_awaited()
if close:
mocked_close.assert_awaited()
else:
mocked_close.assert_not_awaited()

View file

@ -0,0 +1,20 @@
import pytest
from aiogram.api.types import User
class TestUser:
@pytest.mark.parametrize(
"first,last,result",
[
["User", None, "User"],
["", None, ""],
[" ", None, " "],
["User", "Name", "User Name"],
["User", " ", "User "],
[" ", " ", " "],
],
)
def test_full_name(self, first: str, last: str, result: bool):
user = User(id=42, is_bot=False, first_name=first, last_name=last)
assert user.full_name == result