From 31cf663f8b33eef527f57fa30aadd5b779109de8 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 8 Apr 2025 21:30:15 +0000 Subject: [PATCH] api(deltachat-rpc-client): add Account.add_transport() --- .../src/deltachat_rpc_client/account.py | 5 +++++ .../src/deltachat_rpc_client/pytestplugin.py | 2 +- .../tests/test_account_events.py | 2 +- deltachat-rpc-client/tests/test_something.py | 16 ++++++---------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/account.py b/deltachat-rpc-client/src/deltachat_rpc_client/account.py index 2bd4127f8..c56198da2 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/account.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/account.py @@ -110,6 +110,11 @@ class Account: """Configure an account.""" yield self._rpc.configure.future(self.id) + @futuremethod + def add_transport(self, params): + """Add a new transport.""" + yield self._rpc.add_transport.future(self.id, params) + def bring_online(self): """Start I/O and wait until IMAP becomes IDLE.""" self.start_io() diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py index 1aa66b785..bafa464b3 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/pytestplugin.py @@ -34,7 +34,7 @@ class ACFactory: addr, password = self.get_credentials() account = self.get_unconfigured_account() params = {"addr": addr, "password": password} - yield account._rpc.add_transport.future(account.id, params) + yield account.add_transport.future(params) assert account.is_configured() return account diff --git a/deltachat-rpc-client/tests/test_account_events.py b/deltachat-rpc-client/tests/test_account_events.py index fb87fc6f2..b321cc76d 100644 --- a/deltachat-rpc-client/tests/test_account_events.py +++ b/deltachat-rpc-client/tests/test_account_events.py @@ -17,7 +17,7 @@ def test_event_on_configuration(acfactory: ACFactory) -> None: account = acfactory.get_unconfigured_account() account.clear_all_events() assert not account.is_configured() - future = account._rpc.add_transport.future(account.id, {"addr": addr, "password": password}) + future = account.add_transport.future({"addr": addr, "password": password}) while True: event = account.wait_for_event() if event.kind == EventType.ACCOUNTS_ITEM_CHANGED: diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 4ba5fc7be..5488291a8 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -63,8 +63,7 @@ def test_acfactory(acfactory) -> None: def test_configure_starttls(acfactory) -> None: addr, password = acfactory.get_credentials() account = acfactory.get_unconfigured_account() - account._rpc.add_transport( - account.id, + account.add_transport( { "addr": addr, "password": password, @@ -81,8 +80,7 @@ def test_configure_ip(acfactory) -> None: ip_address = socket.gethostbyname(addr.rsplit("@")[-1]) with pytest.raises(JsonRpcError): - account._rpc.add_transport( - account.id, + account.add_transport( { "addr": addr, "password": password, @@ -96,8 +94,7 @@ def test_configure_alternative_port(acfactory) -> None: """Test that configuration with alternative port 443 works.""" addr, password = acfactory.get_credentials() account = acfactory.get_unconfigured_account() - account._rpc.add_transport( - account.id, + account.add_transport( { "addr": addr, "password": password, @@ -111,8 +108,7 @@ def test_configure_alternative_port(acfactory) -> None: def test_list_transports(acfactory) -> None: addr, password = acfactory.get_credentials() account = acfactory.get_unconfigured_account() - account._rpc.add_transport( - account.id, + account.add_transport( { "addr": addr, "password": password, @@ -424,7 +420,7 @@ def test_wait_next_messages(acfactory) -> None: addr, password = acfactory.get_credentials() bot = acfactory.get_unconfigured_account() bot.set_config("bot", "1") - bot._rpc.add_transport(bot.id, {"addr": addr, "password": password}) + bot.add_transport({"addr": addr, "password": password}) assert bot.is_configured() # There are no old messages and the call returns immediately. @@ -607,7 +603,7 @@ def test_reactions_for_a_reordering_move(acfactory, direct_imap): addr, password = acfactory.get_credentials() ac2 = acfactory.get_unconfigured_account() - ac2._rpc.add_transport(ac2.id, {"addr": addr, "password": password}) + ac2.add_transport({"addr": addr, "password": password}) ac2.set_config("mvbox_move", "1") assert ac2.is_configured()