Skip to content

Commit 196461e

Browse files
committed
test: port test_dont_show_emails() from CFFI to JSON-RPC Python
1 parent 1cb0a25 commit 196461e

File tree

2 files changed

+136
-134
lines changed

2 files changed

+136
-134
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,3 +1012,139 @@ def check_account(ac, contact, inviter_side, please_wait_info_msg=False):
10121012
bob2.wait_for_event(EventType.CHAT_MODIFIED)
10131013

10141014
check_account(bob2, bob2.create_contact(alice), inviter_side=False)
1015+
1016+
1017+
def test_dont_show_emails(acfactory, lp):
1018+
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
1019+
So: If it's outgoing AND there is no Received header, then ignore the email.
1020+
1021+
If the draft email is sent out and received later (i.e. it's in "Inbox"), it must be shown.
1022+
1023+
Also, test that unknown emails in the Spam folder are not shown."""
1024+
ac1 = acfactory.new_online_configuring_account()
1025+
ac1.set_config("show_emails", "2")
1026+
ac1.create_contact("[email protected]").create_chat()
1027+
1028+
acfactory.wait_configured(ac1)
1029+
ac1.direct_imap.create_folder("Drafts")
1030+
ac1.direct_imap.create_folder("Spam")
1031+
ac1.direct_imap.create_folder("Junk")
1032+
1033+
acfactory.bring_accounts_online()
1034+
ac1.stop_io()
1035+
1036+
ac1.direct_imap.append(
1037+
"Drafts",
1038+
"""
1039+
From: ac1 <{}>
1040+
Subject: subj
1041+
1042+
Message-ID: <[email protected]>
1043+
Content-Type: text/plain; charset=utf-8
1044+
1045+
message in Drafts received later
1046+
""".format(
1047+
ac1.get_config("configured_addr"),
1048+
),
1049+
)
1050+
ac1.direct_imap.append(
1051+
"Spam",
1052+
"""
1053+
1054+
Subject: subj
1055+
To: {}
1056+
Message-ID: <[email protected]>
1057+
Content-Type: text/plain; charset=utf-8
1058+
1059+
Unknown message in Spam
1060+
""".format(
1061+
ac1.get_config("configured_addr"),
1062+
),
1063+
)
1064+
ac1.direct_imap.append(
1065+
"Spam",
1066+
"""
1067+
1068+
Subject: subj
1069+
To: {}
1070+
Message-ID: <[email protected]>
1071+
Content-Type: text/plain; charset=utf-8
1072+
1073+
Unknown & malformed message in Spam
1074+
""".format(
1075+
ac1.get_config("configured_addr"),
1076+
),
1077+
)
1078+
ac1.direct_imap.append(
1079+
"Spam",
1080+
"""
1081+
From: delta<address: [email protected]>
1082+
Subject: subj
1083+
To: {}
1084+
Message-ID: <[email protected]>
1085+
Content-Type: text/plain; charset=utf-8
1086+
1087+
Unknown & malformed message in Spam
1088+
""".format(
1089+
ac1.get_config("configured_addr"),
1090+
),
1091+
)
1092+
ac1.direct_imap.append(
1093+
"Spam",
1094+
"""
1095+
1096+
Subject: subj
1097+
To: {}
1098+
Message-ID: <[email protected]>
1099+
Content-Type: text/plain; charset=utf-8
1100+
1101+
Actually interesting message in Spam
1102+
""".format(
1103+
ac1.get_config("configured_addr"),
1104+
),
1105+
)
1106+
ac1.direct_imap.append(
1107+
"Junk",
1108+
"""
1109+
1110+
Subject: subj
1111+
To: {}
1112+
Message-ID: <[email protected]>
1113+
Content-Type: text/plain; charset=utf-8
1114+
1115+
Unknown message in Junk
1116+
""".format(
1117+
ac1.get_config("configured_addr"),
1118+
),
1119+
)
1120+
1121+
ac1.set_config("scan_all_folders_debounce_secs", "0")
1122+
lp.sec("All prepared, now let DC find the message")
1123+
ac1.start_io()
1124+
1125+
# Wait until each folder was scanned, this is necessary for this test to test what it should test:
1126+
ac1._evtracker.wait_idle_inbox_ready()
1127+
1128+
fresh_msgs = list(ac1.get_fresh_messages())
1129+
msg = fresh_msgs[0]
1130+
chat_msgs = msg.chat.get_messages()
1131+
assert len(chat_msgs) == 1
1132+
assert any(msg.text == "subj – Actually interesting message in Spam" for msg in chat_msgs)
1133+
1134+
assert not any("unknown.address" in c.get_name() for c in ac1.get_chats())
1135+
ac1.direct_imap.select_folder("Spam")
1136+
assert ac1.direct_imap.get_uid_by_message_id("[email protected]")
1137+
1138+
ac1.stop_io()
1139+
lp.sec("'Send out' the draft by moving it to Inbox, and wait for DC to display it this time")
1140+
ac1.direct_imap.select_folder("Drafts")
1141+
uid = ac1.direct_imap.get_uid_by_message_id("[email protected]")
1142+
ac1.direct_imap.conn.move(uid, "Inbox")
1143+
1144+
ac1.start_io()
1145+
msg2 = ac1._evtracker.wait_next_messages_changed()
1146+
1147+
assert msg2.text == "subj – message in Drafts received later"
1148+
assert len(msg.chat.get_messages()) == 2
1149+
1150+

python/tests/test_1_online.py

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -853,140 +853,6 @@ def test_no_draft_if_cant_send(acfactory):
853853
assert device_chat.get_draft() is None
854854

855855

856-
def test_dont_show_emails(acfactory, lp):
857-
"""Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them.
858-
So: If it's outgoing AND there is no Received header, then ignore the email.
859-
860-
If the draft email is sent out and received later (i.e. it's in "Inbox"), it must be shown.
861-
862-
Also, test that unknown emails in the Spam folder are not shown."""
863-
ac1 = acfactory.new_online_configuring_account()
864-
ac1.set_config("show_emails", "2")
865-
ac1.create_contact("[email protected]").create_chat()
866-
867-
acfactory.wait_configured(ac1)
868-
ac1.direct_imap.create_folder("Drafts")
869-
ac1.direct_imap.create_folder("Spam")
870-
ac1.direct_imap.create_folder("Junk")
871-
872-
acfactory.bring_accounts_online()
873-
ac1.stop_io()
874-
875-
ac1.direct_imap.append(
876-
"Drafts",
877-
"""
878-
From: ac1 <{}>
879-
Subject: subj
880-
881-
Message-ID: <[email protected]>
882-
Content-Type: text/plain; charset=utf-8
883-
884-
message in Drafts received later
885-
""".format(
886-
ac1.get_config("configured_addr"),
887-
),
888-
)
889-
ac1.direct_imap.append(
890-
"Spam",
891-
"""
892-
893-
Subject: subj
894-
To: {}
895-
Message-ID: <[email protected]>
896-
Content-Type: text/plain; charset=utf-8
897-
898-
Unknown message in Spam
899-
""".format(
900-
ac1.get_config("configured_addr"),
901-
),
902-
)
903-
ac1.direct_imap.append(
904-
"Spam",
905-
"""
906-
907-
Subject: subj
908-
To: {}
909-
Message-ID: <[email protected]>
910-
Content-Type: text/plain; charset=utf-8
911-
912-
Unknown & malformed message in Spam
913-
""".format(
914-
ac1.get_config("configured_addr"),
915-
),
916-
)
917-
ac1.direct_imap.append(
918-
"Spam",
919-
"""
920-
From: delta<address: [email protected]>
921-
Subject: subj
922-
To: {}
923-
Message-ID: <[email protected]>
924-
Content-Type: text/plain; charset=utf-8
925-
926-
Unknown & malformed message in Spam
927-
""".format(
928-
ac1.get_config("configured_addr"),
929-
),
930-
)
931-
ac1.direct_imap.append(
932-
"Spam",
933-
"""
934-
935-
Subject: subj
936-
To: {}
937-
Message-ID: <[email protected]>
938-
Content-Type: text/plain; charset=utf-8
939-
940-
Actually interesting message in Spam
941-
""".format(
942-
ac1.get_config("configured_addr"),
943-
),
944-
)
945-
ac1.direct_imap.append(
946-
"Junk",
947-
"""
948-
949-
Subject: subj
950-
To: {}
951-
Message-ID: <[email protected]>
952-
Content-Type: text/plain; charset=utf-8
953-
954-
Unknown message in Junk
955-
""".format(
956-
ac1.get_config("configured_addr"),
957-
),
958-
)
959-
960-
ac1.set_config("scan_all_folders_debounce_secs", "0")
961-
lp.sec("All prepared, now let DC find the message")
962-
ac1.start_io()
963-
964-
# Wait until each folder was scanned, this is necessary for this test to test what it should test:
965-
ac1._evtracker.wait_idle_inbox_ready()
966-
967-
fresh_msgs = list(ac1.get_fresh_messages())
968-
msg = fresh_msgs[0]
969-
chat_msgs = msg.chat.get_messages()
970-
assert len(chat_msgs) == 1
971-
assert any(msg.text == "subj – Actually interesting message in Spam" for msg in chat_msgs)
972-
973-
assert not any("unknown.address" in c.get_name() for c in ac1.get_chats())
974-
ac1.direct_imap.select_folder("Spam")
975-
assert ac1.direct_imap.get_uid_by_message_id("[email protected]")
976-
977-
ac1.stop_io()
978-
lp.sec("'Send out' the draft by moving it to Inbox, and wait for DC to display it this time")
979-
ac1.direct_imap.select_folder("Drafts")
980-
uid = ac1.direct_imap.get_uid_by_message_id("[email protected]")
981-
ac1.direct_imap.conn.move(uid, "Inbox")
982-
983-
ac1.start_io()
984-
msg2 = ac1._evtracker.wait_next_messages_changed()
985-
986-
assert msg2.text == "subj – message in Drafts received later"
987-
assert len(msg.chat.get_messages()) == 2
988-
989-
990856
def test_bot(acfactory, lp):
991857
"""Test that bot messages can be identified as such"""
992858
ac1, ac2 = acfactory.get_online_accounts(2)

0 commit comments

Comments
 (0)