mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 05:38:57 +00:00
simplify and speedup multi-chatmail instance support
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
import random
|
import random
|
||||||
import contextlib
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import imaplib
|
import imaplib
|
||||||
import smtplib
|
import smtplib
|
||||||
@@ -156,24 +155,6 @@ class ChatmailTestProcess:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def switch_maildomain():
|
|
||||||
"""return a function that allows to switch an account factory temporarily
|
|
||||||
to another maildomain.
|
|
||||||
"""
|
|
||||||
|
|
||||||
# nb. a bit hacky
|
|
||||||
# would probably be better if deltachat's test machinery grows native support
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def switch(acfactory, maildomain2):
|
|
||||||
old_domain = acfactory.testprocess.maildomain
|
|
||||||
acfactory.testprocess.maildomain = maildomain2
|
|
||||||
yield
|
|
||||||
acfactory.testprocess.maildomain = old_domain
|
|
||||||
|
|
||||||
return switch
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def cmfactory(request, gencreds, tmpdir, data, maildomain):
|
def cmfactory(request, gencreds, tmpdir, data, maildomain):
|
||||||
# cloned from deltachat.testplugin.amfactory
|
# cloned from deltachat.testplugin.amfactory
|
||||||
@@ -182,6 +163,14 @@ def cmfactory(request, gencreds, tmpdir, data, maildomain):
|
|||||||
|
|
||||||
testproc = ChatmailTestProcess(request.config, maildomain, gencreds)
|
testproc = ChatmailTestProcess(request.config, maildomain, gencreds)
|
||||||
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testproc, data=data)
|
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testproc, data=data)
|
||||||
|
|
||||||
|
# nb. a bit hacky
|
||||||
|
# would probably be better if deltachat's test machinery grows native support
|
||||||
|
def switch_maildomain(maildomain2):
|
||||||
|
am.testprocess.maildomain = maildomain2
|
||||||
|
|
||||||
|
am.switch_maildomain = switch_maildomain
|
||||||
|
|
||||||
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:
|
||||||
if testproc.pytestconfig.getoption("--extra-info"):
|
if testproc.pytestconfig.getoption("--extra-info"):
|
||||||
|
|||||||
@@ -4,10 +4,11 @@ def test_remotelog(remotelog, imap_or_smtp):
|
|||||||
assert imap_or_smtp.logunit in next(lineproducer)
|
assert imap_or_smtp.logunit in next(lineproducer)
|
||||||
|
|
||||||
|
|
||||||
def test_use_two_chatmailservers(cmfactory, maildomain2, switch_maildomain):
|
def test_use_two_chatmailservers(cmfactory, maildomain2):
|
||||||
(ac1,) = cmfactory.get_online_accounts(1)
|
ac1 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
with switch_maildomain(cmfactory, maildomain2):
|
cmfactory.switch_maildomain(maildomain2)
|
||||||
(ac2,) = cmfactory.get_online_accounts(1)
|
ac2 = cmfactory.new_online_configuring_account(cache=False)
|
||||||
|
cmfactory.bring_accounts_online()
|
||||||
cmfactory.get_accepted_chat(ac1, ac2)
|
cmfactory.get_accepted_chat(ac1, ac2)
|
||||||
domain1 = ac1.get_config("addr").split("@")[1]
|
domain1 = ac1.get_config("addr").split("@")[1]
|
||||||
domain2 = ac2.get_config("addr").split("@")[1]
|
domain2 = ac2.get_config("addr").split("@")[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user