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 test_kb_create_with_text(self):

        kb = Buttons.KeyboardButton('name')

        self.assertEqual(kb.get_text(), 'name')
        self.assertEqual(kb.is_request_contact(), False)
        self.assertEqual(kb.is_request_location(), False)
    def test_ikb_create_with_too_big_callback(self):

        with self.assertRaises(AssertionError):
            Buttons.InlineKeyboardButton('name', url='www.google.com',
                                         callback_data=
                                         '12345678910111213141516171819202122232425262728293032333435363738',
                                         switch_inline_query='inline_query',
                                         switch_inline_query_current_chat='inline_query_current_chat')
    def test_ikb_create_with_text_url_callback_switchiq(self):
        ikb = Buttons.InlineKeyboardButton('name', 'www.google.com', 'method-123-234', 'inline_query')

        self.assertEqual(ikb.get_text(), 'name')
        self.assertEqual(ikb.get_url(), 'www.google.com')
        self.assertEqual(ikb.get_callback_data(), 'method-123-234')
        self.assertEqual(ikb.get_switch_inline_query(), 'inline_query')
        self.assertEqual(ikb.get_switch_inline_query_current_chat(), None)
    def test_ikb_create_with_text(self):

        ikb = Buttons.InlineKeyboardButton('name')

        self.assertEqual(ikb.get_text(), 'name')
        self.assertEqual(ikb.get_url(), None)
        self.assertEqual(ikb.get_callback_data(), None)
        self.assertEqual(ikb.get_switch_inline_query(), None)
        self.assertEqual(ikb.get_switch_inline_query_current_chat(), None)
    def test_ikb_create_with_incorrect_switchiqch(self):

        with self.assertRaises(AssertionError):
            Buttons.InlineKeyboardButton('name', 'www.google.com', 'method-123-234', 'inline_query', 1)
    def test_ikb_create_with_incorrect_url(self):

        with self.assertRaises(AssertionError):
            Buttons.InlineKeyboardButton('name', 1.98, 'method-123-234', 'inline_query', 'inline_query_current_chat')
    def test_ikb_create_with_incorrect_callback(self):

        with self.assertRaises(AssertionError):
            Buttons.InlineKeyboardButton('ame', 'www.google.com', True, 'inline_query', 'inline_query_current_chat')
    def test_ikb_create_with_incorrect_name(self):

        with self.assertRaises(AssertionError):
            Buttons.InlineKeyboardButton(1, 'www.google.com', 'method-123-234', 'inline_query',
                                            'inline_query_current_chat')
 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_kb_create_with_incorrect_request_location(self):

        with self.assertRaises(AssertionError):
            Buttons.KeyboardButton('name', request_location=1.0)
    def test_kb_create_with_incorrect_name(self):

        with self.assertRaises(AssertionError):
            Buttons.KeyboardButton(1)