def test_ReplyKeyboardMarkup_2cols(self): rkm = ReplyMarkups.ReplyKeyboardMarkup(resize_keyboard=True) rkm.add_button(Buttons.KeyboardButton('Text1', request_location=True), row=1, col=1) rkm.add_button(Buttons.KeyboardButton('Text2', True), row=2, col=1) self.assertEqual(str(rkm.get_markup()), "{'resize_keyboard': True, 'keyboard': [[{'text': 'Text1', " + "'request_location': True}], [{'text': 'Text2', " + "'request_contact': True}]]}")
def test_ReplyKeyboardMarkup_get_button(self): rkm = ReplyMarkups.ReplyKeyboardMarkup() rkm.add_button(Buttons.KeyboardButton('Text 1'), col=1, row=1) rkm.add_button(Buttons.KeyboardButton('Text 1'), col=1, row=2) button = rkm.get_button(col=1, row=2) self.assertEqual(button.get_markup(), {'text': 'Text 1'}) self.assertEqual(rkm.get_markup(), {'resize_keyboard': True, 'keyboard': [[{'text': 'Text 1'}], [{'text': 'Text 1'}]]})
def test_InlineKeyboardMarkup(self): ikm = ReplyMarkups.InlineKeyboardMarkup(resize_keyboard=False) ikm.add_button(Buttons.InlineKeyboardButton('Text1', callback_data='cbd'), row=1, col=1) ikm.add_button(Buttons.InlineKeyboardButton('Text2', switch_inline_query='switch_inline_query2'), row=1, col=2) ikm.add_button(Buttons.InlineKeyboardButton('Text3', switch_inline_query_current_chat= 'switch_inline_query_current_chat3'), row=1, col=3) button = ikm.pop_button(row=1, col=2) button.set_text('new text') ikm.add_button(button, row=2, col=1) ikm.add_button(Buttons.InlineKeyboardButton('Text1', callback_data='new button'), row=1, col=2) self.assertEqual(str(ikm.get_markup()), "{'inline_keyboard': [[{'text': 'Text1', 'callback_data': 'cbd'}, " + "{'text': 'Text1', 'callback_data': 'new button'}, {'text': 'Text3', " + "'switch_inline_query_current_chat': 'switch_inline_query_current_" + "chat3'}], [{'text': 'new text', 'switch_inline_query': " + "'switch_inline_query2'}]]}")
def __show_lists_of_lists(self, chat_id, arguments): if arguments is 'all': tuple_of_tuples = self.db.get_list_of_lists( self.chat_dict[chat_id].chat_id, deleted=None) elif arguments is 'deleted': tuple_of_tuples = self.db.get_list_of_lists( self.chat_dict[chat_id].chat_id, deleted=True) else: tuple_of_tuples = self.db.get_list_of_lists( self.chat_dict[chat_id].chat_id, deleted=False) ik = ReplyMarkups.InlineKeyboard() for tup in tuple_of_tuples: ik.add_button(text=str(tup[2]) + '. ' + str(tup[1]), callback_data='show_list-' + str(tup[0]), column=0) ik.add_button(text='Dodaj listę', callback_data='add_list', column=0) self.chat_dict[chat_id].respond("Your lists:", ik) self.chat_dict[chat_id].state = 0
def test_InlineKeyboardMarkup_wrong_button(self): with self.assertRaises(AssertionError): ikm = ReplyMarkups.InlineKeyboardMarkup() ikm.add_button('button', row=1, col=1)
def test_ReplyKeyboardMarkup_twice_the_same_place(self): with self.assertRaises(Exception): rkm = ReplyMarkups.ReplyKeyboardMarkup() rkm.add_button(Buttons.KeyboardButton('Text 1'), col=1, row=1) rkm.add_button(Buttons.KeyboardButton('Text 1'), col=1, row=1)
def test_ReplyKeyboardMarkup_3argError(self): with self.assertRaises(AssertionError): ReplyMarkups.ReplyKeyboardMarkup(selective=1.0)
def test_ReplyKeyboardMarkup_2argError(self): with self.assertRaises(AssertionError): ReplyMarkups.ReplyKeyboardMarkup(one_time_keyboard='True')
def test_ReplyKeyboardMarkup_1argError(self): with self.assertRaises(AssertionError): ReplyMarkups.ReplyKeyboardMarkup(resize_keyboard=1)
def test_empty_ReplyKeyboardMarkup(self): rkm = ReplyMarkups.ReplyKeyboardMarkup(resize_keyboard=True) self.assertEqual(rkm.get_markup(), {'resize_keyboard': True, 'keyboard': []})
def test_ForceReply_get_reply_markup(self): fr = ReplyMarkups.ForceReply() self.assertEqual(fr.get_markup(), {'force_reply': True})
def test_reply_keyboard_remove_get_reply_markup(self): rkr = ReplyMarkups.ReplyKeyboardRemove(True) self.assertEqual(rkr.get_markup(), {'selective': True, 'remove_keyboard': True})