mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
remove make_account from get_online_config and rename the latter to get_next_liveconfig to avoid one indirection
This commit is contained in:
@@ -229,17 +229,30 @@ class ACFactory:
|
|||||||
deltachat.unregister_global_plugin(direct_imap)
|
deltachat.unregister_global_plugin(direct_imap)
|
||||||
|
|
||||||
def get_next_liveconfig(self):
|
def get_next_liveconfig(self):
|
||||||
return next(self._liveconfig_producer)
|
""" Base function to get functional online configurations
|
||||||
|
where we can make valid SMTP and IMAP connections with.
|
||||||
|
"""
|
||||||
|
configdict = next(self._liveconfig_producer)
|
||||||
|
if "e2ee_enabled" not in configdict:
|
||||||
|
configdict["e2ee_enabled"] = "1"
|
||||||
|
|
||||||
def make_account(self):
|
if self.strict_tls:
|
||||||
|
# Enable strict certificate checks for online accounts
|
||||||
|
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
|
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
|
|
||||||
|
assert "addr" in configdict and "mail_pw" in configdict
|
||||||
|
return configdict
|
||||||
|
|
||||||
|
def make_account(self, quiet=False):
|
||||||
logid = "ac{}".format(len(self._accounts) + 1)
|
logid = "ac{}".format(len(self._accounts) + 1)
|
||||||
path = self.tmpdir.join(logid)
|
path = self.tmpdir.join(logid)
|
||||||
ac = Account(path.strpath, logging=self._logging)
|
ac = Account(path.strpath, logging=self._logging)
|
||||||
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
||||||
logger = FFIEventLogger(ac)
|
if not quiet:
|
||||||
logger.init_time = self.init_time
|
logger = FFIEventLogger(ac)
|
||||||
ac.add_account_plugin(logger)
|
logger.init_time = self.init_time
|
||||||
|
ac.add_account_plugin(logger)
|
||||||
self._accounts.append(ac)
|
self._accounts.append(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
@@ -281,27 +294,12 @@ class ACFactory:
|
|||||||
self._preconfigure_key(ac, addr)
|
self._preconfigure_key(ac, addr)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def get_online_config(self, quiet=False):
|
|
||||||
""" Base function to get functional online accounts where we can make
|
|
||||||
valid SMTP and IMAP connections with.
|
|
||||||
"""
|
|
||||||
configdict = self.get_next_liveconfig()
|
|
||||||
if "e2ee_enabled" not in configdict:
|
|
||||||
configdict["e2ee_enabled"] = "1"
|
|
||||||
|
|
||||||
if self.strict_tls:
|
|
||||||
# Enable strict certificate checks for online accounts
|
|
||||||
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
|
||||||
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
|
||||||
|
|
||||||
ac = self.make_account()
|
|
||||||
configdict["displayname"] = os.path.basename(ac.db_path)
|
|
||||||
self._preconfigure_key(ac, configdict["addr"])
|
|
||||||
return ac, dict(configdict)
|
|
||||||
|
|
||||||
def get_online_configuring_account(self, sentbox=False, move=False,
|
def get_online_configuring_account(self, sentbox=False, move=False,
|
||||||
quiet=False, config={}):
|
quiet=False, config={}):
|
||||||
ac, configdict = self.get_online_config(quiet=quiet)
|
configdict = self.get_next_liveconfig()
|
||||||
|
ac = self.make_account(quiet=quiet)
|
||||||
|
configdict.setdefault("displayname", os.path.basename(ac.db_path))
|
||||||
|
self._preconfigure_key(ac, configdict["addr"])
|
||||||
configdict.update(config)
|
configdict.update(config)
|
||||||
configdict["mvbox_move"] = str(int(move))
|
configdict["mvbox_move"] = str(int(move))
|
||||||
configdict["sentbox_watch"] = str(int(sentbox))
|
configdict["sentbox_watch"] = str(int(sentbox))
|
||||||
@@ -372,7 +370,10 @@ class ACFactory:
|
|||||||
def run_bot_process(self, module, ffi=True):
|
def run_bot_process(self, module, ffi=True):
|
||||||
fn = module.__file__
|
fn = module.__file__
|
||||||
|
|
||||||
bot_ac, bot_cfg = self.get_online_config()
|
bot_cfg = self.get_next_liveconfig()
|
||||||
|
bot_ac = self.make_account()
|
||||||
|
bot_ac.update_config(bot_cfg)
|
||||||
|
self._preconfigure_key(bot_ac, bot_cfg["addr"])
|
||||||
|
|
||||||
# Avoid starting ac so we don't interfere with the bot operating on
|
# Avoid starting ac so we don't interfere with the bot operating on
|
||||||
# the same database.
|
# the same database.
|
||||||
|
|||||||
@@ -2560,8 +2560,9 @@ class TestOnlineAccount:
|
|||||||
ac2.direct_imap.select_config_folder("inbox")
|
ac2.direct_imap.select_config_folder("inbox")
|
||||||
assert len(ac2.direct_imap.get_all_messages()) == 1
|
assert len(ac2.direct_imap.get_all_messages()) == 1
|
||||||
|
|
||||||
def test_configure_error_msgs(self, acfactory):
|
def test_configure_error_msgs_wrong_pw(self, acfactory):
|
||||||
ac1, configdict = acfactory.get_online_config()
|
configdict = acfactory.get_next_liveconfig()
|
||||||
|
ac1 = acfactory.make_account()
|
||||||
ac1.update_config(configdict)
|
ac1.update_config(configdict)
|
||||||
ac1.set_config("mail_pw", "abc") # Wrong mail pw
|
ac1.set_config("mail_pw", "abc") # Wrong mail pw
|
||||||
ac1.configure()
|
ac1.configure()
|
||||||
@@ -2572,9 +2573,10 @@ class TestOnlineAccount:
|
|||||||
# Password is wrong so it definitely has to say something about "password"
|
# Password is wrong so it definitely has to say something about "password"
|
||||||
assert "password" in ev.data2
|
assert "password" in ev.data2
|
||||||
|
|
||||||
ac2, configdict = acfactory.get_online_config()
|
def test_configure_error_msgs_invalid_server(self, acfactory):
|
||||||
ac2.update_config(configdict)
|
ac2 = acfactory.make_account()
|
||||||
ac2.set_config("addr", "abc@def.invalid") # mail server can't be reached
|
ac2.set_config("addr", "abc@def.invalid") # mail server can't be reached
|
||||||
|
ac2.set_config("mail_pw", "123")
|
||||||
ac2.configure()
|
ac2.configure()
|
||||||
while True:
|
while True:
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_CONFIGURE_PROGRESS")
|
ev = ac2._evtracker.get_matching("DC_EVENT_CONFIGURE_PROGRESS")
|
||||||
@@ -2992,22 +2994,27 @@ class TestGroupStressTests:
|
|||||||
|
|
||||||
class TestOnlineConfigureFails:
|
class TestOnlineConfigureFails:
|
||||||
def test_invalid_password(self, acfactory):
|
def test_invalid_password(self, acfactory):
|
||||||
ac1, configdict = acfactory.get_online_config()
|
configdict = acfactory.get_next_liveconfig()
|
||||||
|
ac1 = acfactory.make_account()
|
||||||
ac1.update_config(dict(addr=configdict["addr"], mail_pw="123"))
|
ac1.update_config(dict(addr=configdict["addr"], mail_pw="123"))
|
||||||
configtracker = ac1.configure()
|
configtracker = ac1.configure()
|
||||||
configtracker.wait_progress(500)
|
configtracker.wait_progress(500)
|
||||||
configtracker.wait_progress(0)
|
configtracker.wait_progress(0)
|
||||||
|
|
||||||
def test_invalid_user(self, acfactory):
|
def test_invalid_user(self, acfactory):
|
||||||
ac1, configdict = acfactory.get_online_config()
|
configdict = acfactory.get_next_liveconfig()
|
||||||
ac1.update_config(dict(addr="x" + configdict["addr"], mail_pw=configdict["mail_pw"]))
|
ac1 = acfactory.make_account()
|
||||||
|
configdict["addr"] = "x" + configdict["addr"]
|
||||||
|
ac1.update_config(configdict)
|
||||||
configtracker = ac1.configure()
|
configtracker = ac1.configure()
|
||||||
configtracker.wait_progress(500)
|
configtracker.wait_progress(500)
|
||||||
configtracker.wait_progress(0)
|
configtracker.wait_progress(0)
|
||||||
|
|
||||||
def test_invalid_domain(self, acfactory):
|
def test_invalid_domain(self, acfactory):
|
||||||
ac1, configdict = acfactory.get_online_config()
|
configdict = acfactory.get_next_liveconfig()
|
||||||
ac1.update_config((dict(addr=configdict["addr"] + "x", mail_pw=configdict["mail_pw"])))
|
ac1 = acfactory.make_account()
|
||||||
|
configdict["addr"] += "x"
|
||||||
|
ac1.update_config(configdict)
|
||||||
configtracker = ac1.configure()
|
configtracker = ac1.configure()
|
||||||
configtracker.wait_progress(500)
|
configtracker.wait_progress(500)
|
||||||
configtracker.wait_progress(0)
|
configtracker.wait_progress(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user