mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 13:26:38 +03:00
fix tests
This commit is contained in:
@@ -198,9 +198,9 @@ class Account:
|
|||||||
if not snapshot:
|
if not snapshot:
|
||||||
return [Chat(self, entry[0]) for entry in entries]
|
return [Chat(self, entry[0]) for entry in entries]
|
||||||
|
|
||||||
items = await self._rpc.get_chatlist_items_by_entries(self.id, flags, query)
|
items = await self._rpc.get_chatlist_items_by_entries(self.id, entries)
|
||||||
chats = []
|
chats = []
|
||||||
for item in items:
|
for item in items.values():
|
||||||
item["chat"] = Chat(self, item["id"])
|
item["chat"] = Chat(self, item["id"])
|
||||||
chats.append(AttrDict(item))
|
chats.append(AttrDict(item))
|
||||||
return chats
|
return chats
|
||||||
|
|||||||
@@ -56,13 +56,21 @@ class Chat:
|
|||||||
"""Leave this chat."""
|
"""Leave this chat."""
|
||||||
await self._rpc.leave_group(self.account.id, self.id)
|
await self._rpc.leave_group(self.account.id, self.id)
|
||||||
|
|
||||||
async def mute(self, duration: int = -1) -> None:
|
async def mute(self, duration: Optional[int] = None) -> None:
|
||||||
"""Mute this chat, if a duration is not provided the chat is muted forever."""
|
"""Mute this chat, if a duration is not provided the chat is muted forever.
|
||||||
await self._rpc.set_chat_mute_duration(self.account.id, self.id, duration)
|
|
||||||
|
:param duration: mute duration from now in seconds. Must be greater than zero.
|
||||||
|
"""
|
||||||
|
if duration is not None:
|
||||||
|
assert duration > 0, "Invalid duration"
|
||||||
|
dur: Union[str, dict] = dict(Until=duration)
|
||||||
|
else:
|
||||||
|
dur = "Forever"
|
||||||
|
await self._rpc.set_chat_mute_duration(self.account.id, self.id, dur)
|
||||||
|
|
||||||
async def unmute(self) -> None:
|
async def unmute(self) -> None:
|
||||||
"""Unmute this chat."""
|
"""Unmute this chat."""
|
||||||
await self._rpc.set_chat_mute_duration(self.account.id, self.id, 0)
|
await self._rpc.set_chat_mute_duration(self.account.id, self.id, "NotMuted")
|
||||||
|
|
||||||
async def pin(self) -> None:
|
async def pin(self) -> None:
|
||||||
"""Pin this chat."""
|
"""Pin this chat."""
|
||||||
@@ -148,7 +156,7 @@ class Chat:
|
|||||||
async def forward_messages(self, messages: List[Message]) -> None:
|
async def forward_messages(self, messages: List[Message]) -> None:
|
||||||
"""Forward a list of messages to this chat."""
|
"""Forward a list of messages to this chat."""
|
||||||
msg_ids = [msg.id for msg in messages]
|
msg_ids = [msg.id for msg in messages]
|
||||||
await self._rpc.markseen_msgs(self.account.id, msg_ids, self.id)
|
await self._rpc.forward_messages(self.account.id, msg_ids, self.id)
|
||||||
|
|
||||||
async def set_draft(
|
async def set_draft(
|
||||||
self,
|
self,
|
||||||
@@ -165,10 +173,16 @@ class Chat:
|
|||||||
"""Remove draft message."""
|
"""Remove draft message."""
|
||||||
await self._rpc.remove_draft(self.account.id, self.id)
|
await self._rpc.remove_draft(self.account.id, self.id)
|
||||||
|
|
||||||
async def get_draft(self) -> Message:
|
async def get_draft(self) -> Optional[AttrDict]:
|
||||||
"""Get draft message."""
|
"""Get draft message."""
|
||||||
msg = await self._rpc.get_draft(self.account.id, self.id)
|
snapshot = await self._rpc.get_draft(self.account.id, self.id)
|
||||||
return Message(self.account, msg["id"])
|
if not snapshot:
|
||||||
|
return None
|
||||||
|
snapshot = AttrDict(snapshot)
|
||||||
|
snapshot["chat"] = Chat(self.account, snapshot.chat_id)
|
||||||
|
snapshot["sender"] = Contact(self.account, snapshot.from_id)
|
||||||
|
snapshot["message"] = Message(self.account, snapshot.id)
|
||||||
|
return snapshot
|
||||||
|
|
||||||
async def get_messages(self, flags: int = 0) -> List[Message]:
|
async def get_messages(self, flags: int = 0) -> List[Message]:
|
||||||
"""get the list of messages in this chat."""
|
"""get the list of messages in this chat."""
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ class Message:
|
|||||||
def _rpc(self) -> Rpc:
|
def _rpc(self) -> Rpc:
|
||||||
return self.account._rpc
|
return self.account._rpc
|
||||||
|
|
||||||
async def send_reaction(self, reactions: str) -> "Message":
|
async def send_reaction(self, *reaction: str):
|
||||||
msg_id = await self._rpc.send_reaction(self.account.id, self.id, reactions)
|
"""Send a reaction to this message."""
|
||||||
return Message(self.account, msg_id)
|
await self._rpc.send_reaction(self.account.id, self.id, reaction)
|
||||||
|
|
||||||
async def get_snapshot(self) -> AttrDict:
|
async def get_snapshot(self) -> AttrDict:
|
||||||
"""Get a snapshot with the properties of this message."""
|
"""Get a snapshot with the properties of this message."""
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from deltachat_rpc_client import AttrDict, EventType, events
|
from deltachat_rpc_client import AttrDict, EventType, events
|
||||||
|
from deltachat_rpc_client.rpc import JsonRpcError
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -54,9 +55,10 @@ async def test_account(acfactory) -> None:
|
|||||||
msg_id = event.msg_id
|
msg_id = event.msg_id
|
||||||
break
|
break
|
||||||
|
|
||||||
message = await bob.get_message_by_id(msg_id).get_snapshot()
|
message = await bob.get_message_by_id(msg_id)
|
||||||
assert message.chat_id == chat_id
|
snapshot = await message.get_snapshot()
|
||||||
assert message.text == "Hello!"
|
assert snapshot.chat_id == chat_id
|
||||||
|
assert snapshot.text == "Hello!"
|
||||||
await bob.mark_seen_messages([message])
|
await bob.mark_seen_messages([message])
|
||||||
|
|
||||||
assert alice != bob
|
assert alice != bob
|
||||||
@@ -77,10 +79,10 @@ async def test_account(acfactory) -> None:
|
|||||||
|
|
||||||
group = await alice.create_group("test group")
|
group = await alice.create_group("test group")
|
||||||
await group.add_contact(alice_contact_bob)
|
await group.add_contact(alice_contact_bob)
|
||||||
msg = await group.send_message(text="hello")
|
group_msg = await group.send_message(text="hello")
|
||||||
assert msg == await alice.get_message_by_id(msg.id)
|
assert group_msg == await alice.get_message_by_id(group_msg.id)
|
||||||
assert group == await alice.get_chat_by_id(group.id)
|
assert group == await alice.get_chat_by_id(group.id)
|
||||||
await alice.delete_messages([msg])
|
await alice.delete_messages([group_msg])
|
||||||
|
|
||||||
await alice.set_config("selfstatus", "test")
|
await alice.set_config("selfstatus", "test")
|
||||||
assert await alice.get_config("selfstatus") == "test"
|
assert await alice.get_config("selfstatus") == "test"
|
||||||
@@ -112,9 +114,10 @@ async def test_chat(acfactory) -> None:
|
|||||||
chat_id = event.chat_id
|
chat_id = event.chat_id
|
||||||
msg_id = event.msg_id
|
msg_id = event.msg_id
|
||||||
break
|
break
|
||||||
message = await bob.get_message_by_id(msg_id).get_snapshot()
|
message = await bob.get_message_by_id(msg_id)
|
||||||
assert message.chat_id == chat_id
|
snapshot = await message.get_snapshot()
|
||||||
assert message.text == "Hello!"
|
assert snapshot.chat_id == chat_id
|
||||||
|
assert snapshot.text == "Hello!"
|
||||||
bob_chat_alice = await bob.get_chat_by_id(chat_id)
|
bob_chat_alice = await bob.get_chat_by_id(chat_id)
|
||||||
|
|
||||||
assert alice_chat_bob != bob_chat_alice
|
assert alice_chat_bob != bob_chat_alice
|
||||||
@@ -122,29 +125,38 @@ async def test_chat(acfactory) -> None:
|
|||||||
await alice_chat_bob.delete()
|
await alice_chat_bob.delete()
|
||||||
await bob_chat_alice.accept()
|
await bob_chat_alice.accept()
|
||||||
await bob_chat_alice.block()
|
await bob_chat_alice.block()
|
||||||
bob_chat_alice = await message.contact.create_chat()
|
bob_chat_alice = await snapshot.sender.create_chat()
|
||||||
await bob_chat_alice.mute()
|
await bob_chat_alice.mute()
|
||||||
await bob_chat_alice.unmute()
|
await bob_chat_alice.unmute()
|
||||||
await bob_chat_alice.pin()
|
await bob_chat_alice.pin()
|
||||||
await bob_chat_alice.unpin()
|
await bob_chat_alice.unpin()
|
||||||
await bob_chat_alice.archive()
|
await bob_chat_alice.archive()
|
||||||
await bob_chat_alice.unarchive()
|
await bob_chat_alice.unarchive()
|
||||||
await bob_chat_alice.set_name("test")
|
with pytest.raises(JsonRpcError): # can't set name for 1:1 chats
|
||||||
|
await bob_chat_alice.set_name("test")
|
||||||
await bob_chat_alice.set_ephemeral_timer(300)
|
await bob_chat_alice.set_ephemeral_timer(300)
|
||||||
await bob_chat_alice.get_encryption_info()
|
await bob_chat_alice.get_encryption_info()
|
||||||
|
|
||||||
group = await alice.create_group("test group")
|
group = await alice.create_group("test group")
|
||||||
await group.add_contact(alice_contact_bob)
|
await group.add_contact(alice_contact_bob)
|
||||||
await group.get_qr_code()
|
await group.get_qr_code()
|
||||||
assert await group.get_basic_snapshot()
|
|
||||||
assert await group.get_full_snapshot()
|
snapshot = await group.get_basic_snapshot()
|
||||||
|
assert snapshot.name == "test group"
|
||||||
|
await group.set_name("new name")
|
||||||
|
snapshot = await group.get_full_snapshot()
|
||||||
|
assert snapshot.name == "new name"
|
||||||
|
|
||||||
msg = await group.send_message(text="hi")
|
msg = await group.send_message(text="hi")
|
||||||
assert (await msg.get_snapshot()).text == "hi"
|
assert (await msg.get_snapshot()).text == "hi"
|
||||||
await group.forward_messages([msg])
|
await group.forward_messages([msg])
|
||||||
await group.set_draft(text="draft")
|
|
||||||
assert await group.get_draft()
|
await group.set_draft(text="test draft")
|
||||||
|
draft = await group.get_draft()
|
||||||
|
assert draft.text == "test draft"
|
||||||
await group.remove_draft()
|
await group.remove_draft()
|
||||||
assert not await group.get_draft()
|
assert not await group.get_draft()
|
||||||
|
|
||||||
assert await group.get_messages()
|
assert await group.get_messages()
|
||||||
await group.get_fresh_message_count()
|
await group.get_fresh_message_count()
|
||||||
await group.mark_noticed()
|
await group.mark_noticed()
|
||||||
@@ -160,7 +172,7 @@ async def test_contact(acfactory) -> None:
|
|||||||
bob_addr = await bob.get_config("addr")
|
bob_addr = await bob.get_config("addr")
|
||||||
alice_contact_bob = await alice.create_contact(bob_addr, "Bob")
|
alice_contact_bob = await alice.create_contact(bob_addr, "Bob")
|
||||||
|
|
||||||
assert alice_contact_bob == alice.get_contact_by_id(alice_contact_bob.id)
|
assert alice_contact_bob == await alice.get_contact_by_id(alice_contact_bob.id)
|
||||||
assert repr(alice_contact_bob)
|
assert repr(alice_contact_bob)
|
||||||
await alice_contact_bob.block()
|
await alice_contact_bob.block()
|
||||||
await alice_contact_bob.unblock()
|
await alice_contact_bob.unblock()
|
||||||
@@ -187,12 +199,19 @@ async def test_message(acfactory) -> None:
|
|||||||
msg_id = event.msg_id
|
msg_id = event.msg_id
|
||||||
break
|
break
|
||||||
|
|
||||||
message = await bob.get_message_by_id(msg_id).get_snapshot()
|
message = await bob.get_message_by_id(msg_id)
|
||||||
assert message.chat_id == chat_id
|
snapshot = await message.get_snapshot()
|
||||||
assert message.text == "Hello!"
|
assert snapshot.chat_id == chat_id
|
||||||
|
assert snapshot.text == "Hello!"
|
||||||
assert repr(message)
|
assert repr(message)
|
||||||
|
|
||||||
|
with pytest.raises(JsonRpcError): # chat is not accepted
|
||||||
|
await snapshot.chat.send_text("hi")
|
||||||
|
await snapshot.chat.accept()
|
||||||
|
await snapshot.chat.send_text("hi")
|
||||||
|
|
||||||
await message.mark_seen()
|
await message.mark_seen()
|
||||||
assert await message.send_reaction("😎")
|
await message.send_reaction("😎")
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
|
|||||||
Reference in New Issue
Block a user