mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
refine low level event handling
slight refactor on printing
This commit is contained in:
@@ -77,5 +77,5 @@ def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
|
|||||||
|
|
||||||
|
|
||||||
def register_global_plugin(plugin):
|
def register_global_plugin(plugin):
|
||||||
gm = hookspect.Global._get_plugin_manager()
|
gm = hookspec.Global._get_plugin_manager()
|
||||||
gm.register(plugin)
|
gm.register(plugin)
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ class Account(object):
|
|||||||
# send all FFI events for this account to a plugin hook
|
# send all FFI events for this account to a plugin hook
|
||||||
def _ll_event(ctx, evt_name, data1, data2):
|
def _ll_event(ctx, evt_name, data1, data2):
|
||||||
assert ctx == self._dc_context
|
assert ctx == self._dc_context
|
||||||
|
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
|
||||||
self._pm.hook.process_ffi_event(
|
self._pm.hook.process_ffi_event(
|
||||||
account=self, event_name=evt_name, data1=data1, data2=data2
|
account=self, ffi_event=ffi_event
|
||||||
)
|
)
|
||||||
deltachat.set_context_callback(self._dc_context, _ll_event)
|
deltachat.set_context_callback(self._dc_context, _ll_event)
|
||||||
|
|
||||||
@@ -61,8 +62,9 @@ class Account(object):
|
|||||||
atexit.register(self.shutdown)
|
atexit.register(self.shutdown)
|
||||||
|
|
||||||
@hookspec.account_hookimpl
|
@hookspec.account_hookimpl
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
if event_name == "DC_EVENT_CONFIGURE_PROGRESS":
|
if ffi_event.name == "DC_EVENT_CONFIGURE_PROGRESS":
|
||||||
|
data1 = ffi_event.data1
|
||||||
if data1 == 0 or data1 == 1000:
|
if data1 == 0 or data1 == 1000:
|
||||||
success = data1 == 1000
|
success = data1 == 1000
|
||||||
self._pm.hook.configure_completed(success=success)
|
self._pm.hook.configure_completed(success=success)
|
||||||
@@ -639,6 +641,16 @@ def _destroy_dc_context(dc_context, dc_context_unref=lib.dc_context_unref):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FFIEvent:
|
||||||
|
def __init__(self, name, data1, data2):
|
||||||
|
self.name = name
|
||||||
|
self.data1 = data1
|
||||||
|
self.data2 = data2
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "{name} data1={data1} data2={data2}".format(**self.__dict__)
|
||||||
|
|
||||||
|
|
||||||
class ScannedQRCode:
|
class ScannedQRCode:
|
||||||
def __init__(self, dc_lot):
|
def __init__(self, dc_lot):
|
||||||
self._dc_lot = dc_lot
|
self._dc_lot = dc_lot
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from .hookspec import account_hookimpl, global_hookimpl
|
from .hookspec import account_hookimpl
|
||||||
|
|
||||||
|
|
||||||
class FFIEventLogger:
|
class FFIEventLogger:
|
||||||
@@ -20,15 +20,14 @@ class FFIEventLogger:
|
|||||||
self.init_time = time.time()
|
self.init_time = time.time()
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
self._log_event(event_name, data1, data2)
|
self._log_event(ffi_event)
|
||||||
|
|
||||||
def _log_event(self, evt_name, data1, data2):
|
def _log_event(self, ffi_event):
|
||||||
# don't show events that are anyway empty impls now
|
# don't show events that are anyway empty impls now
|
||||||
if evt_name == "DC_EVENT_GET_STRING":
|
if ffi_event.name == "DC_EVENT_GET_STRING":
|
||||||
return
|
return
|
||||||
evpart = "{}({!r},{!r})".format(evt_name, data1, data2)
|
self.account.log_line(str(ffi_event))
|
||||||
self.account.log_line(evpart)
|
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def log_line(self, message):
|
def log_line(self, message):
|
||||||
@@ -36,9 +35,10 @@ class FFIEventLogger:
|
|||||||
tname = getattr(t, "name", t)
|
tname = getattr(t, "name", t)
|
||||||
if tname == "MainThread":
|
if tname == "MainThread":
|
||||||
tname = "MAIN"
|
tname = "MAIN"
|
||||||
|
elapsed = time.time() - self.init_time
|
||||||
|
locname = tname
|
||||||
|
if self.logid:
|
||||||
|
locname += "-" + self.logid
|
||||||
|
s = "{:2.2f} [{}] {}".format(elapsed, locname, message)
|
||||||
with self._loglock:
|
with self._loglock:
|
||||||
print("{:2.2f} [{}-{}] {}".format(
|
print(s)
|
||||||
time.time() - self.init_time,
|
|
||||||
tname,
|
|
||||||
self.logid,
|
|
||||||
message))
|
|
||||||
|
|||||||
@@ -24,21 +24,24 @@ class PerAccount:
|
|||||||
return pm
|
return pm
|
||||||
|
|
||||||
@account_hookspec
|
@account_hookspec
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
""" process a CFFI low level events for a given account. """
|
""" process a CFFI low level events for a given account.
|
||||||
|
|
||||||
|
ffi_event has "name", "data1", "data2" attributes according
|
||||||
|
to https://c.delta.chat/group__DC__EVENT.html
|
||||||
|
"""
|
||||||
|
|
||||||
@account_hookspec
|
@account_hookspec
|
||||||
def log_line(self, message):
|
def log_line(self, message):
|
||||||
""" log a message related to the account. """
|
""" log a message related to the account. """
|
||||||
|
|
||||||
@account_hookspec
|
|
||||||
def after_shutdown(self):
|
|
||||||
""" Called when the account has been shutdown. """
|
|
||||||
|
|
||||||
@account_hookspec
|
@account_hookspec
|
||||||
def configure_completed(self, success):
|
def configure_completed(self, success):
|
||||||
""" Called when a configure process completed. """
|
""" Called when a configure process completed. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def after_shutdown(self):
|
||||||
|
""" Called after the account has been shutdown. """
|
||||||
|
|
||||||
|
|
||||||
class Global:
|
class Global:
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ class ImexTracker:
|
|||||||
self._imex_events = Queue()
|
self._imex_events = Queue()
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
if event_name == "DC_EVENT_IMEX_PROGRESS":
|
if ffi_event.name == "DC_EVENT_IMEX_PROGRESS":
|
||||||
self._imex_events.put(data1)
|
self._imex_events.put(ffi_event.data1)
|
||||||
elif event_name == "DC_EVENT_IMEX_FILE_WRITTEN":
|
elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN":
|
||||||
self._imex_events.put(data1)
|
self._imex_events.put(ffi_event.data1)
|
||||||
|
|
||||||
def wait_finish(self, progress_timeout=60):
|
def wait_finish(self, progress_timeout=60):
|
||||||
""" Return list of written files, raise ValueError if ExportFailed. """
|
""" Return list of written files, raise ValueError if ExportFailed. """
|
||||||
@@ -47,11 +47,11 @@ class ConfigureTracker:
|
|||||||
self._ffi_events = []
|
self._ffi_events = []
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
self._ffi_events.append((event_name, data1, data2))
|
self._ffi_events.append(ffi_event)
|
||||||
if event_name == "DC_EVENT_SMTP_CONNECTED":
|
if ffi_event.name == "DC_EVENT_SMTP_CONNECTED":
|
||||||
self._smtp_finished.set()
|
self._smtp_finished.set()
|
||||||
elif event_name == "DC_EVENT_IMAP_CONNECTED":
|
elif ffi_event.name == "DC_EVENT_IMAP_CONNECTED":
|
||||||
self._imap_finished.set()
|
self._imap_finished.set()
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
@@ -72,5 +72,5 @@ class ConfigureTracker:
|
|||||||
Raise Exception if Configure failed
|
Raise Exception if Configure failed
|
||||||
"""
|
"""
|
||||||
if not self._configure_events.get():
|
if not self._configure_events.get():
|
||||||
content = "\n".join("{}: {} {}".format(*args) for args in self._ffi_events)
|
content = "\n".join(map(str, self._ffi_events))
|
||||||
raise ConfigureFailed(content)
|
raise ConfigureFailed(content)
|
||||||
|
|||||||
@@ -284,39 +284,23 @@ def lp():
|
|||||||
def wait_configuration_progress(account, min_target, max_target=1001):
|
def wait_configuration_progress(account, min_target, max_target=1001):
|
||||||
min_target = min(min_target, max_target)
|
min_target = min(min_target, max_target)
|
||||||
while 1:
|
while 1:
|
||||||
evt_name, data1, data2 = \
|
event = account._evtracker.get_matching("DC_EVENT_CONFIGURE_PROGRESS")
|
||||||
account._evtracker.get_matching("DC_EVENT_CONFIGURE_PROGRESS")
|
if event.data1 >= min_target and event.data1 <= max_target:
|
||||||
if data1 >= min_target and data1 <= max_target:
|
|
||||||
print("** CONFIG PROGRESS {}".format(min_target), account)
|
print("** CONFIG PROGRESS {}".format(min_target), account)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def wait_securejoin_inviter_progress(account, target):
|
def wait_securejoin_inviter_progress(account, target):
|
||||||
while 1:
|
while 1:
|
||||||
evt_name, data1, data2 = \
|
event = account._evtracker.get_matching("DC_EVENT_SECUREJOIN_INVITER_PROGRESS")
|
||||||
account._evtracker.get_matching("DC_EVENT_SECUREJOIN_INVITER_PROGRESS")
|
if event.data2 >= target:
|
||||||
if data2 >= target:
|
|
||||||
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), account)
|
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), account)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
def wait_successful_IMAP_SMTP_connection(account):
|
|
||||||
imap_ok = smtp_ok = False
|
|
||||||
while not imap_ok or not smtp_ok:
|
|
||||||
evt_name, data1, data2 = \
|
|
||||||
account._evtracker.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
|
|
||||||
if evt_name == "DC_EVENT_IMAP_CONNECTED":
|
|
||||||
imap_ok = True
|
|
||||||
print("** IMAP OK", account)
|
|
||||||
if evt_name == "DC_EVENT_SMTP_CONNECTED":
|
|
||||||
smtp_ok = True
|
|
||||||
print("** SMTP OK", account)
|
|
||||||
print("** IMAP and SMTP logins successful", account)
|
|
||||||
|
|
||||||
|
|
||||||
def wait_msgs_changed(account, chat_id, msg_id=None):
|
def wait_msgs_changed(account, chat_id, msg_id=None):
|
||||||
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[1] == chat_id
|
assert ev.data1 == chat_id
|
||||||
if msg_id is not None:
|
if msg_id is not None:
|
||||||
assert ev[2] == msg_id
|
assert ev.data2 == msg_id
|
||||||
return ev[2]
|
return ev.data2
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ class FFIEventTracker:
|
|||||||
self._event_queue = Queue()
|
self._event_queue = Queue()
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def process_ffi_event(self, event_name, data1, data2):
|
def process_ffi_event(self, ffi_event):
|
||||||
self._event_queue.put((event_name, data1, data2))
|
self._event_queue.put(ffi_event)
|
||||||
|
|
||||||
def set_timeout(self, timeout):
|
def set_timeout(self, timeout):
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
@@ -23,8 +23,8 @@ class FFIEventTracker:
|
|||||||
def get(self, timeout=None, check_error=True):
|
def get(self, timeout=None, check_error=True):
|
||||||
timeout = timeout if timeout is not None else self._timeout
|
timeout = timeout if timeout is not None else self._timeout
|
||||||
ev = self._event_queue.get(timeout=timeout)
|
ev = self._event_queue.get(timeout=timeout)
|
||||||
if check_error and ev[0] == "DC_EVENT_ERROR":
|
if check_error and ev.name == "DC_EVENT_ERROR":
|
||||||
raise ValueError("{}({!r},{!r})".format(*ev))
|
raise ValueError(str(ev))
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
def ensure_event_not_queued(self, event_name_regex):
|
def ensure_event_not_queued(self, event_name_regex):
|
||||||
@@ -36,24 +36,24 @@ class FFIEventTracker:
|
|||||||
except Empty:
|
except Empty:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert not rex.match(ev[0]), "event found {}".format(ev)
|
assert not rex.match(ev.name), "event found {}".format(ev)
|
||||||
|
|
||||||
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
||||||
self.account.log_line("-- waiting for event with regex: {} --".format(event_name_regex))
|
self.account.log_line("-- waiting for event with regex: {} --".format(event_name_regex))
|
||||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
while 1:
|
while 1:
|
||||||
ev = self.get(timeout=timeout, check_error=check_error)
|
ev = self.get(timeout=timeout, check_error=check_error)
|
||||||
if rex.match(ev[0]):
|
if rex.match(ev.name):
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
def get_info_matching(self, regex):
|
def get_info_matching(self, regex):
|
||||||
rex = re.compile("(?:{}).*".format(regex))
|
rex = re.compile("(?:{}).*".format(regex))
|
||||||
while 1:
|
while 1:
|
||||||
ev = self.get_matching("DC_EVENT_INFO")
|
ev = self.get_matching("DC_EVENT_INFO")
|
||||||
if rex.match(ev[2]):
|
if rex.match(ev.data2):
|
||||||
return ev
|
return ev
|
||||||
|
|
||||||
def wait_next_incoming_message(self):
|
def wait_next_incoming_message(self):
|
||||||
""" wait for and return next incoming message. """
|
""" wait for and return next incoming message. """
|
||||||
ev = self.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = self.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
return self.account.get_message_by_id(ev[2])
|
return self.account.get_message_by_id(ev.data2)
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ class TestOnlineAccount:
|
|||||||
chat.send_text("message1")
|
chat.send_text("message1")
|
||||||
lp.sec("ac2: waiting for message from ac1")
|
lp.sec("ac2: waiting for message from ac1")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg_in = ac2.get_message_by_id(ev[2])
|
msg_in = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg_in.text == "message1"
|
assert msg_in.text == "message1"
|
||||||
assert not msg_in.is_encrypted()
|
assert not msg_in.is_encrypted()
|
||||||
|
|
||||||
@@ -472,7 +472,7 @@ class TestOnlineAccount:
|
|||||||
msg_in.chat.send_text("message2")
|
msg_in.chat.send_text("message2")
|
||||||
lp.sec("ac1: waiting for message from ac2")
|
lp.sec("ac1: waiting for message from ac2")
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg2_in = ac1.get_message_by_id(ev[2])
|
msg2_in = ac1.get_message_by_id(ev.data2)
|
||||||
assert msg2_in.text == "message2"
|
assert msg2_in.text == "message2"
|
||||||
assert msg2_in.is_encrypted()
|
assert msg2_in.is_encrypted()
|
||||||
|
|
||||||
@@ -480,7 +480,7 @@ class TestOnlineAccount:
|
|||||||
msg2_in.chat.send_text("message3")
|
msg2_in.chat.send_text("message3")
|
||||||
lp.sec("ac2: waiting for message from ac1")
|
lp.sec("ac2: waiting for message from ac1")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg3_in = ac1.get_message_by_id(ev[2])
|
msg3_in = ac1.get_message_by_id(ev.data2)
|
||||||
assert msg3_in.text == "message3"
|
assert msg3_in.text == "message3"
|
||||||
assert msg3_in.is_encrypted()
|
assert msg3_in.is_encrypted()
|
||||||
|
|
||||||
@@ -527,8 +527,8 @@ class TestOnlineAccount:
|
|||||||
assert ac1.get_config("bcc_self") == "0"
|
assert ac1.get_config("bcc_self") == "0"
|
||||||
|
|
||||||
# make sure we are not sending message to ourselves
|
# make sure we are not sending message to ourselves
|
||||||
assert self_addr not in ev[2]
|
assert self_addr not in ev.data2
|
||||||
assert other_addr in ev[2]
|
assert other_addr in ev.data2
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
ev = ac1._evtracker.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
||||||
|
|
||||||
lp.sec("ac1: setting bcc_self=1")
|
lp.sec("ac1: setting bcc_self=1")
|
||||||
@@ -542,13 +542,13 @@ class TestOnlineAccount:
|
|||||||
assert ac1.get_config("bcc_self") == "1"
|
assert ac1.get_config("bcc_self") == "1"
|
||||||
|
|
||||||
# now make sure we are sending message to ourselves too
|
# now make sure we are sending message to ourselves too
|
||||||
assert self_addr in ev[2]
|
assert self_addr in ev.data2
|
||||||
assert other_addr in ev[2]
|
assert other_addr in ev.data2
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
ev = ac1._evtracker.get_matching("DC_EVENT_DELETED_BLOB_FILE")
|
||||||
|
|
||||||
# Second client receives only second message, but not the first
|
# Second client receives only second message, but not the first
|
||||||
ev = ac1_clone._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac1_clone._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ac1_clone.get_message_by_id(ev[2]).text == msg_out.text
|
assert ac1_clone.get_message_by_id(ev.data2).text == msg_out.text
|
||||||
|
|
||||||
def test_send_file_twice_unicode_filename_mangling(self, tmpdir, acfactory, lp):
|
def test_send_file_twice_unicode_filename_mangling(self, tmpdir, acfactory, lp):
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
@@ -568,8 +568,8 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("ac2: receive message")
|
lp.sec("ac2: receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
return ac2.get_message_by_id(ev[2])
|
return ac2.get_message_by_id(ev.data2)
|
||||||
|
|
||||||
msg = send_and_receive_message()
|
msg = send_and_receive_message()
|
||||||
assert msg.text == "withfile"
|
assert msg.text == "withfile"
|
||||||
@@ -600,8 +600,8 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("ac2: receive message")
|
lp.sec("ac2: receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
msg = ac2.get_message_by_id(ev[2])
|
msg = ac2.get_message_by_id(ev.data2)
|
||||||
|
|
||||||
assert open(msg.filename).read() == content
|
assert open(msg.filename).read() == content
|
||||||
assert msg.filename.endswith(basename)
|
assert msg.filename.endswith(basename)
|
||||||
@@ -623,7 +623,7 @@ class TestOnlineAccount:
|
|||||||
chat = self.get_chat(ac1, ac2)
|
chat = self.get_chat(ac1, ac2)
|
||||||
chat.send_text("message1")
|
chat.send_text("message1")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
lp.sec("test finished")
|
lp.sec("test finished")
|
||||||
|
|
||||||
def test_move_works(self, acfactory):
|
def test_move_works(self, acfactory):
|
||||||
@@ -634,8 +634,8 @@ class TestOnlineAccount:
|
|||||||
chat = self.get_chat(ac1, ac2)
|
chat = self.get_chat(ac1, ac2)
|
||||||
chat.send_text("message1")
|
chat.send_text("message1")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data2 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_MOVED")
|
ac2._evtracker.get_matching("DC_EVENT_IMAP_MESSAGE_MOVED")
|
||||||
|
|
||||||
def test_move_works_on_self_sent(self, acfactory):
|
def test_move_works_on_self_sent(self, acfactory):
|
||||||
ac1 = acfactory.get_online_configuring_account(mvbox=True)
|
ac1 = acfactory.get_online_configuring_account(mvbox=True)
|
||||||
@@ -660,7 +660,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("ac2: wait for receive")
|
lp.sec("ac2: wait for receive")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] == msg_out.id
|
assert ev.data2 == msg_out.id
|
||||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
msg_in = ac2.get_message_by_id(msg_out.id)
|
||||||
assert msg_in.text == "message2"
|
assert msg_in.text == "message2"
|
||||||
|
|
||||||
@@ -693,7 +693,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("receiving message")
|
lp.sec("receiving message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg_in = ac2.get_message_by_id(ev[2])
|
msg_in = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg_in.text == "message2"
|
assert msg_in.text == "message2"
|
||||||
assert not msg_in.is_forwarded()
|
assert not msg_in.is_forwarded()
|
||||||
|
|
||||||
@@ -704,7 +704,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
# wait for other account to receive
|
# wait for other account to receive
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg_in = ac2.get_message_by_id(ev[2])
|
msg_in = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg_in.text == "message2"
|
assert msg_in.text == "message2"
|
||||||
assert msg_in.is_forwarded()
|
assert msg_in.is_forwarded()
|
||||||
|
|
||||||
@@ -716,9 +716,9 @@ class TestOnlineAccount:
|
|||||||
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
|
ac1._evtracker.get_matching("DC_EVENT_SMTP_MESSAGE_SENT")
|
||||||
ac1.empty_server_folders(inbox=True, mvbox=True)
|
ac1.empty_server_folders(inbox=True, mvbox=True)
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_IMAP_FOLDER_EMPTIED")
|
ev = ac1._evtracker.get_matching("DC_EVENT_IMAP_FOLDER_EMPTIED")
|
||||||
assert ev[2] == "DeltaChat"
|
assert ev.data2 == "DeltaChat"
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_IMAP_FOLDER_EMPTIED")
|
ev = ac1._evtracker.get_matching("DC_EVENT_IMAP_FOLDER_EMPTIED")
|
||||||
assert ev[2] == "INBOX"
|
assert ev.data2 == "INBOX"
|
||||||
|
|
||||||
def test_send_and_receive_message_markseen(self, acfactory, lp):
|
def test_send_and_receive_message_markseen(self, acfactory, lp):
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
@@ -732,14 +732,13 @@ class TestOnlineAccount:
|
|||||||
lp.sec("sending text message from ac1 to ac2")
|
lp.sec("sending text message from ac1 to ac2")
|
||||||
msg_out = chat.send_text("message1")
|
msg_out = chat.send_text("message1")
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
evt_name, data1, data2 = ev
|
assert ev.data1 == chat.id
|
||||||
assert data1 == chat.id
|
assert ev.data2 == msg_out.id
|
||||||
assert data2 == msg_out.id
|
|
||||||
assert msg_out.is_out_delivered()
|
assert msg_out.is_out_delivered()
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] == msg_out.id
|
assert ev.data2 == msg_out.id
|
||||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
msg_in = ac2.get_message_by_id(msg_out.id)
|
||||||
assert msg_in.text == "message1"
|
assert msg_in.text == "message1"
|
||||||
assert not msg_in.is_forwarded()
|
assert not msg_in.is_forwarded()
|
||||||
@@ -768,7 +767,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac2 to receive second message")
|
lp.sec("wait for ac2 to receive second message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
assert ev[2] == msg_out2.id
|
assert ev.data2 == msg_out2.id
|
||||||
msg_in2 = ac2.get_message_by_id(msg_out2.id)
|
msg_in2 = ac2.get_message_by_id(msg_out2.id)
|
||||||
|
|
||||||
lp.sec("mark messages as seen on ac2, wait for changes on ac1")
|
lp.sec("mark messages as seen on ac2, wait for changes on ac1")
|
||||||
@@ -776,8 +775,8 @@ class TestOnlineAccount:
|
|||||||
lp.step("1")
|
lp.step("1")
|
||||||
for i in range(2):
|
for i in range(2):
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_READ")
|
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_READ")
|
||||||
assert ev[1] > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
assert ev[2] > const.DC_MSG_ID_LAST_SPECIAL
|
assert ev.data2 > const.DC_MSG_ID_LAST_SPECIAL
|
||||||
lp.step("2")
|
lp.step("2")
|
||||||
assert msg_out.is_out_mdn_received()
|
assert msg_out.is_out_mdn_received()
|
||||||
assert msg_out2.is_out_mdn_received()
|
assert msg_out2.is_out_mdn_received()
|
||||||
@@ -837,7 +836,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] == msg_out.id
|
assert ev.data2 == msg_out.id
|
||||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
msg_in = ac2.get_message_by_id(msg_out.id)
|
||||||
assert msg_in.text == "message1"
|
assert msg_in.text == "message1"
|
||||||
|
|
||||||
@@ -847,9 +846,9 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac1 to receive message")
|
lp.sec("wait for ac1 to receive message")
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
assert ev[1] == chat.id
|
assert ev.data1 == chat.id
|
||||||
assert ev[2] > msg_out.id
|
assert ev.data2 > msg_out.id
|
||||||
msg_back = ac1.get_message_by_id(ev[2])
|
msg_back = ac1.get_message_by_id(ev.data2)
|
||||||
assert msg_back.text == "message-back"
|
assert msg_back.text == "message-back"
|
||||||
assert msg_back.is_encrypted()
|
assert msg_back.is_encrypted()
|
||||||
|
|
||||||
@@ -915,8 +914,8 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac1 to receive message")
|
lp.sec("wait for ac1 to receive message")
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
assert ev[1] == chat.id
|
assert ev.data1 == chat.id
|
||||||
msg_back = ac1.get_message_by_id(ev[2])
|
msg_back = ac1.get_message_by_id(ev.data2)
|
||||||
assert msg_back.text == "message-back"
|
assert msg_back.text == "message-back"
|
||||||
assert msg_back.is_encrypted()
|
assert msg_back.is_encrypted()
|
||||||
|
|
||||||
@@ -942,7 +941,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg_in = ac2.get_message_by_id(ev[2])
|
msg_in = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg_in.text == "message2 -- should be encrypted"
|
assert msg_in.text == "message2 -- should be encrypted"
|
||||||
assert msg_in.is_encrypted()
|
assert msg_in.is_encrypted()
|
||||||
|
|
||||||
@@ -960,7 +959,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
in_id = ev[2]
|
in_id = ev.data2
|
||||||
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
||||||
assert mime.get_all("From")
|
assert mime.get_all("From")
|
||||||
assert mime.get_all("Received")
|
assert mime.get_all("Received")
|
||||||
@@ -973,14 +972,13 @@ class TestOnlineAccount:
|
|||||||
path = data.get_path("d.png")
|
path = data.get_path("d.png")
|
||||||
msg_out = chat.send_image(path)
|
msg_out = chat.send_image(path)
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
evt_name, data1, data2 = ev
|
assert ev.data1 == chat.id
|
||||||
assert data1 == chat.id
|
assert ev.data2 == msg_out.id
|
||||||
assert data2 == msg_out.id
|
|
||||||
assert msg_out.is_out_delivered()
|
assert msg_out.is_out_delivered()
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] == msg_out.id
|
assert ev.data2 == msg_out.id
|
||||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
msg_in = ac2.get_message_by_id(msg_out.id)
|
||||||
assert msg_in.is_image()
|
assert msg_in.is_image()
|
||||||
assert os.path.exists(msg_in.filename)
|
assert os.path.exists(msg_in.filename)
|
||||||
@@ -1043,7 +1041,7 @@ class TestOnlineAccount:
|
|||||||
setup_code = ac1.initiate_key_transfer()
|
setup_code = ac1.initiate_key_transfer()
|
||||||
ac2._evtracker.set_timeout(30)
|
ac2._evtracker.set_timeout(30)
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
msg = ac2.get_message_by_id(ev[2])
|
msg = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg.is_setup_message()
|
assert msg.is_setup_message()
|
||||||
assert msg.get_setupcodebegin() == setup_code[:2]
|
assert msg.get_setupcodebegin() == setup_code[:2]
|
||||||
lp.sec("try a bad setup code")
|
lp.sec("try a bad setup code")
|
||||||
@@ -1070,7 +1068,7 @@ class TestOnlineAccount:
|
|||||||
lp.sec("trigger second ac setup message, wait for receive ")
|
lp.sec("trigger second ac setup message, wait for receive ")
|
||||||
setup_code2 = ac1.initiate_key_transfer()
|
setup_code2 = ac1.initiate_key_transfer()
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
||||||
msg = ac2.get_message_by_id(ev[2])
|
msg = ac2.get_message_by_id(ev.data2)
|
||||||
assert msg.is_setup_message()
|
assert msg.is_setup_message()
|
||||||
assert msg.get_setupcodebegin() == setup_code2[:2]
|
assert msg.get_setupcodebegin() == setup_code2[:2]
|
||||||
|
|
||||||
@@ -1082,6 +1080,7 @@ class TestOnlineAccount:
|
|||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin")
|
lp.sec("ac1: create QR code and let ac2 scan it, starting the securejoin")
|
||||||
qr = ac1.get_setup_contact_qr()
|
qr = ac1.get_setup_contact_qr()
|
||||||
|
|
||||||
lp.sec("ac2: start QR-code based setup contact protocol")
|
lp.sec("ac2: start QR-code based setup contact protocol")
|
||||||
ch = ac2.qr_setup_contact(qr)
|
ch = ac2.qr_setup_contact(qr)
|
||||||
assert ch.id >= 10
|
assert ch.id >= 10
|
||||||
@@ -1215,7 +1214,7 @@ class TestOnlineAccount:
|
|||||||
|
|
||||||
lp.sec("ac2: wait for receiving message from ac1")
|
lp.sec("ac2: wait for receiving message from ac1")
|
||||||
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac2._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
msg_in = ac2.get_message_by_id(ev[2])
|
msg_in = ac2.get_message_by_id(ev.data2)
|
||||||
assert not msg_in.chat.is_deaddrop()
|
assert not msg_in.chat.is_deaddrop()
|
||||||
|
|
||||||
lp.sec("ac2: create chat and read profile image")
|
lp.sec("ac2: create chat and read profile image")
|
||||||
@@ -1229,8 +1228,8 @@ class TestOnlineAccount:
|
|||||||
lp.sec("ac2: delete profile image from chat")
|
lp.sec("ac2: delete profile image from chat")
|
||||||
chat2.remove_profile_image()
|
chat2.remove_profile_image()
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
ev = ac1._evtracker.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
assert ev[1] == chat.id
|
assert ev.data1 == chat.id
|
||||||
chat1b = ac1.create_chat_by_message(ev[2])
|
chat1b = ac1.create_chat_by_message(ev.data2)
|
||||||
assert chat1b.get_profile_image() is None
|
assert chat1b.get_profile_image() is None
|
||||||
assert chat.get_profile_image() is None
|
assert chat.get_profile_image() is None
|
||||||
|
|
||||||
@@ -1461,8 +1460,8 @@ class TestOnlineConfigureFails:
|
|||||||
ac1.configure(addr=configdict["addr"], mail_pw="123")
|
ac1.configure(addr=configdict["addr"], mail_pw="123")
|
||||||
ac1.start_threads()
|
ac1.start_threads()
|
||||||
wait_configuration_progress(ac1, 500)
|
wait_configuration_progress(ac1, 500)
|
||||||
ev1 = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
ev = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
||||||
assert "cannot login" in ev1[2].lower()
|
assert "cannot login" in ev.data2.lower()
|
||||||
wait_configuration_progress(ac1, 0, 0)
|
wait_configuration_progress(ac1, 0, 0)
|
||||||
|
|
||||||
def test_invalid_user(self, acfactory):
|
def test_invalid_user(self, acfactory):
|
||||||
@@ -1470,8 +1469,8 @@ class TestOnlineConfigureFails:
|
|||||||
ac1.configure(addr="x" + configdict["addr"], mail_pw=configdict["mail_pw"])
|
ac1.configure(addr="x" + configdict["addr"], mail_pw=configdict["mail_pw"])
|
||||||
ac1.start_threads()
|
ac1.start_threads()
|
||||||
wait_configuration_progress(ac1, 500)
|
wait_configuration_progress(ac1, 500)
|
||||||
ev1 = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
ev = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
||||||
assert "cannot login" in ev1[2].lower()
|
assert "cannot login" in ev.data2.lower()
|
||||||
wait_configuration_progress(ac1, 0, 0)
|
wait_configuration_progress(ac1, 0, 0)
|
||||||
|
|
||||||
def test_invalid_domain(self, acfactory):
|
def test_invalid_domain(self, acfactory):
|
||||||
@@ -1479,6 +1478,6 @@ class TestOnlineConfigureFails:
|
|||||||
ac1.configure(addr=configdict["addr"] + "x", mail_pw=configdict["mail_pw"])
|
ac1.configure(addr=configdict["addr"] + "x", mail_pw=configdict["mail_pw"])
|
||||||
ac1.start_threads()
|
ac1.start_threads()
|
||||||
wait_configuration_progress(ac1, 500)
|
wait_configuration_progress(ac1, 500)
|
||||||
ev1 = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
ev = ac1._evtracker.get_matching("DC_EVENT_ERROR_NETWORK")
|
||||||
assert "could not connect" in ev1[2].lower()
|
assert "could not connect" in ev.data2.lower()
|
||||||
wait_configuration_progress(ac1, 0, 0)
|
wait_configuration_progress(ac1, 0, 0)
|
||||||
|
|||||||
@@ -21,26 +21,27 @@ def test_dc_close_events(tmpdir, acfactory):
|
|||||||
ac1 = acfactory.get_unconfigured_account()
|
ac1 = acfactory.get_unconfigured_account()
|
||||||
|
|
||||||
# register after_shutdown function
|
# register after_shutdown function
|
||||||
l = []
|
shutdowns = []
|
||||||
|
|
||||||
class ShutdownPlugin:
|
class ShutdownPlugin:
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def after_shutdown(self):
|
def after_shutdown(self):
|
||||||
assert not hasattr(ac1, "_dc_context")
|
assert not hasattr(ac1, "_dc_context")
|
||||||
l.append(1)
|
shutdowns.append(1)
|
||||||
ac1.add_account_plugin(ShutdownPlugin())
|
ac1.add_account_plugin(ShutdownPlugin())
|
||||||
assert hasattr(ac1, "_dc_context")
|
assert hasattr(ac1, "_dc_context")
|
||||||
ac1.shutdown()
|
ac1.shutdown()
|
||||||
assert l == [1]
|
assert shutdowns == [1]
|
||||||
|
|
||||||
def find(info_string):
|
def find(info_string):
|
||||||
evlog = ac1._evtracker
|
evlog = ac1._evtracker
|
||||||
while 1:
|
while 1:
|
||||||
ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
|
ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
|
||||||
data2 = ev[2]
|
data2 = ev.data2
|
||||||
if info_string in data2:
|
if info_string in data2:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print("skipping event", *ev)
|
print("skipping event", ev)
|
||||||
|
|
||||||
find("disconnecting inbox-thread")
|
find("disconnecting inbox-thread")
|
||||||
find("disconnecting sentbox-thread")
|
find("disconnecting sentbox-thread")
|
||||||
|
|||||||
Reference in New Issue
Block a user