Fixed tests

This commit is contained in:
Alex Root Junior 2023-07-28 22:16:52 +03:00
parent 599f843268
commit 84d767fdfc
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
5 changed files with 24 additions and 28 deletions

View file

@ -18,7 +18,7 @@ from ..fsm.strategy import FSMStrategy
from ..methods import GetUpdates, TelegramMethod
from ..methods.base import TelegramType
from ..types import Update, User
from ..types.base import UNSET_TYPE, UNSET
from ..types.base import UNSET, UNSET_TYPE
from ..types.update import UpdateTypeLookupError
from ..utils.backoff import Backoff, BackoffConfig
from .event.bases import UNHANDLED, SkipHandler

View file

@ -129,7 +129,7 @@ class ChatActionSender:
def typing(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -146,7 +146,7 @@ class ChatActionSender:
def upload_photo(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -163,7 +163,7 @@ class ChatActionSender:
def record_video(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -180,7 +180,7 @@ class ChatActionSender:
def upload_video(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -197,7 +197,7 @@ class ChatActionSender:
def record_voice(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -214,7 +214,7 @@ class ChatActionSender:
def upload_voice(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -231,7 +231,7 @@ class ChatActionSender:
def upload_document(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -248,7 +248,7 @@ class ChatActionSender:
def choose_sticker(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -265,7 +265,7 @@ class ChatActionSender:
def find_location(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -282,7 +282,7 @@ class ChatActionSender:
def record_video_note(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":
@ -299,7 +299,7 @@ class ChatActionSender:
def upload_video_note(
cls,
chat_id: Union[int, str],
bot: Optional[Bot] = None,
bot: Bot,
interval: float = DEFAULT_INTERVAL,
initial_sleep: float = DEFAULT_INITIAL_SLEEP,
) -> "ChatActionSender":

View file

@ -4,7 +4,7 @@ import pytest
from _pytest.config import UsageError
from redis.asyncio.connection import parse_url as parse_redis_url
from aiogram import Bot, Dispatcher
from aiogram import Dispatcher
from aiogram.fsm.storage.memory import (
DisabledEventIsolation,
MemoryStorage,
@ -109,12 +109,7 @@ async def disabled_isolation():
@pytest.fixture()
def bot():
bot = MockedBot()
token = Bot.set_current(bot)
try:
yield bot
finally:
Bot.reset_current(token)
return MockedBot()
@pytest.fixture()

View file

@ -29,15 +29,17 @@ class TestBaseClassBasedHandler:
async def test_bot_from_context(self):
event = Update(update_id=42)
handler = MyHandler(event=event, key=42)
bot = Bot("42:TEST")
with pytest.raises(LookupError):
handler.bot
Bot.set_current(bot)
handler = MyHandler(event=event, key=42, bot=bot)
assert handler.bot == bot
async def test_bot_from_context_missing(self):
event = Update(update_id=42)
handler = MyHandler(event=event, key=42)
with pytest.raises(RuntimeError):
handler.bot
async def test_bot_from_data(self):
event = Update(update_id=42)
bot = Bot("42:TEST")

View file

@ -36,10 +36,9 @@ class TestChatActionSender:
"upload_video_note",
],
)
@pytest.mark.parametrize("pass_bot", [True, False])
async def test_factory(self, action: str, bot: MockedBot, pass_bot: bool):
async def test_factory(self, action: str, bot: MockedBot):
sender_factory = getattr(ChatActionSender, action)
sender = sender_factory(chat_id=42, bot=bot if pass_bot else None)
sender = sender_factory(chat_id=42, bot=bot)
assert isinstance(sender, ChatActionSender)
assert sender.action == action
assert sender.chat_id == 42