Adjust Equality Comparisons to Fit Bot API 6.0 (#3033)

This commit is contained in:
Bibo-Joshi 2022-05-18 07:48:20 +02:00 committed by GitHub
parent 298c5fab3b
commit c1041655f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 9 deletions

View file

@ -35,8 +35,8 @@ class InlineKeyboardButton(TelegramObject):
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`,
:attr:`switch_inline_query`, :attr:`switch_inline_query_current_chat`, :attr:`callback_game`
and :attr:`pay` are equal.
:attr:`switch_inline_query`, :attr:`switch_inline_query_current_chat`, :attr:`callback_game`,
:attr:`web_app` and :attr:`pay` are equal.
Note:
* 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`.
.. versionchanged:: 20.0
:attr:`web_app` is considered as well when comparing objects of this type in terms of
equality.
Args:
text (:obj:`str`): Label text on the button.
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.login_url,
self.callback_data,
self.web_app,
self.switch_inline_query,
self.switch_inline_query_current_chat,
self.callback_game,

View file

@ -35,8 +35,8 @@ class KeyboardButton(TelegramObject):
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
considered equal, if their :attr:`text`, :attr:`request_contact`, :attr:`request_location` and
:attr:`request_poll` are equal.
considered equal, if their :attr:`text`, :attr:`request_contact`, :attr:`request_location`,
:attr:`request_poll` and :attr:`web_app` are equal.
Note:
* 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.
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:
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.
@ -99,6 +103,7 @@ class KeyboardButton(TelegramObject):
self.request_contact,
self.request_location,
self.request_poll,
self.web_app,
)
@classmethod

View file

@ -36,7 +36,12 @@ class WebhookInfo(TelegramObject):
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`,
: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:
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.max_connections,
self.allowed_updates,
self.last_synchronization_error_date,
)
@classmethod

View file

@ -130,7 +130,8 @@ class TestInlineKeyboardButton:
c = InlineKeyboardButton("texts", callback_data="data")
d = InlineKeyboardButton("text", callback_data="info")
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 hash(a) == hash(b)
@ -147,6 +148,9 @@ class TestInlineKeyboardButton:
assert a != f
assert hash(a) != hash(f)
assert a != g
assert hash(a) != hash(g)
@pytest.mark.parametrize("callback_data", ["foo", 1, ("da", "ta"), object()])
def test_update_callback_data(self, callback_data):
button = InlineKeyboardButton(text="test", callback_data="data")

View file

@ -85,7 +85,8 @@ class TestKeyboardButton:
a = KeyboardButton("test", request_contact=True)
b = KeyboardButton("test", request_contact=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 hash(a) == hash(b)
@ -95,3 +96,6 @@ class TestKeyboardButton:
assert a != d
assert hash(a) != hash(d)
assert a != e
assert hash(a) != hash(e)

View file

@ -105,7 +105,6 @@ class TestWebhookInfo:
pending_update_count=self.pending_update_count,
last_error_date=self.last_error_date,
max_connections=self.max_connections,
last_synchronization_error_date=self.last_synchronization_error_date,
)
b = WebhookInfo(
url=self.url,
@ -121,7 +120,15 @@ class TestWebhookInfo:
last_error_date=0,
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 hash(a) == hash(b)
@ -132,3 +139,6 @@ class TestWebhookInfo:
assert a != d
assert hash(a) != hash(d)
assert a != e
assert hash(a) != hash(e)