python-telegram-bot/tests/test_inlinekeyboardmarkup.py

84 lines
3.1 KiB
Python
Raw Normal View History

2016-04-24 16:30:39 +02:00
#!/usr/bin/env python
# encoding: utf-8
#
# A library that provides a Python interface to the Telegram Bot API
# Copyright (C) 2015-2017
2016-04-24 16:30:39 +02:00
# Leandro Toledo de Souza <devs@python-telegram-bot.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see [http://www.gnu.org/licenses/].
2016-10-17 00:22:40 +02:00
"""This module contains an object that represents Tests for Telegram InlineKeyboardMarkup"""
2016-04-24 16:30:39 +02:00
import sys
import unittest
sys.path.append('.')
import telegram
from tests.base import BaseTest
class InlineKeyboardMarkupTest(BaseTest, unittest.TestCase):
"""This object represents Tests for Telegram KeyboardButton."""
def setUp(self):
2016-10-12 22:56:57 +02:00
self.inline_keyboard = [[
telegram.InlineKeyboardButton(
text='button1', callback_data='data1'), telegram.InlineKeyboardButton(
text='button2', callback_data='data2')
]]
2016-04-24 16:30:39 +02:00
self.json_dict = {
2016-10-12 22:56:57 +02:00
'inline_keyboard':
[[self.inline_keyboard[0][0].to_dict(), self.inline_keyboard[0][1].to_dict()]],
2016-04-24 16:30:39 +02:00
}
def test_send_message_with_inline_keyboard_markup(self):
message = self._bot.sendMessage(
self._chat_id,
'Testing InlineKeyboardMarkup',
reply_markup=telegram.InlineKeyboardMarkup(self.inline_keyboard))
2016-04-24 16:30:39 +02:00
self.assertTrue(self.is_json(message.to_json()))
self.assertEqual(message.text, 'Testing InlineKeyboardMarkup')
2016-04-27 03:48:02 +02:00
def test_inline_keyboard_markup_de_json_empty(self):
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(None, self._bot)
2016-04-27 03:48:02 +02:00
self.assertFalse(inline_keyboard_markup)
2016-04-24 16:30:39 +02:00
def test_inline_keyboard_markup_de_json(self):
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
2016-04-24 16:30:39 +02:00
2016-05-15 02:52:35 +02:00
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
2016-08-26 11:17:05 +02:00
self.assertTrue(
isinstance(inline_keyboard_markup.inline_keyboard[0][0],
telegram.InlineKeyboardButton))
2016-04-24 16:30:39 +02:00
def test_inline_keyboard_markup_to_json(self):
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
2016-04-24 16:30:39 +02:00
self.assertTrue(self.is_json(inline_keyboard_markup.to_json()))
def test_inline_keyboard_markup_to_dict(self):
inline_keyboard_markup = telegram.InlineKeyboardMarkup.de_json(self.json_dict, self._bot)
2016-04-24 16:30:39 +02:00
2016-05-15 02:52:35 +02:00
self.assertTrue(isinstance(inline_keyboard_markup.inline_keyboard, list))
2016-08-26 11:17:05 +02:00
self.assertTrue(
isinstance(inline_keyboard_markup.inline_keyboard[0][0],
telegram.InlineKeyboardButton))
2016-04-24 16:30:39 +02:00
if __name__ == '__main__':
unittest.main()