Skip to content

Commit

Permalink
api(deltachat-rpc-client): make it possible to clone accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Mar 10, 2025
1 parent 35d4eb5 commit 82573dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
12 changes: 12 additions & 0 deletions deltachat-rpc-client/src/deltachat_rpc_client/account.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations

from dataclasses import dataclass
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Optional, Union
from warnings import warn

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

def clone(self) -> "Account":
"""Clone given account."""
with TemporaryDirectory() as tmp_dir:
tmp_path = Path(tmp_dir)
self.export_backup(tmp_path)
files = list(tmp_path.glob("*.tar"))
new_account = self.manager.add_account()
new_account.import_backup(files[0])
return new_account

def start_io(self) -> None:
"""Start the account I/O."""
self._rpc.start_io(self.id)
Expand Down
6 changes: 1 addition & 5 deletions deltachat-rpc-client/tests/test_chatlist_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ def get_multi_account_test_setup(acfactory: ACFactory) -> [Account, Account, Acc

bob.wait_for_incoming_msg_event()

alice_second_device: Account = acfactory.get_unconfigured_account()

alice._rpc.provide_backup.future(alice.id)
backup_code = alice._rpc.get_backup_qr(alice.id)
alice_second_device._rpc.get_backup(alice_second_device.id, backup_code)
alice_second_device = alice.clone()
alice_second_device.start_io()
alice.clear_all_events()
alice_second_device.clear_all_events()
Expand Down
7 changes: 2 additions & 5 deletions deltachat-rpc-client/tests/test_securejoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,12 @@ def test_qr_setup_contact_svg(acfactory) -> None:


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

# Setup second device for Alice
# to test observing securejoin protocol.
alice.export_backup(tmp_path)
files = list(tmp_path.glob("*.tar"))
alice2 = acfactory.get_unconfigured_account()
alice2.import_backup(files[0])
alice2 = alice.clone()

logging.info("Alice creates a group")
alice_chat = alice.create_group("Group", protect=protect)
Expand Down
14 changes: 4 additions & 10 deletions deltachat-rpc-client/tests/test_something.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,12 +287,9 @@ def test_message(acfactory) -> None:
assert reactions == snapshot.reactions


def test_reaction_seen_on_another_dev(acfactory, tmp_path) -> None:
def test_reaction_seen_on_another_dev(acfactory) -> None:
alice, bob = acfactory.get_online_accounts(2)
alice.export_backup(tmp_path)
files = list(tmp_path.glob("*.tar"))
alice2 = acfactory.get_unconfigured_account()
alice2.import_backup(files[0])
alice2 = alice.clone()
alice2.start_io()

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


def test_markseen_contact_request(acfactory, tmp_path):
def test_markseen_contact_request(acfactory):
"""
Test that seen status is synchronized for contact request messages
even though read receipt is not sent.
"""
alice, bob = acfactory.get_online_accounts(2)

# Bob sets up a second device.
bob.export_backup(tmp_path)
files = list(tmp_path.glob("*.tar"))
bob2 = acfactory.get_unconfigured_account()
bob2.import_backup(files[0])
bob2 = bob.clone()
bob2.start_io()

alice_chat_bob = alice.create_chat(bob)
Expand Down

0 comments on commit 82573dc

Please sign in to comment.