mirror of
https://github.com/chatmail/core.git
synced 2026-05-24 17:26:30 +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()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
|
||||
class AccountMaker:
|
||||
class ACFactory:
|
||||
_finalizers: List[Callable[[], None]]
|
||||
_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.offline_count = 0
|
||||
self._finalizers = []
|
||||
@@ -255,7 +257,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
|
||||
def get_unconfigured_account(self):
|
||||
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))
|
||||
|
||||
def remove_preconfigured_keys(self):
|
||||
@@ -268,8 +270,8 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
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_pub = self.data.read_path("key/{name}-public.asc".format(name=keyname))
|
||||
fname_sec = self.data.read_path("key/{name}-secret.asc".format(name=keyname))
|
||||
if fname_pub and fname_sec:
|
||||
account._preconfigure_keypair(addr, fname_pub, fname_sec)
|
||||
return True
|
||||
@@ -290,19 +292,19 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
return ac
|
||||
|
||||
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")
|
||||
configdict = session_liveconfig.get(self.live_count)
|
||||
configdict = self.session_liveconfig.get(self.live_count)
|
||||
self.live_count += 1
|
||||
if "e2ee_enabled" not in configdict:
|
||||
configdict["e2ee_enabled"] = "1"
|
||||
|
||||
if pytestconfig.getoption("--strict-tls"):
|
||||
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)
|
||||
|
||||
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)
|
||||
self._preconfigure_key(ac, configdict['addr'])
|
||||
return ac, dict(configdict)
|
||||
@@ -342,7 +344,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
up a new device without importing a backup.
|
||||
"""
|
||||
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))
|
||||
# XXX we might want to transfer the key from the old account for some tests
|
||||
self._preconfigure_key(ac, account.get_config("addr"))
|
||||
@@ -424,7 +426,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
imap.idle_done()
|
||||
except Exception:
|
||||
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):
|
||||
ac2.create_chat(ac1)
|
||||
@@ -443,7 +445,11 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||
for acc in to_wait:
|
||||
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)
|
||||
yield am
|
||||
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("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()
|
||||
chat = acfactory.get_accepted_chat(ac1, ac2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user