From 24f5d68fefb2f7f21342dfd01a36bc7990860f2d Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 19 Sep 2019 18:46:06 +0200 Subject: [PATCH] add configure-failure tests --- python/tests/conftest.py | 13 +++++++++---- python/tests/test_account.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 2a78e806f..6a2933e1c 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -150,7 +150,7 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig): lib.dc_set_config(ac._dc_context, b"configured", b"1") return ac - def get_online_configuring_account(self): + def get_online_config(self): if not session_liveconfig: pytest.skip("specify DCC_PY_LIVECONFIG or --liveconfig") configdict = session_liveconfig.get(self.live_count) @@ -161,6 +161,10 @@ def acfactory(pytestconfig, tmpdir, request, session_liveconfig): ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count)) ac._evlogger.init_time = self.init_time ac._evlogger.set_timeout(30) + return ac, configdict + + def get_online_configuring_account(self): + ac, configdict = self.get_online_config() ac.configure(**configdict) ac.start_threads() return ac @@ -206,12 +210,13 @@ def lp(): return Printer() -def wait_configuration_progress(account, target): +def wait_configuration_progress(account, min_target, max_target=1001): + min_target = min(min_target, max_target) while 1: evt_name, data1, data2 = \ account._evlogger.get_matching("DC_EVENT_CONFIGURE_PROGRESS") - if data1 >= target: - print("** CONFIG PROGRESS {}".format(target), account) + if data1 >= min_target and data1 <= max_target: + print("** CONFIG PROGRESS {}".format(min_target), account) break diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 43963d9aa..18012eb94 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -616,3 +616,38 @@ class TestOnlineAccount: chat1b = ac1.create_chat_by_message(ev[2]) assert chat1b.get_profile_image() is None assert chat.get_profile_image() is None + + +class TestOnlineConfigureFails: + def test_invalid_password(self, acfactory): + ac1, configdict = acfactory.get_online_config() + pw = configdict["mail_pw"] + configdict["mail_pw"] = pw[:-1] # wrong password + ac1.configure(**configdict) + ac1.start_threads() + wait_configuration_progress(ac1, 500) + ev1 = ac1._evlogger.get_matching("DC_EVENT_ERROR_NETWORK") + assert "authentication failed" in ev1[2].lower() + wait_configuration_progress(ac1, 0, 0) + + def test_invalid_user(self, acfactory): + ac1, configdict = acfactory.get_online_config() + addr = configdict["addr"] + configdict["addr"] = "x" + addr # wrong user + ac1.configure(**configdict) + ac1.start_threads() + wait_configuration_progress(ac1, 500) + ev1 = ac1._evlogger.get_matching("DC_EVENT_ERROR_NETWORK") + assert "authentication failed" in ev1[2].lower() + wait_configuration_progress(ac1, 0, 0) + + def test_invalid_domain(self, acfactory): + ac1, configdict = acfactory.get_online_config() + addr = configdict["addr"] + configdict["addr"] = addr + "x" + ac1.configure(**configdict) + ac1.start_threads() + wait_configuration_progress(ac1, 500) + ev1 = ac1._evlogger.get_matching("DC_EVENT_ERROR_NETWORK") + assert "could not connect" in ev1[2].lower() + wait_configuration_progress(ac1, 0, 0)