mirror of
https://github.com/chatmail/relay.git
synced 2026-09-16 20:30:09 +00:00
test: cleanup and allow a repo-root level "pytest -n6" to succeed.
the fixtures from chatmaild and cmdeploy test plugins were clashing, and the "rpc" fixture was shadowed by deltachat-rpc-client. We could change the way plugins load but it's also useful to have disambiguated fixture names as we are often working across the code bases. also removes a few unused historic fluff.
This commit is contained in:
@@ -41,22 +41,22 @@ def ipv4_config(make_config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def maildomain(example_config):
|
def example_maildomain(example_config):
|
||||||
return example_config.mail_domain
|
return example_config.mail_domain
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def testaddr(maildomain):
|
def testaddr(example_maildomain):
|
||||||
return f"user.name@{maildomain}"
|
return f"user.name@{example_maildomain}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def gencreds(maildomain):
|
def example_gencreds(example_maildomain):
|
||||||
count = itertools.count()
|
count = itertools.count()
|
||||||
next(count)
|
next(count)
|
||||||
|
|
||||||
def gen(domain=None):
|
def gen(domain=None):
|
||||||
domain = domain if domain else maildomain
|
domain = domain if domain else example_maildomain
|
||||||
while 1:
|
while 1:
|
||||||
num = next(count)
|
num = next(count)
|
||||||
alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
|
alphanumeric = "abcdefghijklmnopqrstuvwxyz1234567890"
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ def test_read_config_ipv4(ipv4_config):
|
|||||||
assert ipv4_config.mail_domain == "[1.3.3.7]"
|
assert ipv4_config.mail_domain == "[1.3.3.7]"
|
||||||
|
|
||||||
|
|
||||||
def test_read_config_basic_using_defaults(tmp_path, maildomain):
|
def test_read_config_basic_using_defaults(tmp_path, example_maildomain):
|
||||||
inipath = tmp_path.joinpath("chatmail.ini")
|
inipath = tmp_path.joinpath("chatmail.ini")
|
||||||
inipath.write_text(f"[params]\nmail_domain = {maildomain}")
|
inipath.write_text(f"[params]\nmail_domain = {example_maildomain}")
|
||||||
example_config = read_config(inipath)
|
example_config = read_config(inipath)
|
||||||
assert example_config.max_user_send_per_minute == 60
|
assert example_config.max_user_send_per_minute == 60
|
||||||
assert example_config.filtermail_smtp_port_incoming == 10081
|
assert example_config.filtermail_smtp_port_incoming == 10081
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ def dictproxy(example_config):
|
|||||||
return AuthDictProxy(config=example_config)
|
return AuthDictProxy(config=example_config)
|
||||||
|
|
||||||
|
|
||||||
def test_basic(dictproxy, gencreds):
|
def test_basic(dictproxy, example_gencreds):
|
||||||
addr, password = gencreds()
|
addr, password = example_gencreds()
|
||||||
dictproxy.lookup_passdb(addr, password)
|
dictproxy.lookup_passdb(addr, password)
|
||||||
data = dictproxy.lookup_userdb(addr)
|
data = dictproxy.lookup_userdb(addr)
|
||||||
assert data
|
assert data
|
||||||
@@ -107,7 +107,7 @@ def test_handle_dovecot_protocol_user_not_exists(example_config):
|
|||||||
assert wfile.getvalue() == b"N\n"
|
assert wfile.getvalue() == b"N\n"
|
||||||
|
|
||||||
|
|
||||||
def test_handle_dovecot_protocol_iterate(gencreds, example_config):
|
def test_handle_dovecot_protocol_iterate(example_config):
|
||||||
dictproxy = AuthDictProxy(config=example_config)
|
dictproxy = AuthDictProxy(config=example_config)
|
||||||
dictproxy.lookup_passdb("asdf00000@chat.example.org", "q9mr3faue")
|
dictproxy.lookup_passdb("asdf00000@chat.example.org", "q9mr3faue")
|
||||||
dictproxy.lookup_passdb("asdf11111@chat.example.org", "q9mr3faue")
|
dictproxy.lookup_passdb("asdf11111@chat.example.org", "q9mr3faue")
|
||||||
@@ -174,14 +174,14 @@ def test_concurrent_creation_same_account(dictproxy):
|
|||||||
assert len(passwords_seen) == 1
|
assert len(passwords_seen) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_50_concurrent_lookups_different_accounts(gencreds, dictproxy):
|
def test_50_concurrent_lookups_different_accounts(example_gencreds, dictproxy):
|
||||||
num_threads = 50
|
num_threads = 50
|
||||||
req_per_thread = 5
|
req_per_thread = 5
|
||||||
results = queue.Queue()
|
results = queue.Queue()
|
||||||
|
|
||||||
def lookup():
|
def lookup():
|
||||||
for i in range(req_per_thread):
|
for i in range(req_per_thread):
|
||||||
addr, password = gencreds()
|
addr, password = example_gencreds()
|
||||||
try:
|
try:
|
||||||
dictproxy.lookup_passdb(addr, password)
|
dictproxy.lookup_passdb(addr, password)
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -205,14 +205,14 @@ def test_50_concurrent_lookups_different_accounts(gencreds, dictproxy):
|
|||||||
|
|
||||||
|
|
||||||
def test_insufficient_resources_block_creation_not_existing_logins(
|
def test_insufficient_resources_block_creation_not_existing_logins(
|
||||||
dictproxy, gencreds, monkeypatch
|
dictproxy, example_gencreds, monkeypatch
|
||||||
):
|
):
|
||||||
addr, password = gencreds()
|
addr, password = example_gencreds()
|
||||||
assert dictproxy.lookup_passdb(addr, password)
|
assert dictproxy.lookup_passdb(addr, password)
|
||||||
|
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
chatmaild.doveauth, "has_sufficient_resources", lambda config: False
|
chatmaild.doveauth, "has_sufficient_resources", lambda config: False
|
||||||
)
|
)
|
||||||
newaddr, newpassword = gencreds()
|
newaddr, newpassword = example_gencreds()
|
||||||
assert not dictproxy.lookup_passdb(newaddr, newpassword)
|
assert not dictproxy.lookup_passdb(newaddr, newpassword)
|
||||||
assert dictproxy.lookup_passdb(addr, password)
|
assert dictproxy.lookup_passdb(addr, password)
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ def test_create_dclogin_url_ipv4(ipv4_config):
|
|||||||
assert addr in url
|
assert addr in url
|
||||||
|
|
||||||
|
|
||||||
def test_print_new_account(capsys, monkeypatch, maildomain, tmpdir, example_config):
|
def test_print_new_account(capsys, monkeypatch, tmpdir, example_config):
|
||||||
monkeypatch.setattr(chatmaild.newemail, "CONFIG_PATH", str(example_config._inipath))
|
monkeypatch.setattr(chatmaild.newemail, "CONFIG_PATH", str(example_config._inipath))
|
||||||
print_new_account()
|
print_new_account()
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ dependencies = [
|
|||||||
cmdeploy = "cmdeploy.cmdeploy:main"
|
cmdeploy = "cmdeploy.cmdeploy:main"
|
||||||
|
|
||||||
[project.entry-points.pytest11]
|
[project.entry-points.pytest11]
|
||||||
"chatmaild.testplugin" = "chatmaild.tests.plugin"
|
|
||||||
"cmdeploy.testplugin" = "cmdeploy.tests.plugin"
|
"cmdeploy.testplugin" = "cmdeploy.tests.plugin"
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
[tool.pytest.ini_options]
|
||||||
|
|||||||
@@ -20,17 +20,17 @@ def test_fastcgi_working(maildomain, chatmail_config):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.filterwarnings("ignore::urllib3.exceptions.InsecureRequestWarning")
|
@pytest.mark.filterwarnings("ignore::urllib3.exceptions.InsecureRequestWarning")
|
||||||
def test_newemail_configure(maildomain, rpc, chatmail_config):
|
def test_newemail_configure(maildomain, cmrpc, chatmail_config):
|
||||||
"""Test configuring accounts by scanning a QR code works."""
|
"""Test configuring accounts by scanning a QR code works."""
|
||||||
url = f"DCACCOUNT:https://{maildomain}/new"
|
url = f"DCACCOUNT:https://{maildomain}/new"
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
account_id = rpc.add_account()
|
account_id = cmrpc.add_account()
|
||||||
if chatmail_config.tls_cert_mode == "self":
|
if chatmail_config.tls_cert_mode == "self":
|
||||||
# deltachat core's rustls rejects self-signed HTTPS certs during
|
# deltachat core's rustls rejects self-signed HTTPS certs during
|
||||||
# set_config_from_qr, so fetch credentials via requests instead
|
# set_config_from_qr, so fetch credentials via requests instead
|
||||||
res = requests.post(f"https://{maildomain}/new", verify=False)
|
res = requests.post(f"https://{maildomain}/new", verify=False)
|
||||||
data = res.json()
|
data = res.json()
|
||||||
rpc.add_or_update_transport(account_id, {
|
cmrpc.add_or_update_transport(account_id, {
|
||||||
"addr": data["email"],
|
"addr": data["email"],
|
||||||
"password": data["password"],
|
"password": data["password"],
|
||||||
"imapServer": maildomain,
|
"imapServer": maildomain,
|
||||||
@@ -38,4 +38,4 @@ def test_newemail_configure(maildomain, rpc, chatmail_config):
|
|||||||
"certificateChecks": "acceptInvalidCertificates",
|
"certificateChecks": "acceptInvalidCertificates",
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
rpc.add_transport_from_qr(account_id, url)
|
cmrpc.add_transport_from_qr(account_id, url)
|
||||||
|
|||||||
@@ -18,14 +18,8 @@ def format_mail_domain(raw_domain: str) -> str:
|
|||||||
return raw_domain
|
return raw_domain
|
||||||
|
|
||||||
|
|
||||||
conftestdir = Path(__file__).parent
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
def pytest_configure(config):
|
||||||
config._benchresults = {}
|
config._benchresults = {}
|
||||||
config.addinivalue_line(
|
|
||||||
"markers", "slow: mark test to require --slow option to run"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_chatmail_config():
|
def _get_chatmail_config():
|
||||||
@@ -377,8 +371,12 @@ class ChatmailACFactory:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
@pytest.fixture(scope="session")
|
||||||
def rpc(tmp_path_factory):
|
def cmrpc(tmp_path_factory):
|
||||||
"""Start a deltachat-rpc-server process for the test session."""
|
"""Start a deltachat-rpc-server process for the test session.
|
||||||
|
|
||||||
|
Not named "rpc": the deltachat-rpc-client pytest plugin registers a
|
||||||
|
function-scoped fixture under that name and would shadow this one.
|
||||||
|
"""
|
||||||
|
|
||||||
# NB: accounts_dir must NOT already exist as directory --
|
# NB: accounts_dir must NOT already exist as directory --
|
||||||
# core-rust only creates accounts.toml if the dir doesn't exist yet.
|
# core-rust only creates accounts.toml if the dir doesn't exist yet.
|
||||||
@@ -390,10 +388,10 @@ def rpc(tmp_path_factory):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cmfactory(rpc, gencreds, maildomain, chatmail_config):
|
def cmfactory(cmrpc, gencreds, maildomain, chatmail_config):
|
||||||
"""Return a ChatmailACFactory for creating online Delta Chat accounts."""
|
"""Return a ChatmailACFactory for creating online Delta Chat accounts."""
|
||||||
return ChatmailACFactory(
|
return ChatmailACFactory(
|
||||||
rpc=rpc,
|
rpc=cmrpc,
|
||||||
maildomain=maildomain,
|
maildomain=maildomain,
|
||||||
gencreds=gencreds,
|
gencreds=gencreds,
|
||||||
chatmail_config=chatmail_config,
|
chatmail_config=chatmail_config,
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
[pytest]
|
|
||||||
addopts = -vrsx --strict-markers
|
|
||||||
Reference in New Issue
Block a user