Skip to content

Commit a6b0e95

Browse files
committed
Add inline keyboard test.
1 parent 7958264 commit a6b0e95

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎telebot/types.py‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def add(self, *args):
526526
i = 1
527527
row = []
528528
for button in args:
529-
row.append(button.to_json())
529+
row.append(button.to_dic())
530530
if i % self.row_width == 0:
531531
self.keyboard.append(row)
532532
row = []
@@ -571,13 +571,16 @@ def __init__(self, text, request_contact=None, request_location=None):
571571
self.request_location = request_location
572572

573573
def to_json(self):
574+
return json.dumps(self.to_dic())
575+
576+
def to_dic(self):
574577
json_dic = {'text': self.text}
575578
if self.request_contact:
576579
json_dic['request_contact'] = self.request_contact
577580
if self.request_location:
578581
json_dic['request_location'] = self.request_location
582+
return json_dic
579583

580-
return json.dump(json_dic)
581584

582585

583586
class InlineKeyboardMarkup(JsonSerializable):
@@ -598,7 +601,7 @@ def add(self, *args):
598601
i = 1
599602
row = []
600603
for button in args:
601-
row.append(button.to_json())
604+
row.append(button.to_dic())
602605
if i % self.row_width == 0:
603606
self.keyboard.append(row)
604607
row = []
@@ -627,6 +630,7 @@ def to_json(self):
627630
return json.dumps(json_dict)
628631

629632

633+
630634
class InlineKeyboardButton(JsonSerializable):
631635
def __init__(self, text, url=None, callback_data=None, switch_inline_query=None):
632636
self.text = text
@@ -635,15 +639,17 @@ def __init__(self, text, url=None, callback_data=None, switch_inline_query=None)
635639
self.switch_inline_query = switch_inline_query
636640

637641
def to_json(self):
642+
return json.dumps(self.to_dic())
643+
644+
def to_dic(self):
638645
json_dic = {'text': self.text}
639646
if self.url:
640647
json_dic['url'] = self.url
641648
if self.callback_data:
642649
json_dic['callback_data'] = self.callback_data
643650
if self.switch_inline_query:
644651
json_dic['switch_inline_quer'] = self.switch_inline_quer
645-
return json.dump(json_dic)
646-
652+
return json_dic
647653

648654
class CallbackQuery(JsonDeserializable):
649655
@classmethod
@@ -969,3 +975,4 @@ def to_json(self):
969975
if self.description:
970976
json_dict['description'] = self.description
971977
return json.dumps(json_dict)
978+

‎tests/test_telebot.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,24 @@ def test_send_message_dis_noti(self):
236236
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True)
237237
assert ret_msg.message_id
238238

239+
def test_send_message_with_markup(self):
240+
text = 'CI Test Message'
241+
tb = telebot.TeleBot(TOKEN)
242+
markup = types.ReplyKeyboardMarkup()
243+
markup.add(types.KeyboardButton("1"))
244+
markup.add(types.KeyboardButton("2"))
245+
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup)
246+
assert ret_msg.message_id
247+
248+
def test_send_message_with_inlinemarkup(self):
249+
text = 'CI Test Message'
250+
tb = telebot.TeleBot(TOKEN)
251+
markup = types.InlineKeyboardMarkup()
252+
markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com"))
253+
markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com"))
254+
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup)
255+
assert ret_msg.message_id
256+
239257
def test_forward_message(self):
240258
text = 'CI forward_message Test Message'
241259
tb = telebot.TeleBot(TOKEN)
@@ -309,3 +327,5 @@ def test_is_string_string(self):
309327
def test_not_string(self):
310328
i1 = 10
311329
assert not util.is_string(i1)
330+
331+

0 commit comments

Comments
 (0)