1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 10:19:16 +02:00

added a more general way to configure live test accounts for testing

This commit is contained in:
holger krekel 2018-09-07 19:10:14 +02:00
parent 940f665b54
commit c02abb8a61
5 changed files with 67 additions and 39 deletions

View file

@ -1,19 +1,45 @@
import pytest
from deltachat import Account
def pytest_addoption(parser):
parser.addoption("--user", action="store", default=None,
help="user and domain of test account: example user@example.org")
parser.addoption("--password", action="store", default=None)
parser.addoption(
"--liveconfig", action="store", default=None,
help="a file with >=2 lines where each line contains NAME=VALUE config settings for one account"
)
_dummy = object()
@pytest.fixture
def userpassword(pytestconfig):
user = pytestconfig.getoption("--user")
passwd = pytestconfig.getoption("--password")
if user and passwd:
return user, passwd
pytest.skip("specify a test account with --user and --password options")
def acfactory(pytestconfig, tmpdir, request):
fn = pytestconfig.getoption("--liveconfig")
if not fn:
pytest.skip("specify a --liveconfig file to run tests with real accounts")
class AccountMaker:
def __init__(self):
self.configlist = []
for line in open(fn):
if line.strip():
d = {}
for part in line.split():
name, value = part.split("=")
d[name] = value
self.configlist.append(d)
self.count = 0
def get_live_account(self, logcallback=None):
configdict = self.configlist.pop(0)
tmpdb = tmpdir.join("testdb%d" % self.count)
ac = Account(tmpdb.strpath, logcallback=logcallback)
ac.set_config(**configdict)
ac.start()
request.addfinalizer(ac.shutdown)
return ac
return AccountMaker()
@pytest.fixture