async def test_api_methods_send_photo(bot: Bot, make_message: _MakeMessage, reply_kb: ReplyKeyboardMarkup) -> None: message = make_message(photo=[]) bot.safe_request_mock.return_value = APIResponse.from_dict({ 'ok': True, 'result': message.to_dict() }) assert await bot.send_photo(chat_id=1, photo='some photo', parse_mode=ParseMode.HTML, reply_to_message_id=111, reply_markup=reply_kb) == message assert bot.safe_request_mock.call_args_list == [ call(RequestMethod.POST, 'sendPhoto', 1, photo='some photo', caption=None, parse_mode='HTML', caption_entities=None, disable_notification=None, reply_to_message_id=111, allow_sending_without_reply=None, reply_markup=json_dumps(reply_kb.to_dict())) ]
async def test_edit_message_media(bot: Bot, make_message: _MakeMessage) -> None: file = stream_file('bytes1') bot.request_mock.return_value = APIResponse.from_dict({ 'ok': True, 'result': make_message().to_dict() }) await bot.edit_message_media(media=InputMediaPhoto(media=file, caption='f1'), chat_id=1, message_id=1) assert bot.request_mock.call_args_list == [ call(RequestMethod.POST, 'editMessageMedia', chat_id=1, message_id=1, inline_message_id=None, media=json_dumps( InputMediaPhoto(media='attach://attachment0', caption='f1').to_dict()), reply_markup=None, attachment0=file) ]
def test_json_dumps_iterable_base_telegram() -> None: data = (MessageEntity('type1', 10, 5), MessageEntity('type2', 20, 8)) assert api_methods._json_dumps(data) == json_dumps(({ 'type': 'type1', 'offset': 10, 'length': 5 }, { 'type': 'type2', 'offset': 20, 'length': 8 }))
async def test_send_media_group(bot: Bot, make_message: _MakeMessage) -> None: file0 = stream_file('bytes1') file1 = stream_file('bytes2') file2 = stream_file('bytes3') bot.safe_request_mock.return_value = APIResponse.from_dict({ 'ok': True, 'result': [ make_message().to_dict(), make_message().to_dict(), make_message().to_dict() ] }) await bot.send_media_group(1, media=(InputMediaPhoto(media=file0, caption='f1'), InputMediaPhoto(media=file1, caption='f2'), InputMediaPhoto(media=file2, caption='f3'))) assert bot.safe_request_mock.call_args_list == [ call(RequestMethod.POST, 'sendMediaGroup', 1, media=json_dumps([ InputMediaPhoto(media='attach://attachment0', caption='f1').to_dict(), InputMediaPhoto(media='attach://attachment1', caption='f2').to_dict(), InputMediaPhoto(media='attach://attachment2', caption='f3').to_dict() ]), disable_notification=None, reply_to_message_id=None, allow_sending_without_reply=None, attachment0=file0, attachment1=file1, attachment2=file2) ]
def test_json_dumps_iterable_int() -> None: data = (1, 2, 3, 4, 5) assert api_methods._json_dumps(data) == json_dumps(data)
def test_json_dumps_iterable_str() -> None: data = ('one', 'two', 'thee') assert api_methods._json_dumps(data) == json_dumps(data)
def test_json_dumps_base_telegram() -> None: update = Update.from_dict({'update_id': 1}) assert api_methods._json_dumps(update) == json_dumps(update.to_dict())