mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
refator: use MessageFactory instead of Message, just a part
This commit is contained in:
parent
e883366dc6
commit
0e005f661c
15 changed files with 54 additions and 143 deletions
|
|
@ -17,7 +17,7 @@ class MessageFactory(factory.Factory):
|
||||||
chat = factory.SubFactory(ChatFactory)
|
chat = factory.SubFactory(ChatFactory)
|
||||||
text = factory.Sequence(lambda n: f"Message text #{n}")
|
text = factory.Sequence(lambda n: f"Message text #{n}")
|
||||||
|
|
||||||
date = factory.LazyFunction(lambda _: datetime.now().toordinal())
|
date = factory.LazyFunction(lambda: datetime.now().toordinal())
|
||||||
|
|
||||||
def __new__(cls, *args, **kwargs) -> "MessageFactory.Meta.model":
|
def __new__(cls, *args, **kwargs) -> "MessageFactory.Meta.model":
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import datetime
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import EditMessageCaption, Request
|
from aiogram.api.methods import EditMessageCaption, Request
|
||||||
from aiogram.api.types import Message
|
from aiogram.api.types import Message
|
||||||
from tests.factories.chat import ChatFactory
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,9 +14,7 @@ class TestEditMessageCaption:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
EditMessageCaption,
|
EditMessageCaption,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(),
|
||||||
message_id=42, date=datetime.datetime.now(), text="text", chat=ChatFactory(),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Union[Message, bool] = await EditMessageCaption()
|
response: Union[Message, bool] = await EditMessageCaption()
|
||||||
|
|
@ -30,9 +27,7 @@ class TestEditMessageCaption:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
EditMessageCaption,
|
EditMessageCaption,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(),
|
||||||
message_id=42, date=datetime.datetime.now(), text="text", chat=ChatFactory(),
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Union[Message, bool] = await bot.edit_message_caption()
|
response: Union[Message, bool] = await bot.edit_message_caption()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import ForwardMessage, Request
|
from aiogram.api.methods import ForwardMessage, Request
|
||||||
from aiogram.api.types import Chat, Message
|
from aiogram.api.types import Chat, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,8 +14,7 @@ class TestForwardMessage:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
ForwardMessage,
|
ForwardMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42, date=datetime.datetime.now(), chat=private_chat, text="text",
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -31,8 +31,7 @@ class TestForwardMessage:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
ForwardMessage,
|
ForwardMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42, date=datetime.datetime.now(), chat=private_chat, text="text",
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendAnimation
|
from aiogram.api.methods import Request, SendAnimation
|
||||||
from aiogram.api.types import Animation, Chat, Message
|
from aiogram.api.types import Animation, Chat, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,13 +14,10 @@ class TestSendAnimation:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendAnimation,
|
SendAnimation,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
animation=Animation(
|
animation=Animation(
|
||||||
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
|
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,13 +31,10 @@ class TestSendAnimation:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendAnimation,
|
SendAnimation,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
animation=Animation(
|
animation=Animation(
|
||||||
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
|
file_id="file id", width=42, height=42, duration=0, file_unique_id="file id"
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendAudio
|
from aiogram.api.methods import Request, SendAudio
|
||||||
from aiogram.api.types import Audio, Chat, Message
|
from aiogram.api.types import Audio, Chat, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +14,8 @@ class TestSendAudio:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendAudio,
|
SendAudio,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
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"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -31,11 +29,8 @@ class TestSendAudio:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendAudio,
|
SendAudio,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
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"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import datetime
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendContact
|
from aiogram.api.methods import Request, SendContact
|
||||||
from aiogram.api.types import Chat, Contact, Message
|
from aiogram.api.types import Chat, Contact, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +12,8 @@ class TestSendContact:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendContact,
|
SendContact,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
contact=Contact(phone_number="911", first_name="911"),
|
contact=Contact(phone_number="911", first_name="911"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,11 +29,8 @@ class TestSendContact:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendContact,
|
SendContact,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
contact=Contact(phone_number="911", first_name="911"),
|
contact=Contact(phone_number="911", first_name="911"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendDocument
|
from aiogram.api.methods import Request, SendDocument
|
||||||
from aiogram.api.types import Chat, Document, Message
|
from aiogram.api.types import Chat, Document, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +14,8 @@ class TestSendDocument:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendDocument,
|
SendDocument,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
document=Document(file_id="file id", file_unique_id="file id"),
|
document=Document(file_id="file id", file_unique_id="file id"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -31,11 +29,8 @@ class TestSendDocument:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendDocument,
|
SendDocument,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
document=Document(file_id="file id", file_unique_id="file id"),
|
document=Document(file_id="file id", file_unique_id="file id"),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendGame
|
from aiogram.api.methods import Request, SendGame
|
||||||
from aiogram.api.types import Chat, Game, Message, PhotoSize
|
from aiogram.api.types import Chat, Game, Message, PhotoSize
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,9 +14,7 @@ class TestSendGame:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendGame,
|
SendGame,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
game=Game(
|
game=Game(
|
||||||
title="title",
|
title="title",
|
||||||
description="description",
|
description="description",
|
||||||
|
|
@ -23,7 +22,6 @@ class TestSendGame:
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -37,9 +35,7 @@ class TestSendGame:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendGame,
|
SendGame,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
game=Game(
|
game=Game(
|
||||||
title="title",
|
title="title",
|
||||||
description="description",
|
description="description",
|
||||||
|
|
@ -47,7 +43,6 @@ class TestSendGame:
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import datetime
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendInvoice
|
from aiogram.api.methods import Request, SendInvoice
|
||||||
from aiogram.api.types import Chat, Invoice, LabeledPrice, Message
|
from aiogram.api.types import Chat, Invoice, LabeledPrice, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,9 +12,7 @@ class TestSendInvoice:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendInvoice,
|
SendInvoice,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
invoice=Invoice(
|
invoice=Invoice(
|
||||||
title="test",
|
title="test",
|
||||||
description="test",
|
description="test",
|
||||||
|
|
@ -23,7 +20,6 @@ class TestSendInvoice:
|
||||||
currency="BTC",
|
currency="BTC",
|
||||||
total_amount=1,
|
total_amount=1,
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -46,9 +42,7 @@ class TestSendInvoice:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendInvoice,
|
SendInvoice,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
invoice=Invoice(
|
invoice=Invoice(
|
||||||
title="test",
|
title="test",
|
||||||
description="test",
|
description="test",
|
||||||
|
|
@ -56,7 +50,6 @@ class TestSendInvoice:
|
||||||
currency="BTC",
|
currency="BTC",
|
||||||
total_amount=1,
|
total_amount=1,
|
||||||
),
|
),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendLocation
|
from aiogram.api.methods import Request, SendLocation
|
||||||
from aiogram.api.types import Chat, Location, Message
|
from aiogram.api.types import Chat, Location, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +14,8 @@ class TestSendLocation:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendLocation,
|
SendLocation,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
location=Location(longitude=3.14, latitude=3.14),
|
location=Location(longitude=3.14, latitude=3.14),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,11 +31,8 @@ class TestSendLocation:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendLocation,
|
SendLocation,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
location=Location(longitude=3.14, latitude=3.14),
|
location=Location(longitude=3.14, latitude=3.14),
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ from aiogram.api.types import (
|
||||||
PhotoSize,
|
PhotoSize,
|
||||||
Video,
|
Video,
|
||||||
)
|
)
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -23,18 +24,13 @@ class TestSendMediaGroup:
|
||||||
SendMediaGroup,
|
SendMediaGroup,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=[
|
result=[
|
||||||
Message(
|
MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
photo=[
|
photo=[
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
Message(
|
MessageFactory(
|
||||||
message_id=43,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
video=Video(
|
video=Video(
|
||||||
file_id="file id",
|
file_id="file id",
|
||||||
width=42,
|
width=42,
|
||||||
|
|
@ -43,7 +39,6 @@ class TestSendMediaGroup:
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
@ -65,18 +60,13 @@ class TestSendMediaGroup:
|
||||||
SendMediaGroup,
|
SendMediaGroup,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=[
|
result=[
|
||||||
Message(
|
MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
photo=[
|
photo=[
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
Message(
|
MessageFactory(
|
||||||
message_id=43,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
video=Video(
|
video=Video(
|
||||||
file_id="file id",
|
file_id="file id",
|
||||||
width=42,
|
width=42,
|
||||||
|
|
@ -85,7 +75,6 @@ class TestSendMediaGroup:
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=private_chat,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendMessage
|
from aiogram.api.methods import Request, SendMessage
|
||||||
from aiogram.api.types import Chat, Message
|
from aiogram.api.types import Chat, Message
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,11 +14,7 @@ class TestSendMessage:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendMessage,
|
SendMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="test",
|
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -31,11 +28,7 @@ class TestSendMessage:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendMessage,
|
SendMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="test",
|
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import datetime
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendPhoto
|
from aiogram.api.methods import Request, SendPhoto
|
||||||
from aiogram.api.types import Chat, Message, PhotoSize
|
from aiogram.api.types import Message, PhotoSize
|
||||||
|
from tests.factories.message import MessageFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -13,13 +12,10 @@ class TestSendPhoto:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendPhoto,
|
SendPhoto,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
photo=[
|
photo=[
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,13 +29,10 @@ class TestSendPhoto:
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
SendPhoto,
|
SendPhoto,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
photo=[
|
photo=[
|
||||||
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
PhotoSize(file_id="file id", width=42, height=42, file_unique_id="file id")
|
||||||
],
|
],
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,18 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendPoll
|
from aiogram.api.methods import Request, SendPoll
|
||||||
from aiogram.api.types import Chat, Message, Poll, PollOption
|
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
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
class TestSendPoll:
|
class TestSendPoll:
|
||||||
@pytest.mark.asyncio
|
@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(
|
prepare_result = bot.add_result_for(
|
||||||
SendPoll,
|
SendPoll,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
poll=Poll(
|
poll=Poll(
|
||||||
id="QA",
|
id="QA",
|
||||||
question="Q",
|
question="Q",
|
||||||
|
|
@ -30,25 +30,23 @@ class TestSendPoll:
|
||||||
total_voter_count=0,
|
total_voter_count=0,
|
||||||
correct_option_id=0,
|
correct_option_id=0,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendPoll(
|
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()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendPoll"
|
assert request.method == "sendPoll"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@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(
|
prepare_result = bot.add_result_for(
|
||||||
SendPoll,
|
SendPoll,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
poll=Poll(
|
poll=Poll(
|
||||||
id="QA",
|
id="QA",
|
||||||
question="Q",
|
question="Q",
|
||||||
|
|
@ -63,12 +61,12 @@ class TestSendPoll:
|
||||||
total_voter_count=0,
|
total_voter_count=0,
|
||||||
correct_option_id=0,
|
correct_option_id=0,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_poll(
|
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()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendPoll"
|
assert request.method == "sendPoll"
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
import datetime
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.types import Message, User
|
|
||||||
from aiogram.dispatcher.filters import CommandObject
|
from aiogram.dispatcher.filters import CommandObject
|
||||||
from aiogram.dispatcher.handler.message import MessageHandler, MessageHandlerCommandMixin
|
from aiogram.dispatcher.handler.message import MessageHandler, MessageHandlerCommandMixin
|
||||||
from tests.factories.chat import ChatFactory
|
from tests.factories.message import MessageFactory
|
||||||
|
|
||||||
|
|
||||||
class MyHandler(MessageHandler):
|
class MyHandler(MessageHandler):
|
||||||
|
|
@ -17,12 +15,7 @@ class MyHandler(MessageHandler):
|
||||||
class TestClassBasedMessageHandler:
|
class TestClassBasedMessageHandler:
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_message_handler(self):
|
async def test_message_handler(self):
|
||||||
event = Message(
|
event = MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="test",
|
|
||||||
chat=ChatFactory(),
|
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
|
||||||
)
|
)
|
||||||
handler = MyHandler(event=event)
|
handler = MyHandler(event=event)
|
||||||
|
|
||||||
|
|
@ -38,12 +31,8 @@ class HandlerWithCommand(MessageHandlerCommandMixin, MessageHandler):
|
||||||
class TestBaseMessageHandlerCommandMixin:
|
class TestBaseMessageHandlerCommandMixin:
|
||||||
def test_command_accessible(self):
|
def test_command_accessible(self):
|
||||||
handler = HandlerWithCommand(
|
handler = HandlerWithCommand(
|
||||||
Message(
|
MessageFactory(
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="/test args",
|
text="/test args",
|
||||||
chat=ChatFactory(),
|
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
|
||||||
),
|
),
|
||||||
command=CommandObject(prefix="/", command="command", args="args"),
|
command=CommandObject(prefix="/", command="command", args="args"),
|
||||||
)
|
)
|
||||||
|
|
@ -53,13 +42,7 @@ class TestBaseMessageHandlerCommandMixin:
|
||||||
|
|
||||||
def test_command_not_presented(self):
|
def test_command_not_presented(self):
|
||||||
handler = HandlerWithCommand(
|
handler = HandlerWithCommand(
|
||||||
Message(
|
MessageFactory()
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="test",
|
|
||||||
chat=ChatFactory(),
|
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert handler.command is None
|
assert handler.command is None
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue