mirror of
https://github.com/chatmail/core.git
synced 2026-05-14 20:36:30 +03:00
refactor(deltachat-rpc-client): use wait_for_event() type argument
This commit is contained in:
@@ -113,10 +113,7 @@ class Account:
|
|||||||
def bring_online(self):
|
def bring_online(self):
|
||||||
"""Start I/O and wait until IMAP becomes IDLE."""
|
"""Start I/O and wait until IMAP becomes IDLE."""
|
||||||
self.start_io()
|
self.start_io()
|
||||||
while True:
|
self.wait_for_event(EventType.IMAP_INBOX_IDLE)
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.IMAP_INBOX_IDLE:
|
|
||||||
break
|
|
||||||
|
|
||||||
def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
|
def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
|
||||||
"""Create a new Contact or return an existing one.
|
"""Create a new Contact or return an existing one.
|
||||||
@@ -335,24 +332,15 @@ class Account:
|
|||||||
|
|
||||||
def wait_for_incoming_msg_event(self):
|
def wait_for_incoming_msg_event(self):
|
||||||
"""Wait for incoming message event and return it."""
|
"""Wait for incoming message event and return it."""
|
||||||
while True:
|
return self.wait_for_event(EventType.INCOMING_MSG)
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.INCOMING_MSG:
|
|
||||||
return event
|
|
||||||
|
|
||||||
def wait_for_msgs_changed_event(self):
|
def wait_for_msgs_changed_event(self):
|
||||||
"""Wait for messages changed event and return it."""
|
"""Wait for messages changed event and return it."""
|
||||||
while True:
|
return self.wait_for_event(EventType.MSGS_CHANGED)
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.MSGS_CHANGED:
|
|
||||||
return event
|
|
||||||
|
|
||||||
def wait_for_msgs_noticed_event(self):
|
def wait_for_msgs_noticed_event(self):
|
||||||
"""Wait for messages noticed event and return it."""
|
"""Wait for messages noticed event and return it."""
|
||||||
while True:
|
return self.wait_for_event(EventType.MSGS_NOTICED)
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.MSGS_NOTICED:
|
|
||||||
return event
|
|
||||||
|
|
||||||
def wait_for_incoming_msg(self):
|
def wait_for_incoming_msg(self):
|
||||||
"""Wait for incoming message and return it.
|
"""Wait for incoming message and return it.
|
||||||
@@ -373,10 +361,7 @@ class Account:
|
|||||||
break
|
break
|
||||||
|
|
||||||
def wait_for_reactions_changed(self):
|
def wait_for_reactions_changed(self):
|
||||||
while True:
|
return self.wait_for_event(EventType.REACTIONS_CHANGED)
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.REACTIONS_CHANGED:
|
|
||||||
return event
|
|
||||||
|
|
||||||
def get_fresh_messages_in_arrival_order(self) -> list[Message]:
|
def get_fresh_messages_in_arrival_order(self) -> list[Message]:
|
||||||
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
|
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
|
||||||
|
|||||||
@@ -175,17 +175,11 @@ def test_no_duplicate_messages(acfactory, path_to_webxdc):
|
|||||||
|
|
||||||
threading.Thread(target=thread_run, daemon=True).start()
|
threading.Thread(target=thread_run, daemon=True).start()
|
||||||
|
|
||||||
while 1:
|
event = ac2.wait_for_event(EventType.WEBXDC_REALTIME_DATA)
|
||||||
event = ac2.wait_for_event()
|
n = int(bytes(event.data).decode())
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
n = int(bytes(event.data).decode())
|
|
||||||
break
|
|
||||||
|
|
||||||
while 1:
|
event = ac2.wait_for_event(EventType.WEBXDC_REALTIME_DATA)
|
||||||
event = ac2.wait_for_event()
|
assert int(bytes(event.data).decode()) > n
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
assert int(bytes(event.data).decode()) > n
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_reordering(acfactory, path_to_webxdc):
|
def test_no_reordering(acfactory, path_to_webxdc):
|
||||||
@@ -229,8 +223,5 @@ def test_advertisement_after_chatting(acfactory, path_to_webxdc):
|
|||||||
ac2_hello_msg_snapshot.chat.accept()
|
ac2_hello_msg_snapshot.chat.accept()
|
||||||
|
|
||||||
ac2_webxdc_msg.send_webxdc_realtime_advertisement()
|
ac2_webxdc_msg.send_webxdc_realtime_advertisement()
|
||||||
while 1:
|
event = ac1.wait_for_event(EventType.WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED)
|
||||||
event = ac1.wait_for_event()
|
assert event.msg_id == ac1_webxdc_msg.id
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED:
|
|
||||||
assert event.msg_id == ac1_webxdc_msg.id
|
|
||||||
break
|
|
||||||
|
|||||||
@@ -76,17 +76,11 @@ def test_qr_securejoin(acfactory, protect):
|
|||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
|
|
||||||
# Alice deletes "vg-request".
|
# Alice deletes "vg-request".
|
||||||
while True:
|
alice.wait_for_event(EventType.IMAP_MESSAGE_DELETED)
|
||||||
event = alice.wait_for_event()
|
|
||||||
if event["kind"] == "ImapMessageDeleted":
|
|
||||||
break
|
|
||||||
alice.wait_for_securejoin_inviter_success()
|
alice.wait_for_securejoin_inviter_success()
|
||||||
# Bob deletes "vg-auth-required", Alice deletes "vg-request-with-auth".
|
# Bob deletes "vg-auth-required", Alice deletes "vg-request-with-auth".
|
||||||
for ac in [alice, bob]:
|
for ac in [alice, bob]:
|
||||||
while True:
|
ac.wait_for_event(EventType.IMAP_MESSAGE_DELETED)
|
||||||
event = ac.wait_for_event()
|
|
||||||
if event["kind"] == "ImapMessageDeleted":
|
|
||||||
break
|
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
# Test that Alice verified Bob's profile.
|
# Test that Alice verified Bob's profile.
|
||||||
|
|||||||
@@ -110,12 +110,9 @@ def test_account(acfactory) -> None:
|
|||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
alice_chat_bob = alice_contact_bob.create_chat()
|
||||||
alice_chat_bob.send_text("Hello!")
|
alice_chat_bob.send_text("Hello!")
|
||||||
|
|
||||||
while True:
|
event = bob.wait_for_incoming_msg_event()
|
||||||
event = bob.wait_for_event()
|
chat_id = event.chat_id
|
||||||
if event.kind == EventType.INCOMING_MSG:
|
msg_id = event.msg_id
|
||||||
chat_id = event.chat_id
|
|
||||||
msg_id = event.msg_id
|
|
||||||
break
|
|
||||||
|
|
||||||
message = bob.get_message_by_id(msg_id)
|
message = bob.get_message_by_id(msg_id)
|
||||||
snapshot = message.get_snapshot()
|
snapshot = message.get_snapshot()
|
||||||
@@ -330,18 +327,11 @@ def test_reaction_seen_on_another_dev(acfactory) -> None:
|
|||||||
snapshot.chat.accept()
|
snapshot.chat.accept()
|
||||||
message.send_reaction("😎")
|
message.send_reaction("😎")
|
||||||
for a in [alice, alice2]:
|
for a in [alice, alice2]:
|
||||||
while True:
|
a.wait_for_event(EventType.INCOMING_REACTION)
|
||||||
event = a.wait_for_event()
|
|
||||||
if event.kind == EventType.INCOMING_REACTION:
|
|
||||||
break
|
|
||||||
|
|
||||||
alice2.clear_all_events()
|
alice2.clear_all_events()
|
||||||
alice_chat_bob.mark_noticed()
|
alice_chat_bob.mark_noticed()
|
||||||
while True:
|
chat_id = alice2.wait_for_event(EventType.MSGS_NOTICED).chat_id
|
||||||
event = alice2.wait_for_event()
|
|
||||||
if event.kind == EventType.MSGS_NOTICED:
|
|
||||||
chat_id = event.chat_id
|
|
||||||
break
|
|
||||||
alice2_contact_bob = alice2.get_contact_by_addr(bob_addr)
|
alice2_contact_bob = alice2.get_contact_by_addr(bob_addr)
|
||||||
alice2_chat_bob = alice2_contact_bob.create_chat()
|
alice2_chat_bob = alice2_contact_bob.create_chat()
|
||||||
assert chat_id == alice2_chat_bob.id
|
assert chat_id == alice2_chat_bob.id
|
||||||
@@ -359,16 +349,12 @@ def test_is_bot(acfactory) -> None:
|
|||||||
alice.set_config("bot", "1")
|
alice.set_config("bot", "1")
|
||||||
alice_chat_bob.send_text("Hello!")
|
alice_chat_bob.send_text("Hello!")
|
||||||
|
|
||||||
while True:
|
event = bob.wait_for_incoming_msg_event()
|
||||||
event = bob.wait_for_event()
|
message = bob.get_message_by_id(event.msg_id)
|
||||||
if event.kind == EventType.INCOMING_MSG:
|
snapshot = message.get_snapshot()
|
||||||
msg_id = event.msg_id
|
assert snapshot.chat_id == event.chat_id
|
||||||
message = bob.get_message_by_id(msg_id)
|
assert snapshot.text == "Hello!"
|
||||||
snapshot = message.get_snapshot()
|
assert snapshot.is_bot
|
||||||
assert snapshot.chat_id == event.chat_id
|
|
||||||
assert snapshot.text == "Hello!"
|
|
||||||
assert snapshot.is_bot
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_bot(acfactory) -> None:
|
def test_bot(acfactory) -> None:
|
||||||
@@ -529,10 +515,7 @@ def test_mdn_doesnt_break_autocrypt(acfactory) -> None:
|
|||||||
|
|
||||||
# Alice reads Bob's message.
|
# Alice reads Bob's message.
|
||||||
message.mark_seen()
|
message.mark_seen()
|
||||||
while True:
|
bob.wait_for_event(EventType.MSG_READ)
|
||||||
event = bob.wait_for_event()
|
|
||||||
if event.kind == EventType.MSG_READ:
|
|
||||||
break
|
|
||||||
|
|
||||||
# Bob sends a message to Alice, it should also be encrypted.
|
# Bob sends a message to Alice, it should also be encrypted.
|
||||||
bob_chat_alice.send_text("Hi Alice!")
|
bob_chat_alice.send_text("Hi Alice!")
|
||||||
@@ -702,10 +685,7 @@ def test_markseen_contact_request(acfactory):
|
|||||||
assert message2.get_snapshot().state == MessageState.IN_FRESH
|
assert message2.get_snapshot().state == MessageState.IN_FRESH
|
||||||
|
|
||||||
message.mark_seen()
|
message.mark_seen()
|
||||||
while True:
|
bob2.wait_for_event(EventType.MSGS_NOTICED)
|
||||||
event = bob2.wait_for_event()
|
|
||||||
if event.kind == EventType.MSGS_NOTICED:
|
|
||||||
break
|
|
||||||
assert message2.get_snapshot().state == MessageState.IN_SEEN
|
assert message2.get_snapshot().state == MessageState.IN_SEEN
|
||||||
|
|
||||||
|
|
||||||
@@ -753,10 +733,7 @@ def test_no_old_msg_is_fresh(acfactory):
|
|||||||
assert ac1.create_chat(ac2).get_fresh_message_count() == 1
|
assert ac1.create_chat(ac2).get_fresh_message_count() == 1
|
||||||
assert len(list(ac1.get_fresh_messages())) == 1
|
assert len(list(ac1.get_fresh_messages())) == 1
|
||||||
|
|
||||||
while True:
|
ac1.wait_for_event(EventType.IMAP_INBOX_IDLE)
|
||||||
event = ac1.wait_for_event()
|
|
||||||
if event.kind == EventType.IMAP_INBOX_IDLE:
|
|
||||||
break
|
|
||||||
|
|
||||||
logging.info("Send a message from ac1_clone to ac2 and check that ac1 marks the first message as 'noticed'")
|
logging.info("Send a message from ac1_clone to ac2 and check that ac1 marks the first message as 'noticed'")
|
||||||
ac1_clone_chat.send_text("Hi back")
|
ac1_clone_chat.send_text("Hi back")
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
from deltachat_rpc_client import EventType
|
|
||||||
|
|
||||||
|
|
||||||
def test_webxdc(acfactory) -> None:
|
def test_webxdc(acfactory) -> None:
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
@@ -9,12 +6,9 @@ def test_webxdc(acfactory) -> None:
|
|||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
alice_chat_bob = alice_contact_bob.create_chat()
|
||||||
alice_chat_bob.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc")
|
alice_chat_bob.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc")
|
||||||
|
|
||||||
while True:
|
event = bob.wait_for_incoming_msg_event()
|
||||||
event = bob.wait_for_event()
|
bob_chat_alice = bob.get_chat_by_id(event.chat_id)
|
||||||
if event.kind == EventType.INCOMING_MSG:
|
message = bob.get_message_by_id(event.msg_id)
|
||||||
bob_chat_alice = bob.get_chat_by_id(event.chat_id)
|
|
||||||
message = bob.get_message_by_id(event.msg_id)
|
|
||||||
break
|
|
||||||
|
|
||||||
webxdc_info = message.get_webxdc_info()
|
webxdc_info = message.get_webxdc_info()
|
||||||
assert webxdc_info == {
|
assert webxdc_info == {
|
||||||
|
|||||||
Reference in New Issue
Block a user