mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 02:09:17 +02:00
some better printing, fixing py35
This commit is contained in:
parent
5914af77c2
commit
0bfa955f9c
4 changed files with 34 additions and 9 deletions
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
import pytest
|
||||
import re
|
||||
import threading
|
||||
|
@ -48,7 +49,7 @@ def acfactory(pytestconfig, tmpdir, request):
|
|||
configdict = self.configlist.pop(0)
|
||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
||||
ac._evlogger.set_timeout(20)
|
||||
ac._evlogger.set_timeout(30)
|
||||
ac.set_config(**configdict)
|
||||
if started:
|
||||
ac.start()
|
||||
|
@ -61,3 +62,14 @@ def acfactory(pytestconfig, tmpdir, request):
|
|||
@pytest.fixture
|
||||
def tmp_db_path(tmpdir):
|
||||
return tmpdir.join("test.db").strpath
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def lp():
|
||||
class Printer:
|
||||
def sec(self, msg):
|
||||
print()
|
||||
print("=" * 10, msg, "=" * 10)
|
||||
def step(self, msg):
|
||||
print("-" * 5, "step " + msg, "-" * 5)
|
||||
return Printer()
|
||||
|
|
|
@ -330,6 +330,13 @@ class EventLogger:
|
|||
if rex.match(ev[0]):
|
||||
return ev
|
||||
|
||||
def get_info_matching(self, regex):
|
||||
rex = re.compile("(?:{}).*".format(regex))
|
||||
while 1:
|
||||
ev = self.get_matching("DC_EVENT_INFO")
|
||||
if rex.match(ev[2]):
|
||||
return ev
|
||||
|
||||
def _log_event(self, evt_name, data1, data2):
|
||||
# don't show events that are anyway empty impls now
|
||||
if evt_name in ("DC_EVENT_GET_STRING", "DC_EVENT_IS_OFFLINE"):
|
||||
|
|
|
@ -77,9 +77,9 @@ class Chat(object):
|
|||
|
||||
def set_name(self, name):
|
||||
""" set name of this chat. """
|
||||
name = as_dc_charpointer(name)
|
||||
return lib.dc_set_chat_name(self._dc_context, self.id, name)
|
||||
|
||||
|
||||
# ------ chat messaging API ------------------------------
|
||||
|
||||
def send_text_message(self, msg):
|
||||
|
|
|
@ -158,7 +158,8 @@ class TestOnlineAccount:
|
|||
ac2.delete_messages(messages)
|
||||
assert not chat3.get_messages()
|
||||
|
||||
def test_send_and_receive_message(self, acfactory):
|
||||
def test_send_and_receive_message(self, acfactory, lp):
|
||||
lp.sec("starting accounts, waiting for configuration")
|
||||
ac1 = acfactory.get_live_account()
|
||||
ac2 = acfactory.get_live_account()
|
||||
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
||||
|
@ -169,6 +170,8 @@ class TestOnlineAccount:
|
|||
self.wait_successful_IMAP_SMTP_connection(ac2)
|
||||
self.wait_configuration_progress(ac1, 1000)
|
||||
self.wait_configuration_progress(ac2, 1000)
|
||||
|
||||
lp.sec("sending text message from ac1 to ac2")
|
||||
msg_out = chat.send_text_message("message1")
|
||||
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||
evt_name, data1, data2 = ev
|
||||
|
@ -176,28 +179,31 @@ class TestOnlineAccount:
|
|||
assert data2 == msg_out.id
|
||||
assert msg_out.get_state().is_out_delivered()
|
||||
|
||||
# wait for other account to receive
|
||||
lp.sec("wait for ac2 to receive message")
|
||||
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||
assert ev[2] == msg_out.id
|
||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
||||
assert msg_in.text == "message1"
|
||||
|
||||
# check the message arrived in contact-requets/deaddrop
|
||||
lp.sec("check the message arrived in contact-requets/deaddrop")
|
||||
chat2 = msg_in.chat
|
||||
assert msg_in in chat2.get_messages()
|
||||
assert chat2.is_deaddrop()
|
||||
assert chat2.count_fresh_messages() == 0
|
||||
|
||||
# create new chat with contact and verify it's proper
|
||||
lp.sec("create new chat with contact and verify it's proper")
|
||||
chat2b = ac2.create_chat_by_message(msg_in)
|
||||
assert not chat2b.is_deaddrop()
|
||||
assert chat2b.count_fresh_messages() == 1
|
||||
|
||||
# mark chat as noticed
|
||||
lp.sec("mark chat as noticed")
|
||||
chat2b.mark_noticed()
|
||||
assert chat2b.count_fresh_messages() == 0
|
||||
|
||||
# mark messages as seen and check ac1 sees the MDN
|
||||
lp.sec("mark message as seen on ac2, wait for changes on ac1")
|
||||
ac2.mark_seen_messages([msg_in])
|
||||
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||
lp.step("1")
|
||||
ac1._evlogger.get_matching("DC_EVENT_MSG_READ")
|
||||
lp.step("2")
|
||||
ac1._evlogger.get_info_matching("Message marked as seen")
|
||||
assert msg_out.get_state().is_out_mdn_received()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue