diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/account.py b/deltachat-rpc-client/src/deltachat_rpc_client/account.py index 11dbe8f06..b2486c19a 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/account.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/account.py @@ -113,10 +113,7 @@ class Account: def bring_online(self): """Start I/O and wait until IMAP becomes IDLE.""" self.start_io() - while True: - event = self.wait_for_event() - if event.kind == EventType.IMAP_INBOX_IDLE: - break + self.wait_for_event(EventType.IMAP_INBOX_IDLE) def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact: """Create a new Contact or return an existing one. @@ -335,24 +332,15 @@ class Account: def wait_for_incoming_msg_event(self): """Wait for incoming message event and return it.""" - while True: - event = self.wait_for_event() - if event.kind == EventType.INCOMING_MSG: - return event + return self.wait_for_event(EventType.INCOMING_MSG) def wait_for_msgs_changed_event(self): """Wait for messages changed event and return it.""" - while True: - event = self.wait_for_event() - if event.kind == EventType.MSGS_CHANGED: - return event + return self.wait_for_event(EventType.MSGS_CHANGED) def wait_for_msgs_noticed_event(self): """Wait for messages noticed event and return it.""" - while True: - event = self.wait_for_event() - if event.kind == EventType.MSGS_NOTICED: - return event + return self.wait_for_event(EventType.MSGS_NOTICED) def wait_for_incoming_msg(self): """Wait for incoming message and return it. @@ -373,10 +361,7 @@ class Account: break def wait_for_reactions_changed(self): - while True: - event = self.wait_for_event() - if event.kind == EventType.REACTIONS_CHANGED: - return event + return self.wait_for_event(EventType.REACTIONS_CHANGED) def get_fresh_messages_in_arrival_order(self) -> list[Message]: """Return fresh messages list sorted in the order of their arrival, with ascending IDs.""" diff --git a/deltachat-rpc-client/tests/test_iroh_webxdc.py b/deltachat-rpc-client/tests/test_iroh_webxdc.py index 30c24a72a..c2433d2f7 100644 --- a/deltachat-rpc-client/tests/test_iroh_webxdc.py +++ b/deltachat-rpc-client/tests/test_iroh_webxdc.py @@ -175,17 +175,11 @@ def test_no_duplicate_messages(acfactory, path_to_webxdc): threading.Thread(target=thread_run, daemon=True).start() - while 1: - event = ac2.wait_for_event() - if event.kind == EventType.WEBXDC_REALTIME_DATA: - n = int(bytes(event.data).decode()) - break + event = ac2.wait_for_event(EventType.WEBXDC_REALTIME_DATA) + n = int(bytes(event.data).decode()) - while 1: - event = ac2.wait_for_event() - if event.kind == EventType.WEBXDC_REALTIME_DATA: - assert int(bytes(event.data).decode()) > n - break + event = ac2.wait_for_event(EventType.WEBXDC_REALTIME_DATA) + assert int(bytes(event.data).decode()) > n 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_webxdc_msg.send_webxdc_realtime_advertisement() - while 1: - event = ac1.wait_for_event() - if event.kind == EventType.WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED: - assert event.msg_id == ac1_webxdc_msg.id - break + event = ac1.wait_for_event(EventType.WEBXDC_REALTIME_ADVERTISEMENT_RECEIVED) + assert event.msg_id == ac1_webxdc_msg.id diff --git a/deltachat-rpc-client/tests/test_securejoin.py b/deltachat-rpc-client/tests/test_securejoin.py index 73299c48b..a6a05fcc3 100644 --- a/deltachat-rpc-client/tests/test_securejoin.py +++ b/deltachat-rpc-client/tests/test_securejoin.py @@ -76,17 +76,11 @@ def test_qr_securejoin(acfactory, protect): bob.secure_join(qr_code) # Alice deletes "vg-request". - while True: - event = alice.wait_for_event() - if event["kind"] == "ImapMessageDeleted": - break + alice.wait_for_event(EventType.IMAP_MESSAGE_DELETED) alice.wait_for_securejoin_inviter_success() # Bob deletes "vg-auth-required", Alice deletes "vg-request-with-auth". for ac in [alice, bob]: - while True: - event = ac.wait_for_event() - if event["kind"] == "ImapMessageDeleted": - break + ac.wait_for_event(EventType.IMAP_MESSAGE_DELETED) bob.wait_for_securejoin_joiner_success() # Test that Alice verified Bob's profile. diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 177ecf19d..d7015e1b2 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -110,12 +110,9 @@ def test_account(acfactory) -> None: alice_chat_bob = alice_contact_bob.create_chat() alice_chat_bob.send_text("Hello!") - while True: - event = bob.wait_for_event() - if event.kind == EventType.INCOMING_MSG: - chat_id = event.chat_id - msg_id = event.msg_id - break + event = bob.wait_for_incoming_msg_event() + chat_id = event.chat_id + msg_id = event.msg_id message = bob.get_message_by_id(msg_id) snapshot = message.get_snapshot() @@ -330,18 +327,11 @@ def test_reaction_seen_on_another_dev(acfactory) -> None: snapshot.chat.accept() message.send_reaction("😎") for a in [alice, alice2]: - while True: - event = a.wait_for_event() - if event.kind == EventType.INCOMING_REACTION: - break + a.wait_for_event(EventType.INCOMING_REACTION) alice2.clear_all_events() alice_chat_bob.mark_noticed() - while True: - event = alice2.wait_for_event() - if event.kind == EventType.MSGS_NOTICED: - chat_id = event.chat_id - break + chat_id = alice2.wait_for_event(EventType.MSGS_NOTICED).chat_id alice2_contact_bob = alice2.get_contact_by_addr(bob_addr) alice2_chat_bob = alice2_contact_bob.create_chat() assert chat_id == alice2_chat_bob.id @@ -359,16 +349,12 @@ def test_is_bot(acfactory) -> None: alice.set_config("bot", "1") alice_chat_bob.send_text("Hello!") - while True: - event = bob.wait_for_event() - if event.kind == EventType.INCOMING_MSG: - msg_id = event.msg_id - message = bob.get_message_by_id(msg_id) - snapshot = message.get_snapshot() - assert snapshot.chat_id == event.chat_id - assert snapshot.text == "Hello!" - assert snapshot.is_bot - break + event = bob.wait_for_incoming_msg_event() + message = bob.get_message_by_id(event.msg_id) + snapshot = message.get_snapshot() + assert snapshot.chat_id == event.chat_id + assert snapshot.text == "Hello!" + assert snapshot.is_bot def test_bot(acfactory) -> None: @@ -529,10 +515,7 @@ def test_mdn_doesnt_break_autocrypt(acfactory) -> None: # Alice reads Bob's message. message.mark_seen() - while True: - event = bob.wait_for_event() - if event.kind == EventType.MSG_READ: - break + bob.wait_for_event(EventType.MSG_READ) # Bob sends a message to Alice, it should also be encrypted. 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 message.mark_seen() - while True: - event = bob2.wait_for_event() - if event.kind == EventType.MSGS_NOTICED: - break + bob2.wait_for_event(EventType.MSGS_NOTICED) 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 len(list(ac1.get_fresh_messages())) == 1 - while True: - event = ac1.wait_for_event() - if event.kind == EventType.IMAP_INBOX_IDLE: - break + ac1.wait_for_event(EventType.IMAP_INBOX_IDLE) 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") diff --git a/deltachat-rpc-client/tests/test_webxdc.py b/deltachat-rpc-client/tests/test_webxdc.py index e40d16971..17bb6574d 100644 --- a/deltachat-rpc-client/tests/test_webxdc.py +++ b/deltachat-rpc-client/tests/test_webxdc.py @@ -1,6 +1,3 @@ -from deltachat_rpc_client import EventType - - def test_webxdc(acfactory) -> None: 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.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc") - while True: - event = bob.wait_for_event() - if event.kind == EventType.INCOMING_MSG: - bob_chat_alice = bob.get_chat_by_id(event.chat_id) - message = bob.get_message_by_id(event.msg_id) - break + event = bob.wait_for_incoming_msg_event() + bob_chat_alice = bob.get_chat_by_id(event.chat_id) + message = bob.get_message_by_id(event.msg_id) webxdc_info = message.get_webxdc_info() assert webxdc_info == {