mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2025-03-27 08:50:38 +01:00
Add Rich Equality Comparison to WriteAccessAllowed
(#3911)
This commit is contained in:
parent
895403a0b5
commit
39d45124df
2 changed files with 26 additions and 0 deletions
|
@ -28,7 +28,12 @@ class WriteAccessAllowed(TelegramObject):
|
|||
This object represents a service message about a user allowing a bot to write messages after
|
||||
adding the bot to the attachment menu or launching a Web App from a link.
|
||||
|
||||
Objects of this class are comparable in terms of equality. Two objects of this class are
|
||||
considered equal, if their :attr:`web_app_name` is equal.
|
||||
|
||||
.. versionadded:: 20.0
|
||||
.. versionchanged:: NEXT.VERSION
|
||||
Added custom equality comparison for objects of this class.
|
||||
|
||||
Args:
|
||||
web_app_name (:obj:`str`, optional): Name of the Web App which was launched from a link.
|
||||
|
@ -50,4 +55,6 @@ class WriteAccessAllowed(TelegramObject):
|
|||
super().__init__(api_kwargs=api_kwargs)
|
||||
self.web_app_name: Optional[str] = web_app_name
|
||||
|
||||
self._id_attrs = (self.web_app_name,)
|
||||
|
||||
self._freeze()
|
||||
|
|
|
@ -36,3 +36,22 @@ class TestWriteAccessAllowed:
|
|||
action = WriteAccessAllowed()
|
||||
action_dict = action.to_dict()
|
||||
assert action_dict == {}
|
||||
|
||||
def test_equality(self):
|
||||
a = WriteAccessAllowed()
|
||||
b = WriteAccessAllowed()
|
||||
c = WriteAccessAllowed(web_app_name="foo")
|
||||
d = WriteAccessAllowed(web_app_name="foo")
|
||||
e = WriteAccessAllowed(web_app_name="bar")
|
||||
|
||||
assert a == b
|
||||
assert hash(a) == hash(b)
|
||||
|
||||
assert a != c
|
||||
assert hash(a) != hash(c)
|
||||
|
||||
assert c == d
|
||||
assert hash(c) == hash(d)
|
||||
|
||||
assert c != e
|
||||
assert hash(c) != hash(e)
|
||||
|
|
Loading…
Add table
Reference in a new issue