refator: use MessageFactory instead of Message, just a part

This commit is contained in:
Egor 2020-07-03 17:08:55 +05:00
parent 0e005f661c
commit 5a561ea5a3
13 changed files with 37 additions and 78 deletions

View file

@ -11,11 +11,7 @@ from tests.mocked_bot import MockedBot
class TestEditMessageCaption:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
EditMessageCaption,
ok=True,
result=MessageFactory(),
)
prepare_result = bot.add_result_for(EditMessageCaption, ok=True, result=MessageFactory())
response: Union[Message, bool] = await EditMessageCaption()
request: Request = bot.get_request()
@ -24,11 +20,7 @@ class TestEditMessageCaption:
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
EditMessageCaption,
ok=True,
result=MessageFactory(),
)
prepare_result = bot.add_result_for(EditMessageCaption, ok=True, result=MessageFactory())
response: Union[Message, bool] = await bot.edit_message_caption()
request: Request = bot.get_request()

View file

@ -11,12 +11,7 @@ from tests.mocked_bot import MockedBot
class TestForwardMessage:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot, private_chat: Chat):
prepare_result = bot.add_result_for(
ForwardMessage,
ok=True,
result=MessageFactory(
),
)
prepare_result = bot.add_result_for(ForwardMessage, ok=True, result=MessageFactory())
response: Message = await ForwardMessage(
chat_id=private_chat.id, from_chat_id=private_chat.id, message_id=42
@ -28,12 +23,7 @@ class TestForwardMessage:
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot, private_chat: Chat):
prepare_result = bot.add_result_for(
ForwardMessage,
ok=True,
result=MessageFactory(
),
)
prepare_result = bot.add_result_for(ForwardMessage, ok=True, result=MessageFactory())
response: Message = await bot.forward_message(
chat_id=private_chat.id, from_chat_id=private_chat.id, message_id=42

View file

@ -17,7 +17,7 @@ class TestSendAnimation:
result=MessageFactory(
animation=Animation(
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
),
)
),
)
@ -34,7 +34,7 @@ class TestSendAnimation:
result=MessageFactory(
animation=Animation(
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
),
)
),
)

View file

@ -15,7 +15,7 @@ class TestSendAudio:
SendAudio,
ok=True,
result=MessageFactory(
audio=Audio(file_id="file id", duration=42, file_unique_id="file id"),
audio=Audio(file_id="file id", duration=42, file_unique_id="file id")
),
)
@ -30,7 +30,7 @@ class TestSendAudio:
SendAudio,
ok=True,
result=MessageFactory(
audio=Audio(file_id="file id", duration=42, file_unique_id="file id"),
audio=Audio(file_id="file id", duration=42, file_unique_id="file id")
),
)

View file

@ -12,9 +12,7 @@ class TestSendContact:
prepare_result = bot.add_result_for(
SendContact,
ok=True,
result=MessageFactory(
contact=Contact(phone_number="911", first_name="911"),
),
result=MessageFactory(contact=Contact(phone_number="911", first_name="911")),
)
response: Message = await SendContact(
@ -29,9 +27,7 @@ class TestSendContact:
prepare_result = bot.add_result_for(
SendContact,
ok=True,
result=MessageFactory(
contact=Contact(phone_number="911", first_name="911"),
),
result=MessageFactory(contact=Contact(phone_number="911", first_name="911")),
)
response: Message = await bot.send_contact(

View file

@ -14,9 +14,7 @@ class TestSendDocument:
prepare_result = bot.add_result_for(
SendDocument,
ok=True,
result=MessageFactory(
document=Document(file_id="file id", file_unique_id="file id"),
),
result=MessageFactory(document=Document(file_id="file id", file_unique_id="file id")),
)
response: Message = await SendDocument(chat_id=private_chat.id, document="file id")
@ -29,9 +27,7 @@ class TestSendDocument:
prepare_result = bot.add_result_for(
SendDocument,
ok=True,
result=MessageFactory(
document=Document(file_id="file id", file_unique_id="file id"),
),
result=MessageFactory(document=Document(file_id="file id", file_unique_id="file id")),
)
response: Message = await bot.send_document(chat_id=private_chat.id, document="file id")

View file

@ -21,7 +21,7 @@ class TestSendGame:
photo=[
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
],
),
)
),
)
@ -42,7 +42,7 @@ class TestSendGame:
photo=[
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
],
),
)
),
)

View file

@ -19,7 +19,7 @@ class TestSendInvoice:
start_parameter="brilliant",
currency="BTC",
total_amount=1,
),
)
),
)
@ -49,7 +49,7 @@ class TestSendInvoice:
start_parameter="brilliant",
currency="BTC",
total_amount=1,
),
)
),
)

View file

@ -14,9 +14,7 @@ class TestSendLocation:
prepare_result = bot.add_result_for(
SendLocation,
ok=True,
result=MessageFactory(
location=Location(longitude=3.14, latitude=3.14),
),
result=MessageFactory(location=Location(longitude=3.14, latitude=3.14)),
)
response: Message = await SendLocation(
@ -31,9 +29,7 @@ class TestSendLocation:
prepare_result = bot.add_result_for(
SendLocation,
ok=True,
result=MessageFactory(
location=Location(longitude=3.14, latitude=3.14),
),
result=MessageFactory(location=Location(longitude=3.14, latitude=3.14)),
)
response: Message = await bot.send_location(

View file

@ -11,12 +11,7 @@ from tests.mocked_bot import MockedBot
class TestSendMessage:
@pytest.mark.asyncio
async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
SendMessage,
ok=True,
result=MessageFactory(
),
)
prepare_result = bot.add_result_for(SendMessage, ok=True, result=MessageFactory())
response: Message = await SendMessage(chat_id=42, text="test")
request: Request = bot.get_request()
@ -25,12 +20,7 @@ class TestSendMessage:
@pytest.mark.asyncio
async def test_bot_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(
SendMessage,
ok=True,
result=MessageFactory(
),
)
prepare_result = bot.add_result_for(SendMessage, ok=True, result=MessageFactory())
response: Message = await bot.send_message(chat_id=42, text="test")
request: Request = bot.get_request()

View file

@ -13,9 +13,7 @@ class TestSendPhoto:
SendPhoto,
ok=True,
result=MessageFactory(
photo=[
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
],
photo=[PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")]
),
)
@ -30,9 +28,7 @@ class TestSendPhoto:
SendPhoto,
ok=True,
result=MessageFactory(
photo=[
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
],
photo=[PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")]
),
)

View file

@ -30,12 +30,16 @@ class TestSendPoll:
total_voter_count=0,
correct_option_id=0,
),
chat=private_chat
chat=private_chat,
),
)
response: Message = await SendPoll(
chat_id=private_chat.id, 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"
@ -61,12 +65,16 @@ class TestSendPoll:
total_voter_count=0,
correct_option_id=0,
),
chat=private_chat
chat=private_chat,
),
)
response: Message = await bot.send_poll(
chat_id=private_chat.id, 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"

View file

@ -15,8 +15,7 @@ class MyHandler(MessageHandler):
class TestClassBasedMessageHandler:
@pytest.mark.asyncio
async def test_message_handler(self):
event = MessageFactory(
)
event = MessageFactory()
handler = MyHandler(event=event)
assert handler.from_user == event.from_user
@ -31,9 +30,7 @@ class HandlerWithCommand(MessageHandlerCommandMixin, MessageHandler):
class TestBaseMessageHandlerCommandMixin:
def test_command_accessible(self):
handler = HandlerWithCommand(
MessageFactory(
text="/test args",
),
MessageFactory(text="/test args"),
command=CommandObject(prefix="/", command="command", args="args"),
)
@ -41,8 +38,6 @@ class TestBaseMessageHandlerCommandMixin:
assert handler.command.command == "command"
def test_command_not_presented(self):
handler = HandlerWithCommand(
MessageFactory()
)
handler = HandlerWithCommand(MessageFactory())
assert handler.command is None