mirror of
https://github.com/chatmail/core.git
synced 2026-04-06 15:42:10 +03:00
commit6bc5d1b90eAuthor: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:56:37 2019 +0200 fix fmt commit197d94ad9dMerge:7ce337c686678cAuthor: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:51:16 2019 +0200 Merge remote-tracking branch 'origin/master' into eventlogging commit7ce337c6d0Author: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:44:27 2019 +0200 left-over error logging commit10148d2e43Author: holger krekel <holger@merlinux.eu> Date: Sun Jul 21 22:03:17 2019 +0200 ignore non-utf8 parts of header fields (add comment why it shouldn't happen) don't throw error if no sql rows are returned commit69dc237ee3Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sun Jul 21 12:56:04 2019 +0200 fix(receive_imf): remove recursive sql call commitdf5464ea80Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 17:05:24 2019 +0200 fix: blocked is an optional value commite4bf9956a5Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 16:50:56 2019 +0200 fix(msg): handle optional in_reply_to commitd353d9d9d8Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 16:17:25 2019 +0200 fix(chat): remove recursive sql usage commit1ad45ed4d6Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 15:14:11 2019 +0200 fix rust fmt commit496e980a17Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Sat Jul 20 14:34:20 2019 +0200 use forked rusqlite commitfa09e46ed9Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 12:37:51 2019 +0200 another pace where we might (and in my case did) get invalid utf8 commitd6de420b9aAuthor: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 12:30:48 2019 +0200 fix some string issues, introduce to_string_lossy such that to_string() continues to panic on non-utf8 commit38eb708db8Author: holger krekel <holger@merlinux.eu> Date: Sat Jul 20 01:17:53 2019 +0200 for now make to_string() less strict as we often don't want to crash the whole app just because some non-proper utf8 came in (through a message we can't neccesarily congtrol) commit7a59da5f8fAuthor: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:48:39 2019 +0200 fix linting commitf13a1d4a2fAuthor: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:46:58 2019 +0200 fix some test flakyness commit7b3a450918Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 22:35:07 2019 +0200 - fix saved_mime test which broke to improper conversion of imf_raw_not_terminated - some cargo.toml updates no clue where they come from - log Message-ID for received messages commit169923b102Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 12:31:22 2019 +0200 formatting commit42688a0622Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 12:24:56 2019 +0200 remove some print statements commit35f3c0edd1Merge:e7a2362f58b1d6Author: holger krekel <holger@merlinux.eu> Date: Fri Jul 19 10:25:21 2019 +0200 Merge branch 'master' into eventlogging commite7a236264aAuthor: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:20:20 2019 +0200 print invalid strings commitaaa5b820d9Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:12:35 2019 +0200 cleanup commite7f0745010Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 23:03:57 2019 +0200 reduce direc usage of CString commitc68e7ae14eAuthor: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 22:47:47 2019 +0200 audit use of to_cstring and fix ub commit618087e5a7Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 21:38:52 2019 +0200 fix(imap): body ptr lifetime commit245abb8384Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 19:44:10 2019 +0200 remove debug commita3e1042001Author: dignifiedquire <dignifiedquire@users.noreply.github.com> Date: Thu Jul 18 18:30:54 2019 +0200 fix some things, add more debugging statements commit7b7ce9348fAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 15:11:57 2019 +0200 fix python lint issues commit7a4808ba0dAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 14:35:54 2019 +0200 cargofmt commit8f240f7153Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 14:03:57 2019 +0200 (dig,hpk) pull out job collection from sql query/lock logic commit7d0b5d8abbAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 12:52:02 2019 +0200 remove print statements and fix a crash commitee317cb1b5Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 11:38:10 2019 +0200 fix some merge issues commit7b736fe635Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 11:16:38 2019 +0200 (dig,hpk) add test and fix for wrong dbs commitc7db15352aMerge:0b371670c5015dAuthor: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 09:59:44 2019 +0200 Merge branch 'master' into eventlogging commit0b37167be8Author: holger krekel <holger@merlinux.eu> Date: Thu Jul 18 00:06:05 2019 +0200 address @dignifiedquire comments commit5cac4b5076Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 12:47:22 2019 +0200 remove spurious print commit475a41beb3Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 12:31:12 2019 +0200 address @dignifiedquire rustyness comment and fix changelog commitad4be80b4eAuthor: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 10:25:25 2019 +0200 make smtp/imap connect() return bool instead of c-int commit8737c1d142Author: holger krekel <holger@merlinux.eu> Date: Wed Jul 17 09:26:33 2019 +0200 cleanup some parts, add comments commit964fe466ccAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 20:05:41 2019 +0200 wip-commit which passes all tests with proper finalization commit43936e7db7Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 16:17:42 2019 +0200 snapshot of my current debugging state commit0e80ce9c39Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 12:57:19 2019 +0200 more aggressively skip perform API when threads are closing commitc652bae68aAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 12:06:05 2019 +0200 intermediate wip commit commitbc904a495dAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 11:18:56 2019 +0200 add some logging, and a more precise teardown for online python tests commit8d99444c6aAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:22:12 2019 +0200 fix std commit9dab53e0afAuthor: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:20:54 2019 +0200 rustfmt commit360089ac74Author: holger krekel <holger@merlinux.eu> Date: Tue Jul 16 00:03:49 2019 +0200 remove some debugging commite892c5cf4dAuthor: holger krekel <holger@merlinux.eu> Date: Mon Jul 15 23:31:30 2019 +0200 fix test for events commit9ad4c9a6feAuthor: holger krekel <holger@merlinux.eu> Date: Mon Jul 15 22:51:57 2019 +0200 wip try test that we see INFO events from the core
474 lines
19 KiB
Python
474 lines
19 KiB
Python
from __future__ import print_function
|
|
import pytest
|
|
import os
|
|
from deltachat import const, Account
|
|
from datetime import datetime, timedelta
|
|
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection
|
|
|
|
|
|
class TestOfflineAccount:
|
|
def test_wrong_db(self, tmpdir):
|
|
p = tmpdir.join("hello.db")
|
|
p.write("123")
|
|
with pytest.raises(ValueError):
|
|
Account(p.strpath)
|
|
|
|
def test_getinfo(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
d = ac1.get_info()
|
|
assert d["arch"]
|
|
assert d["number_of_chats"] == "0"
|
|
|
|
def test_is_not_configured(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
assert not ac1.is_configured()
|
|
with pytest.raises(ValueError):
|
|
ac1.check_is_configured()
|
|
|
|
def test_wrong_config_keys(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
with pytest.raises(KeyError):
|
|
ac1.set_config("lqkwje", "value")
|
|
with pytest.raises(KeyError):
|
|
ac1.get_config("lqkwje")
|
|
|
|
def test_has_savemime(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
assert "save_mime_headers" in ac1.get_config("sys.config_keys").split()
|
|
|
|
def test_selfcontact_if_unconfigured(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
with pytest.raises(ValueError):
|
|
ac1.get_self_contact()
|
|
|
|
def test_get_info(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
out = ac1.get_infostring()
|
|
assert "number_of_chats=0" in out
|
|
|
|
def test_selfcontact_configured(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
me = ac1.get_self_contact()
|
|
assert me.display_name
|
|
assert me.addr
|
|
|
|
def test_get_config_fails(self, acfactory):
|
|
ac1 = acfactory.get_unconfigured_account()
|
|
with pytest.raises(KeyError):
|
|
ac1.get_config("123123")
|
|
|
|
def test_contact_attr(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact(email="some1@hello.com", name="some1")
|
|
assert contact1.id
|
|
assert contact1.addr == "some1@hello.com"
|
|
assert contact1.display_name == "some1"
|
|
assert not contact1.is_blocked()
|
|
assert not contact1.is_verified()
|
|
|
|
def test_get_contacts(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact(email="some1@hello.com", name="some1")
|
|
contacts = ac1.get_contacts()
|
|
assert len(contacts) == 1
|
|
assert contact1 in contacts
|
|
|
|
assert not ac1.get_contacts(query="some2")
|
|
assert ac1.get_contacts(query="some1")
|
|
assert not ac1.get_contacts(only_verified=True)
|
|
contacts = ac1.get_contacts(with_self=True)
|
|
assert len(contacts) == 2
|
|
|
|
def test_chat(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL, chat.id
|
|
|
|
chat2 = ac1.create_chat_by_contact(contact1.id)
|
|
assert chat2.id == chat.id
|
|
assert chat2.get_name() == chat.get_name()
|
|
assert chat == chat2
|
|
assert not (chat != chat2)
|
|
|
|
for ichat in ac1.get_chats():
|
|
if ichat.id == chat.id:
|
|
break
|
|
else:
|
|
pytest.fail("could not find chat")
|
|
|
|
def test_group_chat_creation(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
contact2 = ac1.create_contact("some2@hello.com", name="some2")
|
|
chat = ac1.create_group_chat(name="title1")
|
|
chat.add_contact(contact1)
|
|
chat.add_contact(contact2)
|
|
assert chat.get_name() == "title1"
|
|
assert contact1 in chat.get_contacts()
|
|
assert contact2 in chat.get_contacts()
|
|
assert not chat.is_promoted()
|
|
chat.set_name("title2")
|
|
assert chat.get_name() == "title2"
|
|
|
|
def test_delete_and_send_fails(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
chat.delete()
|
|
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
|
with pytest.raises(ValueError):
|
|
chat.send_text("msg1")
|
|
|
|
def test_create_message(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
message = ac1.create_message("text")
|
|
assert message.id == 0
|
|
assert message._dc_msg is message._dc_msg
|
|
message.set_text("hello")
|
|
assert message.text == "hello"
|
|
assert message.id == 0
|
|
|
|
def test_message(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
msg = chat.send_text("msg1")
|
|
assert msg
|
|
assert msg.view_type.is_text()
|
|
assert msg.view_type.name == "text"
|
|
assert not msg.view_type.is_audio()
|
|
assert not msg.view_type.is_video()
|
|
assert not msg.view_type.is_gif()
|
|
assert not msg.view_type.is_file()
|
|
assert not msg.view_type.is_image()
|
|
msg_state = msg.get_state()
|
|
assert not msg_state.is_in_fresh()
|
|
assert not msg_state.is_in_noticed()
|
|
assert not msg_state.is_in_seen()
|
|
assert msg_state.is_out_pending()
|
|
assert not msg_state.is_out_failed()
|
|
assert not msg_state.is_out_delivered()
|
|
assert not msg_state.is_out_mdn_received()
|
|
|
|
def test_create_chat_by_mssage_id(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
msg = chat.send_text("msg1")
|
|
assert chat == ac1.create_chat_by_message(msg)
|
|
assert chat == ac1.create_chat_by_message(msg.id)
|
|
|
|
def test_message_image(self, acfactory, data, lp):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
with pytest.raises(ValueError):
|
|
chat.send_image(path="notexists")
|
|
fn = data.get_path("d.png")
|
|
lp.sec("sending image")
|
|
msg = chat.send_image(fn)
|
|
assert msg.view_type.name == "image"
|
|
assert msg
|
|
assert msg.id > 0
|
|
assert os.path.exists(msg.filename)
|
|
assert msg.filemime == "image/png"
|
|
|
|
@pytest.mark.parametrize("typein,typeout", [
|
|
(None, "application/octet-stream"),
|
|
("text/plain", "text/plain"),
|
|
("image/png", "image/png"),
|
|
])
|
|
def test_message_file(self, acfactory, data, lp, typein, typeout):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
lp.sec("sending file")
|
|
fn = data.get_path("r.txt")
|
|
msg = chat.send_file(fn, typein)
|
|
assert msg
|
|
assert msg.id > 0
|
|
assert msg.view_type.name == "file"
|
|
assert msg.view_type.is_file()
|
|
assert os.path.exists(msg.filename)
|
|
assert msg.filename.endswith(msg.basename)
|
|
assert msg.filemime == typeout
|
|
|
|
def test_create_chat_mismatch(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
ac2 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
with pytest.raises(ValueError):
|
|
ac2.create_chat_by_contact(contact1)
|
|
chat1 = ac1.create_chat_by_contact(contact1)
|
|
msg = chat1.send_text("hello")
|
|
with pytest.raises(ValueError):
|
|
ac2.create_chat_by_message(msg)
|
|
|
|
def test_chat_message_distinctions(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
past1s = datetime.utcnow() - timedelta(seconds=1)
|
|
msg = chat.send_text("msg1")
|
|
ts = msg.time_sent
|
|
assert msg.time_received is None
|
|
assert ts.strftime("Y")
|
|
assert past1s < ts
|
|
contact = msg.get_sender_contact()
|
|
assert contact == ac1.get_self_contact()
|
|
|
|
def test_basic_configure_ok_addr_setting_forbidden(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
assert ac1.get_config("mail_pw")
|
|
assert ac1.is_configured()
|
|
with pytest.raises(ValueError):
|
|
ac1.set_config("addr", "123@example.org")
|
|
with pytest.raises(ValueError):
|
|
ac1.configure(addr="123@example.org")
|
|
|
|
def test_import_export_one_contact(self, acfactory, tmpdir):
|
|
backupdir = tmpdir.mkdir("backup")
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
# send a text message
|
|
msg = chat.send_text("msg1")
|
|
# send a binary file
|
|
bin = tmpdir.join("some.bin")
|
|
with bin.open("w") as f:
|
|
f.write("\00123" * 10000)
|
|
msg = chat.send_file(bin.strpath)
|
|
|
|
contact = msg.get_sender_contact()
|
|
assert contact == ac1.get_self_contact()
|
|
assert not backupdir.listdir()
|
|
|
|
path = ac1.export_to_dir(backupdir.strpath)
|
|
assert os.path.exists(path)
|
|
ac2 = acfactory.get_unconfigured_account()
|
|
ac2.import_from_file(path)
|
|
contacts = ac2.get_contacts(query="some1")
|
|
assert len(contacts) == 1
|
|
contact2 = contacts[0]
|
|
assert contact2.addr == "some1@hello.com"
|
|
chat2 = ac2.create_chat_by_contact(contact2)
|
|
messages = chat2.get_messages()
|
|
assert len(messages) == 2
|
|
assert messages[0].text == "msg1"
|
|
assert os.path.exists(messages[1].filename)
|
|
|
|
def test_ac_setup_message_fails(self, acfactory):
|
|
ac1 = acfactory.get_configured_offline_account()
|
|
with pytest.raises(RuntimeError):
|
|
ac1.initiate_key_transfer()
|
|
|
|
|
|
class TestOnlineAccount:
|
|
def test_one_account_init(self, acfactory):
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
wait_successful_IMAP_SMTP_connection(ac1)
|
|
wait_configuration_progress(ac1, 1000)
|
|
|
|
def test_one_account_send(self, acfactory):
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
c2 = ac1.create_contact(email=ac1.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
|
|
wait_successful_IMAP_SMTP_connection(ac1)
|
|
wait_configuration_progress(ac1, 1000)
|
|
|
|
msg_out = chat.send_text("message2")
|
|
# wait for own account to receive
|
|
ev = ac1._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
|
assert ev[1] == msg_out.id
|
|
|
|
def test_two_acocunts_send_receive(self, acfactory):
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.get_online_configuring_account()
|
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
|
|
wait_successful_IMAP_SMTP_connection(ac1)
|
|
wait_configuration_progress(ac1, 1000)
|
|
wait_successful_IMAP_SMTP_connection(ac2)
|
|
wait_configuration_progress(ac2, 1000)
|
|
|
|
msg_out = chat.send_text("message1")
|
|
|
|
# wait for other account to receive
|
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|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"
|
|
|
|
def test_forward_messages(self, acfactory):
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.get_online_configuring_account()
|
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
|
|
wait_successful_IMAP_SMTP_connection(ac1)
|
|
wait_configuration_progress(ac1, 1000)
|
|
wait_successful_IMAP_SMTP_connection(ac2)
|
|
wait_configuration_progress(ac2, 1000)
|
|
|
|
msg_out = chat.send_text("message2")
|
|
|
|
# wait for other account to receive
|
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
|
assert ev[2] == msg_out.id
|
|
msg_in = ac2.get_message_by_id(msg_out.id)
|
|
assert msg_in.text == "message2"
|
|
|
|
# check the message arrived in contact-requests/deaddrop
|
|
chat2 = msg_in.chat
|
|
assert msg_in in chat2.get_messages()
|
|
assert chat2.is_deaddrop()
|
|
assert chat2 == ac2.get_deaddrop_chat()
|
|
chat3 = ac2.create_group_chat("newgroup")
|
|
assert not chat3.is_promoted()
|
|
ac2.forward_messages([msg_in], chat3)
|
|
assert chat3.is_promoted()
|
|
messages = chat3.get_messages()
|
|
ac2.delete_messages(messages)
|
|
assert not chat3.get_messages()
|
|
|
|
def test_send_and_receive_message(self, acfactory, lp):
|
|
lp.sec("starting accounts, waiting for configuration")
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.get_online_configuring_account()
|
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
|
|
|
|
wait_configuration_progress(ac1, 1000)
|
|
wait_configuration_progress(ac2, 1000)
|
|
|
|
lp.sec("sending text message from ac1 to ac2")
|
|
msg_out = chat.send_text("message1")
|
|
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
|
evt_name, data1, data2 = ev
|
|
assert data1 == chat.id
|
|
assert data2 == msg_out.id
|
|
assert msg_out.get_state().is_out_delivered()
|
|
|
|
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"
|
|
|
|
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
|
|
assert msg_in.time_received > msg_in.time_sent
|
|
|
|
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
|
|
|
|
lp.sec("mark chat as noticed")
|
|
chat2b.mark_noticed()
|
|
assert chat2b.count_fresh_messages() == 0
|
|
|
|
lp.sec("mark message as seen on ac2, wait for changes on ac1")
|
|
ac2.mark_seen_messages([msg_in])
|
|
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()
|
|
|
|
def test_saved_mime_on_received_message(self, acfactory, lp):
|
|
lp.sec("starting accounts, waiting for configuration")
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.get_online_configuring_account()
|
|
ac2.set_config("save_mime_headers", "1")
|
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
wait_configuration_progress(ac1, 1000)
|
|
wait_configuration_progress(ac2, 1000)
|
|
lp.sec("sending text message from ac1 to ac2")
|
|
msg_out = chat.send_text("message1")
|
|
ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
|
assert msg_out.get_mime_headers() is None
|
|
|
|
lp.sec("wait for ac2 to receive message")
|
|
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
|
in_id = ev[2]
|
|
mime = ac2.get_message_by_id(in_id).get_mime_headers()
|
|
assert mime.get_all("From")
|
|
assert mime.get_all("Received")
|
|
|
|
def test_send_and_receive_image(self, acfactory, lp, data):
|
|
lp.sec("starting accounts, waiting for configuration")
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.get_online_configuring_account()
|
|
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
|
chat = ac1.create_chat_by_contact(c2)
|
|
|
|
wait_configuration_progress(ac1, 1000)
|
|
wait_configuration_progress(ac2, 1000)
|
|
|
|
lp.sec("sending image message from ac1 to ac2")
|
|
path = data.get_path("d.png")
|
|
msg_out = chat.send_image(path)
|
|
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
|
evt_name, data1, data2 = ev
|
|
assert data1 == chat.id
|
|
assert data2 == msg_out.id
|
|
assert msg_out.get_state().is_out_delivered()
|
|
|
|
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.view_type.is_image()
|
|
assert os.path.exists(msg_in.filename)
|
|
assert os.stat(msg_in.filename).st_size == os.stat(path).st_size
|
|
|
|
def test_import_export_online(self, acfactory, tmpdir):
|
|
backupdir = tmpdir.mkdir("backup")
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
wait_configuration_progress(ac1, 1000)
|
|
|
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
|
chat = ac1.create_chat_by_contact(contact1)
|
|
chat.send_text("msg1")
|
|
path = ac1.export_to_dir(backupdir.strpath)
|
|
assert os.path.exists(path)
|
|
|
|
ac2 = acfactory.get_unconfigured_account()
|
|
ac2.import_from_file(path)
|
|
contacts = ac2.get_contacts(query="some1")
|
|
assert len(contacts) == 1
|
|
contact2 = contacts[0]
|
|
assert contact2.addr == "some1@hello.com"
|
|
chat2 = ac2.create_chat_by_contact(contact2)
|
|
messages = chat2.get_messages()
|
|
assert len(messages) == 1
|
|
assert messages[0].text == "msg1"
|
|
|
|
def test_ac_setup_message(self, acfactory):
|
|
# note that the receiving account needs to be configured and running
|
|
# before ther setup message is send. DC does not read old messages
|
|
# as of Jul2019
|
|
ac1 = acfactory.get_online_configuring_account()
|
|
ac2 = acfactory.clone_online_account(ac1)
|
|
wait_configuration_progress(ac2, 1000)
|
|
wait_configuration_progress(ac1, 1000)
|
|
assert ac1.get_info()["fingerprint"] != ac2.get_info()["fingerprint"]
|
|
setup_code = ac1.initiate_key_transfer()
|
|
ac2._evlogger.set_timeout(10)
|
|
ev = ac2._evlogger.get_matching("DC_EVENT_INCOMING_MSG|DC_EVENT_MSGS_CHANGED")
|
|
msg = ac2.get_message_by_id(ev[2])
|
|
assert msg.is_setup_message()
|
|
print("*************** Incoming ASM File at: ", msg.filename)
|
|
print("*************** Setup Code: ", setup_code)
|
|
msg.continue_key_transfer(setup_code)
|
|
assert ac1.get_info()["fingerprint"] == ac2.get_info()["fingerprint"]
|