mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 02:03:04 +00:00
Reworked request builder (#1142)
* Reworked request builder * Added more default values * Update tests * Fixed timestamp * Fixed Py3.8 support * Describe changes
This commit is contained in:
parent
924a83966d
commit
fea1b7b0a3
300 changed files with 1003 additions and 3448 deletions
|
|
@ -1,61 +1,27 @@
|
|||
from typing import Dict, Optional
|
||||
from unittest.mock import sentinel
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram import Bot
|
||||
from aiogram.methods.base import prepare_parse_mode
|
||||
from aiogram.methods import GetMe, TelegramMethod
|
||||
from aiogram.types import User
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
class TestPrepareFile:
|
||||
# TODO: Add tests
|
||||
pass
|
||||
|
||||
|
||||
class TestPrepareInputMedia:
|
||||
# TODO: Add tests
|
||||
pass
|
||||
|
||||
|
||||
class TestPrepareMediaFile:
|
||||
# TODO: Add tests
|
||||
pass
|
||||
|
||||
|
||||
class TestPrepareParseMode:
|
||||
class TestTelegramMethodRemoveUnset:
|
||||
@pytest.mark.parametrize(
|
||||
"parse_mode,data,result",
|
||||
"values,names",
|
||||
[
|
||||
[None, {}, None],
|
||||
["HTML", {}, "HTML"],
|
||||
["Markdown", {}, "Markdown"],
|
||||
[None, {"parse_mode": "HTML"}, "HTML"],
|
||||
["HTML", {"parse_mode": "HTML"}, "HTML"],
|
||||
["Markdown", {"parse_mode": "HTML"}, "HTML"],
|
||||
[{}, set()],
|
||||
[{"foo": "bar"}, {"foo"}],
|
||||
[{"foo": "bar", "baz": sentinel.DEFAULT}, {"foo"}],
|
||||
],
|
||||
)
|
||||
async def test_default_parse_mode(
|
||||
self, bot: MockedBot, parse_mode: str, data: Dict[str, str], result: Optional[str]
|
||||
):
|
||||
async with Bot(token="42:TEST", parse_mode=parse_mode).context() as bot:
|
||||
assert bot.parse_mode == parse_mode
|
||||
prepare_parse_mode(bot, data)
|
||||
assert data.get("parse_mode") == result
|
||||
def test_remove_unset(self, values, names):
|
||||
validated = TelegramMethod.remove_unset(values)
|
||||
assert set(validated.keys()) == names
|
||||
|
||||
async def test_list(self):
|
||||
data = [{}] * 2
|
||||
data.append({"parse_mode": "HTML"})
|
||||
bot = Bot(token="42:TEST", parse_mode="Markdown")
|
||||
prepare_parse_mode(bot, data)
|
||||
|
||||
assert isinstance(data, list)
|
||||
assert len(data) == 3
|
||||
assert all("parse_mode" in item for item in data)
|
||||
assert data[0]["parse_mode"] == "Markdown"
|
||||
assert data[1]["parse_mode"] == "Markdown"
|
||||
assert data[2]["parse_mode"] == "HTML"
|
||||
|
||||
def test_bot_not_in_context(self, bot: MockedBot):
|
||||
data = {}
|
||||
prepare_parse_mode(bot, data)
|
||||
assert data["parse_mode"] is None
|
||||
class TestTelegramMethodCall:
|
||||
async def test_async_emit(self, bot: MockedBot):
|
||||
bot.add_result_for(GetMe, ok=True, result=User(id=42, is_bot=True, first_name="Test"))
|
||||
assert isinstance(await GetMe(), User)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue