Skip to content

Commit 6a293ae

Browse files
committed
test: Port test_import_export_online_all to JSON-RPC (#7411)
1 parent fd90493 commit 6a293ae

File tree

2 files changed

+97
-81
lines changed

2 files changed

+97
-81
lines changed

deltachat-rpc-client/tests/test_something.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,103 @@ def test_import_export_backup(acfactory, tmp_path) -> None:
507507
assert alice2.manager.get_system_info()
508508

509509

510+
def test_import_export_online_all(acfactory, tmp_path, data, log) -> None:
511+
(ac1, some1) = acfactory.get_online_accounts(2)
512+
513+
log.section("create some chat content")
514+
some1_addr = some1.get_config("addr")
515+
chat1 = ac1.create_contact(some1).create_chat()
516+
chat1.send_text("msg1")
517+
assert len(ac1.get_contacts()) == 1
518+
519+
original_image_path = data.get_path("image/avatar64x64.png")
520+
chat1.send_file(str(original_image_path))
521+
522+
# Add another 100KB file that ensures that the progress is smooth enough
523+
path = tmp_path / "attachment.txt"
524+
with path.open("w") as file:
525+
file.truncate(100000)
526+
chat1.send_file(str(path))
527+
528+
def assert_account_is_proper(ac):
529+
contacts = ac.get_contacts()
530+
assert len(contacts) == 1
531+
contact2 = contacts[0]
532+
assert contact2.get_snapshot().address == some1_addr
533+
chat2 = contact2.create_chat()
534+
messages = chat2.get_messages()
535+
assert len(messages) == 3 + E2EE_INFO_MSGS
536+
assert messages[0 + E2EE_INFO_MSGS].get_snapshot().text == "msg1"
537+
snapshot = messages[1 + E2EE_INFO_MSGS].get_snapshot()
538+
assert snapshot.file_mime == "image/png"
539+
assert os.stat(snapshot.file).st_size == os.stat(original_image_path).st_size
540+
ac.set_config("displayname", "new displayname")
541+
assert ac.get_config("displayname") == "new displayname"
542+
543+
assert_account_is_proper(ac1)
544+
545+
backupdir = tmp_path / "backup"
546+
backupdir.mkdir()
547+
548+
log.section(f"export all to {backupdir}")
549+
ac1.stop_io()
550+
ac1.export_backup(backupdir)
551+
progress = 0
552+
files_written = []
553+
while True:
554+
event = ac1.wait_for_event()
555+
if event.kind == EventType.IMEX_PROGRESS:
556+
assert event.progress > 0 # Progress 0 indicates error.
557+
assert event.progress < progress + 250
558+
progress = event.progress
559+
if progress == 1000:
560+
break
561+
elif event.kind == EventType.IMEX_FILE_WRITTEN:
562+
files_written.append(event.path)
563+
else:
564+
logging.info(event)
565+
assert len(files_written) == 1
566+
assert os.path.exists(files_written[0])
567+
ac1.start_io()
568+
569+
log.section("get fresh empty account")
570+
ac2 = acfactory.get_unconfigured_account()
571+
572+
log.section("import backup and check it's proper")
573+
ac2.import_backup(files_written[0])
574+
progress = 0
575+
while True:
576+
event = ac2.wait_for_event()
577+
if event.kind == EventType.IMEX_PROGRESS:
578+
assert event.progress > 0 # Progress 0 indicates error.
579+
assert event.progress < progress + 250
580+
progress = event.progress
581+
if progress == 1000:
582+
break
583+
else:
584+
logging.info(event)
585+
assert_account_is_proper(ac1)
586+
assert_account_is_proper(ac2)
587+
588+
log.section(f"Second-time export all to {backupdir}")
589+
ac1.stop_io()
590+
ac1.export_backup(backupdir)
591+
while True:
592+
event = ac1.wait_for_event()
593+
if event.kind == EventType.IMEX_PROGRESS:
594+
assert event.progress > 0
595+
if event.progress == 1000:
596+
break
597+
elif event.kind == EventType.IMEX_FILE_WRITTEN:
598+
files_written.append(event.path)
599+
else:
600+
logging.info(event)
601+
assert len(files_written) == 2
602+
assert os.path.exists(files_written[1])
603+
assert files_written[1] != files_written[0]
604+
assert len(list(backupdir.glob("*.tar"))) == 2
605+
606+
510607
def test_import_export_keys(acfactory, tmp_path) -> None:
511608
alice, bob = acfactory.get_online_accounts(2)
512609

python/tests/test_1_online.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import deltachat as dc
1111
from deltachat import account_hookimpl, Message
12-
from deltachat.tracker import ImexTracker
1312
from deltachat.testplugin import E2EE_INFO_MSGS
1413

1514

@@ -826,86 +825,6 @@ def ac_outgoing_message(self, message):
826825
assert m == msg_in
827826

828827

829-
def test_import_export_online_all(acfactory, tmp_path, data, lp):
830-
(ac1, some1) = acfactory.get_online_accounts(2)
831-
832-
lp.sec("create some chat content")
833-
some1_addr = some1.get_config("addr")
834-
chat1 = ac1.create_contact(some1).create_chat()
835-
chat1.send_text("msg1")
836-
assert len(ac1.get_contacts()) == 1
837-
838-
original_image_path = data.get_path("d.png")
839-
chat1.send_image(original_image_path)
840-
841-
# Add another 100KB file that ensures that the progress is smooth enough
842-
path = tmp_path / "attachment.txt"
843-
with path.open("w") as file:
844-
file.truncate(100000)
845-
chat1.send_file(str(path))
846-
847-
def assert_account_is_proper(ac):
848-
contacts = ac.get_contacts()
849-
assert len(contacts) == 1
850-
contact2 = contacts[0]
851-
assert contact2.addr == some1_addr
852-
chat2 = contact2.create_chat()
853-
messages = chat2.get_messages()
854-
assert len(messages) == 3 + E2EE_INFO_MSGS
855-
assert messages[0 + E2EE_INFO_MSGS].text == "msg1"
856-
assert messages[1 + E2EE_INFO_MSGS].filemime == "image/png"
857-
assert os.stat(messages[1 + E2EE_INFO_MSGS].filename).st_size == os.stat(original_image_path).st_size
858-
ac.set_config("displayname", "new displayname")
859-
assert ac.get_config("displayname") == "new displayname"
860-
861-
assert_account_is_proper(ac1)
862-
863-
backupdir = tmp_path / "backup"
864-
backupdir.mkdir()
865-
866-
lp.sec(f"export all to {backupdir}")
867-
with ac1.temp_plugin(ImexTracker()) as imex_tracker:
868-
ac1.stop_io()
869-
ac1.imex(str(backupdir), dc.const.DC_IMEX_EXPORT_BACKUP)
870-
871-
# check progress events for export
872-
assert imex_tracker.wait_progress(1, progress_upper_limit=249)
873-
assert imex_tracker.wait_progress(250, progress_upper_limit=499)
874-
assert imex_tracker.wait_progress(500, progress_upper_limit=749)
875-
assert imex_tracker.wait_progress(750, progress_upper_limit=999)
876-
877-
paths = imex_tracker.wait_finish()
878-
assert len(paths) == 1
879-
path = paths[0]
880-
assert os.path.exists(path)
881-
ac1.start_io()
882-
883-
lp.sec("get fresh empty account")
884-
ac2 = acfactory.get_unconfigured_account()
885-
886-
lp.sec("get latest backup file")
887-
path2 = ac2.get_latest_backupfile(str(backupdir))
888-
assert path2 == path
889-
890-
lp.sec("import backup and check it's proper")
891-
with ac2.temp_plugin(ImexTracker()) as imex_tracker:
892-
ac2.import_all(path)
893-
894-
# check progress events for import
895-
assert imex_tracker.wait_progress(1, progress_upper_limit=249)
896-
assert imex_tracker.wait_progress(1000)
897-
898-
assert_account_is_proper(ac1)
899-
assert_account_is_proper(ac2)
900-
901-
lp.sec(f"Second-time export all to {backupdir}")
902-
ac1.stop_io()
903-
path2 = ac1.export_all(str(backupdir))
904-
assert os.path.exists(path2)
905-
assert path2 != path
906-
assert ac2.get_latest_backupfile(str(backupdir)) == path2
907-
908-
909828
def test_qr_email_capitalization(acfactory, lp):
910829
"""Regression test for a bug
911830
that resulted in failure to propagate verification

0 commit comments

Comments
 (0)