From 0e874735ac6fa6d87b9c0ca8105cd78103deb9ab Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 1 Apr 2025 19:54:41 +0000 Subject: [PATCH] test: encrypt legacy Python tests This makes it possible to run Python tests against chatmail servers that don't allow any unencrypted messages. --- python/src/deltachat/account.py | 6 ++++++ python/tests/test_1_online.py | 10 ++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 6003e4a5e..503462ec8 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -280,6 +280,12 @@ class Account: :param name: (optional) display name for this contact :returns: :class:`deltachat.contact.Contact` instance. """ + if isinstance(obj, Account): + if not obj.is_configured(): + raise ValueError("Can only add configured accounts as contacts") + assert name is None + vcard = obj.get_self_contact().make_vcard() + return self.import_vcard(vcard)[0] (name, addr) = self.get_contact_addr_and_name(obj, name) name_c = as_dc_charpointer(name) addr_c = as_dc_charpointer(addr) diff --git a/python/tests/test_1_online.py b/python/tests/test_1_online.py index bce9506be..c41dfe1d8 100644 --- a/python/tests/test_1_online.py +++ b/python/tests/test_1_online.py @@ -860,7 +860,7 @@ def test_send_first_message_as_long_unicode_with_cr(acfactory, lp): " wrapped using format=flowed and unwrapped on the receiver" ) msg_out = chat.send_text(text1) - assert not msg_out.is_encrypted() + assert msg_out.is_encrypted() lp.sec("wait for ac2 to receive multi-line non-unicode message") msg_in = ac2._evtracker.wait_next_incoming_message() @@ -869,7 +869,7 @@ def test_send_first_message_as_long_unicode_with_cr(acfactory, lp): lp.sec("sending multi-line unicode text message from ac1 to ac2") text2 = "äalis\nthis is ßßÄ" msg_out = chat.send_text(text2) - assert not msg_out.is_encrypted() + assert msg_out.is_encrypted() lp.sec("wait for ac2 to receive multi-line unicode message") msg_in = ac2._evtracker.wait_next_incoming_message() @@ -1374,7 +1374,7 @@ def test_add_remove_member_remote_events(acfactory, lp): lp.sec("ac1: add address2") # note that if the above create_chat() would not # happen we would not receive a proper member_added event - contact2 = chat.add_contact(ac3_addr) + contact2 = chat.add_contact(ac3) ev = in_list.get() assert ev.action == "chat-modified" ev = in_list.get() @@ -1814,9 +1814,7 @@ def test_name_changes(acfactory): ac1, ac2 = acfactory.get_online_accounts(2) ac1.set_config("displayname", "Account 1") - # Similar to acfactory.get_accepted_chat, but without setting the contact name. - ac2.create_contact(ac1.get_config("addr")).create_chat() - chat12 = ac1.create_contact(ac2.get_config("addr")).create_chat() + chat12 = acfactory.get_accepted_chat(ac1, ac2) contact = None def update_name():