mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-04 10:19:16 +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 pytest
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
|
@ -48,7 +49,7 @@ def acfactory(pytestconfig, tmpdir, request):
|
||||||
configdict = self.configlist.pop(0)
|
configdict = self.configlist.pop(0)
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
||||||
ac = Account(tmpdb.strpath, logid="ac{}".format(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)
|
ac.set_config(**configdict)
|
||||||
if started:
|
if started:
|
||||||
ac.start()
|
ac.start()
|
||||||
|
@ -61,3 +62,14 @@ def acfactory(pytestconfig, tmpdir, request):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def tmp_db_path(tmpdir):
|
def tmp_db_path(tmpdir):
|
||||||
return tmpdir.join("test.db").strpath
|
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]):
|
if rex.match(ev[0]):
|
||||||
return ev
|
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):
|
def _log_event(self, evt_name, data1, data2):
|
||||||
# don't show events that are anyway empty impls now
|
# don't show events that are anyway empty impls now
|
||||||
if evt_name in ("DC_EVENT_GET_STRING", "DC_EVENT_IS_OFFLINE"):
|
if evt_name in ("DC_EVENT_GET_STRING", "DC_EVENT_IS_OFFLINE"):
|
||||||
|
|
|
@ -77,9 +77,9 @@ class Chat(object):
|
||||||
|
|
||||||
def set_name(self, name):
|
def set_name(self, name):
|
||||||
""" set name of this chat. """
|
""" set name of this chat. """
|
||||||
|
name = as_dc_charpointer(name)
|
||||||
return lib.dc_set_chat_name(self._dc_context, self.id, name)
|
return lib.dc_set_chat_name(self._dc_context, self.id, name)
|
||||||
|
|
||||||
|
|
||||||
# ------ chat messaging API ------------------------------
|
# ------ chat messaging API ------------------------------
|
||||||
|
|
||||||
def send_text_message(self, msg):
|
def send_text_message(self, msg):
|
||||||
|
|
|
@ -158,7 +158,8 @@ class TestOnlineAccount:
|
||||||
ac2.delete_messages(messages)
|
ac2.delete_messages(messages)
|
||||||
assert not chat3.get_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()
|
ac1 = acfactory.get_live_account()
|
||||||
ac2 = acfactory.get_live_account()
|
ac2 = acfactory.get_live_account()
|
||||||
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
||||||
|
@ -169,6 +170,8 @@ class TestOnlineAccount:
|
||||||
self.wait_successful_IMAP_SMTP_connection(ac2)
|
self.wait_successful_IMAP_SMTP_connection(ac2)
|
||||||
self.wait_configuration_progress(ac1, 1000)
|
self.wait_configuration_progress(ac1, 1000)
|
||||||
self.wait_configuration_progress(ac2, 1000)
|
self.wait_configuration_progress(ac2, 1000)
|
||||||
|
|
||||||
|
lp.sec("sending text message from ac1 to ac2")
|
||||||
msg_out = chat.send_text_message("message1")
|
msg_out = chat.send_text_message("message1")
|
||||||
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
evt_name, data1, data2 = ev
|
evt_name, data1, data2 = ev
|
||||||
|
@ -176,28 +179,31 @@ class TestOnlineAccount:
|
||||||
assert data2 == msg_out.id
|
assert data2 == msg_out.id
|
||||||
assert msg_out.get_state().is_out_delivered()
|
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")
|
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev[2] == msg_out.id
|
assert ev[2] == 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"
|
||||||
|
|
||||||
# check the message arrived in contact-requets/deaddrop
|
lp.sec("check the message arrived in contact-requets/deaddrop")
|
||||||
chat2 = msg_in.chat
|
chat2 = msg_in.chat
|
||||||
assert msg_in in chat2.get_messages()
|
assert msg_in in chat2.get_messages()
|
||||||
assert chat2.is_deaddrop()
|
assert chat2.is_deaddrop()
|
||||||
assert chat2.count_fresh_messages() == 0
|
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)
|
chat2b = ac2.create_chat_by_message(msg_in)
|
||||||
assert not chat2b.is_deaddrop()
|
assert not chat2b.is_deaddrop()
|
||||||
assert chat2b.count_fresh_messages() == 1
|
assert chat2b.count_fresh_messages() == 1
|
||||||
|
|
||||||
# mark chat as noticed
|
lp.sec("mark chat as noticed")
|
||||||
chat2b.mark_noticed()
|
chat2b.mark_noticed()
|
||||||
assert chat2b.count_fresh_messages() == 0
|
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])
|
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()
|
assert msg_out.get_state().is_out_mdn_received()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue