add python tests

This commit is contained in:
Simon Laux
2020-01-24 01:49:50 +01:00
parent ef158504e7
commit 07d698f8dc
2 changed files with 48 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import calendar
import json import json
from datetime import datetime from datetime import datetime
import os import os
import time
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
from .capi import lib, ffi from .capi import lib, ffi
from . import const from . import const
@@ -58,6 +59,13 @@ class Chat(object):
""" """
return self.id == const.DC_CHAT_ID_DEADDROP return self.id == const.DC_CHAT_ID_DEADDROP
def is_muted(self):
""" return true if this chat is muted.
:returns: True if chat is muted, False otherwise.
"""
return lib.dc_chat_is_muted(self._dc_chat)
def is_promoted(self): def is_promoted(self):
""" return True if this chat is promoted, i.e. """ return True if this chat is promoted, i.e.
the member contacts are aware of their membership, the member contacts are aware of their membership,
@@ -84,12 +92,39 @@ class Chat(object):
def set_name(self, name): def set_name(self, name):
""" set name of this chat. """ set name of this chat.
:param: name as a unicode string. :param name: as a unicode string.
:returns: None :returns: None
""" """
name = as_dc_charpointer(name) 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)
def mute(self, duration=None):
""" mutes the chat
:param duration: Number of seconds to mute the chat for. None to mute until unmuted again.
:returns:
"""
if duration is None:
timestamp = -1
else:
timestamp = int(time.time()) + duration
return bool(lib.dc_set_chat_muted(self._dc_context, self.id, timestamp))
def unmute(self):
""" unmutes the chat
:returns:
"""
return bool(lib.dc_set_chat_muted(self._dc_context, self.id, 0))
def get_mute_duration(self):
""" mutes the chat
:param duration:
:returns: Returns the number of seconds the chat is still muted for. (0 for not muted, -1 forever muted)
"""
return bool(lib.dc_chat_get_mute_duration(self.id))
def get_type(self): def get_type(self):
""" return type of this chat. """ return type of this chat.

View File

@@ -220,6 +220,18 @@ class TestOfflineChat:
chat.remove_profile_image() chat.remove_profile_image()
assert chat.get_profile_image() is None assert chat.get_profile_image() is None
def test_mute(self, ac1):
chat = ac1.create_group_chat(name="title1")
assert not chat.is_muted()
assert chat.mute()
assert chat.is_muted()
assert chat.unmute()
assert not chat.is_muted()
assert chat.mute(50)
assert chat.is_muted()
assert chat.mute(-51)
assert not chat.is_muted()
def test_delete_and_send_fails(self, ac1, chat1): def test_delete_and_send_fails(self, ac1, chat1):
chat1.delete() chat1.delete()
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED") ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")