introduce multi-device API for python testing

This commit is contained in:
holger krekel
2022-05-05 18:05:19 +02:00
parent 7319cc6ce8
commit 7557f0d35e
3 changed files with 36 additions and 47 deletions

View File

@@ -473,16 +473,30 @@ class ACFactory:
self._acsetup.init_logging(ac) self._acsetup.init_logging(ac)
return ac return ac
def new_online_configuring_account(self, cloned_from=None, cache=False, **kwargs): def new_online_configuring_account(self, cache=False, **kwargs):
if cloned_from is None: configdict = self.get_next_liveconfig()
configdict = self.get_next_liveconfig()
else:
# XXX we might want to transfer the key to the new account
configdict = dict(
addr=cloned_from.get_config("addr"),
mail_pw=cloned_from.get_config("mail_pw"),
)
configdict.update(kwargs) configdict.update(kwargs)
return self._setup_online_configuring_account(configdict)
def get_online_second_device(self, ac1):
ac1 = self._get_cached_account(addr=ac1.get_config("addr"))
self.bring_accounts_online()
return ac1
def get_online_multidevice_setup(self, copied=True):
ac1 = self.get_online_accounts(1)
if copied:
ac2 = self._get_cached_account(addr=ac1.get_config("addr"))
else:
configdict = dict(addr=ac1.get_config("addr"), mail_pw=ac1.get_config("mail_pw"))
ac2 = self._setup_online_configuring_account(configdict, cache=False)
self.bring_accounts_online()
return ac1, ac2
def get_online_devnull_email(self):
return self.get_next_liveconfig()["addr"]
def _setup_online_configuring_account(self, configdict, cache=False):
ac = self._get_cached_account(addr=configdict["addr"]) if cache else None ac = self._get_cached_account(addr=configdict["addr"]) if cache else None
if ac is not None: if ac is not None:
# make sure we consume a preconfig key, as if we had created a fresh account # make sure we consume a preconfig key, as if we had created a fresh account

View File

@@ -220,10 +220,7 @@ def test_fetch_existing(acfactory, lp, mvbox_move):
assert_folders_configured(ac1) assert_folders_configured(ac1)
lp.sec("create a cloned ac1 and fetch contact history during configure") lp.sec("create a cloned ac1 and fetch contact history during configure")
ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1) ac1_clone = acfactory.get_online_second_device(fetch_existing_msgs=1)
ac1_clone.set_config("fetch_existing_msgs", "1")
acfactory.wait_configured(ac1_clone)
ac1_clone.start_io()
assert_folders_configured(ac1_clone) assert_folders_configured(ac1_clone)
lp.sec("check that ac2 contact was fetchted during configure") lp.sec("check that ac2 contact was fetchted during configure")
@@ -266,12 +263,7 @@ def test_fetch_existing_msgs_group_and_single(acfactory, lp):
assert idle1.wait_for_seen() assert idle1.wait_for_seen()
lp.sec("Clone online account and let it fetch the existing messages") lp.sec("Clone online account and let it fetch the existing messages")
ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1) ac1_clone = acfactory.get_online_second_device(fetch_existing_msgs=1)
ac1_clone.set_config("fetch_existing_msgs", "1")
acfactory.wait_configured(ac1_clone)
ac1_clone.start_io()
ac1_clone._evtracker.wait_idle_inbox_ready()
chats = ac1_clone.get_chats() chats = ac1_clone.get_chats()
assert len(chats) == 4 # two newly created chats + self-chat + device-chat assert len(chats) == 4 # two newly created chats + self-chat + device-chat
@@ -307,13 +299,8 @@ def test_undecipherable_group(acfactory, lp):
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()
acfactory.remove_preconfigured_keys() acfactory.remove_preconfigured_keys()
ac4 = acfactory.new_online_configuring_account(cloned_from=ac3) ac4 = acfactory.get_online_second_device(ac3)
acfactory.wait_configured(ac4)
# 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)
chat42 = ac4.create_chat(ac2)
ac4.start_io()
ac4._evtracker.wait_idle_inbox_ready()
lp.sec("ac1: creating group chat with 2 other members") lp.sec("ac1: creating group chat with 2 other members")
chat = ac1.create_group_chat("title", contacts=[ac2, ac3]) chat = ac1.create_group_chat("title", contacts=[ac2, ac3])
@@ -426,10 +413,7 @@ def test_ephemeral_timer(acfactory, lp):
def test_multidevice_sync_seen(acfactory, lp): def test_multidevice_sync_seen(acfactory, lp):
"""Test that message marked as seen on one device is marked as seen on another.""" """Test that message marked as seen on one device is marked as seen on another."""
ac1 = acfactory.new_online_configuring_account() ac1, ac2 = acfactory.get_online_multidevice_setup()
ac2 = acfactory.new_online_configuring_account()
ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1)
acfactory.bring_accounts_online()
ac1.set_config("bcc_self", "1") ac1.set_config("bcc_self", "1")
ac1_clone.set_config("bcc_self", "1") ac1_clone.set_config("bcc_self", "1")

View File

@@ -92,16 +92,13 @@ def test_export_import_self_keys(acfactory, tmpdir, lp):
def test_one_account_send_bcc_setting(acfactory, lp): def test_one_account_send_bcc_setting(acfactory, lp):
ac1 = acfactory.new_online_configuring_account() ac1, ac1_clone = acfactory.get_online_multidevice_setup()
ac2 = acfactory.new_online_configuring_account()
ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1)
acfactory.bring_accounts_online()
# test if sent messages are copied to it via BCC. # test if sent messages are copied to it via BCC.
chat = acfactory.get_accepted_chat(ac1, ac2) chat = acfactory.get_accepted_chat(ac1, ac2)
self_addr = ac1.get_config("addr") self_addr = ac1.get_config("addr")
other_addr = ac2.get_config("addr") other_addr = acfactory.get_online_devnull_email()
lp.sec("send out message without bcc to ourselves") lp.sec("send out message without bcc to ourselves")
ac1.set_config("bcc_self", "0") ac1.set_config("bcc_self", "0")
@@ -863,14 +860,12 @@ def test_dont_show_emails(acfactory, lp):
def test_no_old_msg_is_fresh(acfactory, lp): def test_no_old_msg_is_fresh(acfactory, lp):
ac1 = acfactory.new_online_configuring_account() ac1, ac1_clone = acfactory.get_online_multidevice_setup()
ac2 = acfactory.new_online_configuring_account() ac2 = acfactory.get_online_accounts(1)
ac1_clone = acfactory.new_online_configuring_account(cloned_from=ac1)
acfactory.bring_accounts_online()
ac1.set_config("e2ee_enabled", "0") #ac1.set_config("e2ee_enabled", "0")
ac1_clone.set_config("e2ee_enabled", "0") #ac1_clone.set_config("e2ee_enabled", "0")
ac2.set_config("e2ee_enabled", "0") #ac2.set_config("e2ee_enabled", "0")
ac1_clone.set_config("bcc_self", "1") ac1_clone.set_config("bcc_self", "1")
@@ -1239,9 +1234,7 @@ def test_ac_setup_message(acfactory, lp):
# note that the receiving account needs to be configured and running # note that the receiving account needs to be configured and running
# before ther setup message is send. DC does not read old messages # before ther setup message is send. DC does not read old messages
# as of Jul2019 # as of Jul2019
ac1 = acfactory.new_online_configuring_account() ac1, ac2 = acfactory.get_online_multidevice_setup(copied=False)
ac2 = acfactory.new_online_configuring_account(cloned_from=ac1)
acfactory.bring_accounts_online()
lp.sec("trigger ac setup message and return setupcode") lp.sec("trigger ac setup message and return setupcode")
assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]
@@ -1261,9 +1254,7 @@ def test_ac_setup_message(acfactory, lp):
def test_ac_setup_message_twice(acfactory, lp): def test_ac_setup_message_twice(acfactory, lp):
ac1 = acfactory.new_online_configuring_account() ac1, ac2 = acfactory.get_online_multidevice_setup(copied=False)
ac2 = acfactory.new_online_configuring_account(cloned_from=ac1)
acfactory.bring_accounts_online()
lp.sec("trigger ac setup message but ignore") lp.sec("trigger ac setup message but ignore")
assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"] assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]