mirror of
https://github.com/chatmail/core.git
synced 2026-05-18 22:36:29 +03:00
move large inlined AccountMaker (renamed to ACFactory) to proper class instead of being defined in closure
This commit is contained in:
@@ -209,14 +209,16 @@ def data(request):
|
|||||||
return Data()
|
return Data()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
class ACFactory:
|
||||||
def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|
||||||
|
|
||||||
class AccountMaker:
|
|
||||||
_finalizers: List[Callable[[], None]]
|
_finalizers: List[Callable[[], None]]
|
||||||
_accounts: List[Account]
|
_accounts: List[Account]
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self, strict_tls, tmpdir, session_liveconfig, data) -> None:
|
||||||
|
self.strict_tls = strict_tls
|
||||||
|
self.tmpdir = tmpdir
|
||||||
|
self.session_liveconfig = session_liveconfig
|
||||||
|
self.data = data
|
||||||
|
|
||||||
self.live_count = 0
|
self.live_count = 0
|
||||||
self.offline_count = 0
|
self.offline_count = 0
|
||||||
self._finalizers = []
|
self._finalizers = []
|
||||||
@@ -255,7 +257,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
|
|
||||||
def get_unconfigured_account(self):
|
def get_unconfigured_account(self):
|
||||||
self.offline_count += 1
|
self.offline_count += 1
|
||||||
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
|
tmpdb = self.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):
|
def remove_preconfigured_keys(self):
|
||||||
@@ -268,8 +270,8 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
fname_pub = data.read_path("key/{name}-public.asc".format(name=keyname))
|
fname_pub = self.data.read_path("key/{name}-public.asc".format(name=keyname))
|
||||||
fname_sec = data.read_path("key/{name}-secret.asc".format(name=keyname))
|
fname_sec = self.data.read_path("key/{name}-secret.asc".format(name=keyname))
|
||||||
if fname_pub and fname_sec:
|
if fname_pub and fname_sec:
|
||||||
account._preconfigure_keypair(addr, fname_pub, fname_sec)
|
account._preconfigure_keypair(addr, fname_pub, fname_sec)
|
||||||
return True
|
return True
|
||||||
@@ -290,19 +292,19 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
return ac
|
return ac
|
||||||
|
|
||||||
def get_online_config(self, quiet=False):
|
def get_online_config(self, quiet=False):
|
||||||
if not session_liveconfig:
|
if not self.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 = self.session_liveconfig.get(self.live_count)
|
||||||
self.live_count += 1
|
self.live_count += 1
|
||||||
if "e2ee_enabled" not in configdict:
|
if "e2ee_enabled" not in configdict:
|
||||||
configdict["e2ee_enabled"] = "1"
|
configdict["e2ee_enabled"] = "1"
|
||||||
|
|
||||||
if pytestconfig.getoption("--strict-tls"):
|
if self.strict_tls:
|
||||||
# Enable strict certificate checks for online accounts
|
# Enable strict certificate checks for online accounts
|
||||||
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
|
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
tmpdb = self.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)
|
||||||
self._preconfigure_key(ac, configdict['addr'])
|
self._preconfigure_key(ac, configdict['addr'])
|
||||||
return ac, dict(configdict)
|
return ac, dict(configdict)
|
||||||
@@ -342,7 +344,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
up a new device without importing a backup.
|
up a new device without importing a backup.
|
||||||
"""
|
"""
|
||||||
self.live_count += 1
|
self.live_count += 1
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
tmpdb = self.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))
|
||||||
# XXX we might want to transfer the key from the old account for some tests
|
# 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"))
|
||||||
@@ -424,7 +426,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
imap.idle_done()
|
imap.idle_done()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
imap.dump_imap_structures(tmpdir, logfile=logfile)
|
imap.dump_imap_structures(self.tmpdir, logfile=logfile)
|
||||||
|
|
||||||
def get_accepted_chat(self, ac1: Account, ac2: Account):
|
def get_accepted_chat(self, ac1: Account, ac2: Account):
|
||||||
ac2.create_chat(ac1)
|
ac2.create_chat(ac1)
|
||||||
@@ -443,7 +445,11 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
for acc in to_wait:
|
for acc in to_wait:
|
||||||
acc._evtracker.wait_next_incoming_message()
|
acc._evtracker.wait_next_incoming_message()
|
||||||
|
|
||||||
am = AccountMaker()
|
|
||||||
|
@pytest.fixture
|
||||||
|
def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||||
|
strict_tls = pytestconfig.getoption("--strict-tls")
|
||||||
|
am = ACFactory(strict_tls, tmpdir, session_liveconfig, data)
|
||||||
request.addfinalizer(am.finalize)
|
request.addfinalizer(am.finalize)
|
||||||
yield am
|
yield am
|
||||||
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
|
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
|
||||||
|
|||||||
@@ -1724,7 +1724,7 @@ class TestOnlineAccount:
|
|||||||
assert mime.get_all("From")
|
assert mime.get_all("From")
|
||||||
assert mime.get_all("Received")
|
assert mime.get_all("Received")
|
||||||
|
|
||||||
def test_send_mark_seen_clean_incoming_events(self, acfactory, lp, data):
|
def test_send_mark_seen_clean_incoming_events(self, acfactory, lp):
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
chat = acfactory.get_accepted_chat(ac1, ac2)
|
chat = acfactory.get_accepted_chat(ac1, ac2)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user