mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
Add inline keyboard test.
This commit is contained in:
parent
7958264d64
commit
a6b0e9598c
@ -526,7 +526,7 @@ class ReplyKeyboardMarkup(JsonSerializable):
|
|||||||
i = 1
|
i = 1
|
||||||
row = []
|
row = []
|
||||||
for button in args:
|
for button in args:
|
||||||
row.append(button.to_json())
|
row.append(button.to_dic())
|
||||||
if i % self.row_width == 0:
|
if i % self.row_width == 0:
|
||||||
self.keyboard.append(row)
|
self.keyboard.append(row)
|
||||||
row = []
|
row = []
|
||||||
@ -571,13 +571,16 @@ class KeyboardButton(JsonSerializable):
|
|||||||
self.request_location = request_location
|
self.request_location = request_location
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
|
return json.dumps(self.to_dic())
|
||||||
|
|
||||||
|
def to_dic(self):
|
||||||
json_dic = {'text': self.text}
|
json_dic = {'text': self.text}
|
||||||
if self.request_contact:
|
if self.request_contact:
|
||||||
json_dic['request_contact'] = self.request_contact
|
json_dic['request_contact'] = self.request_contact
|
||||||
if self.request_location:
|
if self.request_location:
|
||||||
json_dic['request_location'] = self.request_location
|
json_dic['request_location'] = self.request_location
|
||||||
|
return json_dic
|
||||||
|
|
||||||
return json.dump(json_dic)
|
|
||||||
|
|
||||||
|
|
||||||
class InlineKeyboardMarkup(JsonSerializable):
|
class InlineKeyboardMarkup(JsonSerializable):
|
||||||
@ -598,7 +601,7 @@ class InlineKeyboardMarkup(JsonSerializable):
|
|||||||
i = 1
|
i = 1
|
||||||
row = []
|
row = []
|
||||||
for button in args:
|
for button in args:
|
||||||
row.append(button.to_json())
|
row.append(button.to_dic())
|
||||||
if i % self.row_width == 0:
|
if i % self.row_width == 0:
|
||||||
self.keyboard.append(row)
|
self.keyboard.append(row)
|
||||||
row = []
|
row = []
|
||||||
@ -627,6 +630,7 @@ class InlineKeyboardMarkup(JsonSerializable):
|
|||||||
return json.dumps(json_dict)
|
return json.dumps(json_dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class InlineKeyboardButton(JsonSerializable):
|
class InlineKeyboardButton(JsonSerializable):
|
||||||
def __init__(self, text, url=None, callback_data=None, switch_inline_query=None):
|
def __init__(self, text, url=None, callback_data=None, switch_inline_query=None):
|
||||||
self.text = text
|
self.text = text
|
||||||
@ -635,6 +639,9 @@ class InlineKeyboardButton(JsonSerializable):
|
|||||||
self.switch_inline_query = switch_inline_query
|
self.switch_inline_query = switch_inline_query
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
|
return json.dumps(self.to_dic())
|
||||||
|
|
||||||
|
def to_dic(self):
|
||||||
json_dic = {'text': self.text}
|
json_dic = {'text': self.text}
|
||||||
if self.url:
|
if self.url:
|
||||||
json_dic['url'] = self.url
|
json_dic['url'] = self.url
|
||||||
@ -642,8 +649,7 @@ class InlineKeyboardButton(JsonSerializable):
|
|||||||
json_dic['callback_data'] = self.callback_data
|
json_dic['callback_data'] = self.callback_data
|
||||||
if self.switch_inline_query:
|
if self.switch_inline_query:
|
||||||
json_dic['switch_inline_quer'] = self.switch_inline_quer
|
json_dic['switch_inline_quer'] = self.switch_inline_quer
|
||||||
return json.dump(json_dic)
|
return json_dic
|
||||||
|
|
||||||
|
|
||||||
class CallbackQuery(JsonDeserializable):
|
class CallbackQuery(JsonDeserializable):
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -969,3 +975,4 @@ class InlineQueryResultVideo(JsonSerializable):
|
|||||||
if self.description:
|
if self.description:
|
||||||
json_dict['description'] = self.description
|
json_dict['description'] = self.description
|
||||||
return json.dumps(json_dict)
|
return json.dumps(json_dict)
|
||||||
|
|
||||||
|
@ -236,6 +236,24 @@ class TestTeleBot:
|
|||||||
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True)
|
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True)
|
||||||
assert ret_msg.message_id
|
assert ret_msg.message_id
|
||||||
|
|
||||||
|
def test_send_message_with_markup(self):
|
||||||
|
text = 'CI Test Message'
|
||||||
|
tb = telebot.TeleBot(TOKEN)
|
||||||
|
markup = types.ReplyKeyboardMarkup()
|
||||||
|
markup.add(types.KeyboardButton("1"))
|
||||||
|
markup.add(types.KeyboardButton("2"))
|
||||||
|
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup)
|
||||||
|
assert ret_msg.message_id
|
||||||
|
|
||||||
|
def test_send_message_with_inlinemarkup(self):
|
||||||
|
text = 'CI Test Message'
|
||||||
|
tb = telebot.TeleBot(TOKEN)
|
||||||
|
markup = types.InlineKeyboardMarkup()
|
||||||
|
markup.add(types.InlineKeyboardButton("Google", url="http://www.google.com"))
|
||||||
|
markup.add(types.InlineKeyboardButton("Yahoo", url="http://www.yahoo.com"))
|
||||||
|
ret_msg = tb.send_message(CHAT_ID, text, disable_notification=True, reply_markup=markup)
|
||||||
|
assert ret_msg.message_id
|
||||||
|
|
||||||
def test_forward_message(self):
|
def test_forward_message(self):
|
||||||
text = 'CI forward_message Test Message'
|
text = 'CI forward_message Test Message'
|
||||||
tb = telebot.TeleBot(TOKEN)
|
tb = telebot.TeleBot(TOKEN)
|
||||||
@ -309,3 +327,5 @@ class TestTeleBot:
|
|||||||
def test_not_string(self):
|
def test_not_string(self):
|
||||||
i1 = 10
|
i1 = 10
|
||||||
assert not util.is_string(i1)
|
assert not util.is_string(i1)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user