Skip to content

Commit 6916ff2

Browse files
committed
test: port test_move_avoids_loop from CFFI to JSON-RPC
1 parent 4cb1ce2 commit 6916ff2

File tree

2 files changed

+62
-51
lines changed

2 files changed

+62
-51
lines changed

deltachat-rpc-client/tests/test_folders.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,68 @@ def test_move_works(acfactory):
2424
assert msg.text == "message1"
2525

2626

27+
def test_move_avoids_loop(acfactory, direct_imap):
28+
"""Test that the message is only moved from INBOX to DeltaChat.
29+
30+
This is to avoid busy loop if moved message reappears in the Inbox
31+
or some scanned folder later.
32+
For example, this happens on servers that alias `INBOX.DeltaChat` to `DeltaChat` folder,
33+
so the message moved to `DeltaChat` appears as a new message in the `INBOX.DeltaChat` folder.
34+
We do not want to move this message from `INBOX.DeltaChat` to `DeltaChat` again.
35+
"""
36+
ac1, ac2 = acfactory.get_online_accounts(2)
37+
ac2.set_config("mvbox_move", "1")
38+
ac2.set_config("delete_server_after", "0")
39+
ac2.bring_online()
40+
41+
# Create INBOX.DeltaChat folder and make sure
42+
# it is detected by full folder scan.
43+
ac2_direct_imap = direct_imap(ac2)
44+
ac2_direct_imap.create_folder("INBOX.DeltaChat")
45+
ac2.stop_io()
46+
ac2.start_io()
47+
48+
while True:
49+
event = ac2.wait_for_event()
50+
# Wait until the end of folder scan.
51+
if event.kind == EventType.INFO and "Found folders:" in event.msg:
52+
break
53+
54+
ac1_chat = acfactory.get_accepted_chat(ac1, ac2)
55+
ac1_chat.send_text("Message 1")
56+
57+
# Message is moved to the DeltaChat folder and downloaded.
58+
ac2_msg1 = ac2.wait_for_incoming_msg().get_snapshot()
59+
assert ac2_msg1.text == "Message 1"
60+
61+
# Move the message to the INBOX.DeltaChat again.
62+
# We assume that test server uses "." as the delimiter.
63+
ac2_direct_imap.select_folder("DeltaChat")
64+
ac2_direct_imap.conn.move(["*"], "INBOX.DeltaChat")
65+
66+
ac1_chat.send_text("Message 2")
67+
ac2_msg2 = ac2.wait_for_incoming_msg().get_snapshot()
68+
assert ac2_msg2.text == "Message 2"
69+
70+
# Stop and start I/O to trigger folder scan.
71+
ac2.stop_io()
72+
ac2.start_io()
73+
while True:
74+
event = ac2.wait_for_event()
75+
# Wait until the end of folder scan.
76+
if event.kind == EventType.INFO and "Found folders:" in event.msg:
77+
break
78+
79+
# Check that Message 1 is still in the INBOX.DeltaChat folder
80+
# and Message 2 is in the DeltaChat folder.
81+
ac2_direct_imap.select_folder("INBOX")
82+
assert len(ac2_direct_imap.get_all_messages()) == 0
83+
ac2_direct_imap.select_folder("DeltaChat")
84+
assert len(ac2_direct_imap.get_all_messages()) == 1
85+
ac2_direct_imap.select_folder("INBOX.DeltaChat")
86+
assert len(ac2_direct_imap.get_all_messages()) == 1
87+
88+
2789
def test_reactions_for_a_reordering_move(acfactory, direct_imap):
2890
"""When a batch of messages is moved from Inbox to DeltaChat folder with a single MOVE command,
2991
their UIDs may be reordered (e.g. Gmail is known for that) which led to that messages were

python/tests/test_1_online.py

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -269,57 +269,6 @@ def test_enable_mvbox_move(acfactory, lp):
269269
assert ac2._evtracker.wait_next_incoming_message().text == "message1"
270270

271271

272-
def test_move_avoids_loop(acfactory):
273-
"""Test that the message is only moved from INBOX to DeltaChat.
274-
275-
This is to avoid busy loop if moved message reappears in the Inbox
276-
or some scanned folder later.
277-
For example, this happens on servers that alias `INBOX.DeltaChat` to `DeltaChat` folder,
278-
so the message moved to `DeltaChat` appears as a new message in the `INBOX.DeltaChat` folder.
279-
We do not want to move this message from `INBOX.DeltaChat` to `DeltaChat` again.
280-
"""
281-
ac1 = acfactory.new_online_configuring_account()
282-
ac2 = acfactory.new_online_configuring_account(mvbox_move=True)
283-
acfactory.bring_accounts_online()
284-
285-
# Create INBOX.DeltaChat folder and make sure
286-
# it is detected by full folder scan.
287-
ac2.direct_imap.create_folder("INBOX.DeltaChat")
288-
ac2.stop_io()
289-
ac2.start_io()
290-
ac2._evtracker.get_info_contains("Found folders:") # Wait until the end of folder scan.
291-
292-
ac1_chat = acfactory.get_accepted_chat(ac1, ac2)
293-
ac1_chat.send_text("Message 1")
294-
295-
# Message is moved to the DeltaChat folder and downloaded.
296-
ac2_msg1 = ac2._evtracker.wait_next_incoming_message()
297-
assert ac2_msg1.text == "Message 1"
298-
299-
# Move the message to the INBOX.DeltaChat again.
300-
# We assume that test server uses "." as the delimiter.
301-
ac2.direct_imap.select_folder("DeltaChat")
302-
ac2.direct_imap.conn.move(["*"], "INBOX.DeltaChat")
303-
304-
ac1_chat.send_text("Message 2")
305-
ac2_msg2 = ac2._evtracker.wait_next_incoming_message()
306-
assert ac2_msg2.text == "Message 2"
307-
308-
# Stop and start I/O to trigger folder scan.
309-
ac2.stop_io()
310-
ac2.start_io()
311-
ac2._evtracker.get_info_contains("Found folders:") # Wait until the end of folder scan.
312-
313-
# Check that Message 1 is still in the INBOX.DeltaChat folder
314-
# and Message 2 is in the DeltaChat folder.
315-
ac2.direct_imap.select_folder("INBOX")
316-
assert len(ac2.direct_imap.get_all_messages()) == 0
317-
ac2.direct_imap.select_folder("DeltaChat")
318-
assert len(ac2.direct_imap.get_all_messages()) == 1
319-
ac2.direct_imap.select_folder("INBOX.DeltaChat")
320-
assert len(ac2.direct_imap.get_all_messages()) == 1
321-
322-
323272
def test_move_sync_msgs(acfactory):
324273
ac1 = acfactory.new_online_configuring_account(bcc_self=True, sync_msgs=True, fix_is_chatmail=True)
325274
acfactory.bring_accounts_online()

0 commit comments

Comments
 (0)