simplify test setup api by removing pre_generated_keys arguments

This commit is contained in:
holger krekel
2022-04-30 10:17:16 +02:00
parent 0b80ade3ae
commit fd5b224ba0
2 changed files with 23 additions and 23 deletions

View File

@@ -222,8 +222,8 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
self._finalizers = [] self._finalizers = []
self._accounts = [] self._accounts = []
self.init_time = time.time() self.init_time = time.time()
self._generated_keys = ["alice", "bob", "charlie", self._preconfigured_keys = ["alice", "bob", "charlie",
"dom", "elena", "fiona"] "dom", "elena", "fiona"]
self.set_logging_default(False) self.set_logging_default(False)
deltachat.register_global_plugin(direct_imap) deltachat.register_global_plugin(direct_imap)
@@ -258,10 +258,16 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count) tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
return self.make_account(tmpdb.strpath, logid="ac{}".format(self.offline_count)) return self.make_account(tmpdb.strpath, logid="ac{}".format(self.offline_count))
def remove_preconfigured_keys(self):
self._preconfigured_keys = []
def _preconfigure_key(self, account, addr): def _preconfigure_key(self, account, addr):
# Only set a key if we haven't used it yet for another account. # Only set a preconfigured key if we haven't used it yet for another account.
if self._generated_keys: try:
keyname = self._generated_keys.pop(0) keyname = self._preconfigured_keys.pop(0)
except IndexError:
pass
else:
fname_pub = data.read_path("key/{name}-public.asc".format(name=keyname)) fname_pub = data.read_path("key/{name}-public.asc".format(name=keyname))
fname_sec = data.read_path("key/{name}-secret.asc".format(name=keyname)) fname_sec = data.read_path("key/{name}-secret.asc".format(name=keyname))
if fname_pub and fname_sec: if fname_pub and fname_sec:
@@ -283,7 +289,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
lib.dc_set_config(ac._dc_context, b"configured", b"1") lib.dc_set_config(ac._dc_context, b"configured", b"1")
return ac return ac
def get_online_config(self, pre_generated_key=True, quiet=False): def get_online_config(self, quiet=False):
if not session_liveconfig: if not session_liveconfig:
pytest.skip("specify DCC_NEW_TMP_EMAIL or --liveconfig") pytest.skip("specify DCC_NEW_TMP_EMAIL or --liveconfig")
configdict = session_liveconfig.get(self.live_count) configdict = session_liveconfig.get(self.live_count)
@@ -298,14 +304,12 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
tmpdb = tmpdir.join("livedb%d" % self.live_count) tmpdb = tmpdir.join("livedb%d" % self.live_count)
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count), quiet=quiet) ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count), quiet=quiet)
if pre_generated_key: self._preconfigure_key(ac, configdict['addr'])
self._preconfigure_key(ac, configdict['addr'])
return ac, dict(configdict) return ac, dict(configdict)
def get_online_configuring_account(self, sentbox=False, move=False, def get_online_configuring_account(self, sentbox=False, move=False,
pre_generated_key=True, quiet=False, config={}): quiet=False, config={}):
ac, configdict = self.get_online_config( ac, configdict = self.get_online_config(quiet=quiet)
pre_generated_key=pre_generated_key, quiet=quiet)
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))
@@ -313,9 +317,8 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
ac._configtracker = ac.configure() ac._configtracker = ac.configure()
return ac return ac
def get_one_online_account(self, pre_generated_key=True, move=False): def get_one_online_account(self, move=False):
ac1 = self.get_online_configuring_account( ac1 = self.get_online_configuring_account(move=move)
pre_generated_key=pre_generated_key, move=move)
self.wait_configure_and_start_io([ac1]) self.wait_configure_and_start_io([ac1])
return ac1 return ac1
@@ -333,19 +336,16 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
acc.add_account_plugin(FFIEventLogger(acc)) acc.add_account_plugin(FFIEventLogger(acc))
return accounts return accounts
def clone_online_account(self, account, pre_generated_key=True): def clone_online_account(self, account):
""" Clones addr, mail_pw, mvbox_move, sentbox_watch and the """ Clones addr, mail_pw, mvbox_move, sentbox_watch and the
direct_imap object of an online account. This simulates the user setting direct_imap object of an online account. This simulates the user setting
up a new device without importing a backup. up a new device without importing a backup.
`pre_generated_key` only means that a key from python/tests/data/key is
used in order to speed things up.
""" """
self.live_count += 1 self.live_count += 1
tmpdb = tmpdir.join("livedb%d" % self.live_count) tmpdb = tmpdir.join("livedb%d" % self.live_count)
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count)) ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count))
if pre_generated_key: # XXX we might want to transfer the key from the old account for some tests
self._preconfigure_key(ac, account.get_config("addr")) self._preconfigure_key(ac, account.get_config("addr"))
ac.update_config(dict( ac.update_config(dict(
addr=account.get_config("addr"), addr=account.get_config("addr"),
mail_pw=account.get_config("mail_pw"), mail_pw=account.get_config("mail_pw"),

View File

@@ -645,12 +645,11 @@ class TestOnlineAccount:
@pytest.mark.ignored @pytest.mark.ignored
def test_configure_generate_key(self, acfactory, lp): def test_configure_generate_key(self, acfactory, lp):
# A slow test which will generate new keys. # A slow test which will generate new keys.
acfactory.remove_preconfigured_keys()
ac1 = acfactory.get_online_configuring_account( ac1 = acfactory.get_online_configuring_account(
pre_generated_key=False,
config={"key_gen_type": str(const.DC_KEY_GEN_RSA2048)} config={"key_gen_type": str(const.DC_KEY_GEN_RSA2048)}
) )
ac2 = acfactory.get_online_configuring_account( ac2 = acfactory.get_online_configuring_account(
pre_generated_key=False,
config={"key_gen_type": str(const.DC_KEY_GEN_ED25519)} config={"key_gen_type": str(const.DC_KEY_GEN_ED25519)}
) )
acfactory.wait_configure_and_start_io() acfactory.wait_configure_and_start_io()
@@ -2388,7 +2387,8 @@ class TestOnlineAccount:
lp.sec("ac3 reinstalls DC and generates a new key") lp.sec("ac3 reinstalls DC and generates a new key")
ac3.stop_io() ac3.stop_io()
ac4 = acfactory.clone_online_account(ac3, pre_generated_key=False) acfactory.remove_preconfigured_keys()
ac4 = acfactory.clone_online_account(ac3)
ac4._configtracker.wait_finish() ac4._configtracker.wait_finish()
# Create contacts to make sure incoming messages are not treated as contact requests # Create contacts to make sure incoming messages are not treated as contact requests
chat41 = ac4.create_chat(ac1) chat41 = ac4.create_chat(ac1)