remove _configtracker and write a tested "PendingConfigure" helper class for managing configure/started states for test accounts

This commit is contained in:
holger krekel
2022-05-02 23:09:35 +02:00
parent 026dd4480e
commit 7fbdb42695
4 changed files with 146 additions and 49 deletions

View File

@@ -6,9 +6,47 @@ from deltachat import register_global_plugin
from deltachat.hookspec import global_hookimpl
from deltachat.capi import ffi
from deltachat.capi import lib
from deltachat.testplugin import PendingConfigure
# from deltachat.account import EventLogger
class TestPendingConfigure:
def test_basic_states(self, acfactory, monkeypatch):
pc = PendingConfigure()
acc = acfactory.get_unconfigured_account()
monkeypatch.setattr(acc, "configure", lambda **kwargs: None)
pc.add_account(acc)
assert pc._account2state[acc] == pc.CONFIGURING
pc._configured_events.put((acc, True))
pc.wait_one(acc)
assert pc._account2state[acc] == pc.CONFIGURED
accounts = []
pc.wait_all(onconfigured=accounts.append)
assert pc._account2state[acc] == pc.POSTPROCESSED
assert accounts == [acc]
def test_two_accounts_one_waited_all_started(self, monkeypatch, acfactory):
pc = PendingConfigure()
ac1 = acfactory.get_unconfigured_account()
monkeypatch.setattr(ac1, "configure", lambda **kwargs: None)
pc.add_account(ac1)
ac2 = acfactory.get_unconfigured_account()
monkeypatch.setattr(ac2, "configure", lambda **kwargs: None)
pc.add_account(ac2)
assert pc._account2state[ac1] == pc.CONFIGURING
assert pc._account2state[ac2] == pc.CONFIGURING
pc._configured_events.put((ac1, True))
pc.wait_one(ac1)
assert pc._account2state[ac1] == pc.CONFIGURED
assert pc._account2state[ac2] == pc.CONFIGURING
accounts = []
pc._configured_events.put((ac2, True))
pc.wait_all(onconfigured=accounts.append)
assert pc._account2state[ac1] == pc.POSTPROCESSED
assert pc._account2state[ac2] == pc.POSTPROCESSED
assert accounts == [ac1, ac2]
def test_empty_context():
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
capi.lib.dc_context_unref(ctx)