1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-04 10:19:16 +02:00

add chat.delete(), chat.send_image, msg.filename, msg.filemime and msg.type.is_*

This commit is contained in:
holger krekel 2018-10-06 18:40:52 +02:00
parent 60240ce507
commit b6355176de
5 changed files with 181 additions and 3 deletions

View file

@ -1,5 +1,6 @@
from __future__ import print_function
import pytest
import os
from deltachat import const
from datetime import datetime, timedelta
from conftest import wait_configuration_progress, wait_successful_IMAP_SMTP_connection
@ -82,12 +83,28 @@ class TestOfflineAccount:
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_message("msg1")
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_message("msg1")
assert msg
assert msg.type.is_text()
assert msg.type.name == "text"
assert not msg.type.is_audio()
assert not msg.type.is_video()
assert not msg.type.is_gif()
assert not msg.type.is_file()
assert not msg.type.is_image()
msg_state = msg.get_state()
assert not msg_state.is_in_fresh()
assert not msg_state.is_in_noticed()
@ -97,6 +114,20 @@ class TestOfflineAccount:
assert not msg_state.is_out_delivered()
assert not msg_state.is_out_mdn_received()
def test_message_image(self, acfactory, data):
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")
msg = chat.send_image(fn)
assert msg.type.name == "image"
assert msg
assert msg.id > 0
assert os.path.exists(msg.filename)
assert msg.filemime == "image/png"
def test_chat_message_distinctions(self, acfactory):
ac1 = acfactory.get_configured_offline_account()
contact1 = ac1.create_contact("some1@hello.com", name="some1")
@ -199,3 +230,29 @@ class TestOnlineAccount:
lp.step("2")
ac1._evlogger.get_info_matching("Message marked as seen")
assert msg_out.get_state().is_out_mdn_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 os.path.exists(msg_in.filename)
assert os.stat(msg_in.filename).st_size == os.stat(path).st_size