Skip to content

Commit 82573dc

Browse files
committed
api(deltachat-rpc-client): make it possible to clone accounts
1 parent 35d4eb5 commit 82573dc

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

deltachat-rpc-client/src/deltachat_rpc_client/account.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4+
from pathlib import Path
5+
from tempfile import TemporaryDirectory
46
from typing import TYPE_CHECKING, Optional, Union
57
from warnings import warn
68

@@ -38,6 +40,16 @@ def remove(self) -> None:
3840
"""Remove the account."""
3941
self._rpc.remove_account(self.id)
4042

43+
def clone(self) -> "Account":
44+
"""Clone given account."""
45+
with TemporaryDirectory() as tmp_dir:
46+
tmp_path = Path(tmp_dir)
47+
self.export_backup(tmp_path)
48+
files = list(tmp_path.glob("*.tar"))
49+
new_account = self.manager.add_account()
50+
new_account.import_backup(files[0])
51+
return new_account
52+
4153
def start_io(self) -> None:
4254
"""Start the account I/O."""
4355
self._rpc.start_io(self.id)

deltachat-rpc-client/tests/test_chatlist_events.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,7 @@ def get_multi_account_test_setup(acfactory: ACFactory) -> [Account, Account, Acc
157157

158158
bob.wait_for_incoming_msg_event()
159159

160-
alice_second_device: Account = acfactory.get_unconfigured_account()
161-
162-
alice._rpc.provide_backup.future(alice.id)
163-
backup_code = alice._rpc.get_backup_qr(alice.id)
164-
alice_second_device._rpc.get_backup(alice_second_device.id, backup_code)
160+
alice_second_device = alice.clone()
165161
alice_second_device.start_io()
166162
alice.clear_all_events()
167163
alice_second_device.clear_all_events()

deltachat-rpc-client/tests/test_securejoin.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,12 @@ def test_qr_setup_contact_svg(acfactory) -> None:
6060

6161

6262
@pytest.mark.parametrize("protect", [True, False])
63-
def test_qr_securejoin(acfactory, protect, tmp_path):
63+
def test_qr_securejoin(acfactory, protect):
6464
alice, bob, fiona = acfactory.get_online_accounts(3)
6565

6666
# Setup second device for Alice
6767
# to test observing securejoin protocol.
68-
alice.export_backup(tmp_path)
69-
files = list(tmp_path.glob("*.tar"))
70-
alice2 = acfactory.get_unconfigured_account()
71-
alice2.import_backup(files[0])
68+
alice2 = alice.clone()
7269

7370
logging.info("Alice creates a group")
7471
alice_chat = alice.create_group("Group", protect=protect)

deltachat-rpc-client/tests/test_something.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,9 @@ def test_message(acfactory) -> None:
287287
assert reactions == snapshot.reactions
288288

289289

290-
def test_reaction_seen_on_another_dev(acfactory, tmp_path) -> None:
290+
def test_reaction_seen_on_another_dev(acfactory) -> None:
291291
alice, bob = acfactory.get_online_accounts(2)
292-
alice.export_backup(tmp_path)
293-
files = list(tmp_path.glob("*.tar"))
294-
alice2 = acfactory.get_unconfigured_account()
295-
alice2.import_backup(files[0])
292+
alice2 = alice.clone()
296293
alice2.start_io()
297294

298295
bob_addr = bob.get_config("addr")
@@ -661,18 +658,15 @@ def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts):
661658
assert snapshot.chat == bob_chat_alice
662659

663660

664-
def test_markseen_contact_request(acfactory, tmp_path):
661+
def test_markseen_contact_request(acfactory):
665662
"""
666663
Test that seen status is synchronized for contact request messages
667664
even though read receipt is not sent.
668665
"""
669666
alice, bob = acfactory.get_online_accounts(2)
670667

671668
# Bob sets up a second device.
672-
bob.export_backup(tmp_path)
673-
files = list(tmp_path.glob("*.tar"))
674-
bob2 = acfactory.get_unconfigured_account()
675-
bob2.import_backup(files[0])
669+
bob2 = bob.clone()
676670
bob2.start_io()
677671

678672
alice_chat_bob = alice.create_chat(bob)

0 commit comments

Comments
 (0)