diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 8b314f7b..2d990bf5 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -79,9 +79,11 @@ class Contact: def __init__(self, dc_context, contact_id): self.dc_context = dc_context self.id = contact_id - # XXX do we need to free dc_contact_t? (we own it according to API) self.dc_contact_t = capi.lib.dc_get_contact(self.dc_context, contact_id) + def __del__(self): + capi.lib.free(self.dc_contact_t) + @property def addr(self): return ffi_unicode(capi.lib.dc_contact_get_addr(self.dc_contact_t)) @@ -161,6 +163,8 @@ class Account: return ffi_unicode(res) def get_self_contact(self): + if not capi.lib.dc_is_configured(self.dc_context): + raise ValueError("need to configure first") return Contact(self.dc_context, capi.lib.DC_CONTACT_ID_SELF) def create_contact(self, email, name=ffi.NULL): diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 76353489..a6c1628f 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -1,13 +1,13 @@ from __future__ import print_function +import pytest from deltachat.capi import lib class TestOfflineAccount: - def test_selfcontact(self, acfactory): + def test_selfcontact_if_unconfigured(self, acfactory): ac1 = acfactory.get_offline_account() - me = ac1.get_self_contact() - assert me.display_name - # assert me.addr # xxx why is this empty? + with pytest.raises(ValueError): + ac1.get_self_contact() def test_contacts(self, acfactory): ac1 = acfactory.get_offline_account() @@ -50,6 +50,13 @@ class TestOnlineAccount: print("** CONFIG PROGRESS {}".format(target), account.dc_context) break + def test_selfcontact(self, acfactory): + ac1 = acfactory.get_live_account() + self.wait_configuration_progress(ac1, 1000) + me = ac1.get_self_contact() + assert me.display_name + assert me.addr + def test_basic_configure_login_ok(self, acfactory): ac1 = acfactory.get_live_account() self.wait_successful_IMAP_SMTP_connection(ac1) diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index c88d4afe..74332574 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -11,6 +11,7 @@ def test_event_defines(): assert capi.lib.DC_EVENT_INFO == 100 assert capi.lib.DC_CONTACT_ID_SELF + def test_sig(): sig = capi.lib.dc_get_event_signature_types assert sig(capi.lib.DC_EVENT_INFO) == 2 diff --git a/src/dc_chat.c b/src/dc_chat.c index a53dba75..6a34c934 100644 --- a/src/dc_chat.c +++ b/src/dc_chat.c @@ -2181,7 +2181,7 @@ uint32_t dc_send_text_msg(dc_context_t* context, uint32_t chat_id, const char* t uint32_t ret = 0; if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || chat_id<=DC_CHAT_ID_LAST_SPECIAL || text_to_send==NULL) { - dc_log_info(context, 0, "some error"); + dc_log_info(context, 0, "some error"); goto cleanup; }