mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-03 17:59:19 +02:00
- bump version
- add forgotten data file - rename Chat.send_text_message to Chat.send_text - add optional mime-type param to Chat.send_file - properly install the package instead of "usedevelop" mode
This commit is contained in:
parent
b6355176de
commit
5c3e41fcb5
7 changed files with 53 additions and 10 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
0.7
|
||||||
|
---
|
||||||
|
|
||||||
|
- add Chat.delete(), Chat.send_image() and Chat.send_file()
|
||||||
|
|
||||||
|
- renamed Chat.send_text_message to Chat.sent_text
|
||||||
|
|
||||||
0.6
|
0.6
|
||||||
---
|
---
|
||||||
|
|
|
@ -2,7 +2,7 @@ from deltachat import capi, const
|
||||||
from deltachat.capi import ffi
|
from deltachat.capi import ffi
|
||||||
from deltachat.account import Account # noqa
|
from deltachat.account import Account # noqa
|
||||||
|
|
||||||
__version__ = "0.6.0"
|
__version__ = "0.7.0"
|
||||||
|
|
||||||
|
|
||||||
_DC_CALLBACK_MAP = {}
|
_DC_CALLBACK_MAP = {}
|
||||||
|
|
|
@ -107,19 +107,34 @@ class Chat(object):
|
||||||
|
|
||||||
# ------ chat messaging API ------------------------------
|
# ------ chat messaging API ------------------------------
|
||||||
|
|
||||||
def send_text_message(self, msg):
|
def send_text(self, text):
|
||||||
""" send a text message and return the resulting Message instance.
|
""" send a text message and return the resulting Message instance.
|
||||||
|
|
||||||
:param msg: unicode text
|
:param msg: unicode text
|
||||||
:raises: ValueError if message can not be send/chat does not exist.
|
:raises: ValueError if message can not be send/chat does not exist.
|
||||||
:returns: the resulting :class:`deltachat.chatting.Message` instance
|
:returns: the resulting :class:`deltachat.chatting.Message` instance
|
||||||
"""
|
"""
|
||||||
msg = as_dc_charpointer(msg)
|
msg = as_dc_charpointer(text)
|
||||||
msg_id = lib.dc_send_text_msg(self._dc_context, self.id, msg)
|
msg_id = lib.dc_send_text_msg(self._dc_context, self.id, msg)
|
||||||
if msg_id == 0:
|
if msg_id == 0:
|
||||||
raise ValueError("message could not be send, does chat exist?")
|
raise ValueError("message could not be send, does chat exist?")
|
||||||
return Message(self._dc_context, msg_id)
|
return Message(self._dc_context, msg_id)
|
||||||
|
|
||||||
|
def send_file(self, path, mime_type="application/octet-stream"):
|
||||||
|
""" send a file and return the resulting Message instance.
|
||||||
|
|
||||||
|
:param path: path to the file.
|
||||||
|
:param mime_type: the mime-type of this file, defaults to application/octet-stream.
|
||||||
|
:raises: ValueError if message can not be send/chat does not exist.
|
||||||
|
:returns: the resulting :class:`deltachat.chatting.Message` instance
|
||||||
|
"""
|
||||||
|
path = as_dc_charpointer(path)
|
||||||
|
mtype = as_dc_charpointer(mime_type)
|
||||||
|
msg_id = lib.dc_send_file_msg(self._dc_context, self.id, path, mtype)
|
||||||
|
if msg_id == 0:
|
||||||
|
raise ValueError("message could not be send, does chat exist?")
|
||||||
|
return Message(self._dc_context, msg_id)
|
||||||
|
|
||||||
def send_image(self, path):
|
def send_image(self, path):
|
||||||
""" send an image message and return the resulting Message instance.
|
""" send an image message and return the resulting Message instance.
|
||||||
|
|
||||||
|
|
BIN
python/tests/data/d.png
Normal file
BIN
python/tests/data/d.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
2
python/tests/data/r.txt
Normal file
2
python/tests/data/r.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
|
||||||
|
hello
|
|
@ -90,13 +90,13 @@ class TestOfflineAccount:
|
||||||
chat.delete()
|
chat.delete()
|
||||||
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
chat.send_text_message("msg1")
|
chat.send_text("msg1")
|
||||||
|
|
||||||
def test_message(self, acfactory):
|
def test_message(self, acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
msg = chat.send_text_message("msg1")
|
msg = chat.send_text("msg1")
|
||||||
assert msg
|
assert msg
|
||||||
assert msg.type.is_text()
|
assert msg.type.is_text()
|
||||||
assert msg.type.name == "text"
|
assert msg.type.name == "text"
|
||||||
|
@ -114,13 +114,14 @@ class TestOfflineAccount:
|
||||||
assert not msg_state.is_out_delivered()
|
assert not msg_state.is_out_delivered()
|
||||||
assert not msg_state.is_out_mdn_received()
|
assert not msg_state.is_out_mdn_received()
|
||||||
|
|
||||||
def test_message_image(self, acfactory, data):
|
def test_message_image(self, acfactory, data, lp):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
chat.send_image(path="notexists")
|
chat.send_image(path="notexists")
|
||||||
fn = data.get_path("d.png")
|
fn = data.get_path("d.png")
|
||||||
|
lp.sec("sending image")
|
||||||
msg = chat.send_image(fn)
|
msg = chat.send_image(fn)
|
||||||
assert msg.type.name == "image"
|
assert msg.type.name == "image"
|
||||||
assert msg
|
assert msg
|
||||||
|
@ -128,12 +129,31 @@ class TestOfflineAccount:
|
||||||
assert os.path.exists(msg.filename)
|
assert os.path.exists(msg.filename)
|
||||||
assert msg.filemime == "image/png"
|
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.type.name == "file"
|
||||||
|
assert msg.type.is_file()
|
||||||
|
assert os.path.exists(msg.filename)
|
||||||
|
assert msg.filemime == typeout
|
||||||
|
|
||||||
def test_chat_message_distinctions(self, acfactory):
|
def test_chat_message_distinctions(self, acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
contact1 = ac1.create_contact("some1@hello.com", name="some1")
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
chat = ac1.create_chat_by_contact(contact1)
|
||||||
past1s = datetime.now() - timedelta(seconds=1)
|
past1s = datetime.now() - timedelta(seconds=1)
|
||||||
msg = chat.send_text_message("msg1")
|
msg = chat.send_text("msg1")
|
||||||
ts = msg.time_sent
|
ts = msg.time_sent
|
||||||
assert ts.strftime("Y")
|
assert ts.strftime("Y")
|
||||||
assert past1s < ts
|
assert past1s < ts
|
||||||
|
@ -162,7 +182,7 @@ class TestOnlineAccount:
|
||||||
wait_successful_IMAP_SMTP_connection(ac2)
|
wait_successful_IMAP_SMTP_connection(ac2)
|
||||||
wait_configuration_progress(ac2, 1000)
|
wait_configuration_progress(ac2, 1000)
|
||||||
|
|
||||||
msg_out = chat.send_text_message("message2")
|
msg_out = chat.send_text("message2")
|
||||||
|
|
||||||
# wait for other account to receive
|
# wait for other account to receive
|
||||||
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
|
@ -195,7 +215,7 @@ class TestOnlineAccount:
|
||||||
wait_configuration_progress(ac2, 1000)
|
wait_configuration_progress(ac2, 1000)
|
||||||
|
|
||||||
lp.sec("sending text message from ac1 to ac2")
|
lp.sec("sending text message from ac1 to ac2")
|
||||||
msg_out = chat.send_text_message("message1")
|
msg_out = chat.send_text("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
|
||||||
assert data1 == chat.id
|
assert data1 == chat.id
|
||||||
|
@ -254,5 +274,6 @@ class TestOnlineAccount:
|
||||||
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.type.is_image()
|
||||||
assert os.path.exists(msg_in.filename)
|
assert os.path.exists(msg_in.filename)
|
||||||
assert os.stat(msg_in.filename).st_size == os.stat(path).st_size
|
assert os.stat(msg_in.filename).st_size == os.stat(path).st_size
|
||||||
|
|
|
@ -7,7 +7,6 @@ envlist =
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands = pytest -rsXx {posargs:tests}
|
commands = pytest -rsXx {posargs:tests}
|
||||||
usedevelop = True
|
|
||||||
passenv = TRAVIS
|
passenv = TRAVIS
|
||||||
deps =
|
deps =
|
||||||
pytest
|
pytest
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue