diff --git a/python/src/deltachat/account.py b/python/src/deltachat/account.py index 4d74f513..92aa59a0 100644 --- a/python/src/deltachat/account.py +++ b/python/src/deltachat/account.py @@ -35,14 +35,14 @@ class EventHandler: class Account: - def __init__(self, db_path, logcallback=eventprinter, eventhandler=None): + def __init__(self, db_path, logcallback=None, eventhandler=None): self.dc_context = ctx = capi.lib.dc_context_new( capi.lib.py_dc_callback, capi.ffi.NULL, capi.ffi.NULL) if hasattr(db_path, "encode"): db_path = db_path.encode("utf8") capi.lib.dc_open(ctx, db_path, capi.ffi.NULL) - self._logcallback = logcallback or (lambda *args: None) + self._logcallback = logcallback or eventprinter if eventhandler is None: eventhandler = EventHandler(self.dc_context) self._eventhandler = eventhandler diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 9b4929a4..90286ae0 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -1,19 +1,45 @@ import pytest +from deltachat import Account def pytest_addoption(parser): - parser.addoption("--user", action="store", default=None, - help="user and domain of test account: example user@example.org") - parser.addoption("--password", action="store", default=None) + parser.addoption( + "--liveconfig", action="store", default=None, + help="a file with >=2 lines where each line contains NAME=VALUE config settings for one account" + ) + + +_dummy = object() @pytest.fixture -def userpassword(pytestconfig): - user = pytestconfig.getoption("--user") - passwd = pytestconfig.getoption("--password") - if user and passwd: - return user, passwd - pytest.skip("specify a test account with --user and --password options") +def acfactory(pytestconfig, tmpdir, request): + fn = pytestconfig.getoption("--liveconfig") + if not fn: + pytest.skip("specify a --liveconfig file to run tests with real accounts") + + class AccountMaker: + def __init__(self): + self.configlist = [] + for line in open(fn): + if line.strip(): + d = {} + for part in line.split(): + name, value = part.split("=") + d[name] = value + self.configlist.append(d) + self.count = 0 + + def get_live_account(self, logcallback=None): + configdict = self.configlist.pop(0) + tmpdb = tmpdir.join("testdb%d" % self.count) + ac = Account(tmpdb.strpath, logcallback=logcallback) + ac.set_config(**configdict) + ac.start() + request.addfinalizer(ac.shutdown) + return ac + + return AccountMaker() @pytest.fixture diff --git a/python/tests/test_account.py b/python/tests/test_account.py new file mode 100644 index 00000000..f73014e8 --- /dev/null +++ b/python/tests/test_account.py @@ -0,0 +1,27 @@ +from __future__ import print_function +import re + +try: + from queue import Queue +except ImportError: + from Queue import Queue + + +class TestLive: + def test_basic_configure_login_ok(self, acfactory): + q = Queue() + acfactory.get_live_account(logcallback=q.put) + imap_ok = smtp_ok = False + while not imap_ok or not smtp_ok: + evt_name, data1, data2 = q.get(timeout=5.0) + print(evt_name, data1, data2) + if evt_name == "DC_EVENT_ERROR": + assert 0 + if evt_name == "DC_EVENT_INFO": + if re.match("imap-login.*ok.", data2.lower()): + imap_ok = True + if re.match("smtp-login.*ok.", data2.lower()): + smtp_ok = True + + def test_message_send_receive(self, acfactory): + pass diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index 6875ccc9..5e505e40 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -1,12 +1,5 @@ from __future__ import print_function -import deltachat -import re from deltachat import capi -try: - from queue import Queue -except ImportError: - from Queue import Queue - def test_empty_context(): @@ -16,23 +9,3 @@ def test_empty_context(): def test_event_defines(): assert capi.lib.DC_EVENT_INFO == 100 - - -class TestLive: - def test_basic_configure_login_ok(self, request, tmp_db_path, userpassword): - q = Queue() - dc = deltachat.Account(tmp_db_path, logcallback=q.put) - dc.set_config(addr=userpassword[0], mail_pw=userpassword[1]) - dc.start() - request.addfinalizer(dc.shutdown) - imap_ok = smtp_ok = False - while not imap_ok or not smtp_ok: - evt_name, data1, data2 = q.get(timeout=5.0) - print(evt_name, data1, data2) - if evt_name == "DC_EVENT_ERROR": - assert 0 - if evt_name == "DC_EVENT_INFO": - if re.match("imap-login.*ok.", data2.lower()): - imap_ok = True - if re.match("smtp-login.*ok.", data2.lower()): - smtp_ok = True diff --git a/python/tox.ini b/python/tox.ini index 15a4cec9..275b401e 100644 --- a/python/tox.ini +++ b/python/tox.ini @@ -10,7 +10,9 @@ envlist = [testenv] commands = pytest {posargs:tests} usedevelop = True -deps = pytest +deps = + pytest + pdbpp [testenv:linting] skipsdist = True