refator: use MessageFactory instead of Message, just a part

This commit is contained in:
Egor 2020-07-03 17:08:37 +05:00
parent e883366dc6
commit 0e005f661c
15 changed files with 54 additions and 143 deletions

View file

@ -4,18 +4,18 @@ import pytest
from aiogram.api.methods import Request, SendPoll
from aiogram.api.types import Chat, Message, Poll, PollOption
from tests.conftest import private_chat
from tests.factories.message import MessageFactory
from tests.mocked_bot import MockedBot
class TestSendPoll:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
async def test_method(self, bot: MockedBot, private_chat: Chat):
prepare_result = bot.add_result_for(
SendPoll,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
result=MessageFactory(
poll=Poll(
id="QA",
question="Q",
@ -30,25 +30,23 @@ class TestSendPoll:
total_voter_count=0,
correct_option_id=0,
),
chat=Chat(id=42, type="private"),
chat=private_chat
),
)
response: Message = await SendPoll(
chat_id=42, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz"
chat_id=private_chat.id, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz"
)
request: Request = bot.get_request()
assert request.method == "sendPoll"
assert response == prepare_result.result
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
async def test_bot_method(self, bot: MockedBot, private_chat: Chat):
prepare_result = bot.add_result_for(
SendPoll,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
result=MessageFactory(
poll=Poll(
id="QA",
question="Q",
@ -63,12 +61,12 @@ class TestSendPoll:
total_voter_count=0,
correct_option_id=0,
),
chat=Chat(id=42, type="private"),
chat=private_chat
),
)
response: Message = await bot.send_poll(
chat_id=42, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz"
chat_id=private_chat.id, question="Q?", options=["A", "B"], correct_option_id=0, type="quiz"
)
request: Request = bot.get_request()
assert request.method == "sendPoll"