mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 07:32:12 +03:00
simplify and speedup configuration handling
refactor conftest.py away
This commit is contained in:
@@ -543,6 +543,10 @@ class Account(object):
|
||||
self._pm.check_pending()
|
||||
return plugin
|
||||
|
||||
def remove_account_plugin(self, plugin, name=None):
|
||||
""" remove an account plugin. """
|
||||
self._pm.unregister(plugin, name=name)
|
||||
|
||||
@contextmanager
|
||||
def temp_plugin(self, plugin):
|
||||
""" run a with-block with the given plugin temporarily registered. """
|
||||
@@ -569,22 +573,27 @@ class Account(object):
|
||||
:returns: None (account is configured and with io-scheduling running)
|
||||
"""
|
||||
if not self.is_configured():
|
||||
if not self.get_config("addr") or not self.get_config("mail_pw"):
|
||||
raise MissingCredentials("addr or mail_pwd not set in config")
|
||||
with self.temp_plugin(ConfigureTracker()) as config_tracker:
|
||||
lib.dc_configure(self._dc_context)
|
||||
config_tracker.wait_finish()
|
||||
self.configure()
|
||||
self.wait_configure_finish()
|
||||
lib.dc_context_run(self._dc_context)
|
||||
|
||||
@contextmanager
|
||||
def configure(self):
|
||||
if self.is_configured():
|
||||
return
|
||||
assert not self.is_configured()
|
||||
assert not hasattr(self, "_configtracker")
|
||||
if not self.get_config("addr") or not self.get_config("mail_pw"):
|
||||
raise MissingCredentials("addr or mail_pwd not set in config")
|
||||
with self.temp_plugin(ConfigureTracker()) as config_tracker:
|
||||
lib.dc_configure(self._dc_context)
|
||||
yield config_tracker
|
||||
if hasattr(self, "_configtracker"):
|
||||
self.remove_account_plugin(self._configtracker)
|
||||
self._configtracker = ConfigureTracker()
|
||||
self.add_account_plugin(self._configtracker)
|
||||
lib.dc_configure(self._dc_context)
|
||||
|
||||
def wait_configure_finish(self):
|
||||
try:
|
||||
self._configtracker.wait_finish()
|
||||
finally:
|
||||
self.remove_account_plugin(self._configtracker)
|
||||
del self._configtracker
|
||||
|
||||
def is_started(self):
|
||||
return self._event_thread.is_alive() and bool(lib.dc_is_running(self._dc_context))
|
||||
|
||||
@@ -90,6 +90,13 @@ class FFIEventTracker:
|
||||
else:
|
||||
assert not rex.match(ev.name), "event found {}".format(ev)
|
||||
|
||||
def wait_securejoin_inviter_progress(self, target):
|
||||
while 1:
|
||||
event = self.get_matching("DC_EVENT_SECUREJOIN_INVITER_PROGRESS")
|
||||
if event.data2 >= target:
|
||||
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
|
||||
break
|
||||
|
||||
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
||||
self.account.log("-- waiting for event with regex: {} --".format(event_name_regex))
|
||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||
|
||||
@@ -13,7 +13,6 @@ import pytest
|
||||
import requests
|
||||
|
||||
from . import Account, const
|
||||
from .tracker import ConfigureTracker
|
||||
from .capi import lib
|
||||
from .events import FFIEventLogger, FFIEventTracker
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
@@ -234,7 +233,6 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
def make_account(self, path, logid, quiet=False):
|
||||
ac = Account(path, logging=self._logging)
|
||||
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
||||
ac._configtracker = ac.add_account_plugin(ConfigureTracker())
|
||||
if not quiet:
|
||||
ac.add_account_plugin(FFIEventLogger(ac, logid=logid))
|
||||
self._accounts.append(ac)
|
||||
@@ -297,7 +295,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
return ac, dict(configdict)
|
||||
|
||||
def get_online_configuring_account(self, mvbox=False, sentbox=False, move=False,
|
||||
pre_generated_key=True, quiet=False, config={}, start=True):
|
||||
pre_generated_key=True, quiet=False, config={}):
|
||||
ac, configdict = self.get_online_config(
|
||||
pre_generated_key=pre_generated_key, quiet=quiet)
|
||||
configdict.update(config)
|
||||
@@ -305,23 +303,20 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
configdict["mvbox_move"] = str(int(move))
|
||||
configdict["sentbox_watch"] = str(int(sentbox))
|
||||
ac.update_config(configdict)
|
||||
if start:
|
||||
ac.start()
|
||||
ac.configure()
|
||||
return ac
|
||||
|
||||
def get_one_online_account(self, pre_generated_key=True, mvbox=False, move=False):
|
||||
ac1 = self.get_online_configuring_account(
|
||||
pre_generated_key=pre_generated_key, mvbox=mvbox, move=move)
|
||||
ac1._configtracker.wait_imap_connected()
|
||||
ac1._configtracker.wait_smtp_connected()
|
||||
ac1._configtracker.wait_finish()
|
||||
ac1.wait_configure_finish()
|
||||
return ac1
|
||||
|
||||
def get_two_online_accounts(self, move=False, quiet=False):
|
||||
ac1 = self.get_online_configuring_account(move=True, quiet=quiet)
|
||||
ac2 = self.get_online_configuring_account(quiet=quiet)
|
||||
ac1._configtracker.wait_finish()
|
||||
ac2._configtracker.wait_finish()
|
||||
ac1.wait_configure_finish()
|
||||
ac2.wait_configure_finish()
|
||||
return ac1, ac2
|
||||
|
||||
def clone_online_account(self, account, pre_generated_key=True):
|
||||
@@ -339,7 +334,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
mvbox_move=account.get_config("mvbox_move"),
|
||||
sentbox_watch=account.get_config("sentbox_watch"),
|
||||
))
|
||||
ac.start()
|
||||
ac.configure()
|
||||
return ac
|
||||
|
||||
def run_bot_process(self, module, ffi=True):
|
||||
|
||||
Reference in New Issue
Block a user