2019-11-18 22:22:46 +02:00
|
|
|
import pytest
|
2019-11-19 00:05:19 +02:00
|
|
|
|
2019-11-18 22:22:46 +02:00
|
|
|
from aiogram.api.methods import Request, SendContact
|
2019-11-19 00:04:02 +02:00
|
|
|
from aiogram.api.types import Chat, Contact, Message
|
2020-07-03 17:08:37 +05:00
|
|
|
from tests.factories.message import MessageFactory
|
2019-11-18 22:22:46 +02:00
|
|
|
from tests.mocked_bot import MockedBot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestSendContact:
|
|
|
|
|
@pytest.mark.asyncio
|
2020-07-03 16:08:31 +05:00
|
|
|
async def test_method(self, bot: MockedBot, private_chat: Chat):
|
2019-11-19 00:04:02 +02:00
|
|
|
prepare_result = bot.add_result_for(
|
|
|
|
|
SendContact,
|
|
|
|
|
ok=True,
|
2020-07-03 17:08:37 +05:00
|
|
|
result=MessageFactory(
|
2019-11-19 00:04:02 +02:00
|
|
|
contact=Contact(phone_number="911", first_name="911"),
|
|
|
|
|
),
|
2019-11-18 22:22:46 +02:00
|
|
|
)
|
2019-11-19 00:04:02 +02:00
|
|
|
|
2020-07-03 16:15:37 +05:00
|
|
|
response: Message = await SendContact(
|
|
|
|
|
chat_id=private_chat.id, phone_number="911", first_name="911"
|
|
|
|
|
)
|
2019-11-18 22:22:46 +02:00
|
|
|
request: Request = bot.get_request()
|
|
|
|
|
assert request.method == "sendContact"
|
|
|
|
|
assert response == prepare_result.result
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
2020-07-03 16:08:31 +05:00
|
|
|
async def test_bot_method(self, bot: MockedBot, private_chat: Chat):
|
2019-11-19 00:05:19 +02:00
|
|
|
prepare_result = bot.add_result_for(
|
|
|
|
|
SendContact,
|
|
|
|
|
ok=True,
|
2020-07-03 17:08:37 +05:00
|
|
|
result=MessageFactory(
|
2019-11-19 00:04:02 +02:00
|
|
|
contact=Contact(phone_number="911", first_name="911"),
|
2019-11-19 00:05:19 +02:00
|
|
|
),
|
|
|
|
|
)
|
2019-11-18 22:22:46 +02:00
|
|
|
|
2019-11-19 00:05:19 +02:00
|
|
|
response: Message = await bot.send_contact(
|
2020-07-03 16:08:31 +05:00
|
|
|
chat_id=private_chat.id, phone_number="911", first_name="911"
|
2019-11-19 00:05:19 +02:00
|
|
|
)
|
2019-11-18 22:22:46 +02:00
|
|
|
request: Request = bot.get_request()
|
|
|
|
|
assert request.method == "sendContact"
|
|
|
|
|
assert response == prepare_result.result
|