Reworked defaults

This commit is contained in:
JRoot Junior 2024-01-03 00:02:41 +02:00
parent 1281bf551a
commit 47bd869bbd
No known key found for this signature in database
GPG key ID: 738964250D5FF6E2
139 changed files with 591 additions and 531 deletions

View file

@ -12,6 +12,7 @@ from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.client.telegram import TelegramAPIServer
from aiogram.methods import GetFile, GetMe
from aiogram.types import File, PhotoSize
from tests.deprecated import check_deprecated
from tests.mocked_bot import MockedBot
@ -41,6 +42,13 @@ class TestBot:
assert isinstance(bot.session, AiohttpSession)
assert bot.id == 42
def test_init_default(self):
with check_deprecated(
max_version="3.5.0",
exception=TypeError,
):
bot = Bot(token="42:Test", parse_mode="HTML")
def test_hashable(self):
bot = Bot("42:TEST")
assert hash(bot) == hash("42:TEST")

View file

@ -1,5 +1,5 @@
import asyncio
from typing import Any, AsyncContextManager, AsyncGenerator, AsyncIterable, Dict, List
from typing import Any, AsyncContextManager, AsyncGenerator, AsyncIterable, Dict, List, Union
from unittest.mock import AsyncMock, patch
import aiohttp_socks
@ -8,6 +8,7 @@ from aiohttp import ClientError
from aresponses import ResponsesMockServer
from aiogram import Bot
from aiogram.client.default import Default
from aiogram.client.session import aiohttp
from aiogram.client.session.aiohttp import AiohttpSession
from aiogram.exceptions import TelegramNetworkError
@ -106,7 +107,7 @@ class TestAiohttpSession:
str_: str
int_: int
bool_: bool
unset_: str = UNSET_PARSE_MODE
unset_: Union[str, Default] = Default("parse_mode")
null_: None
list_: List[str]
dict_: Dict[str, Any]
@ -118,7 +119,7 @@ class TestAiohttpSession:
str_="value",
int_=42,
bool_=True,
unset_=UNSET_PARSE_MODE,
unset_=Default("parse_mode"),
null_=None,
list_=["foo"],
dict_={"bar": "baz"},

View file

@ -7,6 +7,7 @@ import pytest
from pytz import utc
from aiogram import Bot
from aiogram.client.default import Default, DefaultBotProperties
from aiogram.client.session.base import BaseSession, TelegramType
from aiogram.client.telegram import PRODUCTION, TelegramAPIServer
from aiogram.enums import ChatType, ParseMode, TopicIconColor
@ -125,15 +126,18 @@ class TestBaseSession:
def test_prepare_value_defaults_replace(self):
bot = MockedBot(
parse_mode=ParseMode.HTML,
protect_content=True,
disable_web_page_preview=True,
default=DefaultBotProperties(
parse_mode=ParseMode.HTML,
protect_content=True,
link_preview_is_disabled=True,
)
)
assert bot.session.prepare_value(UNSET_PARSE_MODE, bot=bot, files={}) == "HTML"
assert bot.session.prepare_value(Default("parse_mode"), bot=bot, files={}) == "HTML"
assert (
bot.session.prepare_value(UNSET_DISABLE_WEB_PAGE_PREVIEW, bot=bot, files={}) == "true"
bot.session.prepare_value(Default("link_preview_is_disabled"), bot=bot, files={})
== "true"
)
assert bot.session.prepare_value(UNSET_PROTECT_CONTENT, bot=bot, files={}) == "true"
assert bot.session.prepare_value(Default("protect_content"), bot=bot, files={}) == "true"
def test_prepare_value_defaults_unset(self):
bot = MockedBot()