Merge pull request #3412 from deltachat/adb/allow-comparing-with-none

avoid exceptions when messages/contacts/chats are compared with None
This commit is contained in:
Asiel Díaz Benítez
2022-06-10 03:21:41 -04:00
committed by GitHub
5 changed files with 15 additions and 3 deletions

View File

@@ -6,7 +6,7 @@
### Fixes
- set a default error if NDN does not provide an error
- python: avoid exceptions when messages/contacts/chats are compared with `None`
## 1.86.0

View File

@@ -32,6 +32,8 @@ class Chat(object):
self.id = id
def __eq__(self, other) -> bool:
if other is None:
return False
return self.id == getattr(other, "id", None) and self.account._dc_context == other.account._dc_context
def __ne__(self, other) -> bool:

View File

@@ -22,7 +22,9 @@ class Contact(object):
self.account = account
self.id = id
def __eq__(self, other):
def __eq__(self, other) -> bool:
if other is None:
return False
return self.account._dc_context == other.account._dc_context and self.id == other.id
def __ne__(self, other):

View File

@@ -26,7 +26,9 @@ class Message(object):
msg_id = self.id
assert msg_id is not None and msg_id >= 0, repr(msg_id)
def __eq__(self, other):
def __eq__(self, other) -> bool:
if other is None:
return False
return self.account == other.account and self.id == other.id
def __repr__(self):

View File

@@ -155,9 +155,11 @@ class TestOfflineContact:
ac1 = acfactory.get_pseudo_configured_account()
contact1 = ac1.create_contact("some1@example.org", name="some1")
contact2 = ac1.create_contact("some1@example.org", name="some1")
contact3 = None
str(contact1)
repr(contact1)
assert contact1 == contact2
assert contact1 != contact3
assert contact1.id
assert contact1.addr == "some1@example.org"
assert contact1.display_name == "some1"
@@ -251,10 +253,12 @@ class TestOfflineChat:
def test_chat_idempotent(self, chat1, ac1):
contact1 = chat1.get_contacts()[0]
chat2 = contact1.create_chat()
chat3 = None
assert chat2.id == chat1.id
assert chat2.get_name() == chat1.get_name()
assert chat1 == chat2
assert not (chat1 != chat2)
assert chat1 != chat3
for ichat in ac1.get_chats():
if ichat.id == chat1.id:
@@ -406,6 +410,8 @@ class TestOfflineChat:
def test_message_eq_contains(self, chat1):
msg = chat1.send_text("msg1")
msg2 = None
assert msg != msg2
assert msg in chat1.get_messages()
assert not (msg not in chat1.get_messages())
str(msg)