From af5ebd3d5e6c25be95de847385d7509d74dda5d7 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Fri, 3 Nov 2023 10:35:37 -0700 Subject: [PATCH] unit test fixes Signed-off-by: Andrew Whitehead --- aries_cloudagent/admin/tests/test_admin_server.py | 3 +++ aries_cloudagent/core/in_memory/profile.py | 9 ++++++--- .../v1_0/handlers/tests/test_request_handler.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index c93d53b0f6..7eae850288 100644 --- a/aries_cloudagent/admin/tests/test_admin_server.py +++ b/aries_cloudagent/admin/tests/test_admin_server.py @@ -1,3 +1,4 @@ +import gc import json import pytest @@ -501,6 +502,8 @@ def _smaller_scope(): return test_module.AdminResponder(profile, None) responder = _smaller_scope() + gc.collect() # help ensure collection of profile + with pytest.raises(RuntimeError): await responder.send_outbound(None) diff --git a/aries_cloudagent/core/in_memory/profile.py b/aries_cloudagent/core/in_memory/profile.py index ece8c5d00f..8ae09dd0f1 100644 --- a/aries_cloudagent/core/in_memory/profile.py +++ b/aries_cloudagent/core/in_memory/profile.py @@ -6,7 +6,7 @@ from ...config.injection_context import InjectionContext from ...config.provider import ClassProvider -from ...storage.base import BaseStorage +from ...storage.base import BaseStorage, BaseStorageSearch from ...storage.vc_holder.base import VCHolder from ...utils.classloader import DeferLoad from ...wallet.base import BaseWallet @@ -28,7 +28,6 @@ class InMemoryProfile(Profile): def __init__(self, *, context: InjectionContext = None, name: str = None): """Create a new InMemoryProfile instance.""" - global STORAGE_CLASS, WALLET_CLASS super().__init__(context=context, name=name, created=True) self.keys = {} self.local_dids = {} @@ -40,6 +39,8 @@ def bind_providers(self): """Initialize the profile-level instance providers.""" injector = self._context.injector + injector.bind_instance(BaseStorageSearch, STORAGE_CLASS(self)) + injector.bind_provider( VCHolder, ClassProvider( @@ -114,7 +115,9 @@ async def _setup(self): def _init_context(self): """Initialize the session context.""" - self._context.injector.bind_instance(BaseStorage, STORAGE_CLASS(self.profile)) + self._context.injector.bind_instance( + BaseStorage, self.profile.inject(BaseStorageSearch) + ) self._context.injector.bind_instance(BaseWallet, WALLET_CLASS(self.profile)) @property diff --git a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py index 1820a71820..1937deb549 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py @@ -145,7 +145,7 @@ async def test_connection_record_without_mediation_metadata( with mock.patch.object( storage, "find_record", - mock.CoroutineMock(raises=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_storage_find_record: handler_inst = handler.ConnectionRequestHandler() responder = MockResponder()