update exception matcher and fix tests

This commit is contained in:
Ilya Samartsev 2019-06-02 14:39:17 +03:00
parent fb991570d2
commit 5421982482
3 changed files with 35 additions and 6 deletions

View file

@ -12,6 +12,7 @@ TelegramAPIError
MessageCantBeEdited
MessageCantBeDeleted
MessageToEditNotFound
MessageToReplyNotFound
ToMuchMessages
PollError
PollCantBeStopped
@ -182,6 +183,13 @@ class MessageToDeleteNotFound(MessageError):
match = 'message to delete not found'
class MessageToReplyNotFound(MessageError):
"""
Will be raised when you try to reply to very old or deleted or unknown message.
"""
match = 'message to reply not found'
class MessageIdentifierNotSpecified(MessageError):
match = 'message identifier is not specified'
@ -297,8 +305,7 @@ class ChatDescriptionIsNotModified(BadRequest):
class InvalidQueryID(BadRequest):
match = 'QUERY_ID_INVALID'
text = 'Invalid query ID'
match = 'query is too old and response timeout expired or query id is invalid'
class InvalidPeerID(BadRequest):

View file

@ -3,7 +3,7 @@
ujson>=1.35
python-rapidjson>=0.7.0
emoji>=0.5.2
pytest>=4.4.1
pytest>=4.4.1,<4.6
pytest-asyncio>=0.10.0
tox>=3.9.0
aresponses>=1.1.1

View file

@ -185,7 +185,7 @@ async def test_send_location(bot: Bot, event_loop):
@pytest.mark.asyncio
async def test_edit_message_live_location(bot: Bot, event_loop):
async def test_edit_message_live_location_by_bot(bot: Bot, event_loop):
""" editMessageLiveLocation method test """
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
msg = types.Message(**MESSAGE_WITH_LOCATION)
@ -197,6 +197,14 @@ async def test_edit_message_live_location(bot: Bot, event_loop):
latitude=location.latitude, longitude=location.longitude)
assert result == msg
@pytest.mark.asyncio
async def test_edit_message_live_location_by_user(bot: Bot, event_loop):
""" editMessageLiveLocation method test """
from .types.dataset import MESSAGE_WITH_LOCATION, LOCATION
msg = types.Message(**MESSAGE_WITH_LOCATION)
location = types.Location(**LOCATION)
# editing user's message
async with FakeTelegram(message_dict=True, loop=event_loop):
result = await bot.edit_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id,
@ -205,7 +213,7 @@ async def test_edit_message_live_location(bot: Bot, event_loop):
@pytest.mark.asyncio
async def test_stop_message_live_location(bot: Bot, event_loop):
async def test_stop_message_live_location_by_bot(bot: Bot, event_loop):
""" stopMessageLiveLocation method test """
from .types.dataset import MESSAGE_WITH_LOCATION
msg = types.Message(**MESSAGE_WITH_LOCATION)
@ -215,6 +223,13 @@ async def test_stop_message_live_location(bot: Bot, event_loop):
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
assert result == msg
@pytest.mark.asyncio
async def test_stop_message_live_location_by_user(bot: Bot, event_loop):
""" stopMessageLiveLocation method test """
from .types.dataset import MESSAGE_WITH_LOCATION
msg = types.Message(**MESSAGE_WITH_LOCATION)
# stopping user's message
async with FakeTelegram(message_dict=True, loop=event_loop):
result = await bot.stop_message_live_location(chat_id=msg.chat.id, message_id=msg.message_id)
@ -509,7 +524,7 @@ async def test_answer_callback_query(bot: Bot, event_loop):
@pytest.mark.asyncio
async def test_edit_message_text(bot: Bot, event_loop):
async def test_edit_message_text_by_bot(bot: Bot, event_loop):
""" editMessageText method test """
from .types.dataset import EDITED_MESSAGE
msg = types.Message(**EDITED_MESSAGE)
@ -519,6 +534,13 @@ async def test_edit_message_text(bot: Bot, event_loop):
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)
assert result == msg
@pytest.mark.asyncio
async def test_edit_message_text_by_user(bot: Bot, event_loop):
""" editMessageText method test """
from .types.dataset import EDITED_MESSAGE
msg = types.Message(**EDITED_MESSAGE)
# message by user
async with FakeTelegram(message_dict=True, loop=event_loop):
result = await bot.edit_message_text(text=msg.text, chat_id=msg.chat.id, message_id=msg.message_id)