More tests

This commit is contained in:
jrootjunior 2019-11-19 18:54:02 +02:00
parent 635f08b88f
commit 33c661d732
5 changed files with 150 additions and 54 deletions

View file

@ -1,27 +1,45 @@
import datetime
import pytest 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 tests.mocked_bot import MockedBot from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSendDocument: class TestSendDocument:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_method(self, bot: MockedBot): async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SendDocument, ok=True, result=None) prepare_result = bot.add_result_for(
SendDocument,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
document=Document(file_id="file id"),
chat=Chat(id=42, type="private"),
),
)
response: Message = await SendDocument(chat_id=..., document=...) response: Message = await SendDocument(chat_id=42, document="file id")
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendDocument" assert request.method == "sendDocument"
# 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):
prepare_result = bot.add_result_for(SendDocument, ok=True, result=None) prepare_result = bot.add_result_for(
SendDocument,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
document=Document(file_id="file id"),
chat=Chat(id=42, type="private"),
),
)
response: Message = await bot.send_document(chat_id=..., document=...) response: Message = await bot.send_document(chat_id=42, document="file id")
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendDocument" assert request.method == "sendDocument"
# assert request.data == {}
assert response == prepare_result.result assert response == prepare_result.result

View file

@ -1,27 +1,53 @@
import datetime
import pytest 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 tests.mocked_bot import MockedBot from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSendGame: class TestSendGame:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_method(self, bot: MockedBot): async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SendGame, ok=True, result=None) prepare_result = bot.add_result_for(
SendGame,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
game=Game(
title="title",
description="description",
photo=[PhotoSize(file_id="file id", width=42, height=42)],
),
chat=Chat(id=42, type="private"),
),
)
response: Message = await SendGame(chat_id=..., game_short_name=...) response: Message = await SendGame(chat_id=42, game_short_name="game")
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendGame" assert request.method == "sendGame"
# 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):
prepare_result = bot.add_result_for(SendGame, ok=True, result=None) prepare_result = bot.add_result_for(
SendGame,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
game=Game(
title="title",
description="description",
photo=[PhotoSize(file_id="file id", width=42, height=42)],
),
chat=Chat(id=42, type="private"),
),
)
response: Message = await bot.send_game(chat_id=..., game_short_name=...) response: Message = await bot.send_game(chat_id=42, game_short_name="game")
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendGame" assert request.method == "sendGame"
# assert request.data == {}
assert response == prepare_result.result assert response == prepare_result.result

View file

@ -1,45 +1,75 @@
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 tests.mocked_bot import MockedBot from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSendInvoice: class TestSendInvoice:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_method(self, bot: MockedBot): async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SendInvoice, ok=True, result=None) prepare_result = bot.add_result_for(
SendInvoice,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
invoice=Invoice(
title="test",
description="test",
start_parameter="brilliant",
currency="BTC",
total_amount=1,
),
chat=Chat(id=42, type="private"),
),
)
response: Message = await SendInvoice( response: Message = await SendInvoice(
chat_id=..., chat_id=42,
title=..., title="test",
description=..., description="test",
payload=..., payload="payload",
provider_token=..., provider_token="TEST:token",
start_parameter=..., start_parameter="brilliant",
currency=..., currency="BTC",
prices=..., prices=[LabeledPrice(amount=1, label="test")],
) )
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendInvoice" assert request.method == "sendInvoice"
# 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):
prepare_result = bot.add_result_for(SendInvoice, ok=True, result=None) prepare_result = bot.add_result_for(
SendInvoice,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
invoice=Invoice(
title="test",
description="test",
start_parameter="brilliant",
currency="BTC",
total_amount=1,
),
chat=Chat(id=42, type="private"),
),
)
response: Message = await bot.send_invoice( response: Message = await bot.send_invoice(
chat_id=..., chat_id=42,
title=..., title="test",
description=..., description="test",
payload=..., payload="payload",
provider_token=..., provider_token="TEST:token",
start_parameter=..., start_parameter="brilliant",
currency=..., currency="BTC",
prices=..., prices=[LabeledPrice(amount=1, label="test")],
) )
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendInvoice" assert request.method == "sendInvoice"
# assert request.data == {}
assert response == prepare_result.result assert response == prepare_result.result

View file

@ -1,27 +1,45 @@
import datetime
import pytest 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 tests.mocked_bot import MockedBot from tests.mocked_bot import MockedBot
@pytest.mark.skip
class TestSendLocation: class TestSendLocation:
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_method(self, bot: MockedBot): async def test_method(self, bot: MockedBot):
prepare_result = bot.add_result_for(SendLocation, ok=True, result=None) prepare_result = bot.add_result_for(
SendLocation,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
location=Location(longitude=3.14, latitude=3.14),
chat=Chat(id=42, type="private"),
),
)
response: Message = await SendLocation(chat_id=..., latitude=..., longitude=...) response: Message = await SendLocation(chat_id=42, 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 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):
prepare_result = bot.add_result_for(SendLocation, ok=True, result=None) prepare_result = bot.add_result_for(
SendLocation,
ok=True,
result=Message(
message_id=42,
date=datetime.datetime.now(),
location=Location(longitude=3.14, latitude=3.14),
chat=Chat(id=42, type="private"),
),
)
response: Message = await bot.send_location(chat_id=..., latitude=..., longitude=...) response: Message = await bot.send_location(chat_id=42, 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 request.data == {}
assert response == prepare_result.result assert response == prepare_result.result

View file

@ -1,6 +1,9 @@
from typing import List
import pytest import pytest
from aiogram.api.methods import Request, SendMediaGroup from aiogram.api.methods import Request, SendMediaGroup
from aiogram.api.types import Message, InputMediaPhoto
from tests.mocked_bot import MockedBot from tests.mocked_bot import MockedBot
@ -8,20 +11,21 @@ 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):
prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=None) prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=...)
response: List[Message] = await SendMediaGroup(chat_id=..., media=...) response: List[Message] = await SendMediaGroup(
chat_id=42, media=[InputMediaPhoto(media="file id")]
)
request: Request = bot.get_request() request: Request = bot.get_request()
assert request.method == "sendMediaGroup" assert request.method == "sendMediaGroup"
# assert request.data == {}
assert response == prepare_result.result assert response == prepare_result.result
@pytest.mark.asyncio #
async def test_bot_method(self, bot: MockedBot): # @pytest.mark.asyncio
prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=None) # async def test_bot_method(self, bot: MockedBot):
# prepare_result = bot.add_result_for(SendMediaGroup, ok=True, result=None)
response: List[Message] = await bot.send_media_group(chat_id=..., media=...) #
request: Request = bot.get_request() # response: List[Message] = await bot.send_media_group(chat_id=..., media=...)
assert request.method == "sendMediaGroup" # request: Request = bot.get_request()
# assert request.data == {} # assert request.method == "sendMediaGroup"
assert response == prepare_result.result # assert response == prepare_result.result