mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
starting on provider tests, two basic tests pass for me on a three provider file
This commit is contained in:
@@ -18,6 +18,8 @@ from .capi import lib
|
|||||||
from .events import FFIEventLogger, FFIEventTracker
|
from .events import FFIEventLogger, FFIEventTracker
|
||||||
from _pytest._code import Source
|
from _pytest._code import Source
|
||||||
from deltachat import direct_imap
|
from deltachat import direct_imap
|
||||||
|
from deltachat.account import parseaddr
|
||||||
|
|
||||||
|
|
||||||
import deltachat
|
import deltachat
|
||||||
|
|
||||||
@@ -36,6 +38,9 @@ def pytest_addoption(parser):
|
|||||||
"--strict-tls", action="store_true",
|
"--strict-tls", action="store_true",
|
||||||
help="Never accept invalid TLS certificates for test accounts",
|
help="Never accept invalid TLS certificates for test accounts",
|
||||||
)
|
)
|
||||||
|
parser.addoption(
|
||||||
|
"--provider-file", "-P", default=None,
|
||||||
|
help="file which contains config settings for real-world providers")
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
@@ -125,17 +130,30 @@ def pytest_report_header(config, startdir):
|
|||||||
return summary
|
return summary
|
||||||
|
|
||||||
|
|
||||||
|
def parse_accountfile(fn):
|
||||||
|
if fn is None:
|
||||||
|
return []
|
||||||
|
|
||||||
|
for line in open(fn):
|
||||||
|
if line.strip() and not line.strip().startswith('#'):
|
||||||
|
config_dict = {}
|
||||||
|
for part in line.split():
|
||||||
|
name, value = part.split("=")
|
||||||
|
config_dict[name] = value
|
||||||
|
yield config_dict
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_generate_tests(metafunc):
|
||||||
|
if "real_provider_config" in metafunc.fixturenames:
|
||||||
|
account_configs = list(parse_accountfile(metafunc.config.getoption("--provider-file")))
|
||||||
|
ids = [parseaddr(cfg["addr"])[1] for cfg in account_configs]
|
||||||
|
metafunc.parametrize("real_provider_config", account_configs, ids=ids)
|
||||||
|
|
||||||
|
|
||||||
class SessionLiveConfigFromFile:
|
class SessionLiveConfigFromFile:
|
||||||
def __init__(self, fn):
|
def __init__(self, fn):
|
||||||
self.fn = fn
|
self.fn = fn
|
||||||
self.configlist = []
|
self.configlist = list(parse_accountfile(fn))
|
||||||
for line in open(fn):
|
|
||||||
if line.strip() and not line.strip().startswith('#'):
|
|
||||||
d = {}
|
|
||||||
for part in line.split():
|
|
||||||
name, value = part.split("=")
|
|
||||||
d[name] = value
|
|
||||||
self.configlist.append(d)
|
|
||||||
|
|
||||||
def get(self, index):
|
def get(self, index):
|
||||||
return self.configlist[index]
|
return self.configlist[index]
|
||||||
@@ -232,6 +250,15 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
acc.disable_logging()
|
acc.disable_logging()
|
||||||
deltachat.unregister_global_plugin(direct_imap)
|
deltachat.unregister_global_plugin(direct_imap)
|
||||||
|
|
||||||
|
def make_account_from_real_config(self, provider_config):
|
||||||
|
configdict = provider_config
|
||||||
|
addr = parseaddr(configdict["addr"])[1]
|
||||||
|
domain = addr.split("@")[1]
|
||||||
|
if "e2ee_enabled" not in configdict:
|
||||||
|
configdict["e2ee_enabled"] = "1"
|
||||||
|
tmpdb = tmpdir.join(domain)
|
||||||
|
return self.make_account(tmpdb.strpath, logid=domain)
|
||||||
|
|
||||||
def make_account(self, path, logid, quiet=False):
|
def make_account(self, path, logid, quiet=False):
|
||||||
ac = Account(path, logging=self._logging)
|
ac = Account(path, logging=self._logging)
|
||||||
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
||||||
@@ -361,6 +388,11 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
accounts = self._accounts[:]
|
accounts = self._accounts[:]
|
||||||
started_accounts = []
|
started_accounts = []
|
||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
|
if hasattr(acc, "_configtracker"):
|
||||||
|
acc._configtracker.wait_finish()
|
||||||
|
acc._evtracker.consume_events()
|
||||||
|
acc.get_device_chat().mark_noticed()
|
||||||
|
del acc._configtracker
|
||||||
if acc not in started_accounts:
|
if acc not in started_accounts:
|
||||||
self.wait_configure(acc)
|
self.wait_configure(acc)
|
||||||
acc.set_config("bcc_self", "0")
|
acc.set_config("bcc_self", "0")
|
||||||
@@ -369,6 +401,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
|||||||
started_accounts.append(acc)
|
started_accounts.append(acc)
|
||||||
print("{}: {} account was started".format(
|
print("{}: {} account was started".format(
|
||||||
acc.get_config("displayname"), acc.get_config("addr")))
|
acc.get_config("displayname"), acc.get_config("addr")))
|
||||||
|
|
||||||
for acc in started_accounts:
|
for acc in started_accounts:
|
||||||
acc._evtracker.wait_all_initial_fetches()
|
acc._evtracker.wait_all_initial_fetches()
|
||||||
|
|
||||||
|
|||||||
@@ -541,7 +541,7 @@ impl Contact {
|
|||||||
{
|
{
|
||||||
row_id = u32::try_from(new_row_id)?;
|
row_id = u32::try_from(new_row_id)?;
|
||||||
sth_modified = Modifier::Created;
|
sth_modified = Modifier::Created;
|
||||||
info!(context, "added contact id={} addr={}", row_id, &addr);
|
info!(context, "added contact id={} addr={} origin={:?}", row_id, &addr, &origin);
|
||||||
} else {
|
} else {
|
||||||
error!(context, "Cannot add contact.");
|
error!(context, "Cannot add contact.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user