mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
refine test / chat API
This commit is contained in:
@@ -12,7 +12,7 @@ class EchoPlugin:
|
|||||||
message.account.shutdown()
|
message.account.shutdown()
|
||||||
else:
|
else:
|
||||||
# unconditionally accept the chat
|
# unconditionally accept the chat
|
||||||
message.accept_sender_contact()
|
message.create_chat()
|
||||||
addr = message.get_sender_contact().addr
|
addr = message.get_sender_contact().addr
|
||||||
if message.is_system_message():
|
if message.is_system_message():
|
||||||
message.chat.send_text("echoing system message from {}:\n{}".format(addr, message))
|
message.chat.send_text("echoing system message from {}:\n{}".format(addr, message))
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class GroupTrackingPlugin:
|
|||||||
message.account.shutdown()
|
message.account.shutdown()
|
||||||
else:
|
else:
|
||||||
# unconditionally accept the chat
|
# unconditionally accept the chat
|
||||||
message.accept_sender_contact()
|
message.create_chat()
|
||||||
addr = message.get_sender_contact().addr
|
addr = message.get_sender_contact().addr
|
||||||
text = message.text
|
text = message.text
|
||||||
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ class FFIEventTracker:
|
|||||||
if ev.data2 > 0:
|
if ev.data2 > 0:
|
||||||
return self.account.get_message_by_id(ev.data2)
|
return self.account.get_message_by_id(ev.data2)
|
||||||
|
|
||||||
|
def wait_msg_delivered(self, msg):
|
||||||
|
ev = self.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
|
assert ev.data1 == msg.chat.id
|
||||||
|
assert ev.data2 == msg.id
|
||||||
|
assert msg.is_out_delivered()
|
||||||
|
|
||||||
|
|
||||||
class EventThread(threading.Thread):
|
class EventThread(threading.Thread):
|
||||||
""" Event Thread for an account.
|
""" Event Thread for an account.
|
||||||
|
|||||||
@@ -53,15 +53,15 @@ class Message(object):
|
|||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
))
|
))
|
||||||
|
|
||||||
def accept_sender_contact(self):
|
def create_chat(self):
|
||||||
""" ensure that the sender is an accepted contact
|
""" create a chat from a message (eg Contact-Request message).
|
||||||
and that the message has a non-deaddrop chat object.
|
|
||||||
"""
|
"""
|
||||||
self.account.create_chat_by_message(self)
|
chat = self.account.create_chat_by_message(self)
|
||||||
self._dc_msg = ffi.gc(
|
self._dc_msg = ffi.gc(
|
||||||
lib.dc_get_msg(self.account._dc_context, self.id),
|
lib.dc_get_msg(self.account._dc_context, self.id),
|
||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
)
|
)
|
||||||
|
return chat
|
||||||
|
|
||||||
@props.with_doc
|
@props.with_doc
|
||||||
def text(self):
|
def text(self):
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ class AutoReplier:
|
|||||||
if self.current_sent >= self.num_send:
|
if self.current_sent >= self.num_send:
|
||||||
self.report_func(self, ReportType.exit)
|
self.report_func(self, ReportType.exit)
|
||||||
return
|
return
|
||||||
message.accept_sender_contact()
|
message.create_chat()
|
||||||
message.mark_seen()
|
message.mark_seen()
|
||||||
self.log("incoming message: {}".format(message))
|
self.log("incoming message: {}".format(message))
|
||||||
|
|
||||||
|
|||||||
@@ -818,29 +818,24 @@ class TestOnlineAccount:
|
|||||||
chat = acfactory.get_chat(ac1, ac2, both=False)
|
chat = acfactory.get_chat(ac1, ac2, both=False)
|
||||||
|
|
||||||
lp.sec("sending text message from ac1 to ac2")
|
lp.sec("sending text message from ac1 to ac2")
|
||||||
msg_out = chat.send_text("message1")
|
msg1 = chat.send_text("message1")
|
||||||
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
ac1._evtracker.wait_msg_delivered(msg1)
|
||||||
assert ev.data1 == chat.id
|
|
||||||
assert ev.data2 == msg_out.id
|
|
||||||
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")
|
msg2 = ac2._evtracker.wait_next_messages_changed()
|
||||||
assert ev.data2 == msg_out.id
|
assert msg2.text == "message1"
|
||||||
msg_in = ac2.get_message_by_id(msg_out.id)
|
assert not msg2.is_forwarded()
|
||||||
assert msg_in.text == "message1"
|
assert msg2.get_sender_contact().display_name == ac1.get_config("displayname")
|
||||||
assert not msg_in.is_forwarded()
|
|
||||||
assert msg_in.get_sender_contact().display_name == ac1.get_config("displayname")
|
|
||||||
|
|
||||||
lp.sec("check the message arrived in contact-requests/deaddrop")
|
lp.sec("check the message arrived in contact-requests/deaddrop")
|
||||||
chat2 = msg_in.chat
|
chat2 = msg2.chat
|
||||||
assert msg_in in chat2.get_messages()
|
assert msg2 in chat2.get_messages()
|
||||||
assert chat2.is_deaddrop()
|
assert chat2.is_deaddrop()
|
||||||
assert chat2.count_fresh_messages() == 0
|
assert chat2.count_fresh_messages() == 0
|
||||||
assert msg_in.time_received >= msg_out.time_sent
|
assert msg2.time_received >= msg1.time_sent
|
||||||
|
|
||||||
lp.sec("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 = msg2.create_chat()
|
||||||
assert not chat2b.is_deaddrop()
|
assert not chat2b.is_deaddrop()
|
||||||
assert chat2b.count_fresh_messages() == 1
|
assert chat2b.count_fresh_messages() == 1
|
||||||
|
|
||||||
@@ -851,27 +846,25 @@ class TestOnlineAccount:
|
|||||||
ac2._evtracker.consume_events()
|
ac2._evtracker.consume_events()
|
||||||
|
|
||||||
lp.sec("sending a second message from ac1 to ac2")
|
lp.sec("sending a second message from ac1 to ac2")
|
||||||
msg_out2 = chat.send_text("message2")
|
msg3 = chat.send_text("message2")
|
||||||
|
|
||||||
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")
|
msg4 = ac2._evtracker.wait_next_incoming_message()
|
||||||
assert ev.data2 == 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")
|
||||||
ac2.mark_seen_messages([msg_in, msg_in2])
|
ac2.mark_seen_messages([msg2, msg4])
|
||||||
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.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
assert ev.data2 > 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 msg1.is_out_mdn_received()
|
||||||
assert msg_out2.is_out_mdn_received()
|
assert msg3.is_out_mdn_received()
|
||||||
|
|
||||||
lp.sec("check that a second call to mark_seen does not create change or smtp job")
|
lp.sec("try check that a second call to mark_seen doesn't happen")
|
||||||
ac2._evtracker.consume_events()
|
ac2._evtracker.consume_events()
|
||||||
msg_in.mark_seen()
|
msg2.mark_seen()
|
||||||
try:
|
try:
|
||||||
ac2._evtracker.get_matching("DC_EVENT_MSG_READ", timeout=0.01)
|
ac2._evtracker.get_matching("DC_EVENT_MSG_READ", timeout=0.01)
|
||||||
except queue.Empty:
|
except queue.Empty:
|
||||||
@@ -1049,7 +1042,7 @@ 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")
|
||||||
ac1._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
ac1._evtracker.wait_msg_delivered(msg_out)
|
||||||
assert msg_out.get_mime_headers() is None
|
assert msg_out.get_mime_headers() is None
|
||||||
|
|
||||||
lp.sec("wait for ac2 to receive message")
|
lp.sec("wait for ac2 to receive message")
|
||||||
@@ -1117,10 +1110,7 @@ class TestOnlineAccount:
|
|||||||
lp.sec("sending image message from ac1 to ac2")
|
lp.sec("sending image message from ac1 to ac2")
|
||||||
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")
|
ac1._evtracker.wait_msg_delivered(msg_out)
|
||||||
assert ev.data1 == chat.id
|
|
||||||
assert ev.data2 == msg_out.id
|
|
||||||
assert msg_out.is_out_delivered()
|
|
||||||
m = out.get()
|
m = out.get()
|
||||||
assert m == msg_out
|
assert m == msg_out
|
||||||
m = delivered.get()
|
m = delivered.get()
|
||||||
@@ -1351,7 +1341,7 @@ class TestOnlineAccount:
|
|||||||
def ac_incoming_message(self, message):
|
def ac_incoming_message(self, message):
|
||||||
# we immediately accept the sender because
|
# we immediately accept the sender because
|
||||||
# otherwise we won't see member_added contacts
|
# otherwise we won't see member_added contacts
|
||||||
message.accept_sender_contact()
|
message.create_chat()
|
||||||
|
|
||||||
@account_hookimpl
|
@account_hookimpl
|
||||||
def ac_chat_modified(self, chat):
|
def ac_chat_modified(self, chat):
|
||||||
@@ -1381,7 +1371,7 @@ class TestOnlineAccount:
|
|||||||
sorted(x.addr for x in ev.chat.get_contacts())
|
sorted(x.addr for x in ev.chat.get_contacts())
|
||||||
|
|
||||||
lp.sec("ac1: add address2")
|
lp.sec("ac1: add address2")
|
||||||
# note that if the above accept_sender_contact() would not
|
# note that if the above create_chat() would not
|
||||||
# happen we would not receive a proper member_added event
|
# happen we would not receive a proper member_added event
|
||||||
contact2 = ac1.create_contact(email="notexistingaccountihope@testrun.org")
|
contact2 = ac1.create_contact(email="notexistingaccountihope@testrun.org")
|
||||||
chat.add_contact(contact2)
|
chat.add_contact(contact2)
|
||||||
@@ -1462,15 +1452,6 @@ class TestOnlineAccount:
|
|||||||
assert msg_back.chat == chat
|
assert msg_back.chat == chat
|
||||||
assert chat.get_profile_image() is None
|
assert chat.get_profile_image() is None
|
||||||
|
|
||||||
def test_accept_sender_contact(self, acfactory, lp):
|
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
|
||||||
ch = ac1.create_chat_by_contact(ac1.create_contact(ac2.get_config("addr")))
|
|
||||||
ch.send_text("hello")
|
|
||||||
msg = ac2._evtracker.wait_next_messages_changed()
|
|
||||||
assert msg.chat.is_deaddrop()
|
|
||||||
msg.accept_sender_contact()
|
|
||||||
assert not msg.chat.is_deaddrop()
|
|
||||||
|
|
||||||
def test_send_receive_locations(self, acfactory, lp):
|
def test_send_receive_locations(self, acfactory, lp):
|
||||||
now = datetime.utcnow()
|
now = datetime.utcnow()
|
||||||
ac1, ac2 = acfactory.get_two_online_accounts()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
|||||||
Reference in New Issue
Block a user