aiogram/tests/test_api/test_methods/test_answer_inline_query.py
Alex Root Junior f4ce4431f9
Migrate to hatchling (#1095)
* Migrate to hatchling instead of poetry, ruff instead of flake8

* Migrate to hatchling instead of poetry, ruff instead of flake8

* Update tests suite

* venv?

* -m venv?

* Change dependencies

* Remove venv

* Change mypy config

* Added changelog

* Mark uvloop incompatible with pypy

* Update release script

* Use internal caching for dependencies

* Re-disable cov branches

* Added contributing guide
2023-01-12 02:49:58 +02:00

61 lines
2.3 KiB
Python

from aiogram import Bot
from aiogram.methods import AnswerInlineQuery, Request
from aiogram.types import (
InlineQueryResult,
InlineQueryResultPhoto,
InputTextMessageContent,
)
from tests.mocked_bot import MockedBot
class TestAnswerInlineQuery:
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)
response: bool = await AnswerInlineQuery(
inline_query_id="query id", results=[InlineQueryResult()]
)
request: Request = bot.get_request()
assert request.method == "answerInlineQuery"
assert response == prepare_result.result
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(AnswerInlineQuery, ok=True, result=True)
response: bool = await bot.answer_inline_query(
inline_query_id="query id", results=[InlineQueryResult()]
)
request: Request = bot.get_request()
assert request.method == "answerInlineQuery"
assert response == prepare_result.result
def test_parse_mode(self, bot: MockedBot):
query = AnswerInlineQuery(
inline_query_id="query id",
results=[InlineQueryResultPhoto(id="result id", photo_url="photo", thumb_url="thumb")],
)
request = query.build_request(bot)
assert request.data["results"][0]["parse_mode"] is None
new_bot = Bot(token="42:TEST", parse_mode="HTML")
request = query.build_request(new_bot)
assert request.data["results"][0]["parse_mode"] == "HTML"
def test_parse_mode_input_message_content(self, bot: MockedBot):
query = AnswerInlineQuery(
inline_query_id="query id",
results=[
InlineQueryResultPhoto(
id="result id",
photo_url="photo",
thumb_url="thumb",
input_message_content=InputTextMessageContent(message_text="test"),
)
],
)
request = query.build_request(bot)
assert request.data["results"][0]["input_message_content"]["parse_mode"] is None
new_bot = Bot(token="42:TEST", parse_mode="HTML")
request = query.build_request(new_bot)
assert request.data["results"][0]["input_message_content"]["parse_mode"] == "HTML"