mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
feat: ChatFactory and private_chat fixture
This commit is contained in:
parent
2cf2c2e98b
commit
3016c8e21e
18 changed files with 161 additions and 131 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram import Bot
|
from aiogram import Bot
|
||||||
|
from tests.factories.chat import ChatFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -11,3 +12,8 @@ def bot():
|
||||||
yield bot
|
yield bot
|
||||||
Bot.reset_current(token)
|
Bot.reset_current(token)
|
||||||
bot.me.invalidate(bot)
|
bot.me.invalidate(bot)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def private_chat():
|
||||||
|
return ChatFactory()
|
||||||
|
|
|
||||||
28
tests/factories/chat.py
Normal file
28
tests/factories/chat.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import factory
|
||||||
|
|
||||||
|
from aiogram.api.types import Chat
|
||||||
|
from aiogram.api.types.chat import ChatType
|
||||||
|
from tests.factories import sequences
|
||||||
|
|
||||||
|
|
||||||
|
class ChatFactory(factory.Factory):
|
||||||
|
class Meta:
|
||||||
|
model = Chat
|
||||||
|
|
||||||
|
id = None # lazy attribute
|
||||||
|
first_name = sequences.first_name
|
||||||
|
last_name = sequences.last_name
|
||||||
|
username = sequences.username
|
||||||
|
type = ChatType.PRIVATE
|
||||||
|
|
||||||
|
@factory.lazy_attribute_sequence
|
||||||
|
def id(self, n):
|
||||||
|
_id = n
|
||||||
|
if self.type is ChatType.CHANNEL:
|
||||||
|
_id = -_id
|
||||||
|
return _id
|
||||||
|
|
||||||
|
@factory.lazy_attribute_sequence
|
||||||
|
def title(self, n):
|
||||||
|
if self.type is ChatType.CHANNEL:
|
||||||
|
return f"Title #{n}"
|
||||||
|
|
@ -4,7 +4,8 @@ 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 Chat, Message
|
from aiogram.api.types import Message
|
||||||
|
from tests.factories.chat import ChatFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -15,10 +16,7 @@ class TestEditMessageCaption:
|
||||||
EditMessageCaption,
|
EditMessageCaption,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=Message(
|
||||||
message_id=42,
|
message_id=42, date=datetime.datetime.now(), text="text", chat=ChatFactory(),
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="text",
|
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -33,10 +31,7 @@ class TestEditMessageCaption:
|
||||||
EditMessageCaption,
|
EditMessageCaption,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=Message(
|
||||||
message_id=42,
|
message_id=42, date=datetime.datetime.now(), text="text", chat=ChatFactory(),
|
||||||
date=datetime.datetime.now(),
|
|
||||||
text="text",
|
|
||||||
chat=Chat(id=42, type="private"),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,38 +9,32 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestForwardMessage:
|
class TestForwardMessage:
|
||||||
@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(
|
||||||
ForwardMessage,
|
ForwardMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=Message(message_id=42, date=datetime.datetime.now(), chat=private_chat, text="text", ),
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
chat=Chat(id=42, title="chat", type="private"),
|
|
||||||
text="text",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await ForwardMessage(chat_id=42, from_chat_id=42, message_id=42)
|
response: Message = await ForwardMessage(
|
||||||
|
chat_id=private_chat.id, from_chat_id=private_chat.id, message_id=42
|
||||||
|
)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "forwardMessage"
|
assert request.method == "forwardMessage"
|
||||||
# assert request.data == {}
|
# assert request.data == {}
|
||||||
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(
|
||||||
ForwardMessage,
|
ForwardMessage,
|
||||||
ok=True,
|
ok=True,
|
||||||
result=Message(
|
result=Message(message_id=42, date=datetime.datetime.now(), chat=private_chat, text="text", ),
|
||||||
message_id=42,
|
|
||||||
date=datetime.datetime.now(),
|
|
||||||
chat=Chat(id=42, title="chat", type="private"),
|
|
||||||
text="text",
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.forward_message(chat_id=42, from_chat_id=42, message_id=42)
|
response: Message = await bot.forward_message(
|
||||||
|
chat_id=private_chat.id, from_chat_id=private_chat.id, message_id=42
|
||||||
|
)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "forwardMessage"
|
assert request.method == "forwardMessage"
|
||||||
# assert request.data == {}
|
# assert request.data == {}
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,32 @@ import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import GetChat, Request
|
from aiogram.api.methods import GetChat, Request
|
||||||
from aiogram.api.types import Chat
|
from aiogram.api.types import Chat
|
||||||
|
from aiogram.api.types.chat import ChatType
|
||||||
|
from tests.factories.chat import ChatFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
class TestGetChat:
|
class TestGetChat:
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_method(self, bot: MockedBot):
|
async def test_method(self, bot: MockedBot):
|
||||||
|
channel = ChatFactory(type=ChatType.CHANNEL)
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
GetChat, ok=True, result=Chat(id=-42, type="channel", title="chat")
|
GetChat, ok=True, result=channel
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Chat = await GetChat(chat_id=-42)
|
response: Chat = await GetChat(chat_id=channel.id)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "getChat"
|
assert request.method == "getChat"
|
||||||
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):
|
||||||
|
channel = ChatFactory(type=ChatType.CHANNEL)
|
||||||
prepare_result = bot.add_result_for(
|
prepare_result = bot.add_result_for(
|
||||||
GetChat, ok=True, result=Chat(id=-42, type="channel", title="chat")
|
GetChat, ok=True, result=channel
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Chat = await bot.get_chat(chat_id=-42)
|
response: Chat = await bot.get_chat(chat_id=channel.id)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "getChat"
|
assert request.method == "getChat"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendAnimation:
|
class TestSendAnimation:
|
||||||
@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(
|
||||||
SendAnimation,
|
SendAnimation,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -19,17 +19,17 @@ class TestSendAnimation:
|
||||||
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendAnimation(chat_id=42, animation="file id")
|
response: Message = await SendAnimation(chat_id=private_chat.id, animation="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendAnimation"
|
assert request.method == "sendAnimation"
|
||||||
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(
|
||||||
SendAnimation,
|
SendAnimation,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -39,11 +39,11 @@ class TestSendAnimation:
|
||||||
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_animation(chat_id=42, animation="file id")
|
response: Message = await bot.send_animation(chat_id=private_chat.id, animation="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendAnimation"
|
assert request.method == "sendAnimation"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ import datetime
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendAudio
|
from aiogram.api.methods import Request, SendAudio
|
||||||
from aiogram.api.types import Audio, Chat, File, Message
|
from aiogram.api.types import Audio, Chat, Message
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
class TestSendAudio:
|
class TestSendAudio:
|
||||||
@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(
|
||||||
SendAudio,
|
SendAudio,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -17,17 +17,17 @@ class TestSendAudio:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendAudio(chat_id=42, audio="file id")
|
response: Message = await SendAudio(chat_id=private_chat.id, audio="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendAudio"
|
assert request.method == "sendAudio"
|
||||||
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(
|
||||||
SendAudio,
|
SendAudio,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -35,11 +35,11 @@ class TestSendAudio:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_audio(chat_id=42, audio="file id")
|
response: Message = await bot.send_audio(chat_id=private_chat.id, audio="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendAudio"
|
assert request.method == "sendAudio"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendContact:
|
class TestSendContact:
|
||||||
@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(
|
||||||
SendContact,
|
SendContact,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -17,17 +17,17 @@ class TestSendContact:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
contact=Contact(phone_number="911", first_name="911"),
|
contact=Contact(phone_number="911", first_name="911"),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendContact(chat_id=42, phone_number="911", first_name="911")
|
response: Message = await SendContact(chat_id=private_chat.id, phone_number="911", first_name="911")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendContact"
|
assert request.method == "sendContact"
|
||||||
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(
|
||||||
SendContact,
|
SendContact,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -35,12 +35,12 @@ class TestSendContact:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
contact=Contact(phone_number="911", first_name="911"),
|
contact=Contact(phone_number="911", first_name="911"),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_contact(
|
response: Message = await bot.send_contact(
|
||||||
chat_id=42, phone_number="911", first_name="911"
|
chat_id=private_chat.id, phone_number="911", first_name="911"
|
||||||
)
|
)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendContact"
|
assert request.method == "sendContact"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendDocument:
|
class TestSendDocument:
|
||||||
@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(
|
||||||
SendDocument,
|
SendDocument,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -17,17 +17,17 @@ class TestSendDocument:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendDocument(chat_id=42, document="file id")
|
response: Message = await SendDocument(chat_id=private_chat.id, document="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendDocument"
|
assert request.method == "sendDocument"
|
||||||
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(
|
||||||
SendDocument,
|
SendDocument,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -35,11 +35,11 @@ class TestSendDocument:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_document(chat_id=42, document="file id")
|
response: Message = await bot.send_document(chat_id=private_chat.id, document="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendDocument"
|
assert request.method == "sendDocument"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendGame:
|
class TestSendGame:
|
||||||
@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(
|
||||||
SendGame,
|
SendGame,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -23,17 +23,17 @@ 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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendGame(chat_id=42, game_short_name="game")
|
response: Message = await SendGame(chat_id=private_chat.id, game_short_name="game")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendGame"
|
assert request.method == "sendGame"
|
||||||
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(
|
||||||
SendGame,
|
SendGame,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -47,11 +47,11 @@ 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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_game(chat_id=42, game_short_name="game")
|
response: Message = await bot.send_game(chat_id=private_chat.id, game_short_name="game")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendGame"
|
assert request.method == "sendGame"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,13 @@ 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.chat import ChatFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
class TestSendInvoice:
|
class TestSendInvoice:
|
||||||
@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(
|
||||||
SendInvoice,
|
SendInvoice,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -23,12 +24,12 @@ class TestSendInvoice:
|
||||||
currency="BTC",
|
currency="BTC",
|
||||||
total_amount=1,
|
total_amount=1,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendInvoice(
|
response: Message = await SendInvoice(
|
||||||
chat_id=42,
|
chat_id=private_chat.id,
|
||||||
title="test",
|
title="test",
|
||||||
description="test",
|
description="test",
|
||||||
payload="payload",
|
payload="payload",
|
||||||
|
|
@ -42,7 +43,7 @@ class TestSendInvoice:
|
||||||
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(
|
||||||
SendInvoice,
|
SendInvoice,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -56,12 +57,12 @@ class TestSendInvoice:
|
||||||
currency="BTC",
|
currency="BTC",
|
||||||
total_amount=1,
|
total_amount=1,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_invoice(
|
response: Message = await bot.send_invoice(
|
||||||
chat_id=42,
|
chat_id=private_chat.id,
|
||||||
title="test",
|
title="test",
|
||||||
description="test",
|
description="test",
|
||||||
payload="payload",
|
payload="payload",
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendLocation:
|
class TestSendLocation:
|
||||||
@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(
|
||||||
SendLocation,
|
SendLocation,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -17,17 +17,17 @@ class TestSendLocation:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
location=Location(longitude=3.14, latitude=3.14),
|
location=Location(longitude=3.14, latitude=3.14),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendLocation(chat_id=42, latitude=3.14, longitude=3.14)
|
response: Message = await SendLocation(chat_id=private_chat.id, latitude=3.14, longitude=3.14)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendLocation"
|
assert request.method == "sendLocation"
|
||||||
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(
|
||||||
SendLocation,
|
SendLocation,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -35,11 +35,11 @@ class TestSendLocation:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
location=Location(longitude=3.14, latitude=3.14),
|
location=Location(longitude=3.14, latitude=3.14),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_location(chat_id=42, latitude=3.14, longitude=3.14)
|
response: Message = await bot.send_location(chat_id=private_chat.id, latitude=3.14, longitude=3.14)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendLocation"
|
assert request.method == "sendLocation"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendMediaGroup:
|
class TestSendMediaGroup:
|
||||||
@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(
|
||||||
SendMediaGroup,
|
SendMediaGroup,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -30,7 +30,7 @@ class TestSendMediaGroup:
|
||||||
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
Message(
|
Message(
|
||||||
message_id=43,
|
message_id=43,
|
||||||
|
|
@ -43,13 +43,13 @@ class TestSendMediaGroup:
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
response: List[Message] = await SendMediaGroup(
|
response: List[Message] = await SendMediaGroup(
|
||||||
chat_id=42,
|
chat_id=private_chat.id,
|
||||||
media=[
|
media=[
|
||||||
InputMediaPhoto(media="file id"),
|
InputMediaPhoto(media="file id"),
|
||||||
InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")),
|
InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")),
|
||||||
|
|
@ -60,7 +60,7 @@ class TestSendMediaGroup:
|
||||||
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(
|
||||||
SendMediaGroup,
|
SendMediaGroup,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -72,7 +72,7 @@ class TestSendMediaGroup:
|
||||||
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=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
Message(
|
Message(
|
||||||
message_id=43,
|
message_id=43,
|
||||||
|
|
@ -85,13 +85,13 @@ class TestSendMediaGroup:
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
media_group_id="media group",
|
media_group_id="media group",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
response: List[Message] = await bot.send_media_group(
|
response: List[Message] = await bot.send_media_group(
|
||||||
chat_id=42,
|
chat_id=private_chat.id,
|
||||||
media=[
|
media=[
|
||||||
InputMediaPhoto(media="file id"),
|
InputMediaPhoto(media="file id"),
|
||||||
InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")),
|
InputMediaVideo(media=BufferedInputFile(b"", "video.mp4")),
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendSticker:
|
class TestSendSticker:
|
||||||
@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(
|
||||||
SendSticker,
|
SendSticker,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -23,17 +23,17 @@ class TestSendSticker:
|
||||||
is_animated=False,
|
is_animated=False,
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendSticker(chat_id=42, sticker="file id")
|
response: Message = await SendSticker(chat_id=private_chat.id, sticker="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendSticker"
|
assert request.method == "sendSticker"
|
||||||
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(
|
||||||
SendSticker,
|
SendSticker,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -47,11 +47,11 @@ class TestSendSticker:
|
||||||
is_animated=False,
|
is_animated=False,
|
||||||
file_unique_id="file id",
|
file_unique_id="file id",
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_sticker(chat_id=42, sticker="file id")
|
response: Message = await bot.send_sticker(chat_id=private_chat.id, sticker="file id")
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendSticker"
|
assert request.method == "sendSticker"
|
||||||
assert response == prepare_result.result
|
assert response == prepare_result.result
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
class TestSendVideoNote:
|
class TestSendVideoNote:
|
||||||
@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(
|
||||||
SendVideoNote,
|
SendVideoNote,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -19,19 +19,19 @@ class TestSendVideoNote:
|
||||||
video_note=VideoNote(
|
video_note=VideoNote(
|
||||||
file_id="file id", length=0, duration=0, file_unique_id="file id"
|
file_id="file id", length=0, duration=0, file_unique_id="file id"
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await SendVideoNote(
|
response: Message = await SendVideoNote(
|
||||||
chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png")
|
chat_id=private_chat.id, video_note="file id", thumb=BufferedInputFile(b"", "file.png")
|
||||||
)
|
)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendVideoNote"
|
assert request.method == "sendVideoNote"
|
||||||
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(
|
||||||
SendVideoNote,
|
SendVideoNote,
|
||||||
ok=True,
|
ok=True,
|
||||||
|
|
@ -41,12 +41,12 @@ class TestSendVideoNote:
|
||||||
video_note=VideoNote(
|
video_note=VideoNote(
|
||||||
file_id="file id", length=0, duration=0, file_unique_id="file id"
|
file_id="file id", length=0, duration=0, file_unique_id="file id"
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=private_chat,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
response: Message = await bot.send_video_note(
|
response: Message = await bot.send_video_note(
|
||||||
chat_id=42, video_note="file id", thumb=BufferedInputFile(b"", "file.png")
|
chat_id=private_chat.id, video_note="file id", thumb=BufferedInputFile(b"", "file.png")
|
||||||
)
|
)
|
||||||
request: Request = bot.get_request()
|
request: Request = bot.get_request()
|
||||||
assert request.method == "sendVideoNote"
|
assert request.method == "sendVideoNote"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@ import datetime
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.methods import Request, SendVoice
|
from aiogram.api.methods import Request, SendVoice
|
||||||
from aiogram.api.types import Chat, Message, Voice
|
from aiogram.api.types import Message, Voice
|
||||||
|
from tests.factories.chat import ChatFactory
|
||||||
from tests.mocked_bot import MockedBot
|
from tests.mocked_bot import MockedBot
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +18,7 @@ class TestSendVoice:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
voice=Voice(file_id="file id", duration=0, file_unique_id="file id"),
|
voice=Voice(file_id="file id", duration=0, file_unique_id="file id"),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -35,7 +36,7 @@ class TestSendVoice:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
voice=Voice(file_id="file id", duration=0, file_unique_id="file id"),
|
voice=Voice(file_id="file id", duration=0, file_unique_id="file id"),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ from aiogram.api.methods import (
|
||||||
from aiogram.api.types import (
|
from aiogram.api.types import (
|
||||||
Animation,
|
Animation,
|
||||||
Audio,
|
Audio,
|
||||||
Chat,
|
|
||||||
Contact,
|
Contact,
|
||||||
Dice,
|
Dice,
|
||||||
Document,
|
Document,
|
||||||
|
|
@ -45,6 +44,7 @@ from aiogram.api.types import (
|
||||||
Voice,
|
Voice,
|
||||||
)
|
)
|
||||||
from aiogram.api.types.message import ContentType, Message
|
from aiogram.api.types.message import ContentType, Message
|
||||||
|
from tests.factories.chat import ChatFactory
|
||||||
from tests.factories.user import UserFactory
|
from tests.factories.user import UserFactory
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
text="test",
|
text="test",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.TEXT,
|
ContentType.TEXT,
|
||||||
|
|
@ -67,7 +67,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
audio=Audio(file_id="file id", file_unique_id="file id", duration=42),
|
audio=Audio(file_id="file id", file_unique_id="file id", duration=42),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.AUDIO,
|
ContentType.AUDIO,
|
||||||
|
|
@ -83,7 +83,7 @@ class TestMessage:
|
||||||
height=42,
|
height=42,
|
||||||
duration=0,
|
duration=0,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.ANIMATION,
|
ContentType.ANIMATION,
|
||||||
|
|
@ -93,7 +93,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
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=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.DOCUMENT,
|
ContentType.DOCUMENT,
|
||||||
|
|
@ -111,7 +111,7 @@ class TestMessage:
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.GAME,
|
ContentType.GAME,
|
||||||
|
|
@ -123,7 +123,7 @@ class TestMessage:
|
||||||
photo=[
|
photo=[
|
||||||
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
||||||
],
|
],
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.PHOTO,
|
ContentType.PHOTO,
|
||||||
|
|
@ -139,7 +139,7 @@ class TestMessage:
|
||||||
height=42,
|
height=42,
|
||||||
is_animated=False,
|
is_animated=False,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.STICKER,
|
ContentType.STICKER,
|
||||||
|
|
@ -155,7 +155,7 @@ class TestMessage:
|
||||||
height=42,
|
height=42,
|
||||||
duration=0,
|
duration=0,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.VIDEO,
|
ContentType.VIDEO,
|
||||||
|
|
@ -167,7 +167,7 @@ class TestMessage:
|
||||||
video_note=VideoNote(
|
video_note=VideoNote(
|
||||||
file_id="file id", file_unique_id="file id", length=0, duration=0
|
file_id="file id", file_unique_id="file id", length=0, duration=0
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.VIDEO_NOTE,
|
ContentType.VIDEO_NOTE,
|
||||||
|
|
@ -177,7 +177,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
voice=Voice(file_id="file id", file_unique_id="file id", duration=0),
|
voice=Voice(file_id="file id", file_unique_id="file id", duration=0),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.VOICE,
|
ContentType.VOICE,
|
||||||
|
|
@ -187,7 +187,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
contact=Contact(phone_number="911", first_name="911"),
|
contact=Contact(phone_number="911", first_name="911"),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.CONTACT,
|
ContentType.CONTACT,
|
||||||
|
|
@ -202,7 +202,7 @@ class TestMessage:
|
||||||
address="Under the stairs, 4 Privet Drive, "
|
address="Under the stairs, 4 Privet Drive, "
|
||||||
"Little Whinging, Surrey, England, Great Britain",
|
"Little Whinging, Surrey, England, Great Britain",
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.VENUE,
|
ContentType.VENUE,
|
||||||
|
|
@ -212,7 +212,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
location=Location(longitude=3.14, latitude=3.14),
|
location=Location(longitude=3.14, latitude=3.14),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.LOCATION,
|
ContentType.LOCATION,
|
||||||
|
|
@ -222,7 +222,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
new_chat_members=[UserFactory()],
|
new_chat_members=[UserFactory()],
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.NEW_CHAT_MEMBERS,
|
ContentType.NEW_CHAT_MEMBERS,
|
||||||
|
|
@ -232,7 +232,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
left_chat_member=UserFactory(),
|
left_chat_member=UserFactory(),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.LEFT_CHAT_MEMBER,
|
ContentType.LEFT_CHAT_MEMBER,
|
||||||
|
|
@ -248,7 +248,7 @@ class TestMessage:
|
||||||
currency="BTC",
|
currency="BTC",
|
||||||
total_amount=1,
|
total_amount=1,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.INVOICE,
|
ContentType.INVOICE,
|
||||||
|
|
@ -264,7 +264,7 @@ class TestMessage:
|
||||||
telegram_payment_charge_id="charge",
|
telegram_payment_charge_id="charge",
|
||||||
provider_payment_charge_id="payment",
|
provider_payment_charge_id="payment",
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.SUCCESSFUL_PAYMENT,
|
ContentType.SUCCESSFUL_PAYMENT,
|
||||||
|
|
@ -274,7 +274,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
connected_website="token",
|
connected_website="token",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.CONNECTED_WEBSITE,
|
ContentType.CONNECTED_WEBSITE,
|
||||||
|
|
@ -284,7 +284,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
migrate_from_chat_id=42,
|
migrate_from_chat_id=42,
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.MIGRATE_FROM_CHAT_ID,
|
ContentType.MIGRATE_FROM_CHAT_ID,
|
||||||
|
|
@ -294,7 +294,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
migrate_to_chat_id=42,
|
migrate_to_chat_id=42,
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.MIGRATE_TO_CHAT_ID,
|
ContentType.MIGRATE_TO_CHAT_ID,
|
||||||
|
|
@ -307,10 +307,10 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
text="pinned",
|
text="pinned",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.PINNED_MESSAGE,
|
ContentType.PINNED_MESSAGE,
|
||||||
|
|
@ -320,7 +320,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
new_chat_title="test",
|
new_chat_title="test",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.NEW_CHAT_TITLE,
|
ContentType.NEW_CHAT_TITLE,
|
||||||
|
|
@ -332,7 +332,7 @@ class TestMessage:
|
||||||
new_chat_photo=[
|
new_chat_photo=[
|
||||||
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
PhotoSize(file_id="file id", file_unique_id="file id", width=42, height=42)
|
||||||
],
|
],
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.NEW_CHAT_PHOTO,
|
ContentType.NEW_CHAT_PHOTO,
|
||||||
|
|
@ -342,7 +342,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
delete_chat_photo=True,
|
delete_chat_photo=True,
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.DELETE_CHAT_PHOTO,
|
ContentType.DELETE_CHAT_PHOTO,
|
||||||
|
|
@ -352,7 +352,7 @@ class TestMessage:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
group_chat_created=True,
|
group_chat_created=True,
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.GROUP_CHAT_CREATED,
|
ContentType.GROUP_CHAT_CREATED,
|
||||||
|
|
@ -365,7 +365,7 @@ class TestMessage:
|
||||||
data=[],
|
data=[],
|
||||||
credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
|
credentials=EncryptedCredentials(data="test", hash="test", secret="test"),
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.PASSPORT_DATA,
|
ContentType.PASSPORT_DATA,
|
||||||
|
|
@ -388,7 +388,7 @@ class TestMessage:
|
||||||
total_voter_count=0,
|
total_voter_count=0,
|
||||||
correct_option_id=1,
|
correct_option_id=1,
|
||||||
),
|
),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.POLL,
|
ContentType.POLL,
|
||||||
|
|
@ -397,7 +397,7 @@ class TestMessage:
|
||||||
Message(
|
Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
dice=Dice(value=6, emoji="X"),
|
dice=Dice(value=6, emoji="X"),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
|
|
@ -407,7 +407,7 @@ class TestMessage:
|
||||||
Message(
|
Message(
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=UserFactory(),
|
from_user=UserFactory(),
|
||||||
),
|
),
|
||||||
ContentType.UNKNOWN,
|
ContentType.UNKNOWN,
|
||||||
|
|
@ -485,7 +485,7 @@ class TestMessage:
|
||||||
],
|
],
|
||||||
):
|
):
|
||||||
message = Message(
|
message = Message(
|
||||||
message_id=42, chat=Chat(id=42, type="private"), date=datetime.datetime.now()
|
message_id=42, chat=ChatFactory(), date=datetime.datetime.now()
|
||||||
)
|
)
|
||||||
alias_name = "_".join(item for item in [alias_type, alias_for_method] if item)
|
alias_name = "_".join(item for item in [alias_type, alias_for_method] if item)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,10 @@ from typing import Any
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from aiogram.api.types import Chat, Message, User
|
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
|
||||||
|
|
||||||
|
|
||||||
class MyHandler(MessageHandler):
|
class MyHandler(MessageHandler):
|
||||||
|
|
@ -20,7 +21,7 @@ class TestClassBasedMessageHandler:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
text="test",
|
text="test",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
)
|
)
|
||||||
handler = MyHandler(event=event)
|
handler = MyHandler(event=event)
|
||||||
|
|
@ -41,7 +42,7 @@ class TestBaseMessageHandlerCommandMixin:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
text="/test args",
|
text="/test args",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
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"),
|
||||||
|
|
@ -56,7 +57,7 @@ class TestBaseMessageHandlerCommandMixin:
|
||||||
message_id=42,
|
message_id=42,
|
||||||
date=datetime.datetime.now(),
|
date=datetime.datetime.now(),
|
||||||
text="test",
|
text="test",
|
||||||
chat=Chat(id=42, type="private"),
|
chat=ChatFactory(),
|
||||||
from_user=User(id=42, is_bot=False, first_name="Test"),
|
from_user=User(id=42, is_bot=False, first_name="Test"),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue