aiogram/tests/test_api/test_methods/test_send_contact.py

43 lines
1.4 KiB
Python
Raw Normal View History

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
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
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,
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
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,
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(
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