mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 02:09:17 +02:00
use the technique @r10s described for getting an offline but configured account
this also resolves a number of XXX
This commit is contained in:
parent
da78552622
commit
366da3e9fa
3 changed files with 36 additions and 23 deletions
|
@ -4,6 +4,7 @@ import re
|
|||
import threading
|
||||
from deltachat import Account
|
||||
from deltachat.types import cached_property
|
||||
from deltachat.capi import lib
|
||||
|
||||
|
||||
def pytest_addoption(parser):
|
||||
|
@ -35,13 +36,26 @@ def acfactory(pytestconfig, tmpdir, request):
|
|||
configlist.append(d)
|
||||
return configlist
|
||||
|
||||
def get_offline_account(self):
|
||||
def get_unconfigured_account(self):
|
||||
self.offline_count += 1
|
||||
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
|
||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.offline_count))
|
||||
ac._evlogger.set_timeout(2)
|
||||
return ac
|
||||
|
||||
def get_configured_offline_account(self):
|
||||
self.offline_count += 1
|
||||
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
|
||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.offline_count))
|
||||
|
||||
# do a pseudo-configured account
|
||||
addr = "addr{}@offline.org".format(self.offline_count)
|
||||
ac.set_config("addr", addr)
|
||||
lib.dc_set_config(ac._dc_context, b"configured_addr", addr.encode("ascii"))
|
||||
lib.dc_set_config_int(ac._dc_context, b"configured", 1);
|
||||
ac._evlogger.set_timeout(2)
|
||||
return ac
|
||||
|
||||
def get_live_account(self, started=True):
|
||||
if not fn:
|
||||
pytest.skip("specify a --liveconfig file to run tests with real accounts")
|
||||
|
|
|
@ -65,7 +65,9 @@ class Account(object):
|
|||
:raises: KeyError if no config value was found.
|
||||
"""
|
||||
name = name.encode("utf8")
|
||||
res = lib.dc_get_config(self._dc_context, name, b'')
|
||||
res = lib.dc_get_config(self._dc_context, name, ffi.NULL)
|
||||
if res == ffi.NULL:
|
||||
raise KeyError("config value not found for: {!r}".format(name))
|
||||
return from_dc_charpointer(res)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
|
|
|
@ -5,23 +5,29 @@ from deltachat.capi import lib
|
|||
|
||||
class TestOfflineAccount:
|
||||
def test_is_not_configured(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_unconfigured_account()
|
||||
assert not ac1.is_configured()
|
||||
with pytest.raises(ValueError):
|
||||
ac1.check_is_configured()
|
||||
|
||||
def test_selfcontact_if_unconfigured(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_unconfigured_account()
|
||||
with pytest.raises(ValueError):
|
||||
ac1.get_self_contact()
|
||||
|
||||
# def test_get_config_fails(self, acfactory):
|
||||
# ac1 = acfactory.get_offline_account()
|
||||
# with pytest.raises(KeyError):
|
||||
# ac1.get_config("123123")
|
||||
def test_selfcontact_configured(self, acfactory):
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
me = ac1.get_self_contact()
|
||||
assert me.display_name
|
||||
assert me.addr
|
||||
|
||||
def test_get_config_fails(self, acfactory):
|
||||
ac1 = acfactory.get_unconfigured_account()
|
||||
with pytest.raises(KeyError):
|
||||
ac1.get_config("123123")
|
||||
|
||||
def test_contact_attr(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
contact1 = ac1.create_contact(email="some1@hello.com", name="some1")
|
||||
assert contact1.id
|
||||
assert contact1.addr == "some1@hello.com"
|
||||
|
@ -29,9 +35,8 @@ class TestOfflineAccount:
|
|||
assert not contact1.is_blocked()
|
||||
assert not contact1.is_verified()
|
||||
|
||||
@pytest.mark.xfail(reason="on travis it fails, needs investigation")
|
||||
def test_get_contacts(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
contact1 = ac1.create_contact(email="some1@hello.com", name="some1")
|
||||
contacts = ac1.get_contacts()
|
||||
assert len(contacts) == 1
|
||||
|
@ -44,7 +49,7 @@ class TestOfflineAccount:
|
|||
assert len(contacts) == 2
|
||||
|
||||
def test_chat(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||
chat = ac1.create_chat_by_contact(contact1)
|
||||
assert chat.id >= lib.DC_CHAT_ID_LAST_SPECIAL, chat.id
|
||||
|
@ -62,7 +67,7 @@ class TestOfflineAccount:
|
|||
pytest.fail("could not find chat")
|
||||
|
||||
def test_group_chat_creation(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||
contact2 = ac1.create_contact("some2@hello.com", name="some2")
|
||||
chat = ac1.create_group_chat(name="title1")
|
||||
|
@ -76,7 +81,7 @@ class TestOfflineAccount:
|
|||
assert chat.get_name() == "title2"
|
||||
|
||||
def test_message(self, acfactory):
|
||||
ac1 = acfactory.get_offline_account()
|
||||
ac1 = acfactory.get_configured_offline_account()
|
||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||
chat = ac1.create_chat_by_contact(contact1)
|
||||
msg = chat.send_text_message("msg1")
|
||||
|
@ -85,8 +90,7 @@ class TestOfflineAccount:
|
|||
assert not msg_state.is_in_fresh()
|
||||
assert not msg_state.is_in_noticed()
|
||||
assert not msg_state.is_in_seen()
|
||||
# XXX the following line should work but doesn't:
|
||||
# assert msg_state.is_out_pending()
|
||||
assert msg_state.is_out_pending()
|
||||
assert not msg_state.is_out_failed()
|
||||
assert not msg_state.is_out_delivered()
|
||||
assert not msg_state.is_out_mdn_received()
|
||||
|
@ -112,13 +116,6 @@ class TestOnlineAccount:
|
|||
print("** CONFIG PROGRESS {}".format(target), account)
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue