diff --git a/aries_cloudagent/multitenant/askar_profile_manager.py b/aries_cloudagent/multitenant/askar_profile_manager.py index 96fe137780..c692b04ea8 100644 --- a/aries_cloudagent/multitenant/askar_profile_manager.py +++ b/aries_cloudagent/multitenant/askar_profile_manager.py @@ -83,3 +83,12 @@ async def get_wallet_profile( ).extend(extra_settings) return AskarProfile(multitenant_wallet.opened, profile_context) + + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + await profile.remove() diff --git a/aries_cloudagent/multitenant/base.py b/aries_cloudagent/multitenant/base.py index 51b217953d..5bdd9a9787 100644 --- a/aries_cloudagent/multitenant/base.py +++ b/aries_cloudagent/multitenant/base.py @@ -270,8 +270,7 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None): {"wallet.key": wallet_key}, ) - del self._instances[wallet_id] - await profile.remove() + await self.remove_wallet_profile(profile) # Remove all routing records associated with wallet async with self._profile.session() as session: @@ -282,6 +281,15 @@ async def remove_wallet(self, wallet_id: str, wallet_key: str = None): await wallet.delete_record(session) + @abstractmethod + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + async def add_key( self, wallet_id: str, recipient_key: str, *, skip_if_exists: bool = False ): diff --git a/aries_cloudagent/multitenant/manager.py b/aries_cloudagent/multitenant/manager.py index f52eda7713..5bbbcc6632 100644 --- a/aries_cloudagent/multitenant/manager.py +++ b/aries_cloudagent/multitenant/manager.py @@ -71,3 +71,14 @@ async def get_wallet_profile( self._instances[wallet_id] = profile return self._instances[wallet_id] + + async def remove_wallet_profile(self, profile: Profile): + """Remove the wallet profile instance. + + Args: + profile: The wallet profile instance + + """ + wallet_id = profile.settings.get("wallet.id") + del self._instances[wallet_id] + await profile.remove() diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 5483ac2c7d..6bad949cb4 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -170,3 +170,10 @@ def side_effect(context, provision): wallet_config.call_args[0][0].settings.get("wallet.name") == multitenant_sub_wallet_name ) + + async def test_remove_wallet_profile(self): + test_profile = InMemoryProfile.test_profile() + + with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + await self.manager.remove_wallet_profile(test_profile) + profile_remove.assert_called_once_with() diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index d984c0e4d5..4f6cb8dabf 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -307,8 +307,8 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self): ) as retrieve_by_id, async_mock.patch.object( BaseMultitenantManager, "get_wallet_profile" ) as get_wallet_profile, async_mock.patch.object( - InMemoryProfile, "remove" - ) as remove_profile, async_mock.patch.object( + BaseMultitenantManager, "remove_wallet_profile" + ) as remove_wallet_profile, async_mock.patch.object( WalletRecord, "delete_record" ) as wallet_delete_record, async_mock.patch.object( InMemoryStorage, "delete_all_records" @@ -320,17 +320,15 @@ async def test_remove_wallet_removes_profile_wallet_storage_records(self): ) wallet_profile = InMemoryProfile.test_profile() - self.manager._instances["test"] = wallet_profile retrieve_by_id.return_value = wallet_record get_wallet_profile.return_value = wallet_profile await self.manager.remove_wallet("test") - assert "test" not in self.manager._instances get_wallet_profile.assert_called_once_with( self.profile.context, wallet_record, {"wallet.key": "test_key"} ) - remove_profile.assert_called_once_with() + remove_wallet_profile.assert_called_once_with(wallet_profile) assert wallet_delete_record.call_count == 1 delete_all_records.assert_called_once_with( RouteRecord.RECORD_TYPE, {"wallet_id": "test"} diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index 60ef8c624d..7e01959f95 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -173,3 +173,14 @@ def side_effect(context, provision): assert profile.settings.get("mediation.invite") == "http://invite.com" assert profile.settings.get("mediation.default_id") == "24a96ef5" assert profile.settings.get("mediation.clear") == True + + async def test_remove_wallet_profile(self): + test_profile = InMemoryProfile.test_profile( + settings={"wallet.id": "test"}, + ) + self.manager._instances["test"] = test_profile + + with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + await self.manager.remove_wallet_profile(test_profile) + assert "test" not in self.manager._instances + profile_remove.assert_called_once_with()