mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-28 19:22:54 +01:00
Adjust Equality Comparisons to Fit Bot API 6.0 (#3033)
This commit is contained in:
parent
298c5fab3b
commit
c1041655f6
6 changed files with 43 additions and 9 deletions
|
@ -35,8 +35,8 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
|
|
||||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||||
considered equal, if their :attr:`text`, :attr:`url`, :attr:`login_url`, :attr:`callback_data`,
|
considered equal, if their :attr:`text`, :attr:`url`, :attr:`login_url`, :attr:`callback_data`,
|
||||||
:attr:`switch_inline_query`, :attr:`switch_inline_query_current_chat`, :attr:`callback_game`
|
:attr:`switch_inline_query`, :attr:`switch_inline_query_current_chat`, :attr:`callback_game`,
|
||||||
and :attr:`pay` are equal.
|
:attr:`web_app` and :attr:`pay` are equal.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
* You must use exactly one of the optional fields. Mind that :attr:`callback_game` is not
|
* You must use exactly one of the optional fields. Mind that :attr:`callback_game` is not
|
||||||
|
@ -62,6 +62,10 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
|
|
||||||
* After Bot API 6.1, only ``HTTPS`` links will be allowed in :paramref:`login_url`.
|
* After Bot API 6.1, only ``HTTPS`` links will be allowed in :paramref:`login_url`.
|
||||||
|
|
||||||
|
.. versionchanged:: 20.0
|
||||||
|
:attr:`web_app` is considered as well when comparing objects of this type in terms of
|
||||||
|
equality.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (:obj:`str`): Label text on the button.
|
text (:obj:`str`): Label text on the button.
|
||||||
url (:obj:`str`, optional): HTTP or tg:// url to be opened when the button is pressed.
|
url (:obj:`str`, optional): HTTP or tg:// url to be opened when the button is pressed.
|
||||||
|
@ -185,6 +189,7 @@ class InlineKeyboardButton(TelegramObject):
|
||||||
self.url,
|
self.url,
|
||||||
self.login_url,
|
self.login_url,
|
||||||
self.callback_data,
|
self.callback_data,
|
||||||
|
self.web_app,
|
||||||
self.switch_inline_query,
|
self.switch_inline_query,
|
||||||
self.switch_inline_query_current_chat,
|
self.switch_inline_query_current_chat,
|
||||||
self.callback_game,
|
self.callback_game,
|
||||||
|
|
|
@ -35,8 +35,8 @@ class KeyboardButton(TelegramObject):
|
||||||
used instead of this object to specify text of the button.
|
used instead of this object to specify text of the button.
|
||||||
|
|
||||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||||
considered equal, if their :attr:`text`, :attr:`request_contact`, :attr:`request_location` and
|
considered equal, if their :attr:`text`, :attr:`request_contact`, :attr:`request_location`,
|
||||||
:attr:`request_poll` are equal.
|
:attr:`request_poll` and :attr:`web_app` are equal.
|
||||||
|
|
||||||
Note:
|
Note:
|
||||||
* Optional fields are mutually exclusive.
|
* Optional fields are mutually exclusive.
|
||||||
|
@ -47,6 +47,10 @@ class KeyboardButton(TelegramObject):
|
||||||
* :attr:`web_app` option will only work in Telegram versions released after 16 April, 2022.
|
* :attr:`web_app` option will only work in Telegram versions released after 16 April, 2022.
|
||||||
Older clients will display unsupported message.
|
Older clients will display unsupported message.
|
||||||
|
|
||||||
|
.. versionchanged:: 20.0
|
||||||
|
:attr:`web_app` is considered as well when comparing objects of this type in terms of
|
||||||
|
equality.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
text (:obj:`str`): Text of the button. If none of the optional fields are used, it will be
|
text (:obj:`str`): Text of the button. If none of the optional fields are used, it will be
|
||||||
sent to the bot as a message when the button is pressed.
|
sent to the bot as a message when the button is pressed.
|
||||||
|
@ -99,6 +103,7 @@ class KeyboardButton(TelegramObject):
|
||||||
self.request_contact,
|
self.request_contact,
|
||||||
self.request_location,
|
self.request_location,
|
||||||
self.request_poll,
|
self.request_poll,
|
||||||
|
self.web_app,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -36,7 +36,12 @@ class WebhookInfo(TelegramObject):
|
||||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||||
considered equal, if their :attr:`url`, :attr:`has_custom_certificate`,
|
considered equal, if their :attr:`url`, :attr:`has_custom_certificate`,
|
||||||
:attr:`pending_update_count`, :attr:`ip_address`, :attr:`last_error_date`,
|
:attr:`pending_update_count`, :attr:`ip_address`, :attr:`last_error_date`,
|
||||||
:attr:`last_error_message`, :attr:`max_connections` and :attr:`allowed_updates` are equal.
|
:attr:`last_error_message`, :attr:`max_connections`, :attr:`allowed_updates` and
|
||||||
|
:attr:`last_synchronization_error_date` are equal.
|
||||||
|
|
||||||
|
.. versionchanged:: 20.0
|
||||||
|
:attr:`last_synchronization_error_date` is considered as well when comparing objects of
|
||||||
|
this type in terms of equality.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
url (:obj:`str`): Webhook URL, may be empty if webhook is not set up.
|
url (:obj:`str`): Webhook URL, may be empty if webhook is not set up.
|
||||||
|
@ -121,6 +126,7 @@ class WebhookInfo(TelegramObject):
|
||||||
self.last_error_message,
|
self.last_error_message,
|
||||||
self.max_connections,
|
self.max_connections,
|
||||||
self.allowed_updates,
|
self.allowed_updates,
|
||||||
|
self.last_synchronization_error_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -130,7 +130,8 @@ class TestInlineKeyboardButton:
|
||||||
c = InlineKeyboardButton("texts", callback_data="data")
|
c = InlineKeyboardButton("texts", callback_data="data")
|
||||||
d = InlineKeyboardButton("text", callback_data="info")
|
d = InlineKeyboardButton("text", callback_data="info")
|
||||||
e = InlineKeyboardButton("text", url="http://google.com")
|
e = InlineKeyboardButton("text", url="http://google.com")
|
||||||
f = LoginUrl("http://google.com")
|
f = InlineKeyboardButton("text", web_app=WebAppInfo(url="https://ptb.org"))
|
||||||
|
g = LoginUrl("http://google.com")
|
||||||
|
|
||||||
assert a == b
|
assert a == b
|
||||||
assert hash(a) == hash(b)
|
assert hash(a) == hash(b)
|
||||||
|
@ -147,6 +148,9 @@ class TestInlineKeyboardButton:
|
||||||
assert a != f
|
assert a != f
|
||||||
assert hash(a) != hash(f)
|
assert hash(a) != hash(f)
|
||||||
|
|
||||||
|
assert a != g
|
||||||
|
assert hash(a) != hash(g)
|
||||||
|
|
||||||
@pytest.mark.parametrize("callback_data", ["foo", 1, ("da", "ta"), object()])
|
@pytest.mark.parametrize("callback_data", ["foo", 1, ("da", "ta"), object()])
|
||||||
def test_update_callback_data(self, callback_data):
|
def test_update_callback_data(self, callback_data):
|
||||||
button = InlineKeyboardButton(text="test", callback_data="data")
|
button = InlineKeyboardButton(text="test", callback_data="data")
|
||||||
|
|
|
@ -85,7 +85,8 @@ class TestKeyboardButton:
|
||||||
a = KeyboardButton("test", request_contact=True)
|
a = KeyboardButton("test", request_contact=True)
|
||||||
b = KeyboardButton("test", request_contact=True)
|
b = KeyboardButton("test", request_contact=True)
|
||||||
c = KeyboardButton("Test", request_location=True)
|
c = KeyboardButton("Test", request_location=True)
|
||||||
d = InlineKeyboardButton("test", callback_data="test")
|
d = KeyboardButton("Test", web_app=WebAppInfo(url="https://ptb.org"))
|
||||||
|
e = InlineKeyboardButton("test", callback_data="test")
|
||||||
|
|
||||||
assert a == b
|
assert a == b
|
||||||
assert hash(a) == hash(b)
|
assert hash(a) == hash(b)
|
||||||
|
@ -95,3 +96,6 @@ class TestKeyboardButton:
|
||||||
|
|
||||||
assert a != d
|
assert a != d
|
||||||
assert hash(a) != hash(d)
|
assert hash(a) != hash(d)
|
||||||
|
|
||||||
|
assert a != e
|
||||||
|
assert hash(a) != hash(e)
|
||||||
|
|
|
@ -105,7 +105,6 @@ class TestWebhookInfo:
|
||||||
pending_update_count=self.pending_update_count,
|
pending_update_count=self.pending_update_count,
|
||||||
last_error_date=self.last_error_date,
|
last_error_date=self.last_error_date,
|
||||||
max_connections=self.max_connections,
|
max_connections=self.max_connections,
|
||||||
last_synchronization_error_date=self.last_synchronization_error_date,
|
|
||||||
)
|
)
|
||||||
b = WebhookInfo(
|
b = WebhookInfo(
|
||||||
url=self.url,
|
url=self.url,
|
||||||
|
@ -121,7 +120,15 @@ class TestWebhookInfo:
|
||||||
last_error_date=0,
|
last_error_date=0,
|
||||||
max_connections=1,
|
max_connections=1,
|
||||||
)
|
)
|
||||||
d = LoginUrl("text.com")
|
d = WebhookInfo(
|
||||||
|
url="http://github.com",
|
||||||
|
has_custom_certificate=True,
|
||||||
|
pending_update_count=78,
|
||||||
|
last_error_date=0,
|
||||||
|
max_connections=1,
|
||||||
|
last_synchronization_error_date=123,
|
||||||
|
)
|
||||||
|
e = LoginUrl("text.com")
|
||||||
|
|
||||||
assert a == b
|
assert a == b
|
||||||
assert hash(a) == hash(b)
|
assert hash(a) == hash(b)
|
||||||
|
@ -132,3 +139,6 @@ class TestWebhookInfo:
|
||||||
|
|
||||||
assert a != d
|
assert a != d
|
||||||
assert hash(a) != hash(d)
|
assert hash(a) != hash(d)
|
||||||
|
|
||||||
|
assert a != e
|
||||||
|
assert hash(a) != hash(e)
|
||||||
|
|
Loading…
Reference in a new issue