diff --git a/UnitTests.md b/UnitTests.md index bbaaa104fe..50dc1f6edd 100644 --- a/UnitTests.md +++ b/UnitTests.md @@ -130,7 +130,7 @@ class TestDidExchangeManager(AsyncTestCase, TestConfig): self.responder = MockResponder() self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + clean_finished_oob_record=async_mock.AsyncMock(return_value=None) ) self.route_manager = async_mock.MagicMock(RouteManager) diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index c3887ad61c..c93d53b0f6 100644 --- a/aries_cloudagent/admin/tests/test_admin_server.py +++ b/aries_cloudagent/admin/tests/test_admin_server.py @@ -1,7 +1,7 @@ import json import pytest -import mock as async_mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from aiohttp import ClientSession, DummyCookieJar, TCPConnector, web from aiohttp.test_utils import unused_port @@ -36,37 +36,33 @@ async def asyncTearDown(self): self.client_session = None async def test_debug_middleware(self): - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger: - mock_logger.isEnabledFor = async_mock.MagicMock(return_value=True) - mock_logger.debug = async_mock.MagicMock() + with mock.patch.object(test_module, "LOGGER", mock.MagicMock()) as mock_logger: + mock_logger.isEnabledFor = mock.MagicMock(return_value=True) + mock_logger.debug = mock.MagicMock() - request = async_mock.MagicMock( + request = mock.MagicMock( method="GET", path_qs="/hello/world?a=1&b=2", match_info={"match": "info"}, - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - handler = async_mock.AsyncMock() + handler = mock.CoroutineMock() await test_module.debug_middleware(request, handler) mock_logger.isEnabledFor.assert_called_once() assert mock_logger.debug.call_count == 3 async def test_ready_middleware(self): - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger: - mock_logger.isEnabledFor = async_mock.MagicMock(return_value=True) - mock_logger.debug = async_mock.MagicMock() - mock_logger.info = async_mock.MagicMock() - mock_logger.error = async_mock.MagicMock() - - request = async_mock.MagicMock( - rel_url="/", app=async_mock.MagicMock(_state={"ready": False}) + with mock.patch.object(test_module, "LOGGER", mock.MagicMock()) as mock_logger: + mock_logger.isEnabledFor = mock.MagicMock(return_value=True) + mock_logger.debug = mock.MagicMock() + mock_logger.info = mock.MagicMock() + mock_logger.error = mock.MagicMock() + + request = mock.MagicMock( + rel_url="/", app=mock.MagicMock(_state={"ready": False}) ) - handler = async_mock.AsyncMock(return_value="OK") + handler = mock.CoroutineMock(return_value="OK") with self.assertRaises(test_module.web.HTTPServiceUnavailable): await test_module.ready_middleware(request, handler) @@ -74,28 +70,28 @@ async def test_ready_middleware(self): assert await test_module.ready_middleware(request, handler) == "OK" request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.LedgerConfigError("Bad config") ) with self.assertRaises(test_module.LedgerConfigError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.web.HTTPFound(location="/api/doc") ) with self.assertRaises(test_module.web.HTTPFound): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.asyncio.CancelledError("Cancelled") ) with self.assertRaises(test_module.asyncio.CancelledError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock(side_effect=KeyError("No such thing")) + handler = mock.CoroutineMock(side_effect=KeyError("No such thing")) with self.assertRaises(KeyError): await test_module.ready_middleware(request, handler) @@ -110,10 +106,8 @@ def get_admin_server( # middleware is task queue xor collector: cover both over test suite task_queue = (settings or {}).pop("task_queue", None) - plugin_registry = async_mock.MagicMock( - test_module.PluginRegistry, autospec=True - ) - plugin_registry.post_process_routes = async_mock.MagicMock() + plugin_registry = mock.MagicMock(test_module.PluginRegistry, autospec=True) + plugin_registry.post_process_routes = mock.MagicMock() context.injector.bind_instance(test_module.PluginRegistry, plugin_registry) collector = Collector() @@ -129,10 +123,10 @@ def get_admin_server( profile, self.outbound_message_router, self.webhook_router, - conductor_stop=async_mock.AsyncMock(), + conductor_stop=mock.CoroutineMock(), task_queue=TaskQueue(max_active=4) if task_queue else None, conductor_stats=( - None if task_queue else async_mock.AsyncMock(return_value={"a": 1}) + None if task_queue else mock.CoroutineMock(return_value={"a": 1}) ), ) @@ -165,16 +159,16 @@ async def test_start_stop(self): server = self.get_admin_server(settings) await server.start() assert server.app._client_max_size == 4 * 1024 * 1024 - with async_mock.patch.object( - server, "websocket_queues", async_mock.MagicMock() + with mock.patch.object( + server, "websocket_queues", mock.MagicMock() ) as mock_wsq: - mock_wsq.values = async_mock.MagicMock( - return_value=[async_mock.MagicMock(stop=async_mock.MagicMock())] + mock_wsq.values = mock.MagicMock( + return_value=[mock.MagicMock(stop=mock.MagicMock())] ) await server.stop() - with async_mock.patch.object( - web.TCPSite, "start", async_mock.AsyncMock() + with mock.patch.object( + web.TCPSite, "start", mock.CoroutineMock() ) as mock_start: mock_start.side_effect = OSError("Failure to launch") with self.assertRaises(AdminSetupError): @@ -199,7 +193,7 @@ async def test_import_routes_multitenant_middleware(self): context.injector.bind_instance(GoalCodeRegistry, GoalCodeRegistry()) context.injector.bind_instance( test_module.BaseMultitenantManager, - async_mock.MagicMock(spec=test_module.BaseMultitenantManager), + mock.MagicMock(spec=test_module.BaseMultitenantManager), ) await DefaultContextBuilder().load_plugins(context) server = self.get_admin_server( @@ -220,66 +214,66 @@ async def test_import_routes_multitenant_middleware(self): m for m in app.middlewares if ".check_multitenant_authorization" in str(m) ] - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/multitenancy/etc", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) - assert mock_handler.called_once_with(mock_request) + mock_handler.assert_called_once_with(mock_request) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Non-bearer ..."}, path="/test", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) - assert mock_handler.called_once_with(mock_request) + mock_handler.assert_called_once_with(mock_request) # multitenant setup context exception paths [setup_ctx_middle] = [m for m in app.middlewares if ".setup_context" in str(m)] - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Non-bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await setup_ctx_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - with async_mock.patch.object( + with mock.patch.object( server.multitenant_manager, "get_profile_for_token", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_profile: mock_get_profile.side_effect = [ test_module.MultitenantManagerError("corrupt token"), @@ -493,8 +487,8 @@ async def server(): ) async def test_on_record_event(server, event_topic, webhook_topic): profile = InMemoryProfile.test_profile() - with async_mock.patch.object( - server, "send_webhook", async_mock.AsyncMock() + with mock.patch.object( + server, "send_webhook", mock.CoroutineMock() ) as mock_send_webhook: await server._on_record_event(profile, Event(event_topic, None)) mock_send_webhook.assert_called_once_with(profile, webhook_topic, None) diff --git a/aries_cloudagent/admin/tests/test_request_context.py b/aries_cloudagent/admin/tests/test_request_context.py index 8ab5159cf4..10c4ac5c8e 100644 --- a/aries_cloudagent/admin/tests/test_request_context.py +++ b/aries_cloudagent/admin/tests/test_request_context.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...core.profile import ProfileSession @@ -7,7 +7,7 @@ from .. import request_context as test_module -class TestAdminRequestContext(AsyncTestCase): +class TestAdminRequestContext(IsolatedAsyncioTestCase): def setUp(self): self.ctx = test_module.AdminRequestContext(InMemoryProfile.test_profile()) assert self.ctx.__class__.__name__ in str(self.ctx) diff --git a/aries_cloudagent/askar/didcomm/tests/test_v2.py b/aries_cloudagent/askar/didcomm/tests/test_v2.py index b9d5fde4d6..ec3fa53dba 100644 --- a/aries_cloudagent/askar/didcomm/tests/test_v2.py +++ b/aries_cloudagent/askar/didcomm/tests/test_v2.py @@ -1,6 +1,6 @@ import json -from asynctest import mock as async_mock +from unittest import mock import pytest from aries_askar import AskarError, Key, KeyAlg, Session @@ -70,9 +70,9 @@ async def test_es_encrypt_x(self, session: Session): ): _ = test_module.ecdh_es_encrypt({}, MESSAGE) - with async_mock.patch( + with mock.patch( "aries_askar.Key.generate", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -80,9 +80,9 @@ async def test_es_encrypt_x(self, session: Session): ): _ = test_module.ecdh_es_encrypt({BOB_KID: bob_pk}, MESSAGE) - with async_mock.patch( + with mock.patch( "aries_askar.Key.aead_encrypt", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -188,9 +188,9 @@ async def test_1pu_encrypt_x(self, session: Session): {BOB_KID: bob_pk, "alt": alt_pk}, ALICE_KID, alice_sk, MESSAGE ) - with async_mock.patch( + with mock.patch( "aries_askar.Key.generate", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -200,9 +200,9 @@ async def test_1pu_encrypt_x(self, session: Session): {BOB_KID: bob_pk}, ALICE_KID, alice_sk, MESSAGE ) - with async_mock.patch( + with mock.patch( "aries_askar.Key.aead_encrypt", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, diff --git a/aries_cloudagent/askar/tests/test_profile.py b/aries_cloudagent/askar/tests/test_profile.py index 453952271c..c9ad71a32e 100644 --- a/aries_cloudagent/askar/tests/test_profile.py +++ b/aries_cloudagent/askar/tests/test_profile.py @@ -1,7 +1,7 @@ import asyncio import pytest -from asynctest import mock +from unittest import mock from ...askar.profile import AskarProfile from ...config.injection_context import InjectionContext diff --git a/aries_cloudagent/askar/tests/test_store.py b/aries_cloudagent/askar/tests/test_store.py index 2af479165f..5d128d1840 100644 --- a/aries_cloudagent/askar/tests/test_store.py +++ b/aries_cloudagent/askar/tests/test_store.py @@ -1,11 +1,11 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...core.error import ProfileError from ..store import AskarStoreConfig -class TestStoreConfig(AsyncTestCase): +class TestStoreConfig(IsolatedAsyncioTestCase): key_derivation_method = "Raw" key = "key" storage_type = "postgres" diff --git a/aries_cloudagent/commands/tests/test_help.py b/aries_cloudagent/commands/tests/test_help.py index d52d41929d..b94906795e 100644 --- a/aries_cloudagent/commands/tests/test_help.py +++ b/aries_cloudagent/commands/tests/test_help.py @@ -1,14 +1,15 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from .. import help as command -class TestHelp(AsyncTestCase): +class TestHelp(IsolatedAsyncioTestCase): def test_exec_help(self): - with async_mock.patch.object( + with mock.patch.object( command.ArgumentParser, "print_help" - ) as mock_print_help, async_mock.patch( - "builtins.print", async_mock.MagicMock() + ) as mock_print_help, mock.patch( + "builtins.print", mock.MagicMock() ) as mock_print: command.execute([]) mock_print_help.assert_called_once() @@ -17,10 +18,10 @@ def test_exec_help(self): mock_print.assert_called_once_with(command.__version__) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( command, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - command, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + command, "execute", mock.MagicMock() ) as mock_execute: command.main() mock_execute.assert_called_once diff --git a/aries_cloudagent/commands/tests/test_init.py b/aries_cloudagent/commands/tests/test_init.py index 3af30bbb04..0944977dff 100644 --- a/aries_cloudagent/commands/tests/test_init.py +++ b/aries_cloudagent/commands/tests/test_init.py @@ -1,19 +1,20 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ... import commands as test_module -class TestInit(AsyncTestCase): +class TestInit(IsolatedAsyncioTestCase): def test_available(self): avail = test_module.available_commands() assert len(avail) == 4 def test_run(self): - with async_mock.patch.object( - test_module, "load_command", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_command", mock.MagicMock() ) as mock_load: - mock_module = async_mock.MagicMock() - mock_module.execute = async_mock.MagicMock() + mock_module = mock.MagicMock() + mock_module.execute = mock.MagicMock() mock_load.return_value = mock_module test_module.run_command("hello", ["world"]) diff --git a/aries_cloudagent/commands/tests/test_provision.py b/aries_cloudagent/commands/tests/test_provision.py index f8fa55ea3a..15b7438791 100644 --- a/aries_cloudagent/commands/tests/test_provision.py +++ b/aries_cloudagent/commands/tests/test_provision.py @@ -1,6 +1,7 @@ import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...config.base import ConfigError from ...config.error import ArgsParseError @@ -10,7 +11,7 @@ ) -class TestProvision(AsyncTestCase): +class TestProvision(IsolatedAsyncioTestCase): def test_bad_calls(self): with self.assertRaises(ArgsParseError): test_module.execute([]) @@ -39,34 +40,34 @@ def test_provision_wallet(self): ) async def test_provision_ledger_configured(self): - profile = async_mock.MagicMock(close=async_mock.CoroutineMock()) - with async_mock.patch.object( + profile = mock.MagicMock(close=mock.CoroutineMock()) + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ) as mock_wallet_config, async_mock.patch.object( - test_module, "ledger_config", async_mock.CoroutineMock(return_value=True) + ) as mock_wallet_config, mock.patch.object( + test_module, "ledger_config", mock.CoroutineMock(return_value=True) ) as mock_ledger_config: await test_module.provision({}) async def test_provision_config_x(self): - with async_mock.patch.object( - test_module, "wallet_config", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "wallet_config", mock.CoroutineMock() ) as mock_wallet_config: mock_wallet_config.side_effect = ConfigError("oops") with self.assertRaises(test_module.ProvisionError): await test_module.provision({}) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once @@ -75,7 +76,7 @@ async def test_provision_should_store_provided_mediation_invite(self): # given mediation_invite = "test-invite" - with async_mock.patch.object( + with mock.patch.object( test_module.MediationInviteStore, "store" ) as invite_store: # when diff --git a/aries_cloudagent/commands/tests/test_start.py b/aries_cloudagent/commands/tests/test_start.py index 9f3142cdec..372e61224b 100644 --- a/aries_cloudagent/commands/tests/test_start.py +++ b/aries_cloudagent/commands/tests/test_start.py @@ -1,13 +1,14 @@ import sys -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...config.error import ArgsParseError from .. import start as test_module -class TestStart(AsyncTestCase): +class TestStart(IsolatedAsyncioTestCase): def test_bad_args(self): with self.assertRaises(ArgsParseError): test_module.execute([]) @@ -16,25 +17,32 @@ def test_bad_args(self): test_module.execute(["bad"]) async def test_start_shutdown_app(self): - mock_conductor = async_mock.MagicMock( - setup=async_mock.CoroutineMock(), - start=async_mock.CoroutineMock(), - stop=async_mock.CoroutineMock(), + mock_conductor = mock.MagicMock( + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(), + stop=mock.CoroutineMock(), ) await test_module.start_app(mock_conductor) await test_module.shutdown_app(mock_conductor) def test_exec_start(self): - with async_mock.patch.object( - test_module, "start_app", autospec=True - ) as start_app, async_mock.patch.object( + with mock.patch.object( + # Normally this would be a CoroutineMock. However, it is awaited by + # run_loop, which is mocked out. So we mock it as a MagicMock. + test_module, + "start_app", + mock.MagicMock(), + ) as start_app, mock.patch.object( test_module, "run_loop" - ) as run_loop, async_mock.patch.object( - test_module, "shutdown_app", autospec=True - ) as shutdown_app, async_mock.patch.object( - test_module, "uvloop", async_mock.MagicMock() + ) as run_loop, mock.patch.object( + # Same here as note above + test_module, + "shutdown_app", + mock.MagicMock(), + ) as shutdown_app, mock.patch.object( + test_module, "uvloop", mock.MagicMock() ) as mock_uvloop: - mock_uvloop.install = async_mock.MagicMock() + mock_uvloop.install = mock.MagicMock() test_module.execute( [ "-it", @@ -56,13 +64,11 @@ def test_exec_start(self): run_loop.assert_called_once() async def test_run_loop(self): - startup = async_mock.CoroutineMock() + startup = mock.CoroutineMock() startup_call = startup() - shutdown = async_mock.CoroutineMock() + shutdown = mock.CoroutineMock() shutdown_call = shutdown() - with async_mock.patch.object( - test_module, "asyncio", autospec=True - ) as mock_asyncio: + with mock.patch.object(test_module, "asyncio", autospec=True) as mock_asyncio: test_module.run_loop(startup_call, shutdown_call) mock_add = mock_asyncio.get_event_loop.return_value.add_signal_handler mock_add.assert_called_once() @@ -77,10 +83,10 @@ async def test_run_loop(self): done_calls[0][1]() # exec partial done_coro = mock_asyncio.ensure_future.call_args[0][0] tasks = [ - async_mock.MagicMock(), - async_mock.MagicMock(cancel=async_mock.MagicMock()), + mock.MagicMock(), + mock.MagicMock(cancel=mock.MagicMock()), ] - mock_asyncio.gather = async_mock.CoroutineMock() + mock_asyncio.gather = mock.CoroutineMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = tasks @@ -93,13 +99,13 @@ async def test_run_loop(self): shutdown.assert_awaited_once() async def test_run_loop_init_x(self): - startup = async_mock.CoroutineMock(side_effect=KeyError("the front fell off")) + startup = mock.CoroutineMock(side_effect=KeyError("the front fell off")) startup_call = startup() - shutdown = async_mock.CoroutineMock() + shutdown = mock.CoroutineMock() shutdown_call = shutdown() - with async_mock.patch.object( + with mock.patch.object( test_module, "asyncio", autospec=True - ) as mock_asyncio, async_mock.patch.object( + ) as mock_asyncio, mock.patch.object( test_module, "LOGGER", autospec=True ) as mock_logger: test_module.run_loop(startup_call, shutdown_call) @@ -115,8 +121,8 @@ async def test_run_loop_init_x(self): ) done_calls[0][1]() # exec partial done_coro = mock_asyncio.ensure_future.call_args[0][0] - task = async_mock.MagicMock() - mock_asyncio.gather = async_mock.CoroutineMock() + task = mock.MagicMock() + mock_asyncio.gather = mock.CoroutineMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = [task] @@ -130,10 +136,10 @@ async def test_run_loop_init_x(self): mock_logger.exception.assert_called_once() def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once diff --git a/aries_cloudagent/commands/tests/test_upgrade.py b/aries_cloudagent/commands/tests/test_upgrade.py index 55451387c0..918b6cec4a 100644 --- a/aries_cloudagent/commands/tests/test_upgrade.py +++ b/aries_cloudagent/commands/tests/test_upgrade.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...connections.models.conn_record import ConnRecord @@ -14,8 +15,8 @@ from ..upgrade import UpgradeError -class TestUpgrade(AsyncTestCase): - async def setUp(self): +class TestUpgrade(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.profile.context.injector.bind_instance( @@ -51,21 +52,21 @@ def test_bad_calls(self): test_module.execute(["bad"]) async def test_upgrade_storage_from_version_included(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.CoroutineMock() ): await test_module.upgrade( settings={ @@ -75,21 +76,21 @@ async def test_upgrade_storage_from_version_included(self): ) async def test_upgrade_storage_missing_from_version(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.CoroutineMock() ): await test_module.upgrade(settings={}) @@ -99,11 +100,11 @@ async def test_upgrade_from_version(self): "upgrade.from_version": "v0.7.2", } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -117,11 +118,11 @@ async def test_upgrade_all_subwallets(self): "upgrade.page_size": 1, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -139,11 +140,11 @@ async def test_upgrade_specified_subwallets(self): "upgrade.force_upgrade": True, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -156,11 +157,11 @@ async def test_upgrade_specified_subwallets(self): "upgrade.page_size": 1, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -170,19 +171,19 @@ async def test_upgrade_callable(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -206,19 +207,19 @@ async def test_upgrade_callable_named_tag(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -244,13 +245,13 @@ async def test_upgrade_x_same_version(self): type_filter="acapy_version", tag_query={} ) await self.storage.update_record(version_storage_record, f"v{__version__}", {}) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ): @@ -265,21 +266,21 @@ async def test_upgrade_missing_from_version(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.CoroutineMock() ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade( @@ -296,19 +297,19 @@ async def test_upgrade_x_callable_not_set(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -331,19 +332,19 @@ async def test_upgrade_x_callable_not_set(self): assert "No function specified for" in str(ctx.exception) async def test_upgrade_x_class_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -364,26 +365,33 @@ async def test_upgrade_x_class_not_found(self): assert "Unknown Record type" in str(ctx.exception) async def test_execute(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() - ), async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() - ) as mock_get_event_loop: - mock_get_event_loop.return_value = async_mock.MagicMock( - run_until_complete=async_mock.MagicMock(), + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.CoroutineMock() + ), mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() + ) as mock_get_event_loop, mock.patch.object( + # Normally, this would be a CoroutingMock. However, the coroutine + # is awaited by run_until_complete, which is mocked out. + # Use MagicMock to prevent unawaited coroutine warnings. + test_module, + "upgrade", + mock.MagicMock(), + ): + mock_get_event_loop.return_value = mock.MagicMock( + run_until_complete=mock.MagicMock(), ) test_module.execute( [ @@ -396,19 +404,19 @@ async def test_execute(self): ) async def test_upgrade_x_invalid_record_type(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -429,19 +437,19 @@ async def test_upgrade_x_invalid_record_type(self): assert "Only BaseRecord can be resaved" in str(ctx.exception) async def test_upgrade_force(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -486,10 +494,10 @@ async def test_add_version_record(self): assert version_storage_record.value == "v0.7.5" async def test_upgrade_x_invalid_config(self): - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock(return_value={}), + mock.MagicMock(return_value={}), ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade(profile=self.profile) @@ -504,10 +512,10 @@ async def test_upgrade_x_params(self): assert "upgrade requires either profile or settings" in str(ctx.exception) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once @@ -651,10 +659,10 @@ async def test_upgrade_explicit_check(self): "upgrade.from_version": "v0.7.0", } ) - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -680,10 +688,10 @@ async def test_upgrade_explicit_check(self): ctx.exception ) - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -710,12 +718,12 @@ async def test_upgrade_explicit_check(self): ctx.exception ) - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger, async_mock.patch.object( + with mock.patch.object( + test_module, "LOGGER", mock.MagicMock() + ) as mock_logger, mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { diff --git a/aries_cloudagent/config/tests/test_argparse.py b/aries_cloudagent/config/tests/test_argparse.py index 0ddc0eec81..c110666606 100644 --- a/aries_cloudagent/config/tests/test_argparse.py +++ b/aries_cloudagent/config/tests/test_argparse.py @@ -1,12 +1,13 @@ from configargparse import ArgumentTypeError -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from .. import argparse from ..util import BoundedInt, ByteSize -class TestArgParse(AsyncTestCase): +class TestArgParse(IsolatedAsyncioTestCase): async def test_groups(self): """Test optional argument parsing.""" parser = argparse.create_argument_parser() @@ -27,7 +28,7 @@ async def test_transport_settings(self): group = argparse.TransportGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -60,7 +61,7 @@ async def test_get_genesis_transactions_list_with_ledger_selection(self): group = argparse.LedgerGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -128,7 +129,7 @@ async def test_upgrade_config(self): group = argparse.UpgradeGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -249,7 +250,7 @@ async def test_general_settings_file(self): group = argparse.GeneralGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -304,7 +305,7 @@ async def test_transport_settings_file(self): group = argparse.TransportGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -595,7 +596,7 @@ async def test_discover_features_args(self): group = argparse.DiscoverFeaturesGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() diff --git a/aries_cloudagent/config/tests/test_default_context.py b/aries_cloudagent/config/tests/test_default_context.py index 52028e9e90..722038715a 100644 --- a/aries_cloudagent/config/tests/test_default_context.py +++ b/aries_cloudagent/config/tests/test_default_context.py @@ -1,6 +1,6 @@ from tempfile import NamedTemporaryFile -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...cache.base import BaseCache from ...core.profile import ProfileManager @@ -11,7 +11,7 @@ from ..injection_context import InjectionContext -class TestDefaultContext(AsyncTestCase): +class TestDefaultContext(IsolatedAsyncioTestCase): async def test_build_context(self): """Test context init.""" diff --git a/aries_cloudagent/config/tests/test_injection_context.py b/aries_cloudagent/config/tests/test_injection_context.py index 9f0b0a2ed0..e6bd1fd4f0 100644 --- a/aries_cloudagent/config/tests/test_injection_context.py +++ b/aries_cloudagent/config/tests/test_injection_context.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..base import InjectionError from ..injection_context import InjectionContext, InjectionContextError -class TestInjectionContext(AsyncTestCase): +class TestInjectionContext(IsolatedAsyncioTestCase): def setUp(self): self.test_key = "TEST" self.test_value = "VALUE" diff --git a/aries_cloudagent/config/tests/test_injector.py b/aries_cloudagent/config/tests/test_injector.py index d44e39fa63..76da5f7992 100644 --- a/aries_cloudagent/config/tests/test_injector.py +++ b/aries_cloudagent/config/tests/test_injector.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..base import BaseProvider, BaseInjector, BaseSettings, InjectionError from ..injector import Injector @@ -27,7 +27,7 @@ def open(self): self.opened = True -class TestInjector(AsyncTestCase): +class TestInjector(IsolatedAsyncioTestCase): def setUp(self): self.test_key = "TEST" self.test_value = "VALUE" diff --git a/aries_cloudagent/config/tests/test_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index dc46041bc0..4cd0a3e4b2 100644 --- a/aries_cloudagent/config/tests/test_ledger.py +++ b/aries_cloudagent/config/tests/test_ledger.py @@ -1,5 +1,6 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .. import argparse from ...core.in_memory import InMemoryProfile @@ -13,16 +14,16 @@ TEST_GENESIS = "GENESIS" -class TestLedgerConfig(AsyncTestCase): +class TestLedgerConfig(IsolatedAsyncioTestCase): async def test_fetch_genesis_transactions(self): - with async_mock.patch.object( - test_module, "fetch", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "fetch", mock.CoroutineMock() ) as mock_fetch: await test_module.fetch_genesis_transactions("http://1.2.3.4:9000/genesis") async def test_fetch_genesis_transactions_x(self): - with async_mock.patch.object( - test_module, "fetch", async_mock.CoroutineMock(return_value=TEST_GENESIS) + with mock.patch.object( + test_module, "fetch", mock.CoroutineMock(return_value=TEST_GENESIS) ) as mock_fetch: mock_fetch.side_effect = test_module.FetchError("404 Not Found") with self.assertRaises(test_module.ConfigError): @@ -34,10 +35,10 @@ async def test_get_genesis_url(self): settings = { "ledger.genesis_url": "00000000000000000000000000000000", } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS), + mock.CoroutineMock(return_value=TEST_GENESIS), ) as mock_fetch: await test_module.get_genesis_transactions(settings) self.assertEqual(settings["ledger.genesis_transactions"], TEST_GENESIS) @@ -46,11 +47,11 @@ async def test_get_genesis_file(self): settings = { "ledger.genesis_file": "/tmp/genesis/path", } - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS) + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS) ) ) ) @@ -62,7 +63,7 @@ async def test_get_genesis_file_io_x(self): "ledger.genesis_file": "/tmp/genesis/path", } - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.side_effect = IOError("no read permission") with self.assertRaises(test_module.ConfigError): await test_module.get_genesis_transactions(settings) @@ -72,8 +73,8 @@ async def test_ledger_config_no_taa_accept(self): "ledger.genesis_transactions": TEST_GENESIS, "default_endpoint": "http://1.2.3.4:8051", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={ "taa_required": True, "taa_record": { @@ -81,7 +82,7 @@ async def test_ledger_config_no_taa_accept(self): }, } ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock( + get_latest_txn_author_acceptance=mock.CoroutineMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), read_only=False, @@ -96,8 +97,8 @@ async def _get_session(): setattr(profile, "session", _get_session) session.context.injector.bind_instance(BaseLedger, mock_ledger) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: mock_accept_taa.return_value = False assert not await test_module.ledger_config( @@ -108,8 +109,8 @@ async def test_accept_taa(self): settings = { "ledger.genesis_transactions": TEST_GENESIS, } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={ "taa_required": True, "taa_record": { @@ -117,13 +118,13 @@ async def test_accept_taa(self): }, } ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock( + get_latest_txn_author_acceptance=mock.CoroutineMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), - update_endpoint_for_did=async_mock.CoroutineMock(), + update_endpoint_for_did=mock.CoroutineMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock(set_did_endpoint=async_mock.CoroutineMock()) + mock_wallet = mock.MagicMock(set_did_endpoint=mock.CoroutineMock()) session = InMemoryProfile.test_session(settings=settings) profile = session.profile @@ -135,8 +136,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: mock_accept_taa.return_value = True await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -146,13 +147,13 @@ async def test_ledger_config_read_only_skip_taa_accept(self): settings = { "ledger.genesis_transactions": TEST_GENESIS, } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock(), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.CoroutineMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock( + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.CoroutineMock( side_effect=LedgerError( "Error cannot update endpoint when ledger is in read only mode" ) @@ -169,8 +170,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: with self.assertRaises(test_module.ConfigError) as x_context: await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -183,13 +184,13 @@ async def test_ledger_config_read_only_skip_profile_endpoint_publish(self): "ledger.genesis_url": "00000000000000000000000000000000", "profile_endpoint": "http://agent.ca", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock(), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.CoroutineMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.CoroutineMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -202,8 +203,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: await test_module.ledger_config(profile, TEST_DID, provision=True) mock_ledger.get_txn_author_agreement.assert_not_called() @@ -216,16 +217,16 @@ async def test_ledger_config_read_write_skip_taa_endpoint_publish(self): "default_endpoint": "http://agent-default.ca", "profile_endpoint": "http://agent-profile.ca", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={"taa_required": False} ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), - update_endpoint_for_did=async_mock.CoroutineMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), + update_endpoint_for_did=mock.CoroutineMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.CoroutineMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -238,17 +239,17 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: await test_module.ledger_config( profile, public_did=TEST_DID, provision=False, ) - mock_ledger.get_txn_author_agreement.called_once_with() + mock_ledger.get_txn_author_agreement.assert_called_once_with() mock_ledger.get_latest_txn_author_acceptance.assert_not_called() - mock_ledger.update_endpoint_for_did.called_once_with( + mock_ledger.update_endpoint_for_did.assert_called_once_with( TEST_DID, settings["profile_endpoint"], test_module.EndpointType.PROFILE, @@ -336,17 +337,15 @@ async def test_load_multiple_genesis_transactions_from_config_a(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -433,17 +432,15 @@ async def test_load_multiple_genesis_transactions_from_config_b(self): ], "ledger.genesis_url": "http://localhost:9000/genesis", } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -497,17 +494,15 @@ async def test_load_multiple_genesis_transactions_config_error_a(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -564,17 +559,15 @@ async def test_load_multiple_genesis_transactions_multiple_write(self): }, ] } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -625,22 +618,20 @@ async def test_load_multiple_genesis_transactions_from_config_io_x(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.side_effect = IOError("no read permission") with self.assertRaises(test_module.ConfigError): await test_module.load_multiple_genesis_transactions_from_config( settings ) - @async_mock.patch("sys.stdout") + @mock.patch("sys.stdout") async def test_ledger_accept_taa_not_tty_not_accept_config(self, mock_stdout): - mock_stdout.isatty = async_mock.MagicMock(return_value=False) + mock_stdout.isatty = mock.MagicMock(return_value=False) mock_profile = InMemoryProfile.test_profile() taa_info = { @@ -652,9 +643,9 @@ async def test_ledger_accept_taa_not_tty_not_accept_config(self, mock_stdout): None, mock_profile, taa_info, provision=False ) - @async_mock.patch("sys.stdout") + @mock.patch("sys.stdout") async def test_ledger_accept_taa_tty(self, mock_stdout): - mock_stdout.isatty = async_mock.MagicMock(return_value=True) + mock_stdout.isatty = mock.MagicMock(return_value=True) mock_profile = InMemoryProfile.test_profile() taa_info = { @@ -662,33 +653,33 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): "aml_record": {"aml": ["wallet_agreement", "on_file"]}, } - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: mock_prompt.side_effect = EOFError() assert not await test_module.accept_taa( None, mock_profile, taa_info, provision=False ) - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: mock_prompt.return_value = "x" assert not await test_module.accept_taa( None, mock_profile, taa_info, provision=False ) - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: - mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.CoroutineMock() + mock_ledger = mock.MagicMock( + accept_txn_author_agreement=mock.CoroutineMock() ) mock_prompt.return_value = "" assert await test_module.accept_taa( @@ -732,9 +723,7 @@ async def test_ledger_accept_taa(self): "ledger.taa_acceptance_version": "1.0", } ) - mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.CoroutineMock() - ) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.CoroutineMock()) assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False ) @@ -746,7 +735,7 @@ async def test_ledger_config(self): group = argparse.LedgerGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() diff --git a/aries_cloudagent/config/tests/test_logging.py b/aries_cloudagent/config/tests/test_logging.py index 853b723692..13ceff1f8d 100644 --- a/aries_cloudagent/config/tests/test_logging.py +++ b/aries_cloudagent/config/tests/test_logging.py @@ -3,7 +3,8 @@ from io import StringIO -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from tempfile import NamedTemporaryFile from .. import logging as test_module @@ -14,14 +15,14 @@ from ...wallet.key_type import ED25519 -class TestLoggingConfigurator(AsyncTestCase): +class TestLoggingConfigurator(IsolatedAsyncioTestCase): agent_label_arg_value = "Aries Cloud Agent" transport_arg_value = "transport" host_arg_value = "host" port_arg_value = "port" - @async_mock.patch.object(test_module, "load_resource", autospec=True) - @async_mock.patch.object(test_module, "fileConfig", autospec=True) + @mock.patch.object(test_module, "load_resource", autospec=True) + @mock.patch.object(test_module, "fileConfig", autospec=True) def test_configure_default(self, mock_file_config, mock_load_resource): test_module.LoggingConfigurator.configure() @@ -33,24 +34,24 @@ def test_configure_default(self, mock_file_config, mock_load_resource): ) def test_configure_default_no_resource(self): - with async_mock.patch.object( - test_module, "load_resource", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_resource", mock.MagicMock() ) as mock_load: mock_load.return_value = None test_module.LoggingConfigurator.configure() def test_configure_default_file(self): log_file = NamedTemporaryFile() - with async_mock.patch.object( - test_module, "load_resource", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_resource", mock.MagicMock() ) as mock_load: mock_load.return_value = None test_module.LoggingConfigurator.configure( log_level="ERROR", log_file=log_file.name ) - @async_mock.patch.object(test_module, "load_resource", autospec=True) - @async_mock.patch.object(test_module, "fileConfig", autospec=True) + @mock.patch.object(test_module, "load_resource", autospec=True) + @mock.patch.object(test_module, "fileConfig", autospec=True) def test_configure_path(self, mock_file_config, mock_load_resource): path = "a path" test_module.LoggingConfigurator.configure(path) @@ -62,9 +63,9 @@ def test_configure_path(self, mock_file_config, mock_load_resource): def test_banner_did(self): stdout = StringIO() - mock_http = async_mock.MagicMock(scheme="http", host="1.2.3.4", port=8081) - mock_https = async_mock.MagicMock(schemes=["https", "archie"]) - mock_admin_server = async_mock.MagicMock(host="1.2.3.4", port=8091) + mock_http = mock.MagicMock(scheme="http", host="1.2.3.4", port=8081) + mock_https = mock.MagicMock(schemes=["https", "archie"]) + mock_admin_server = mock.MagicMock(host="1.2.3.4", port=8091) with contextlib.redirect_stdout(stdout): test_label = "Aries Cloud Agent" test_did = "55GkHamhTU1ZbTbV2ab9DE" @@ -82,20 +83,20 @@ def test_banner_did(self): assert test_did in output def test_load_resource(self): - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: test_module.load_resource("abc", encoding="utf-8") mock_open.side_effect = IOError("insufficient privilege") test_module.load_resource("abc", encoding="utf-8") - with async_mock.patch.object( - test_module.pkg_resources, "resource_stream", async_mock.MagicMock() - ) as mock_res_stream, async_mock.patch.object( - test_module, "TextIOWrapper", async_mock.MagicMock() + with mock.patch.object( + test_module.pkg_resources, "resource_stream", mock.MagicMock() + ) as mock_res_stream, mock.patch.object( + test_module, "TextIOWrapper", mock.MagicMock() ) as mock_text_io_wrapper: test_module.load_resource("abc:def", encoding="utf-8") - with async_mock.patch.object( - test_module.pkg_resources, "resource_stream", async_mock.MagicMock() + with mock.patch.object( + test_module.pkg_resources, "resource_stream", mock.MagicMock() ) as mock_res_stream: test_module.load_resource("abc:def", encoding=None) diff --git a/aries_cloudagent/config/tests/test_provider.py b/aries_cloudagent/config/tests/test_provider.py index 6999ddfe1a..944b4a7b86 100644 --- a/aries_cloudagent/config/tests/test_provider.py +++ b/aries_cloudagent/config/tests/test_provider.py @@ -1,7 +1,8 @@ from tempfile import NamedTemporaryFile from weakref import ref -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ...utils.stats import Collector @@ -22,7 +23,7 @@ def __init__(self, *args, **kwargs): pass -class TestProvider(AsyncTestCase): +class TestProvider(IsolatedAsyncioTestCase): async def test_stats_provider_init_x(self): """Cover stats provider init error on no provider.""" with self.assertRaises(ValueError): @@ -33,7 +34,7 @@ async def test_stats_provider_provide_collector(self): timing_log = NamedTemporaryFile().name settings = {"timing.enabled": True, "timing.log.file": timing_log} - mock_provider = async_mock.MagicMock(BaseProvider, autospec=True) + mock_provider = mock.MagicMock(BaseProvider, autospec=True) mock_provider.provide.return_value.mock_method = lambda: () stats_provider = StatsProvider(mock_provider, ("mock_method",)) collector = Collector(log_path=timing_log) diff --git a/aries_cloudagent/config/tests/test_wallet.py b/aries_cloudagent/config/tests/test_wallet.py index 3ff2e5a8b8..45b96b5f9a 100644 --- a/aries_cloudagent/config/tests/test_wallet.py +++ b/aries_cloudagent/config/tests/test_wallet.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...core.profile import ProfileManager, ProfileSession @@ -29,16 +30,16 @@ async def open(self, context, config): return self.profile -class TestWalletConfig(AsyncTestCase): - async def setUp(self): +class TestWalletConfig(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.injector = Injector(enforce_typing=False) - self.session = async_mock.MagicMock(ProfileSession)() - self.session.commit = async_mock.CoroutineMock() - self.profile = async_mock.MagicMock( + self.session = mock.MagicMock(ProfileSession)() + self.session.commit = mock.CoroutineMock() + self.profile = mock.MagicMock( backend="indy", created=True, name="Test Wallet", - transaction=async_mock.CoroutineMock(return_value=self.session), + transaction=mock.CoroutineMock(return_value=self.session), ) def _inject(cls): @@ -56,32 +57,32 @@ async def test_wallet_config_existing_replace(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_existing_open(self): - self.profile = async_mock.MagicMock( + self.profile = mock.MagicMock( backend="indy", created=False, name="Test Wallet", - transaction=async_mock.CoroutineMock(return_value=self.session), + transaction=mock.CoroutineMock(return_value=self.session), ) self.context.injector.clear_binding(ProfileManager) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) @@ -93,23 +94,23 @@ async def test_wallet_config_existing_open(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -124,21 +125,21 @@ async def test_wallet_config_auto_provision(self): "auto_provision": False, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - MockManager, "open", async_mock.CoroutineMock() - ) as mock_mgr_open, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + MockManager, "open", mock.CoroutineMock() + ) as mock_mgr_open, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_mgr_open.side_effect = test_module.ProfileNotFoundError() @@ -155,14 +156,14 @@ async def test_wallet_config_non_indy_x(self): } ) self.profile.backend = "not-indy" - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -173,19 +174,19 @@ async def test_wallet_config_bad_seed_x(self): "wallet.seed": "00000000000000000000000000000000", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( test_module, "seed_to_did", - async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -197,19 +198,19 @@ async def test_wallet_config_seed_local(self): "wallet.local_did": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -221,38 +222,38 @@ async def test_wallet_config_seed_public(self): "wallet.seed": "00000000000000000000000000000000", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( test_module, "seed_to_did", - async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_seed_no_public_did(self): - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -264,21 +265,21 @@ async def test_wallet_config_for_key_derivation_method(self): "wallet.key_derivation_method": "derivation_method", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - MockManager, "provision", async_mock.CoroutineMock() - ) as mock_mgr_provision, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + with mock.patch.object( + MockManager, "provision", mock.CoroutineMock() + ) as mock_mgr_provision, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_mgr_provision.return_value = self.profile diff --git a/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py b/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py index bc720acffb..d9d45bc271 100644 --- a/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py +++ b/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py @@ -16,13 +16,13 @@ """ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .. import DIDDoc, PublicKey, PublicKeyType, Service from ..util import canon_did, canon_ref -class TestDIDDoc(AsyncTestCase): +class TestDIDDoc(IsolatedAsyncioTestCase): async def test_basic(self): # One authn key by reference dd_in = { diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index 19f540adda..13bb06df58 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....protocols.connections.v1_0.messages.connection_invitation import ( @@ -13,7 +13,7 @@ from ..diddoc.diddoc import DIDDoc -class TestConnRecord(AsyncTestCase): +class TestConnRecord(IsolatedAsyncioTestCase): def setUp(self): self.session = InMemoryProfile.test_session() diff --git a/aries_cloudagent/connections/tests/test_base_manager.py b/aries_cloudagent/connections/tests/test_base_manager.py index 0932b992cc..341d27b2e6 100644 --- a/aries_cloudagent/connections/tests/test_base_manager.py +++ b/aries_cloudagent/connections/tests/test_base_manager.py @@ -2,7 +2,8 @@ from unittest.mock import call -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from pydid import DID, DIDDocument, DIDDocumentBuilder from pydid.doc.builder import ServiceBuilder from pydid.verification_method import ( @@ -53,7 +54,7 @@ from ..base_manager import BaseConnectionManager -class TestBaseConnectionManager(AsyncTestCase): +class TestBaseConnectionManager(IsolatedAsyncioTestCase): def make_did_doc(self, did, verkey): doc = DIDDoc(did=did) controller = did @@ -71,7 +72,7 @@ def make_did_doc(self, did, verkey): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.test_seed = "testseed000000000000000000000001" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" @@ -82,8 +83,8 @@ async def setUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) self.route_manager = CoordinateMediationV1RouteManager() self.resolver = DIDResolver() @@ -109,7 +110,7 @@ async def setUp(self): ) self.context = self.profile.context - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) @@ -214,7 +215,7 @@ async def test_create_did_document_mediation_svc_endpoints_overwritten(self): routing_keys=self.test_mediator_routing_keys, endpoint=self.test_mediator_endpoint, ) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(mediation_record.routing_keys, mediation_record.endpoint) ) doc = await self.manager.create_did_document( @@ -307,7 +308,7 @@ async def test_store_did_document_with_routing_keys(self): assert context.output and "Key already associated with DID" in context.output[0] async def test_fetch_connection_targets_no_my_did(self): - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.my_did = None assert await self.manager.fetch_connection_targets(mock_conn) == [] @@ -329,13 +330,13 @@ async def test_fetch_connection_targets_conn_invitation_did_no_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): @@ -353,11 +354,11 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -377,13 +378,13 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -424,11 +425,11 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -447,13 +448,13 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -490,10 +491,10 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se ], } did_doc = DIDDocument.deserialize(did_doc_json) - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( @@ -511,13 +512,13 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -530,10 +531,10 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self ) builder.service.add(type_="LinkedData", service_endpoint=self.test_endpoint) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( method=SOV, @@ -550,13 +551,13 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -578,11 +579,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -601,13 +602,13 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -640,11 +641,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -663,13 +664,13 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -702,11 +703,11 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -725,13 +726,13 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -763,11 +764,11 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -786,13 +787,13 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -808,13 +809,11 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_no_resolver(self) metadata=None, ) - mock_oob_invite = async_mock.MagicMock(services=[self.test_did]) + mock_oob_invite = mock.MagicMock(services=[self.test_did]) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, - retrieve_invitation=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=mock.CoroutineMock(return_value=mock_oob_invite), state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER.rfc23, ) @@ -837,8 +836,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): ) did_doc = builder.build() - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -851,20 +850,18 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): metadata=None, ) - mock_oob_invite = async_mock.MagicMock( + mock_oob_invite = mock.MagicMock( label="a label", their_did=self.test_target_did, services=["dummy"], ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=mock.CoroutineMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -879,10 +876,10 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): async with self.profile.session() as session: - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.get_key_for_did = async_mock.CoroutineMock( + self.resolver.get_key_for_did = mock.CoroutineMock( return_value=self.test_target_verkey ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -895,11 +892,11 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): metadata=None, ) - mock_oob_invite = async_mock.MagicMock( + mock_oob_invite = mock.MagicMock( label="a label", their_did=self.test_target_did, services=[ - async_mock.MagicMock( + mock.MagicMock( service_endpoint=self.test_endpoint, recipient_keys=[ DIDKey.from_public_key_b58( @@ -910,15 +907,13 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): ) ], ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=mock.CoroutineMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -941,7 +936,7 @@ async def test_fetch_connection_targets_conn_initiator_completed_no_their_did(se metadata=None, ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=None, state=ConnRecord.State.COMPLETED.rfc23, @@ -961,7 +956,7 @@ async def test_fetch_connection_targets_conn_completed_their_did(self): did_doc = self.make_did_doc(did=self.test_did, verkey=self.test_verkey) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_did, their_label="label", @@ -990,7 +985,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): metadata=None, ) - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( self.test_endpoint, [self.test_verkey], @@ -1000,7 +995,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): did_doc = self.make_did_doc(did=self.test_did, verkey=self.test_verkey) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_did, their_label="label", @@ -1035,7 +1030,7 @@ async def test_verification_methods_for_service(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) recip, routing = await self.manager.verification_methods_for_service( @@ -1047,7 +1042,7 @@ async def test_verification_methods_for_service(self): async def test_resolve_connection_targets_empty(self): """Test resolve connection targets.""" did = "did:sov:" + self.test_did - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(DIDDocument(id=DID(did)), []) ) targets = await self.manager.resolve_connection_targets(did) @@ -1069,7 +1064,7 @@ async def test_resolve_connection_targets(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) targets = await self.manager.resolve_connection_targets(did) @@ -1091,7 +1086,7 @@ async def test_resolve_connection_targets_x_bad_reference(self): routing_keys=["did:example:123#some-random-id"], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) with self.assertLogs() as cm: @@ -1116,7 +1111,7 @@ async def test_resolve_connection_targets_x_bad_key_material(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1138,7 +1133,7 @@ async def test_resolve_connection_targets_x_unsupported_key(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1151,7 +1146,7 @@ async def test_record_did_empty(self): service_builder.add_didcomm( self.test_endpoint, recipient_keys=[], routing_keys=[] ) - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(DIDDocument(id=DID(did)), service_builder.services) ) await self.manager.record_did(did) @@ -1167,7 +1162,7 @@ async def test_record_did(self): self.test_endpoint, recipient_keys=[vm], routing_keys=[] ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) await self.manager.record_did(did) @@ -1194,14 +1189,14 @@ async def test_find_inbound_connection(self): recipient_did_public=False, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" # First pass: not yet in cache - with async_mock.patch.object( + with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_conn_mgr_resolve_conn: mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1209,8 +1204,8 @@ async def test_find_inbound_connection(self): assert conn_rec # Second pass: in cache - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1224,13 +1219,13 @@ async def test_find_inbound_connection_no_cache(self): recipient_did_public=False, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( + with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_conn_mgr_resolve_conn: self.context.injector.clear_binding(BaseCache) mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1245,13 +1240,13 @@ async def test_resolve_inbound_connection(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -1271,13 +1266,13 @@ async def test_resolve_inbound_connection_injector_error(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = InjectionError() mock_mgr_find_conn.return_value = mock_conn @@ -1291,13 +1286,13 @@ async def test_resolve_inbound_connection_wallet_not_found_error(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = WalletNotFoundError() mock_mgr_find_conn.return_value = mock_conn @@ -1327,13 +1322,13 @@ async def test_get_connection_targets_conn_invitation_no_did(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1386,19 +1381,19 @@ async def test_get_connection_targets_retrieve_connection(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn mock_conn_target_ser.return_value = {"serialized": "value"} @@ -1430,7 +1425,7 @@ async def test_get_connection_targets_from_cache(self): ) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", @@ -1438,12 +1433,12 @@ async def test_get_connection_targets_from_cache(self): state=ConnRecord.State.COMPLETED.rfc160, ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.CoroutineMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.CoroutineMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1474,7 +1469,7 @@ async def test_get_connection_targets_no_cache(self): ) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", @@ -1482,12 +1477,12 @@ async def test_get_connection_targets_no_cache(self): state=ConnRecord.State.COMPLETED.rfc160, ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.CoroutineMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.CoroutineMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1531,13 +1526,13 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1554,9 +1549,7 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): assert target.sender_key == local_did.verkey async def test_create_static_connection(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: _my, _their, conn_rec = await self.manager.create_static_connection( my_did=self.test_did, their_did=self.test_target_did, @@ -1572,11 +1565,9 @@ async def test_create_static_connection_multitenant(self): ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.CoroutineMock() + self.route_manager.route_static = mock.CoroutineMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1605,13 +1596,11 @@ async def test_create_static_connection_multitenant_auto_disclose_features(self) } ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.CoroutineMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + self.route_manager.route_static = mock.CoroutineMock() + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + ) as mock_wallet_create_local_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -1634,16 +1623,14 @@ async def test_create_static_connection_multitenant_mediator(self): {"wallet.id": "test_wallet", "multitenant.enabled": True} ) - default_mediator = async_mock.MagicMock() - self.route_manager.route_static = async_mock.CoroutineMock() + default_mediator = mock.MagicMock() + self.route_manager.route_static = mock.CoroutineMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( BaseConnectionManager, "create_did_document" - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( BaseConnectionManager, "store_did_document" ) as store_did_document: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1693,9 +1680,7 @@ async def test_create_static_connection_multitenant_mediator(self): ) async def test_create_static_connection_no_their(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: with self.assertRaises(BaseConnectionManagerError): await self.manager.create_static_connection( my_did=self.test_did, @@ -1705,9 +1690,7 @@ async def test_create_static_connection_no_their(self): ) async def test_create_static_connection_their_seed_only(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: _my, _their, conn_rec = await self.manager.create_static_connection( my_did=self.test_did, their_seed=self.test_seed, @@ -1717,12 +1700,12 @@ async def test_create_static_connection_their_seed_only(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_find_connection_retrieve_by_did(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1735,14 +1718,14 @@ async def test_find_connection_retrieve_by_did(self): async def test_find_connection_retrieve_by_did_auto_disclose_features(self): self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1755,15 +1738,15 @@ async def test_find_connection_retrieve_by_did_auto_disclose_features(self): mock_proactive_disclose_features.assert_called_once() async def test_find_connection_retrieve_by_invitation_key(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_invitation_key.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_invitation_key.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1774,10 +1757,10 @@ async def test_find_connection_retrieve_by_invitation_key(self): assert conn_rec async def test_find_connection_retrieve_none_by_invitation_key(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.side_effect = StorageNotFoundError() @@ -1792,19 +1775,19 @@ async def test_find_connection_retrieve_none_by_invitation_key(self): async def test_get_endpoints(self): conn_id = "dummy" - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( InMemoryWallet, "get_local_did", autospec=True - ) as mock_wallet_get_local_did, async_mock.patch.object( - self.manager, "get_connection_targets", async_mock.CoroutineMock() + ) as mock_wallet_get_local_did, mock.patch.object( + self.manager, "get_connection_targets", mock.CoroutineMock() ) as mock_get_conn_targets: - mock_retrieve.return_value = async_mock.MagicMock() - mock_wallet_get_local_did.return_value = async_mock.MagicMock( + mock_retrieve.return_value = mock.MagicMock() + mock_wallet_get_local_did.return_value = mock.MagicMock( metadata={"endpoint": "localhost:8020"} ) mock_get_conn_targets.return_value = [ - async_mock.MagicMock(endpoint="10.20.30.40:5060") + mock.MagicMock(endpoint="10.20.30.40:5060") ] assert await self.manager.get_endpoints(conn_id) == ( "localhost:8020", diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index 7da2c37c34..8e6360b4b2 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -1,6 +1,6 @@ from io import StringIO -import mock as async_mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...admin.base_server import BaseAdminServer @@ -80,7 +80,7 @@ def make_did_doc(self, did, verkey): class StubContextBuilder(ContextBuilder): def __init__(self, settings): super().__init__(settings) - self.wire_format = async_mock.create_autospec(PackWireFormat()) + self.wire_format = mock.create_autospec(PackWireFormat()) async def build_context(self) -> InjectionContext: context = InjectionContext(settings=self.settings, enforce_typing=False) @@ -105,29 +105,29 @@ async def test_startup_version_record_exists(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.7.3")), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.7.3")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock( + mock.MagicMock( return_value=["v0.7.4", "0.7.5", "v0.8.0-rc1", "v8.0.0", "v0.8.1-rc2"] ), - ), async_mock.patch.object( + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -161,25 +161,25 @@ async def test_startup_version_no_upgrade_add_record(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.8.1")), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.8.1")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=[]), - ), async_mock.patch.object( + mock.MagicMock(return_value=[]), + ), mock.patch.object( test_module, "add_version_record", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -193,23 +193,21 @@ async def test_startup_version_no_upgrade_add_record(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=[]), + mock.MagicMock(return_value=[]), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -231,27 +229,27 @@ async def test_startup_version_force_upgrade(self): } builder: ContextBuilder = StubContextBuilder(test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.8.0")), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.8.0")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -265,27 +263,27 @@ async def test_startup_version_force_upgrade(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.7.0")), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.7.0")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.7.2", "v0.7.3", "v0.7.4"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.7.2", "v0.7.3", "v0.7.4"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -299,24 +297,24 @@ async def test_startup_version_force_upgrade(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.CoroutineMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): await conductor.setup() session = await conductor.root_profile.session() @@ -335,27 +333,27 @@ async def test_startup_version_record_not_exists(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.CoroutineMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -389,17 +387,17 @@ async def test_startup_admin_server_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( - test_module, "AdminServer", async_mock.MagicMock() + ) as mock_logger, mock.patch.object( + test_module, "AdminServer", mock.MagicMock() ) as mock_admin_server: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } mock_admin_server.side_effect = ValueError() with self.assertRaises(ValueError): @@ -409,23 +407,21 @@ async def test_startup_no_public_did(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): mock_outbound_mgr.return_value.registered_transports = {} - mock_outbound_mgr.return_value.enqueue_message = async_mock.AsyncMock() - mock_outbound_mgr.return_value.start = async_mock.AsyncMock() - mock_outbound_mgr.return_value.stop = async_mock.AsyncMock() + mock_outbound_mgr.return_value.enqueue_message = mock.CoroutineMock() + mock_outbound_mgr.return_value.start = mock.CoroutineMock() + mock_outbound_mgr.return_value.stop = mock.CoroutineMock() await conductor.setup() mock_inbound_mgr.return_value.setup.assert_awaited_once() @@ -451,20 +447,20 @@ async def test_stats(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_inbound_mgr.return_value.sessions = ["dummy"] mock_outbound_mgr.return_value.outbound_buffer = [ - async_mock.MagicMock(state=QueuedOutboundMessage.STATE_ENCODE), - async_mock.MagicMock(state=QueuedOutboundMessage.STATE_DELIVER), + mock.MagicMock(state=QueuedOutboundMessage.STATE_ENCODE), + mock.MagicMock(state=QueuedOutboundMessage.STATE_DELIVER), ] mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -487,15 +483,15 @@ async def test_inbound_message_handler(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.dispatcher, "queue_message", autospec=True ) as mock_dispatch_q: message_body = "{}" @@ -516,18 +512,18 @@ async def test_inbound_message_handler_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.dispatcher, "queue_message", autospec=True - ) as mock_dispatch_q, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + ) as mock_dispatch_q, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: mock_dispatch_q.side_effect = test_module.LedgerConfigError("ledger down") @@ -559,7 +555,7 @@ async def test_outbound_message_handler_return_route(self): receipt.recipient_verkey = test_from_verkey inbound = InboundMessage("[]", receipt) - with async_mock.patch.object( + with mock.patch.object( conductor.inbound_transport_manager, "return_to_session" ) as mock_return: mock_return.return_value = True @@ -577,11 +573,11 @@ async def test_outbound_message_handler_with_target(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -609,13 +605,13 @@ async def test_outbound_message_handler_with_connection(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as conn_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -651,11 +647,11 @@ async def test_outbound_message_handler_with_verkey_no_target(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -669,8 +665,8 @@ async def test_outbound_message_handler_with_verkey_no_target(self): status = await conductor.outbound_message_router( conductor.root_profile, message, - inbound=async_mock.MagicMock( - receipt=async_mock.MagicMock(recipient_verkey=TestDIDs.test_verkey) + inbound=mock.MagicMock( + receipt=mock.MagicMock(recipient_verkey=TestDIDs.test_verkey) ), ) @@ -688,12 +684,12 @@ async def test_handle_nots(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( - test_module, "OutboundTransportManager", async_mock.MagicMock() + with mock.patch.object( + test_module, "OutboundTransportManager", mock.MagicMock() ) as mock_outbound_mgr: - mock_outbound_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - enqueue_message=async_mock.AsyncMock(), + mock_outbound_mgr.return_value = mock.MagicMock( + setup=mock.CoroutineMock(), + enqueue_message=mock.CoroutineMock(), ) payload = "{}" @@ -707,14 +703,15 @@ async def test_handle_nots(self): conductor.handle_not_returned(conductor.root_profile, message) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_conn_mgr, async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() + ) as mock_conn_mgr, mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() ) as mock_run_task: - mock_conn_mgr.return_value.get_connection_targets = ( - async_mock.AsyncMock() - ) + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + mock_conn_mgr.return_value.get_connection_targets = mock.MagicMock() mock_run_task.side_effect = test_module.ConnectionManagerError() await conductor.queue_outbound(conductor.root_profile, message) mock_outbound_mgr.return_value.enqueue_message.assert_not_called() @@ -729,13 +726,13 @@ async def test_handle_nots(self): async def test_handle_outbound_queue(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - encoded_outbound_message_mock = async_mock.MagicMock(payload="message_payload") + encoded_outbound_message_mock = mock.MagicMock(payload="message_payload") payload = "{}" message = OutboundMessage( payload=payload, connection_id="dummy-conn-id", - target=async_mock.MagicMock(endpoint="endpoint"), + target=mock.MagicMock(endpoint="endpoint"), reply_to_verkey=TestDIDs.test_verkey, ) await conductor.setup() @@ -745,19 +742,24 @@ async def test_handle_not_returned_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() - ) as mock_dispatch_run, async_mock.patch.object( - conductor, "queue_outbound", async_mock.AsyncMock() - ) as mock_queue, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() + ) as mock_dispatch_run, mock.patch.object( + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + conductor, + "queue_outbound", + mock.MagicMock(), + ) as mock_queue, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" @@ -780,22 +782,25 @@ async def test_queue_outbound_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as conn_mgr, async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() - ) as mock_dispatch_run, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + ) as conn_mgr, mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() + ) as mock_dispatch_run, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: - conn_mgr.return_value.get_connection_targets = async_mock.AsyncMock() + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + conn_mgr.return_value.get_connection_targets = mock.MagicMock() mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" ) @@ -817,11 +822,11 @@ async def test_admin(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) builder.update_settings({"admin.enabled": "1"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() admin = conductor.context.inject(BaseAdminServer) @@ -834,16 +839,14 @@ async def test_admin(self): ED25519, ) - with async_mock.patch.object( + with mock.patch.object( admin, "start", autospec=True - ) as admin_start, async_mock.patch.object( + ) as admin_start, mock.patch.object( admin, "stop", autospec=True - ) as admin_stop, async_mock.patch.object( + ) as admin_stop, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() admin_start.assert_awaited_once_with() @@ -861,11 +864,11 @@ async def test_admin_startx(self): } ) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() admin = conductor.context.inject(BaseAdminServer) @@ -878,26 +881,24 @@ async def test_admin_startx(self): ED25519, ) - with async_mock.patch.object( + with mock.patch.object( admin, "start", autospec=True - ) as admin_start, async_mock.patch.object( + ) as admin_start, mock.patch.object( admin, "stop", autospec=True - ) as admin_stop, async_mock.patch.object( + ) as admin_stop, mock.patch.object( test_module, "OutOfBandManager" - ) as oob_mgr, async_mock.patch.object( + ) as oob_mgr, mock.patch.object( test_module, "ConnectionManager" - ) as conn_mgr, async_mock.patch.object( + ) as conn_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): admin_start.side_effect = KeyError("trouble") - oob_mgr.return_value.create_invitation = async_mock.AsyncMock( + oob_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=KeyError("double trouble") ) - conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=KeyError("triple trouble") ) await conductor.start() @@ -910,15 +911,15 @@ async def test_setup_collector(self): builder: ContextBuilder = StubCollectorContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -927,19 +928,17 @@ async def test_start_static(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -950,7 +949,7 @@ async def test_start_static(self): ED25519, ) - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() await conductor.start() mock_mgr.return_value.create_static_connection.assert_awaited_once() @@ -959,22 +958,22 @@ async def test_start_x_in(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "InboundTransportManager" - ) as mock_intx_mgr, async_mock.patch.object( + ) as mock_intx_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: - mock_intx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), + mock_intx_mgr.return_value = mock.MagicMock( + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), ) mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -983,18 +982,18 @@ async def test_start_x_out_a(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "OutboundTransportManager" ) as mock_outx_mgr: - mock_outx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), - registered_transports={"test": async_mock.MagicMock(schemes=["http"])}, + mock_outx_mgr.return_value = mock.MagicMock( + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), + registered_transports={"test": mock.MagicMock(schemes=["http"])}, ) await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -1003,20 +1002,20 @@ async def test_start_x_out_b(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "OutboundTransportManager" ) as mock_outx_mgr: - mock_outx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), - stop=async_mock.AsyncMock(), + mock_outx_mgr.return_value = mock.MagicMock( + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), + stop=mock.CoroutineMock(), registered_transports={}, - enqueue_message=async_mock.AsyncMock(), + enqueue_message=mock.CoroutineMock(), ) await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -1028,7 +1027,7 @@ async def test_dispatch_complete_non_fatal_x(self): receipt = MessageReceipt(direct_response_mode="snail mail") message = InboundMessage(message_body, receipt) exc = KeyError("sample exception") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -1039,16 +1038,16 @@ async def test_dispatch_complete_non_fatal_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: conductor.dispatch_complete(message, mock_task) mock_notify.assert_not_called() @@ -1061,7 +1060,7 @@ async def test_dispatch_complete_fatal_x(self): receipt = MessageReceipt(direct_response_mode="snail mail") message = InboundMessage(message_body, receipt) exc = test_module.LedgerTransactionError("Ledger is wobbly") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -1072,16 +1071,16 @@ async def test_dispatch_complete_fatal_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: conductor.dispatch_complete(message, mock_task) mock_notify.assert_called_once_with() @@ -1097,19 +1096,15 @@ async def test_print_invite_connection(self): ) conductor = test_module.Conductor(builder) - with async_mock.patch( - "sys.stdout", new=StringIO() - ) as captured, async_mock.patch.object( + with mock.patch("sys.stdout", new=StringIO()) as captured, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -1131,26 +1126,22 @@ async def test_clear_default_mediator(self): builder.update_settings({"mediation.clear": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", - return_value=async_mock.MagicMock( - clear_default_mediator=async_mock.AsyncMock() - ), - ) as mock_mgr, async_mock.patch.object( + return_value=mock.MagicMock(clear_default_mediator=mock.CoroutineMock()), + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1161,36 +1152,34 @@ async def test_set_default_mediator(self): builder.update_settings({"mediation.default_id": "test-id"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", - return_value=async_mock.MagicMock( - set_default_mediator_by_id=async_mock.AsyncMock() + return_value=mock.MagicMock( + set_default_mediator_by_id=mock.CoroutineMock() ), - ) as mock_mgr, async_mock.patch.object( - MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ), async_mock.patch.object( + ) as mock_mgr, mock.patch.object( + MediationRecord, "retrieve_by_id", mock.CoroutineMock() + ), mock.patch.object( test_module, "LOGGER", - async_mock.MagicMock( - exception=async_mock.MagicMock( + mock.MagicMock( + exception=mock.MagicMock( side_effect=Exception("This method should not have been called") ) ), - ), async_mock.patch.object( + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1201,26 +1190,22 @@ async def test_set_default_mediator_x(self): builder.update_settings({"mediation.default_id": "test-id"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=Exception()), - ), async_mock.patch.object( - test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + mock.CoroutineMock(side_effect=Exception()), + ), mock.patch.object(test_module, "LOGGER") as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1238,14 +1223,14 @@ async def test_webhook_router(self): test_endpoint = "http://example" test_attempts = 2 - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.outbound_transport_manager, "enqueue_webhook" ) as mock_enqueue: conductor.webhook_router( @@ -1256,7 +1241,7 @@ async def test_webhook_router(self): ) # swallow error - with async_mock.patch.object( + with mock.patch.object( conductor.outbound_transport_manager, "enqueue_webhook", side_effect=OutboundDeliveryError, @@ -1274,15 +1259,15 @@ async def test_shutdown_multitenant_profiles(self): ) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() multitenant_mgr = conductor.context.inject(BaseMultitenantManager) @@ -1290,11 +1275,11 @@ async def test_shutdown_multitenant_profiles(self): multitenant_mgr._profiles.put( "test1", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.CoroutineMock()), ) multitenant_mgr._profiles.put( "test2", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.CoroutineMock()), ) await conductor.stop() @@ -1305,13 +1290,13 @@ async def test_shutdown_multitenant_profiles(self): def get_invite_store_mock( invite_string: str, invite_already_used: bool = False -) -> async_mock.MagicMock: +) -> mock.MagicMock: unused_invite = MediationInviteRecord(invite_string, invite_already_used) used_invite = MediationInviteRecord(invite_string, used=True) - return async_mock.MagicMock( - get_mediation_invite_record=async_mock.AsyncMock(return_value=unused_invite), - mark_default_invite_as_used=async_mock.AsyncMock(return_value=used_invite), + return mock.MagicMock( + get_mediation_invite_record=mock.CoroutineMock(return_value=unused_invite), + mark_default_invite_as_used=mock.CoroutineMock(return_value=used_invite), ) @@ -1330,65 +1315,61 @@ def __get_mediator_config( return builder - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), ) - @async_mock.patch.object(test_module.ConnectionInvitation, "from_url") + @mock.patch.object(test_module.ConnectionInvitation, "from_url") async def test_mediator_invitation_0160(self, mock_from_url, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_conn_record = async_mock.MagicMock() + mock_conn_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", - async_mock.MagicMock( - return_value=async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock( - return_value=mock_conn_record - ) + mock.MagicMock( + return_value=mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=mock_conn_record) ) ), - ) as mock_mgr, async_mock.patch.object( - mock_conn_record, "metadata_set", async_mock.AsyncMock() - ), async_mock.patch.object( + ) as mock_mgr, mock.patch.object( + mock_conn_record, "metadata_set", mock.CoroutineMock() + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() mock_from_url.assert_called_once_with("test-invite") mock_mgr.return_value.receive_invitation.assert_called_once() - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), ) - @async_mock.patch.object(test_module.InvitationMessage, "from_url") + @mock.patch.object(test_module.InvitationMessage, "from_url") async def test_mediator_invitation_0434(self, mock_from_url, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", False) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() conductor.root_profile.context.update_settings( @@ -1410,20 +1391,18 @@ async def test_mediator_invitation_0434(self, mock_from_url, _): connection_id=conn_record.connection_id, state=OobRecord.STATE_INITIAL, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", - async_mock.MagicMock( - return_value=async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=oob_record) + mock.MagicMock( + return_value=mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=oob_record) ) ), - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): assert not conductor.root_profile.settings["mediation.connections_invite"] await conductor.start() @@ -1431,8 +1410,8 @@ async def test_mediator_invitation_0434(self, mock_from_url, _): mock_from_url.assert_called_once_with("test-invite") mock_mgr.return_value.receive_invitation.assert_called_once() - @async_mock.patch.object(test_module, "MediationInviteStore") - @async_mock.patch.object(test_module.ConnectionInvitation, "from_url") + @mock.patch.object(test_module, "MediationInviteStore") + @mock.patch.object(test_module.ConnectionInvitation, "from_url") async def test_mediation_invitation_should_use_stored_invitation( self, patched_from_url, patched_invite_store ): @@ -1448,37 +1427,35 @@ async def test_mediation_invitation_should_use_stored_invitation( conductor = test_module.Conductor( self.__get_mediator_config(invite_string, True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_conn_record = async_mock.MagicMock() + mock_conn_record = mock.MagicMock() mocked_store = get_invite_store_mock(invite_string) patched_invite_store.return_value = mocked_store - connection_manager_mock = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn_record) + connection_manager_mock = mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=mock_conn_record) ) - mock_mediation_manager = async_mock.MagicMock( - clear_default_mediator=async_mock.AsyncMock() + mock_mediation_manager = mock.MagicMock( + clear_default_mediator=mock.CoroutineMock() ) # when - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", return_value=connection_manager_mock - ), async_mock.patch.object( - mock_conn_record, "metadata_set", async_mock.AsyncMock() - ), async_mock.patch.object( + ), mock.patch.object( + mock_conn_record, "metadata_set", mock.CoroutineMock() + ), mock.patch.object( test_module, "MediationManager", return_value=mock_mediation_manager - ), async_mock.patch.object( + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1490,8 +1467,8 @@ async def test_mediation_invitation_should_use_stored_invitation( patched_from_url.assert_called_with(invite_string) mock_mediation_manager.clear_default_mediator.assert_called_once() - @async_mock.patch.object(test_module, "MediationInviteStore") - @async_mock.patch.object(test_module, "ConnectionManager") + @mock.patch.object(test_module, "MediationInviteStore") + @mock.patch.object(test_module, "ConnectionManager") async def test_mediation_invitation_should_not_create_connection_for_old_invitation( self, patched_connection_manager, patched_invite_store ): @@ -1501,27 +1478,25 @@ async def test_mediation_invitation_should_not_create_connection_for_old_invitat conductor = test_module.Conductor( self.__get_mediator_config(invite_string, True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() invite_store_mock = get_invite_store_mock(invite_string, True) patched_invite_store.return_value = invite_store_mock - connection_manager_mock = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock() + connection_manager_mock = mock.MagicMock( + receive_invitation=mock.CoroutineMock() ) patched_connection_manager.return_value = connection_manager_mock - with async_mock.patch.object( + with mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): # when await conductor.start() @@ -1533,7 +1508,7 @@ async def test_mediation_invitation_should_not_create_connection_for_old_invitat ) connection_manager_mock.receive_invitation.assert_not_called() - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), @@ -1542,26 +1517,24 @@ async def test_mediator_invitation_x(self, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "from_url", - async_mock.MagicMock(side_effect=Exception()), - ) as mock_from_url, async_mock.patch.object( + mock.MagicMock(side_effect=Exception()), + ) as mock_from_url, mock.patch.object( test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1574,17 +1547,17 @@ async def test_setup_ledger_both_multiple_and_base(self): builder.update_settings({"ledger.ledger_config_list": [{"...": "..."}]}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "load_multiple_genesis_transactions_from_config", - async_mock.AsyncMock(), - ) as mock_multiple_genesis_load, async_mock.patch.object( - test_module, "get_genesis_transactions", async_mock.AsyncMock() - ) as mock_genesis_load, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_multiple_genesis_load, mock.patch.object( + test_module, "get_genesis_transactions", mock.CoroutineMock() + ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() mock_multiple_genesis_load.assert_called_once() @@ -1595,13 +1568,13 @@ async def test_setup_ledger_only_base(self): builder.update_settings({"ledger.genesis_transactions": "..."}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( - test_module, "get_genesis_transactions", async_mock.AsyncMock() - ) as mock_genesis_load, async_mock.patch.object( + with mock.patch.object( + test_module, "get_genesis_transactions", mock.CoroutineMock() + ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() mock_genesis_load.assert_called_once() @@ -1610,23 +1583,23 @@ async def test_startup_x_no_storage_version(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.CoroutineMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index 8c793c327d..adceb7d5ec 100644 --- a/aries_cloudagent/core/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -1,7 +1,7 @@ import json from unittest import IsolatedAsyncioTestCase -import mock as async_mock +from aries_cloudagent.tests import mock import pytest from marshmallow import EXCLUDE @@ -35,7 +35,7 @@ def make_profile() -> Profile: profile.context.injector.bind_instance(ProtocolRegistry, ProtocolRegistry()) profile.context.injector.bind_instance(Collector, Collector()) profile.context.injector.bind_instance(EventBus, EventBus()) - profile.context.injector.bind_instance(RouteManager, async_mock.MagicMock()) + profile.context.injector.bind_instance(RouteManager, mock.MagicMock()) return profile @@ -109,22 +109,22 @@ async def test_dispatch(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "BaseConnectionManager", autospec=True - ) as conn_mgr_mock, async_mock.patch.object( + ) as conn_mgr_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.MagicMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): - conn_mgr_mock.return_value = async_mock.MagicMock( - find_inbound_connection=async_mock.AsyncMock( - return_value=async_mock.MagicMock(connection_id="dummy") + conn_mgr_mock.return_value = mock.MagicMock( + find_inbound_connection=mock.CoroutineMock( + return_value=mock.MagicMock(connection_id="dummy") ) ) await dispatcher.queue_message( @@ -160,16 +160,16 @@ async def test_dispatch_versioned_message(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.MagicMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -202,7 +202,7 @@ async def test_dispatch_versioned_message_no_message_class(self): rcv = Receiver() message = {"@type": "proto-name/1.1/no-such-message-type"} - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True ) as handler_mock: await dispatcher.queue_message( @@ -236,15 +236,13 @@ async def test_dispatch_versioned_message_message_class_deserialize_x(self): rcv = Receiver() message = {"@type": "proto-name/1.1/no-such-message-type"} - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( - registry, "resolve_message_class", async_mock.MagicMock() + ) as handler_mock, mock.patch.object( + registry, "resolve_message_class", mock.MagicMock() ) as mock_resolve: - mock_resolve.return_value = async_mock.MagicMock( - deserialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ) + mock_resolve.return_value = mock.MagicMock( + deserialize=mock.MagicMock(side_effect=test_module.BaseModelError()) ) await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -281,16 +279,16 @@ async def test_dispatch_versioned_message_handle_greater_succeeds(self): ) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.MagicMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -325,7 +323,7 @@ async def test_dispatch_versioned_message_fail(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True ) as handler_mock: await dispatcher.queue_message( @@ -343,10 +341,10 @@ async def test_bad_message_dispatch_parse_x(self): await dispatcher.setup() rcv = Receiver() bad_messages = ["not even a dict", {"bad": "message"}] - with async_mock.patch.object( - test_module, "get_version_from_message_type", async_mock.AsyncMock() - ), async_mock.patch.object( - test_module, "validate_get_response_version", async_mock.AsyncMock() + with mock.patch.object( + test_module, "get_version_from_message_type", mock.MagicMock() + ), mock.patch.object( + test_module, "validate_get_response_version", mock.CoroutineMock() ): for bad in bad_messages: await dispatcher.queue_message( @@ -397,7 +395,7 @@ async def test_dispatch_log(self): await dispatcher.setup() exc = KeyError("sample exception") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -427,12 +425,12 @@ async def test_create_send_outbound(self): outbound_message = await responder.create_outbound( json.dumps(message.serialize()) ) - with async_mock.patch.object( - responder, "_send", async_mock.AsyncMock() - ), async_mock.patch.object( + with mock.patch.object( + responder, "_send", mock.CoroutineMock() + ), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ): await responder.send_outbound(outbound_message) @@ -452,12 +450,12 @@ async def test_create_send_outbound_with_msg_attrs(self): message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) outbound_message = await responder.create_outbound(message) - with async_mock.patch.object( - responder, "_send", async_mock.AsyncMock() - ), async_mock.patch.object( + with mock.patch.object( + responder, "_send", mock.CoroutineMock() + ), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ): await responder.send_outbound( message=outbound_message, @@ -482,10 +480,10 @@ async def test_create_send_outbound_with_msg_attrs_x(self): responder = test_module.DispatcherResponder(context, message, None) outbound_message = await responder.create_outbound(message) outbound_message.connection_id = "123" - with async_mock.patch.object( + with mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ): with self.assertRaises(RuntimeError): await responder.send_outbound( @@ -508,8 +506,8 @@ async def test_conn_rec_active_state_check_a(self): context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_ret_by_id: conn_rec = test_module.ConnRecord() conn_rec.state = test_module.ConnRecord.State.COMPLETED @@ -529,13 +527,13 @@ async def test_conn_rec_active_state_check_b(self): profile = make_profile() profile.context.injector.bind_instance(BaseCache, InMemoryCache()) profile.context.injector.bind_instance( - EventBus, async_mock.MagicMock(notify=async_mock.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.CoroutineMock()) ) context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_ret_by_id: conn_rec_a = test_module.ConnRecord() conn_rec_a.state = test_module.ConnRecord.State.REQUEST @@ -553,28 +551,28 @@ async def test_create_enc_outbound(self): context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send(message) - assert mock_send_outbound.called_once() + mock_send_outbound.assert_called_once() msg_json = json.dumps(StubAgentMessage().serialize()) message = msg_json.encode("utf-8") - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send(message) message = StubAgentMessage() - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send_reply(message) - assert mock_send_outbound.called_once() + mock_send_outbound.assert_called_once() message = json.dumps(StubAgentMessage().serialize()) - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send_reply(message) @@ -611,14 +609,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.CoroutineMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), + # mock.CoroutineMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -640,14 +638,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.CoroutineMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "version-with-degraded-features")), + # mock.CoroutineMock(return_value=("1.1", "version-with-degraded-features")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -669,14 +667,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.CoroutineMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "version-not-supported")), + # mock.CoroutineMock(return_value=("1.1", "version-not-supported")), # ): # with self.assertRaises(test_module.MessageParseError): # await dispatcher.queue_message( diff --git a/aries_cloudagent/core/tests/test_error.py b/aries_cloudagent/core/tests/test_error.py index 3497b6ca9d..710d450d8a 100644 --- a/aries_cloudagent/core/tests/test_error.py +++ b/aries_cloudagent/core/tests/test_error.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..error import BaseError -class TestBaseError(AsyncTestCase): +class TestBaseError(IsolatedAsyncioTestCase): async def test_base_error(self): err = BaseError() assert err.error_code is None diff --git a/aries_cloudagent/core/tests/test_event_bus.py b/aries_cloudagent/core/tests/test_event_bus.py index 26ce28dacf..0d93b584ce 100644 --- a/aries_cloudagent/core/tests/test_event_bus.py +++ b/aries_cloudagent/core/tests/test_event_bus.py @@ -3,7 +3,7 @@ import pytest import re -from asynctest import mock as async_mock +from unittest import mock from .. import event_bus as test_module from ..event_bus import EventBus, Event @@ -18,7 +18,7 @@ def event_bus(): @pytest.fixture def profile(): - yield async_mock.MagicMock() + yield mock.MagicMock() @pytest.fixture @@ -105,12 +105,12 @@ def _raise_exception(profile, event): bad_processor = _raise_exception event_bus.subscribe(re.compile(".*"), bad_processor) event_bus.subscribe(re.compile(".*"), processor) - with async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: await event_bus.notify(profile, event) - assert mock_log_exc.called_once_with("Error occurred while processing event") + mock_log_exc.assert_called_once_with("Error occurred while processing event") assert processor.profile == profile assert processor.event == event diff --git a/aries_cloudagent/core/tests/test_goal_code_registry.py b/aries_cloudagent/core/tests/test_goal_code_registry.py index 06d161881c..a59aed56c1 100644 --- a/aries_cloudagent/core/tests/test_goal_code_registry.py +++ b/aries_cloudagent/core/tests/test_goal_code_registry.py @@ -1,11 +1,11 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...protocols.issue_credential.v1_0.message_types import CONTROLLERS from ..goal_code_registry import GoalCodeRegistry -class TestGoalCodeRegistry(AsyncTestCase): +class TestGoalCodeRegistry(IsolatedAsyncioTestCase): test_goal_code_queries = "*" test_goal_code_queries_fail = "aries.fake.*" diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index 1db8762c89..dedf89d50c 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -1,8 +1,8 @@ import json -from asynctest import ANY -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock +from unittest.mock import ANY from ...connections.models.conn_record import ConnRecord from ...messaging.decorators.attach_decorator import AttachDecorator @@ -20,15 +20,15 @@ from ..oob_processor import OobMessageProcessor, OobMessageProcessorError -class TestOobProcessor(AsyncTestCase): - async def setUp(self): +class TestOobProcessor(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = async_mock.CoroutineMock() + self.inbound_message_router = mock.MagicMock() self.oob_processor = OobMessageProcessor( inbound_message_router=self.inbound_message_router ) - self.oob_record = async_mock.MagicMock( + self.oob_record = mock.MagicMock( connection_id="a-connection-id", attach_thread_id="the-thid", their_service={ @@ -36,9 +36,9 @@ async def setUp(self): "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], "serviceEndpoint": "http://their-service-endpoint.com", }, - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), + save=mock.CoroutineMock(), ) self.context = RequestContext.test_context() self.context.message = ConnectionInvitation() @@ -47,17 +47,17 @@ async def test_clean_finished_oob_record_no_multi_use_no_request_attach(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - mock_oob = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_oob = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=False, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -75,17 +75,17 @@ async def test_clean_finished_oob_record_multi_use(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - mock_oob = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_oob = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -102,10 +102,10 @@ async def test_clean_finished_oob_record_x(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError(),) @@ -114,11 +114,11 @@ async def test_clean_finished_oob_record_x(self): ) async def test_find_oob_target_for_outbound_message(self): - mock_oob = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_oob = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", their_service={ @@ -136,10 +136,10 @@ async def test_find_oob_target_for_outbound_message(self): message = json.dumps({"~thread": {"thid": "the-thid"}}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -174,10 +174,10 @@ async def test_find_oob_target_for_outbound_message_oob_not_found(self): message = json.dumps({}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -189,11 +189,11 @@ async def test_find_oob_target_for_outbound_message_oob_not_found(self): ) async def test_find_oob_target_for_outbound_message_update_service_thread(self): - mock_oob = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_oob = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", their_service={ @@ -208,10 +208,10 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): }, ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ): message = json.dumps({}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) @@ -247,10 +247,10 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): async def test_find_oob_record_for_inbound_message_parent_thread_id(self): # With pthid - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -263,10 +263,10 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # With pthid, throws error - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -279,10 +279,10 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Without pthid - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -295,10 +295,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( self, ): # With thread_id and recipient_verkey - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -319,10 +319,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( ) # With thread_id and recipient_verkey, throws error - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" @@ -341,15 +341,15 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( ) # With connection - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" ) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() assert not await self.oob_processor.find_oob_record_for_inbound_message( self.context @@ -357,10 +357,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( mock_retrieve.assert_not_called() # Without thread_id and recipient_verkey - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -372,14 +372,14 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="a-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -393,14 +393,14 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is different - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -414,14 +414,14 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is not the same, state is not await response - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -435,22 +435,20 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is not the same, state is AWAIT_RESPONSE. oob has connection_id - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), - ) as mock_retrieve, async_mock.patch.object( + mock.CoroutineMock(return_value=self.oob_record), + ) as mock_retrieve, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - delete_record=async_mock.CoroutineMock() - ) + mock.CoroutineMock( + return_value=mock.MagicMock(delete_record=mock.CoroutineMock()) ), ) as mock_retrieve_conn: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -475,10 +473,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_set(self): AttachDecorator.data_json({"@id": "the-thid"}) ] - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -502,10 +500,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( AttachDecorator.data_json({"@id": "another-thid"}) ] - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -520,10 +518,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( async def test_find_oob_record_for_inbound_message_not_attach_thread_id_matching( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -540,10 +538,10 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc ): self.oob_record.attach_thread_id = "another-thid" - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -558,10 +556,10 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their_service( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -579,10 +577,10 @@ async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their async def test_find_oob_record_for_inbound_message_their_service_matching_with_message_receipt( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -608,10 +606,10 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco self.oob_record.their_service = None - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -633,10 +631,10 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco async def test_find_oob_record_for_inbound_message_session_emit_delete( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -659,10 +657,10 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( ): self.oob_record.connection_id = None - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -680,9 +678,9 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( self.oob_record.save.assert_called_once() async def test_handle_message_connection(self): - oob_record = async_mock.MagicMock( + oob_record = mock.MagicMock( connection_id="the-conn-id", - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), attach_thread_id=None, their_service=None, ) @@ -711,9 +709,7 @@ async def test_handle_message_connection(self): self.inbound_message_router.assert_called_once_with(self.profile, ANY, False) async def test_handle_message_connectionless(self): - oob_record = async_mock.MagicMock( - save=async_mock.CoroutineMock(), connection_id=None - ) + oob_record = mock.MagicMock(save=mock.CoroutineMock(), connection_id=None) await self.oob_processor.handle_message( self.profile, @@ -745,7 +741,7 @@ async def test_handle_message_connectionless(self): async def test_handle_message_unsupported_message_type(self): with self.assertRaises(OobMessageProcessorError) as err: await self.oob_processor.handle_message( - self.profile, [{"@type": "unsupported"}], async_mock.MagicMock() + self.profile, [{"@type": "unsupported"}], mock.MagicMock() ) assert ( "None of the oob attached messages supported. Supported message types are issue-credential/1.0/offer-credential, issue-credential/2.0/offer-credential, present-proof/1.0/request-presentation, present-proof/2.0/request-presentation" diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index 0bbe8c9be4..07c3bd0f69 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,6 +1,8 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock, call +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase +from unittest.mock import call from ...config.injection_context import InjectionContext from ...utils.classloader import ClassLoader, ModuleLoadError @@ -12,42 +14,42 @@ from ..error import ProtocolDefinitionValidationError -class TestPluginRegistry(AsyncTestCase): +class TestPluginRegistry(IsolatedAsyncioTestCase): def setUp(self): self.blocked_module = "blocked_module" self.registry = PluginRegistry(blocklist=[self.blocked_module]) self.context = InjectionContext(enforce_typing=False) - self.proto_registry = async_mock.MagicMock( - register_message_types=async_mock.MagicMock(), - register_controllers=async_mock.MagicMock(), + self.proto_registry = mock.MagicMock( + register_message_types=mock.MagicMock(), + register_controllers=mock.MagicMock(), ) - self.goal_code_registry = async_mock.MagicMock( - register_controllers=async_mock.MagicMock(), + self.goal_code_registry = mock.MagicMock( + register_controllers=mock.MagicMock(), ) self.context.injector.bind_instance(ProtocolRegistry, self.proto_registry) self.context.injector.bind_instance(GoalCodeRegistry, self.goal_code_registry) async def test_setup(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - ctx = async_mock.MagicMock() + ctx = mock.MagicMock() self.registry._plugins[mod_name] = mod assert list(self.registry.plugin_names) == [mod_name] assert list(self.registry.plugins) == [mod] - mod.setup = async_mock.CoroutineMock() + mod.setup = mock.CoroutineMock() await self.registry.init_context(ctx) mod.setup.assert_awaited_once_with(ctx) async def test_register_routes(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() - definition = async_mock.MagicMock() + mod.routes.register = mock.CoroutineMock() + definition = mock.MagicMock() definition.versions = [ { "major_version": 1, @@ -57,10 +59,10 @@ async def test_register_routes(self): } ] - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, mod.routes]), + mock.MagicMock(side_effect=[definition, mod.routes]), ) as load_module: await self.registry.register_admin_routes(app) @@ -71,10 +73,10 @@ async def test_register_routes(self): load_module.assert_has_calls(calls) assert mod.routes.register.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]), + mock.MagicMock(side_effect=[definition, ModuleLoadError()]), ) as load_module: await self.registry.register_admin_routes(app) @@ -87,16 +89,16 @@ async def test_register_routes(self): async def test_register_routes_mod_no_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() + mod.routes.register = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, mod.routes]), + mock.MagicMock(side_effect=[None, mod.routes]), ) as load_module: await self.registry.register_admin_routes(app) @@ -104,10 +106,10 @@ async def test_register_routes_mod_no_version(self): load_module.assert_has_calls(calls) assert mod.routes.register.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, ModuleLoadError()]), + mock.MagicMock(side_effect=[None, ModuleLoadError()]), ) as load_module: await self.registry.register_admin_routes(app) @@ -120,12 +122,12 @@ async def test_register_routes_mod_no_version(self): async def test_post_process_routes(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.post_process_routes = async_mock.MagicMock() - definition = async_mock.MagicMock() + mod.routes.post_process_routes = mock.MagicMock() + definition = mock.MagicMock() definition.versions = [ { "major_version": 1, @@ -135,10 +137,10 @@ async def test_post_process_routes(self): } ] - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, mod.routes]), + mock.MagicMock(side_effect=[definition, mod.routes]), ) as load_module: self.registry.post_process_routes(app) @@ -149,10 +151,10 @@ async def test_post_process_routes(self): load_module.assert_has_calls(calls) assert mod.routes.post_process_routes.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]), + mock.MagicMock(side_effect=[definition, ModuleLoadError()]), ) as load_module: self.registry.post_process_routes(app) @@ -165,16 +167,16 @@ async def test_post_process_routes(self): async def test_post_process_routes_mod_no_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() + mod.routes.register = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, mod.routes]), + mock.MagicMock(side_effect=[None, mod.routes]), ) as load_module: self.registry.post_process_routes(app) @@ -182,10 +184,10 @@ async def test_post_process_routes_mod_no_version(self): load_module.assert_has_calls(calls) assert mod.routes.post_process_routes.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, ModuleLoadError()]), + mock.MagicMock(side_effect=[None, ModuleLoadError()]), ) as load_module: self.registry.post_process_routes(app) @@ -195,46 +197,46 @@ async def test_post_process_routes_mod_no_version(self): async def test_validate_version_not_a_list(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions_not_a_list = {} - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) async def test_validate_version_list_element_not_an_object(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [{}, []] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_element_empty(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_missing_attribute(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -246,15 +248,15 @@ async def test_validate_version_list_missing_attribute(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_negative_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -266,15 +268,15 @@ async def test_validate_version_negative_version(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_min_greater_current(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -286,15 +288,15 @@ async def test_validate_version_min_greater_current(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_multiple_major(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -312,15 +314,15 @@ async def test_validate_version_multiple_major(self): }, ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_bad_path(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -332,15 +334,15 @@ async def test_validate_version_bad_path(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=None) + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock(return_value=None) ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_correct(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -358,8 +360,8 @@ async def test_validate_version_list_correct(self): }, ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions, mod_name) is True @@ -370,7 +372,7 @@ async def test_validate_version_list_correct(self): async def test_validate_version_list_extra_attributes_ok(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -383,14 +385,14 @@ async def test_validate_version_list_extra_attributes_ok(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions, mod_name) is True async def test_validate_version_no_such_mod(self): mod_name = "no_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -402,8 +404,8 @@ async def test_validate_version_no_such_mod(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = None @@ -412,20 +414,20 @@ async def test_validate_version_no_such_mod(self): async def test_register_plugin_already_present(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() self.registry._plugins[mod_name] = mod assert mod == self.registry.register_plugin(mod_name) async def test_register_plugin_load_x(self): - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError("failure to load") assert self.registry.register_plugin("dummy") is None async def test_register_plugin_no_mod(self): - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = None assert self.registry.register_plugin("dummy") is None @@ -435,8 +437,8 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -451,8 +453,8 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -467,8 +469,8 @@ class MODULE: setup = "present" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -483,8 +485,8 @@ class MODULE: setup = "present" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -500,58 +502,58 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module None, # routes None, # message types - async_mock.MagicMock(versions="not-a-list"), + mock.MagicMock(versions="not-a-list"), ] assert self.registry.register_plugin("dummy") is None async def test_register_package_x(self): - with async_mock.patch.object( - ClassLoader, "scan_subpackages", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "scan_subpackages", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError() assert not self.registry.register_package("dummy") async def test_load_protocols_load_x(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + mock_plugin = mock.MagicMock(__name__="dummy") + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError() await self.registry.load_protocols(None, mock_plugin) assert load_module.call_count == 1 async def test_load_protocols_load_mod(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_mod = async_mock.MagicMock() - mock_mod.MESSAGE_TYPES = async_mock.MagicMock() - mock_mod.CONTROLLERS = async_mock.MagicMock() + mock_plugin = mock.MagicMock(__name__="dummy") + mock_mod = mock.MagicMock() + mock_mod.MESSAGE_TYPES = mock.MagicMock() + mock_mod.CONTROLLERS = mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = mock_mod await self.registry.load_protocols(self.context, mock_plugin) async def test_load_protocols_no_mod_load_x(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") + mock_plugin = mock.MagicMock(__name__="dummy") - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, ModuleLoadError()] await self.registry.load_protocols(self.context, mock_plugin) assert load_module.call_count == 2 async def test_load_protocols_no_mod_def_no_message_types(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_def = async_mock.MagicMock( + mock_plugin = mock.MagicMock(__name__="dummy") + mock_def = mock.MagicMock( versions=[ { "major_version": 1, @@ -562,16 +564,16 @@ async def test_load_protocols_no_mod_def_no_message_types(self): ] ) - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, mock_def, ModuleLoadError()] await self.registry.load_protocols(self.context, mock_plugin) assert load_module.call_count == 3 async def test_load_protocols_no_mod_def_message_types(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_def = async_mock.MagicMock( + mock_plugin = mock.MagicMock(__name__="dummy") + mock_def = mock.MagicMock( versions=[ { "major_version": 1, @@ -587,12 +589,12 @@ async def test_load_protocols_no_mod_def_message_types(self): }, ] ) - mock_mod = async_mock.MagicMock() - mock_mod.MESSAGE_TYPES = async_mock.MagicMock() - mock_mod.CONTROLLERS = async_mock.MagicMock() + mock_mod = mock.MagicMock() + mock_mod.MESSAGE_TYPES = mock.MagicMock() + mock_mod.CONTROLLERS = mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, mock_def, mock_mod, mock_mod] await self.registry.load_protocols(self.context, mock_plugin) diff --git a/aries_cloudagent/core/tests/test_profile.py b/aries_cloudagent/core/tests/test_profile.py index 72d4c3e0e8..9e45badeb0 100644 --- a/aries_cloudagent/core/tests/test_profile.py +++ b/aries_cloudagent/core/tests/test_profile.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...config.base import InjectionError from ...config.injection_context import InjectionContext @@ -20,7 +20,7 @@ def transaction(self, context: InjectionContext = None) -> ProfileSession: """ -class TestProfileSession(AsyncTestCase): +class TestProfileSession(IsolatedAsyncioTestCase): async def test_session_active(self): profile = MockProfile() session = ProfileSession(profile) @@ -55,7 +55,7 @@ async def test_session_active(self): await session2.rollback() -class TestProfileManagerProvider(AsyncTestCase): +class TestProfileManagerProvider(IsolatedAsyncioTestCase): async def test_basic_wallet_type(self): context = InjectionContext() provider = ProfileManagerProvider() diff --git a/aries_cloudagent/core/tests/test_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py index 2800f2c46f..d5383bba1d 100644 --- a/aries_cloudagent/core/tests/test_protocol_registry.py +++ b/aries_cloudagent/core/tests/test_protocol_registry.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...utils.classloader import ClassLoader @@ -6,7 +7,7 @@ from ..protocol_registry import ProtocolRegistry -class TestProtocolRegistry(AsyncTestCase): +class TestProtocolRegistry(IsolatedAsyncioTestCase): no_type_message = {"a": "b"} unknown_type_message = {"@type": 1} test_message_type = "PROTOCOL/MESSAGE" @@ -204,17 +205,17 @@ async def test_disclosed(self): self.registry.register_message_types( {self.test_message_type: self.test_message_handler} ) - mock = async_mock.MagicMock() - mock.return_value.check_access = async_mock.CoroutineMock() - mock.return_value.check_access.return_value = True - mock.return_value.determine_roles = async_mock.CoroutineMock() - mock.return_value.determine_roles.return_value = ["ROLE"] - self.registry.register_controllers({self.test_protocol: mock}) + mocked = mock.MagicMock() + mocked.return_value.check_access = mock.CoroutineMock() + mocked.return_value.check_access.return_value = True + mocked.return_value.determine_roles = mock.CoroutineMock() + mocked.return_value.determine_roles.return_value = ["ROLE"] + self.registry.register_controllers({self.test_protocol: mocked}) protocols = [self.test_protocol] ctx = InjectionContext() published = await self.registry.prepare_disclosed(ctx, protocols) - mock.return_value.check_access.assert_called_once_with(ctx) - mock.return_value.determine_roles.assert_called_once_with(ctx) + mocked.return_value.check_access.assert_called_once_with(ctx) + mocked.return_value.determine_roles.assert_called_once_with(ctx) assert len(published) == 1 assert published[0]["pid"] == self.test_protocol assert published[0]["roles"] == ["ROLE"] @@ -234,8 +235,8 @@ def __init__(self, protocol): async def check_access(self, context): return False - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.return_value = Mockery published = await self.registry.prepare_disclosed(ctx, protocols) @@ -245,9 +246,9 @@ def test_resolve_message_class_str(self): self.registry.register_message_types( {self.test_message_type: self.test_message_handler} ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.return_value = mock_class result = self.registry.resolve_message_class(self.test_message_type) @@ -268,9 +269,9 @@ def test_resolve_message_load_class_str(self): "path": "v1_2", }, ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.side_effect = [mock_class, mock_class] result = self.registry.resolve_message_class("proto/1.1/aaa") @@ -287,9 +288,9 @@ def test_resolve_message_load_class_none(self): "path": "v1_2", }, ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.side_effect = [mock_class, mock_class] result = self.registry.resolve_message_class("proto/1.2/bbb") diff --git a/aries_cloudagent/holder/tests/test_routes.py b/aries_cloudagent/holder/tests/test_routes.py index ad92934be5..88323ce8e0 100644 --- a/aries_cloudagent/holder/tests/test_routes.py +++ b/aries_cloudagent/holder/tests/test_routes.py @@ -1,6 +1,7 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -30,14 +31,14 @@ ) -class TestHolderRoutes(AsyncTestCase): +class TestHolderRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) self.request_dict = {"context": self.context} - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -48,15 +49,15 @@ async def test_credentials_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credential=async_mock.CoroutineMock( + mock.MagicMock( + get_credential=mock.CoroutineMock( return_value=json.dumps({"hello": "world"}) ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_get(self.request) json_response.assert_called_once_with({"hello": "world"}) @@ -66,8 +67,8 @@ async def test_credentials_get_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credential=async_mock.CoroutineMock( + mock.MagicMock( + get_credential=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -79,17 +80,15 @@ async def test_credentials_get_not_found(self): async def test_credentials_revoked(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock(return_value=False) - ), + mock.MagicMock(credential_revoked=mock.CoroutineMock(return_value=False)), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_revoked(self.request) json_response.assert_called_once_with({"revoked": False}) @@ -104,12 +103,12 @@ async def test_credentials_revoked_no_ledger(self): async def test_credentials_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock( + mock.MagicMock( + credential_revoked=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError("no such cred") ) ), @@ -120,14 +119,14 @@ async def test_credentials_not_found(self): async def test_credentials_x_ledger(self): self.request.match_info = {"credential_id": "dummy"} - ledger = async_mock.create_autospec(BaseLedger) + ledger = mock.create_autospec(BaseLedger) self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock( + mock.MagicMock( + credential_revoked=mock.CoroutineMock( side_effect=test_module.LedgerError("down for maintenance") ) ), @@ -140,18 +139,18 @@ async def test_attribute_mime_types_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_mime_type=async_mock.CoroutineMock( + mock.MagicMock( + get_mime_type=mock.CoroutineMock( side_effect=[None, {"a": "application/jpeg"}] ) ), ) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credentials_attr_mime_types_get(self.request) mock_response.assert_called_once_with({"results": None}) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credentials_attr_mime_types_get(self.request) mock_response.assert_called_once_with( {"results": {"a": "application/jpeg"}} @@ -161,13 +160,11 @@ async def test_credentials_remove(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - delete_credential=async_mock.CoroutineMock(return_value=None) - ), + mock.MagicMock(delete_credential=mock.CoroutineMock(return_value=None)), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_remove(self.request) json_response.assert_called_once_with({}) @@ -177,8 +174,8 @@ async def test_credentials_remove_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - delete_credential=async_mock.CoroutineMock( + mock.MagicMock( + delete_credential=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -190,15 +187,13 @@ async def test_credentials_list(self): self.request.query = {"start": "0", "count": "10"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials=async_mock.CoroutineMock( - return_value=[{"hello": "world"}] - ) + mock.MagicMock( + get_credentials=mock.CoroutineMock(return_value=[{"hello": "world"}]) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_list(self.request) json_response.assert_called_once_with({"results": [{"hello": "world"}]}) @@ -208,8 +203,8 @@ async def test_credentials_list_x_holder(self): self.request.query = {"start": "0", "count": "10"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials=async_mock.CoroutineMock( + mock.MagicMock( + get_credentials=mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) ), @@ -222,15 +217,13 @@ async def test_w3c_cred_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ) + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_cred_get(self.request) json_response.assert_called_once_with(VC_RECORD.serialize()) @@ -239,8 +232,8 @@ async def test_w3c_cred_get_not_found_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -253,8 +246,8 @@ async def test_w3c_cred_get_storage_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageError() ) ), @@ -267,16 +260,14 @@ async def test_w3c_cred_remove(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ), - delete_credential=async_mock.CoroutineMock(return_value=None), + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD), + delete_credential=mock.CoroutineMock(return_value=None), ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_cred_remove(self.request) json_response.assert_called_once_with({}) @@ -286,8 +277,8 @@ async def test_w3c_cred_remove_not_found_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -300,11 +291,9 @@ async def test_w3c_cred_remove_storage_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ), - delete_credential=async_mock.CoroutineMock( + mock.MagicMock( + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD), + delete_credential=mock.CoroutineMock( side_effect=test_module.StorageError() ), ), @@ -314,7 +303,7 @@ async def test_w3c_cred_remove_storage_x(self): await test_module.w3c_cred_remove(self.request) async def test_w3c_creds_list(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -327,23 +316,23 @@ async def test_w3c_creds_list(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=[VC_RECORD]) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=[VC_RECORD]) ) ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_creds_list(self.request) json_response.assert_called_once_with({"results": [VC_RECORD.serialize()]}) async def test_w3c_creds_list_not_found_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -356,10 +345,10 @@ async def test_w3c_creds_list_not_found_x(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -371,7 +360,7 @@ async def test_w3c_creds_list_not_found_x(self): await test_module.w3c_creds_list(self.request) async def test_w3c_creds_list_storage_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -384,12 +373,10 @@ async def test_w3c_creds_list_storage_x(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(side_effect=test_module.StorageError()) ) ) ), @@ -399,13 +386,13 @@ async def test_w3c_creds_list_storage_x(self): await test_module.w3c_creds_list(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py index 33ff63b930..4ef865101f 100644 --- a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py +++ b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py @@ -2,7 +2,8 @@ import tempfile import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager from ....config.injection_context import InjectionContext @@ -42,21 +43,19 @@ @pytest.mark.askar @pytest.mark.indy_credx -class TestIndyCredxIssuance(AsyncTestCase): - async def setUp(self): +class TestIndyCredxIssuance(IsolatedAsyncioTestCase): + async def asyncSetUp(self): context = InjectionContext(enforce_typing=False) - mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( - return_value={"value": {}} - ), - get_revoc_reg_delta=async_mock.CoroutineMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.CoroutineMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.CoroutineMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.CoroutineMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.CoroutineMock(return_value=mock_ledger) self.ledger = mock_ledger self.holder_profile = await AskarProfileManager().provision( @@ -78,8 +77,8 @@ async def setUp(self): self.issuer_profile._context.injector.bind_instance(BaseLedger, mock_ledger) self.issuer_profile._context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, mock_ledger) ) ), diff --git a/aries_cloudagent/indy/models/tests/test_pres_preview.py b/aries_cloudagent/indy/models/tests/test_pres_preview.py index 5f5809b889..85efec79f9 100644 --- a/aries_cloudagent/indy/models/tests/test_pres_preview.py +++ b/aries_cloudagent/indy/models/tests/test_pres_preview.py @@ -5,8 +5,8 @@ from time import time from unittest import TestCase -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....ledger.multiple_ledger.ledger_requests_executor import ( @@ -351,7 +351,7 @@ def test_eq(self): @pytest.mark.indy -class TestIndyPresPreviewAsync(AsyncTestCase): +class TestIndyPresPreviewAsync(IsolatedAsyncioTestCase): """Presentation preview tests""" @pytest.mark.asyncio @@ -402,13 +402,13 @@ async def test_to_indy_proof_request_revo_default_interval(self): context.injector.bind_instance( IndyLedgerRequestsExecutor, IndyLedgerRequestsExecutor(mock_profile) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + mock.MagicMock( + get_credential_definition=mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), @@ -447,15 +447,15 @@ async def test_to_indy_proof_request_revo(self): ) context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + mock.MagicMock( + get_credential_definition=mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), diff --git a/aries_cloudagent/indy/sdk/tests/test_holder.py b/aries_cloudagent/indy/sdk/tests/test_holder.py index c67cfd375c..f9a3084958 100644 --- a/aries_cloudagent/indy/sdk/tests/test_holder.py +++ b/aries_cloudagent/indy/sdk/tests/test_holder.py @@ -1,7 +1,8 @@ import json import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase import indy.anoncreds @@ -13,25 +14,25 @@ @pytest.mark.indy -class TestIndySdkHolder(AsyncTestCase): +class TestIndySdkHolder(IsolatedAsyncioTestCase): def setUp(self): - mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.MagicMock(return_value={"value": {}}), - get_revoc_reg_delta=async_mock.CoroutineMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.MagicMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.CoroutineMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.CoroutineMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.CoroutineMock(return_value=mock_ledger) self.ledger = mock_ledger - self.wallet = async_mock.MagicMock() + self.wallet = mock.MagicMock() self.holder = test_module.IndySdkHolder(self.wallet) assert "IndySdkHolder" in str(self.holder) - @async_mock.patch("indy.anoncreds.prover_create_credential_req") + @mock.patch("indy.anoncreds.prover_create_credential_req") async def test_create_credential_request(self, mock_create_credential_req): mock_create_credential_req.return_value = ("{}", "[]") @@ -49,7 +50,7 @@ async def test_create_credential_request(self, mock_create_credential_req): assert (json.loads(cred_req_json), json.loads(cred_req_meta_json)) == ({}, []) - @async_mock.patch("indy.anoncreds.prover_store_credential") + @mock.patch("indy.anoncreds.prover_store_credential") async def test_store_credential(self, mock_store_cred): mock_store_cred.return_value = "cred_id" @@ -68,14 +69,12 @@ async def test_store_credential(self, mock_store_cred): assert cred_id == "cred_id" - @async_mock.patch("indy.anoncreds.prover_store_credential") + @mock.patch("indy.anoncreds.prover_store_credential") async def test_store_credential_with_mime_types(self, mock_store_cred): - with async_mock.patch.object( - test_module, "IndySdkStorage", async_mock.MagicMock() + with mock.patch.object( + test_module, "IndySdkStorage", mock.MagicMock() ) as mock_storage: - mock_storage.return_value = async_mock.MagicMock( - add_record=async_mock.CoroutineMock() - ) + mock_storage.return_value = mock.MagicMock(add_record=mock.CoroutineMock()) mock_store_cred.return_value = "cred_id" @@ -99,7 +98,7 @@ async def test_store_credential_with_mime_types(self, mock_store_cred): assert cred_id == "cred_id" - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attrs_mime_types(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -124,7 +123,7 @@ async def test_get_credential_attrs_mime_types(self, mock_nonsec_get_wallet_reco assert mime_types == dummy_tags - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attr_mime_type(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -149,7 +148,7 @@ async def test_get_credential_attr_mime_type(self, mock_nonsec_get_wallet_record assert a_mime_type == dummy_tags["a"] - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attr_mime_type_x(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -163,9 +162,9 @@ async def test_get_credential_attr_mime_type_x(self, mock_nonsec_get_wallet_reco assert await self.holder.get_mime_type(cred_id, "a") is None - @async_mock.patch("indy.anoncreds.prover_search_credentials") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search") + @mock.patch("indy.anoncreds.prover_search_credentials") + @mock.patch("indy.anoncreds.prover_fetch_credentials") + @mock.patch("indy.anoncreds.prover_close_credentials_search") async def test_get_credentials( self, mock_close_cred_search, mock_fetch_credentials, mock_search_credentials ): @@ -193,9 +192,9 @@ async def test_get_credentials( credentials = await self.holder.get_credentials(0, 0, {}) # 0 defaults to all assert len(credentials) == SIZE - @async_mock.patch("indy.anoncreds.prover_search_credentials") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search") + @mock.patch("indy.anoncreds.prover_search_credentials") + @mock.patch("indy.anoncreds.prover_fetch_credentials") + @mock.patch("indy.anoncreds.prover_close_credentials_search") async def test_get_credentials_seek( self, mock_close_cred_search, mock_fetch_credentials, mock_search_credentials ): @@ -208,9 +207,9 @@ async def test_get_credentials_seek( (("search_handle", 3),), ] - @async_mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") + @mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") async def test_get_credentials_for_presentation_request_by_reft( self, mock_prover_close_credentials_search_for_proof_req, @@ -288,9 +287,9 @@ async def test_get_credentials_for_presentation_request_by_reft( for c in credentials[-test_module.IndyHolder.CHUNK // 2 :] ) # revocable last - @async_mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") + @mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") async def test_get_credentials_for_presentation_request_by_referent_default_refts( self, mock_prover_close_credentials_search_for_proof_req, @@ -323,7 +322,7 @@ async def test_get_credentials_for_presentation_request_by_referent_default_reft self.wallet.handle, json.dumps(PRES_REQ), json.dumps({}) ) - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential(self, mock_get_cred): mock_get_cred.return_value = "{}" credential_json = await self.holder.get_credential("credential_id") @@ -331,13 +330,13 @@ async def test_get_credential(self, mock_get_cred): assert json.loads(credential_json) == {} - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential_not_found(self, mock_get_cred): mock_get_cred.side_effect = IndyError(error_code=ErrorCode.WalletItemNotFound) with self.assertRaises(test_module.WalletNotFoundError): await self.holder.get_credential("credential_id") - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential_x(self, mock_get_cred): mock_get_cred.side_effect = IndyError("unexpected failure") @@ -345,8 +344,8 @@ async def test_get_credential_x(self, mock_get_cred): await self.holder.get_credential("credential_id") async def test_credential_revoked(self): - with async_mock.patch.object( # no creds revoked - self.holder, "get_credential", async_mock.CoroutineMock() + with mock.patch.object( # no creds revoked + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -358,8 +357,8 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - with async_mock.patch.object( # cred not revocable - self.holder, "get_credential", async_mock.CoroutineMock() + with mock.patch.object( # cred not revocable + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -371,7 +370,7 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "value": { @@ -382,8 +381,8 @@ async def test_credential_revoked(self): 1234567890, ) ) - with async_mock.patch.object( # cred not revoked - self.holder, "get_credential", async_mock.CoroutineMock() + with mock.patch.object( # cred not revoked + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -395,8 +394,8 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - with async_mock.patch.object( # cred revoked - self.holder, "get_credential", async_mock.CoroutineMock() + with mock.patch.object( # cred revoked + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -408,9 +407,9 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert result - @async_mock.patch("indy.anoncreds.prover_delete_credential") - @async_mock.patch("indy.non_secrets.get_wallet_record") - @async_mock.patch("indy.non_secrets.delete_wallet_record") + @mock.patch("indy.anoncreds.prover_delete_credential") + @mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.delete_wallet_record") async def test_delete_credential( self, mock_nonsec_del_wallet_record, @@ -432,9 +431,9 @@ async def test_delete_credential( self.wallet.handle, "credential_id" ) - @async_mock.patch("indy.anoncreds.prover_delete_credential") - @async_mock.patch("indy.non_secrets.get_wallet_record") - @async_mock.patch("indy.non_secrets.delete_wallet_record") + @mock.patch("indy.anoncreds.prover_delete_credential") + @mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.delete_wallet_record") async def test_delete_credential_x( self, mock_nonsec_del_wallet_record, @@ -459,7 +458,7 @@ async def test_delete_credential_x( await self.holder.delete_credential("credential_id") assert mock_prover_del_cred.call_count == 2 - @async_mock.patch("indy.anoncreds.prover_create_proof") + @mock.patch("indy.anoncreds.prover_create_proof") async def test_create_presentation(self, mock_create_proof): mock_create_proof.return_value = "{}" PROOF_REQ = { @@ -577,10 +576,10 @@ async def test_create_revocation_state(self): "timestamp": 1234567890, } - with async_mock.patch.object( - test_module, "create_tails_reader", async_mock.CoroutineMock() - ) as mock_create_tails_reader, async_mock.patch.object( - indy.anoncreds, "create_revocation_state", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "create_tails_reader", mock.CoroutineMock() + ) as mock_create_tails_reader, mock.patch.object( + indy.anoncreds, "create_revocation_state", mock.CoroutineMock() ) as mock_create_rr_state: mock_create_rr_state.return_value = json.dumps(rr_state) diff --git a/aries_cloudagent/indy/sdk/tests/test_issuer.py b/aries_cloudagent/indy/sdk/tests/test_issuer.py index b977512fef..d0946a65d7 100644 --- a/aries_cloudagent/indy/sdk/tests/test_issuer.py +++ b/aries_cloudagent/indy/sdk/tests/test_issuer.py @@ -1,7 +1,8 @@ import json import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from indy.error import ( AnoncredsRevocationRegistryFullError, @@ -35,8 +36,8 @@ @pytest.mark.indy -class TestIndySdkIssuer(AsyncTestCase): - async def setUp(self): +class TestIndySdkIssuer(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = InjectionContext() self.context.injector.bind_instance( IndySdkLedgerPool, IndySdkLedgerPool("name") @@ -51,7 +52,7 @@ async def setUp(self): "name": "test-wallet", } ).create_wallet() - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile(self.wallet, self.context) self.issuer = test_module.IndySdkIssuer(self.profile) @@ -61,7 +62,7 @@ async def tearDown(self): async def test_repr(self): assert "IndySdkIssuer" in str(self.issuer) # cover __repr__ - @async_mock.patch("indy.anoncreds.issuer_create_and_store_credential_def") + @mock.patch("indy.anoncreds.issuer_create_and_store_credential_def") async def test_schema_cred_def(self, mock_indy_cred_def): assert ( self.issuer.make_schema_id(TEST_DID, SCHEMA_NAME, SCHEMA_VERSION) @@ -93,19 +94,19 @@ async def test_schema_cred_def(self, mock_indy_cred_def): ) ) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet(self, mock_indy_create_offer): mock_indy_create_offer.return_value = {"sample": "offer"} assert await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet_no(self, mock_indy_create_offer): mock_indy_create_offer.side_effect = WalletItemNotFound( error_code=ErrorCode.WalletItemNotFound ) assert not await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet_x(self, mock_indy_create_offer): mock_indy_create_offer.side_effect = IndyError( error_code=ErrorCode.WalletInvalidHandle @@ -113,12 +114,12 @@ async def test_credential_definition_in_wallet_x(self, mock_indy_create_offer): with self.assertRaises(test_module.IndyIssuerError): await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_create_credential_offer(self, mock_create_offer): test_offer = {"test": "offer"} test_cred_def_id = "test-cred-def-id" mock_create_offer.return_value = json.dumps(test_offer) - mock_profile = async_mock.MagicMock() + mock_profile = mock.MagicMock() issuer = test_module.IndySdkIssuer(mock_profile) offer_json = await issuer.create_credential_offer(test_cred_def_id) assert json.loads(offer_json) == test_offer @@ -126,10 +127,10 @@ async def test_create_credential_offer(self, mock_create_offer): mock_profile.wallet.handle, test_cred_def_id ) - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) - @async_mock.patch("indy.anoncreds.issuer_revoke_credential") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_revoke_credential") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_create_revoke_credentials( self, mock_indy_merge_rr_deltas, @@ -211,10 +212,10 @@ async def test_create_revoke_credentials( assert mock_indy_revoke_credential.call_count == 2 mock_indy_merge_rr_deltas.assert_called_once() - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) - @async_mock.patch("indy.anoncreds.issuer_revoke_credential") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_revoke_credential") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_create_revoke_credentials_x( self, mock_indy_merge_rr_deltas, @@ -309,8 +310,8 @@ def mock_revoke(_h, _t, _r, cred_rev_id): assert mock_indy_revoke_credential.call_count == 3 mock_indy_merge_rr_deltas.assert_not_called() - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) async def test_create_credential_rr_full( self, mock_tails_reader, @@ -340,8 +341,8 @@ async def test_create_credential_rr_full( test_values, ) - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) async def test_create_credential_x_indy( self, mock_tails_reader, @@ -372,8 +373,8 @@ async def test_create_credential_x_indy( test_values, ) - @async_mock.patch("indy.anoncreds.issuer_create_and_store_revoc_reg") - @async_mock.patch.object(test_module, "create_tails_writer", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_and_store_revoc_reg") + @mock.patch.object(test_module, "create_tails_writer", autospec=True) async def test_create_and_store_revocation_registry( self, mock_indy_tails_writer, mock_indy_rr ): @@ -387,7 +388,7 @@ async def test_create_and_store_revocation_registry( ) assert (rr_id, rrdef_json, rre_json) == ("a", "b", "c") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_merge_revocation_registry_deltas(self, mock_indy_merge): mock_indy_merge.return_value = json.dumps({"net": "delta"}) assert {"net": "delta"} == json.loads( diff --git a/aries_cloudagent/indy/sdk/tests/test_profile.py b/aries_cloudagent/indy/sdk/tests/test_profile.py index 9440adc605..11f7edc6bf 100644 --- a/aries_cloudagent/indy/sdk/tests/test_profile.py +++ b/aries_cloudagent/indy/sdk/tests/test_profile.py @@ -1,6 +1,6 @@ import logging -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock import pytest from ....config.injection_context import InjectionContext @@ -20,7 +20,7 @@ async def open_wallet(): handle=1, master_secret_id="master-secret", ) - with async_mock.patch.object(opened, "close", async_mock.CoroutineMock()): + with mock.patch.object(opened, "close", mock.CoroutineMock()): yield opened @@ -47,12 +47,12 @@ async def test_init_multi_ledger(open_wallet): "is_write": True, "endorser_did": "9QPa6tHvBHttLg6U4xvviv", "endorser_alias": "endorser_dev", - "genesis_transactions": async_mock.MagicMock(), + "genesis_transactions": mock.MagicMock(), }, { "id": "SovrinStagingNet", "is_production": False, - "genesis_transactions": async_mock.MagicMock(), + "genesis_transactions": mock.MagicMock(), }, ] } @@ -82,18 +82,18 @@ async def test_properties(profile: IndySdkProfile): assert profile.wallet.created assert profile.wallet.master_secret_id == "master-secret" - with async_mock.patch.object(profile, "opened", False): + with mock.patch.object(profile, "opened", False): with pytest.raises(ProfileError): await profile.remove() - with async_mock.patch.object(profile.opened, "close", async_mock.CoroutineMock()): + with mock.patch.object(profile.opened, "close", mock.CoroutineMock()): await profile.remove() assert profile.opened is None def test_settings_genesis_transactions(open_wallet): context = InjectionContext( - settings={"ledger.genesis_transactions": async_mock.MagicMock()} + settings={"ledger.genesis_transactions": mock.MagicMock()} ) context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) profile = IndySdkProfile(open_wallet, context) @@ -103,8 +103,8 @@ def test_settings_ledger_config(open_wallet): context = InjectionContext( settings={ "ledger.ledger_config_list": [ - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ] } ) diff --git a/aries_cloudagent/indy/sdk/tests/test_util.py b/aries_cloudagent/indy/sdk/tests/test_util.py index be3f5ee36b..fb587d8f40 100644 --- a/aries_cloudagent/indy/sdk/tests/test_util.py +++ b/aries_cloudagent/indy/sdk/tests/test_util.py @@ -4,7 +4,8 @@ import indy.blob_storage -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...util import indy_client_dir, generate_pr_nonce @@ -12,7 +13,7 @@ @pytest.mark.indy -class TestIndyUtils(AsyncTestCase): +class TestIndyUtils(IsolatedAsyncioTestCase): TAILS_HASH = "8UW1Sz5cqoUnK9hqQk7nvtKK65t7Chu3ui866J23sFyJ" def tearDown(self): @@ -26,8 +27,8 @@ async def test_tails_reader(self): with open(tails_local, "a") as f: print("1234123412431234", file=f) - with async_mock.patch.object( - indy.blob_storage, "open_reader", async_mock.CoroutineMock() + with mock.patch.object( + indy.blob_storage, "open_reader", mock.CoroutineMock() ) as mock_blob_open_reader: result = await create_tails_reader(tails_local) assert result == mock_blob_open_reader.return_value diff --git a/aries_cloudagent/indy/sdk/tests/test_verifier.py b/aries_cloudagent/indy/sdk/tests/test_verifier.py index d4abc1bdd1..964514c0c9 100644 --- a/aries_cloudagent/indy/sdk/tests/test_verifier.py +++ b/aries_cloudagent/indy/sdk/tests/test_verifier.py @@ -3,7 +3,8 @@ from copy import deepcopy -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from indy.error import IndyError from ....core.in_memory import InMemoryProfile @@ -291,10 +292,10 @@ @pytest.mark.indy -class TestIndySdkVerifier(AsyncTestCase): +class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": { @@ -323,15 +324,15 @@ def setUp(self): self.verifier = IndySdkVerifier(mock_profile) assert repr(self.verifier) == "" - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_verify_presentation(self, mock_verify): mock_verify.return_value = "val" - with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.CoroutineMock() - ) as mock_pre_verify, async_mock.patch.object( - self.verifier, "non_revoc_intervals", async_mock.MagicMock() - ) as mock_non_revox, async_mock.patch.object( + with mock.patch.object( + self.verifier, "pre_verify", mock.CoroutineMock() + ) as mock_pre_verify, mock.patch.object( + self.verifier, "non_revoc_intervals", mock.MagicMock() + ) as mock_non_revox, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -358,15 +359,15 @@ async def test_verify_presentation(self, mock_verify): assert verified == "val" - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_verify_presentation_x_indy(self, mock_verify): mock_verify.side_effect = IndyError(error_code=1) - with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.CoroutineMock() - ) as mock_pre_verify, async_mock.patch.object( - self.verifier, "non_revoc_intervals", async_mock.MagicMock() - ) as mock_non_revox, async_mock.patch.object( + with mock.patch.object( + self.verifier, "pre_verify", mock.CoroutineMock() + ) as mock_pre_verify, mock.patch.object( + self.verifier, "non_revoc_intervals", mock.MagicMock() + ) as mock_non_revox, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -390,9 +391,9 @@ async def test_verify_presentation_x_indy(self, mock_verify): assert not verified - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr(self, mock_verify): - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -418,13 +419,13 @@ async def test_check_encoding_attr(self, mock_verify): assert len(msgs) == 1 assert "TS_OUT_NRI::19_uuid" in msgs - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr_tamper_raw(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_NAME) INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][ "raw" ] = "Mock chicken" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -446,13 +447,13 @@ async def test_check_encoding_attr_tamper_raw(self, mock_verify): "VALUE_ERROR::Encoded representation mismatch for 'Preferred Name'" in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr_tamper_encoded(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_NAME) INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][ "encoded" ] = "1234567890" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -474,9 +475,9 @@ async def test_check_encoding_attr_tamper_encoded(self, mock_verify): "VALUE_ERROR::Encoded representation mismatch for 'Preferred Name'" in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names(self, mock_verify): - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -508,13 +509,13 @@ async def test_check_pred_names(self, mock_verify): assert "TS_OUT_NRI::18_id_GE_uuid" in msgs assert "TS_OUT_NRI::18_busid_GE_uuid" in msgs - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_pred_value(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES) INDY_PROOF_X["proof"]["proofs"][0]["primary_proof"]["ge_proofs"][0][ "predicate" ]["value"] = 0 - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -539,11 +540,11 @@ async def test_check_pred_names_tamper_pred_value(self, mock_verify): in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify): INDY_PROOF_REQ_X = deepcopy(INDY_PROOF_REQ_PRED_NAMES) INDY_PROOF_REQ_X["requested_predicates"]["18_busid_GE_uuid"]["name"] = "dummy" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -568,13 +569,13 @@ async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify): in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_attr_groups(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES) INDY_PROOF_X["requested_proof"]["revealed_attr_groups"][ "x_uuid" ] = INDY_PROOF_X["requested_proof"]["revealed_attr_groups"].pop("18_uuid") - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) diff --git a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py index ab5e9dea96..1ca4f752f5 100644 --- a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py +++ b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py @@ -1,10 +1,11 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from .. import wallet_plugin as test_module -class TestWalletCrypto(AsyncTestCase): +class TestWalletCrypto(IsolatedAsyncioTestCase): def setUp(self): test_module.LOADED = False @@ -14,12 +15,12 @@ async def test_file_ext(self): def test_load_postgres_plugin(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=0), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=0), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib test_module.load_postgres_plugin(storage_config, storage_creds) @@ -29,11 +30,11 @@ def test_load_postgres_plugin(self): def test_load_postgres_plugin_init_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=2) + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=2) ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -45,11 +46,11 @@ def test_load_postgres_plugin_init_x_raise(self): def test_load_postgres_plugin_init_x_exit(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=2) + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=2) ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): @@ -60,12 +61,12 @@ def test_load_postgres_plugin_init_x_exit(self): def test_load_postgres_plugin_config_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -77,12 +78,12 @@ def test_load_postgres_plugin_config_x_raise(self): def test_load_postgres_plugin_config_x_exit(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): @@ -93,12 +94,12 @@ def test_load_postgres_plugin_config_x_exit(self): def test_load_postgres_plugin_bad_json_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '"account":"test"' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -110,12 +111,12 @@ def test_load_postgres_plugin_bad_json_x_raise(self): def test_load_postgres_plugin_bad_json_x_exit(self): storage_config = '"wallet_scheme":"MultiWalletSingleTable"' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): diff --git a/aries_cloudagent/indy/tests/test_verifier.py b/aries_cloudagent/indy/tests/test_verifier.py index 90b75b92a6..54c836d42a 100644 --- a/aries_cloudagent/indy/tests/test_verifier.py +++ b/aries_cloudagent/indy/tests/test_verifier.py @@ -3,8 +3,8 @@ from copy import deepcopy from time import time -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...ledger.multiple_ledger.ledger_requests_executor import ( @@ -307,10 +307,10 @@ async def verify_presentation( @pytest.mark.indy -class TestIndySdkVerifier(AsyncTestCase): +class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": { @@ -343,9 +343,9 @@ async def test_check_timestamps(self): ) context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -362,7 +362,7 @@ async def test_check_timestamps(self): context.injector.bind_instance( IndyLedgerRequestsExecutor, IndyLedgerRequestsExecutor(mock_profile) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -374,13 +374,13 @@ async def test_check_timestamps(self): ) # timestamp for irrevocable credential - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + mock.MagicMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": {"no": "revocation"}, @@ -398,7 +398,7 @@ async def test_check_timestamps(self): assert "Timestamp in presentation identifier #" in str(context.exception) # all clear, no timestamps - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -442,9 +442,9 @@ async def test_check_timestamps(self): proof_req_x = deepcopy(INDY_PROOF_REQ_NAME) proof_req_x["non_revoked"] = {"from": 1600000000, "to": 1600001000} proof_x["identifiers"][0]["timestamp"] = 1579890000 - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger, async_mock.patch.object( + with mock.patch.object( + test_module, "LOGGER", mock.MagicMock() + ) as mock_logger, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -461,7 +461,7 @@ async def test_check_timestamps(self): proof_req_x = deepcopy(INDY_PROOF_REQ_NAME) proof_x = deepcopy(INDY_PROOF_NAME) proof_req_x.pop("non_revoked") - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) diff --git a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py index bf2f27f1da..239edc4d73 100644 --- a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py +++ b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase from ..domain_txn_handler import ( prepare_for_state_read, @@ -28,7 +28,7 @@ ) -class TestSubTrie(TestCase): +class TestSubTrie(IsolatedAsyncioTestCase): def test_get_setter_root_hash(self): test_trie = SubTrie() test_trie.root_hash = 530343892119126197 @@ -43,7 +43,7 @@ async def test_verify_spv_proof_catch_exception(self): ) -class TestMPTStateProofValidation(TestCase): +class TestMPTStateProofValidation(IsolatedAsyncioTestCase): async def test_validate_get_nym(self): reply = GET_NYM_REPLY assert await SubTrie.verify_spv_proof( @@ -135,7 +135,7 @@ async def test_validate_get_revoc_reg_delta(self): ) -class TestMerkleRootHashValidation(TestCase): +class TestMerkleRootHashValidation(IsolatedAsyncioTestCase): async def test_verify_leaf_inclusion_x(self): merkle_verifier = MerkleVerifier(HexTreeHasher()) leaf_index = 848049 diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py index f087660fa5..cb7ebf0529 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile @@ -13,8 +13,8 @@ from ..ledger_requests_executor import IndyLedgerRequestsExecutor -class TestIndyLedgerRequestsExecutor(AsyncTestCase): - async def setUp(self): +class TestIndyLedgerRequestsExecutor(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) @@ -31,16 +31,14 @@ async def setUp(self): ) self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - extract_did_from_identifier=async_mock.CoroutineMock( + mock.MagicMock( + extract_did_from_identifier=mock.MagicMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.CoroutineMock( + lookup_did_in_configured_ledgers=mock.CoroutineMock( return_value=("test_prod_1", self.ledger) ), - get_ledger_inst_by_id=async_mock.CoroutineMock( - return_value=self.ledger - ), + get_ledger_inst_by_id=mock.CoroutineMock(return_value=self.ledger), ), ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -70,11 +68,11 @@ async def test_get_ledger_for_identifier_is_digit(self): async def test_get_ledger_for_identifier_x(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - extract_did_from_identifier=async_mock.CoroutineMock( + mock.MagicMock( + extract_did_from_identifier=mock.MagicMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.CoroutineMock( + lookup_did_in_configured_ledgers=mock.CoroutineMock( side_effect=MultipleLedgerManagerError ), ), diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py index ba384b561d..f280c8b06c 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py @@ -3,8 +3,8 @@ import pytest import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from collections import OrderedDict @@ -24,12 +24,12 @@ @pytest.mark.indy -class TestMultiIndyLedgerManager(AsyncTestCase): - async def setUp(self): +class TestMultiIndyLedgerManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -136,17 +136,17 @@ async def test_get_ledger_inst_by_id(self): ledger_inst = await self.manager.get_ledger_inst_by_id("test_invalid") assert not ledger_inst - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -160,10 +160,10 @@ async def test_get_ledger_by_did_self_cert_a( assert ledger_inst.pool.name == "test_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_self_cert_b( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -178,10 +178,10 @@ async def test_get_ledger_by_did_self_cert_b( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -195,10 +195,10 @@ async def test_get_ledger_by_did_self_cert_b( assert ledger_inst.pool.name == "test_non_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -213,12 +213,12 @@ async def test_get_ledger_by_did_not_self_cert( "verkey": "ABUF7uxYTxZ6qYdZ4G9e1Gi", } ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -233,81 +233,81 @@ async def test_get_ledger_by_did_not_self_cert( assert ledger_inst.pool.name == "test_prod_1" assert not is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_state_proof_not_valid( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_no_data( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply.get("result").pop("data") - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_timeout( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = asyncio.TimeoutError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_ledger_error( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = LedgerError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -319,21 +319,21 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -346,10 +346,10 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -364,10 +364,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -379,10 +379,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -399,12 +399,12 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( ) get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -417,19 +417,19 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = False @@ -439,17 +439,17 @@ async def test_lookup_did_in_configured_ledgers_x( ) assert "not found in any of the ledgers total: (production: " in cm - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py index b61813db8e..196bd87390 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py @@ -2,8 +2,8 @@ import json import pytest -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from copy import deepcopy from collections import OrderedDict @@ -56,12 +56,12 @@ @pytest.mark.indy_vdr -class TestMultiIndyVDRLedgerManager(AsyncTestCase): - async def setUp(self): +class TestMultiIndyVDRLedgerManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -165,19 +165,17 @@ async def test_get_ledger_inst_by_id(self): ledger_inst = await self.manager.get_ledger_inst_by_id("test_invalid") assert not ledger_inst - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -191,12 +189,10 @@ async def test_get_ledger_by_did_self_cert_a( assert ledger_inst.pool.name == "test_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_self_cert_b( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -211,10 +207,10 @@ async def test_get_ledger_by_did_self_cert_b( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -228,12 +224,10 @@ async def test_get_ledger_by_did_self_cert_b( assert ledger_inst.pool.name == "test_non_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -248,12 +242,12 @@ async def test_get_ledger_by_did_not_self_cert( "verkey": "ABUF7uxYTxZ6qYdZ4G9e1Gi", } ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -268,91 +262,81 @@ async def test_get_ledger_by_did_not_self_cert( assert ledger_inst.pool.name == "test_prod_1" assert not is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_state_proof_not_valid( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_no_data( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply.pop("data") - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_timeout( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = asyncio.TimeoutError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_ledger_error( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = LedgerError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -364,23 +348,21 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -393,12 +375,10 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -413,10 +393,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value ( @@ -428,12 +408,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -450,12 +428,12 @@ async def test_get_ledger_by_did_not_self_cert_non_prod( ) get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -468,21 +446,19 @@ async def test_get_ledger_by_did_not_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = False @@ -492,19 +468,17 @@ async def test_lookup_did_in_configured_ledgers_x( ) assert "not found in any of the ledgers total: (production: " in cm - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value ( diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py index 9adb82e5ad..d6b8b70706 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py @@ -1,6 +1,7 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager from ....config.injection_context import InjectionContext @@ -56,7 +57,7 @@ ] -class TestMultiIndyLedgerManagerProvider(AsyncTestCase): +class TestMultiIndyLedgerManagerProvider(IsolatedAsyncioTestCase): async def test_provide_invalid_manager(self): profile = InMemoryProfile.test_profile() provider = MultiIndyLedgerManagerProvider(profile) @@ -68,7 +69,7 @@ async def test_provide_invalid_manager(self): @pytest.mark.indy async def test_provide_indy_manager(self): context = InjectionContext() - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): profile = IndySdkProfile( IndyOpenWallet( config=IndyWalletConfig({"name": "test-profile"}), diff --git a/aries_cloudagent/ledger/tests/test_endpoint_type.py b/aries_cloudagent/ledger/tests/test_endpoint_type.py index 799103864a..027e65a811 100644 --- a/aries_cloudagent/ledger/tests/test_endpoint_type.py +++ b/aries_cloudagent/ledger/tests/test_endpoint_type.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..endpoint_type import EndpointType -class TestEndpointType(AsyncTestCase): +class TestEndpointType(IsolatedAsyncioTestCase): async def test_endpoint_type(self): assert EndpointType.ENDPOINT is EndpointType.get("endpoint") assert EndpointType.PROFILE is EndpointType.get("PROFILE") diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index 7b3012a9d6..9b702d98bd 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -5,7 +5,8 @@ from os import path -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...cache.in_memory import InMemoryCache @@ -45,12 +46,10 @@ @pytest.mark.indy -class TestIndySdkLedgerPoolProvider(AsyncTestCase): +class TestIndySdkLedgerPoolProvider(IsolatedAsyncioTestCase): async def test_provide(self): provider = IndySdkLedgerPoolProvider() - mock_injector = async_mock.MagicMock( - inject=async_mock.MagicMock(return_value=None) - ) + mock_injector = mock.MagicMock(inject=mock.MagicMock(return_value=None)) provider.provide( settings={ "ledger.read_only": True, @@ -61,8 +60,8 @@ async def test_provide(self): @pytest.mark.indy -class TestIndySdkLedger(AsyncTestCase): - async def setUp(self): +class TestIndySdkLedger(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_did_info = DIDInfo( did=self.test_did, @@ -74,24 +73,24 @@ async def setUp(self): self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile( - async_mock.CoroutineMock(), + mock.CoroutineMock(), context, ) self.session = await self.profile.session() - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("builtins.open") async def test_init( self, mock_open, mock_open_ledger, mock_list_pools, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", genesis_transactions="genesis_transactions"), @@ -114,17 +113,17 @@ async def test_init( ) assert ledger.did_to_nym(ledger.nym_to_did(self.test_did)) == self.test_did - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("builtins.open") async def test_init_not_checked( self, mock_open, mock_open_ledger, mock_list_pools, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name"), self.profile) @@ -138,10 +137,10 @@ async def test_init_not_checked( mock_list_pools.return_value = [{"pool": ledger.pool_name}] await ledger.__aenter__() - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.list_pools") + @mock.patch("builtins.open") async def test_init_do_not_recreate(self, mock_open, mock_list_pools): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [{"pool": "name"}, {"pool": "another"}] pool = IndySdkLedgerPool("name") @@ -152,14 +151,14 @@ async def test_init_do_not_recreate(self, mock_open, mock_list_pools): mock_open.assert_called_once_with(GENESIS_TRANSACTION_PATH, "w") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.delete_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.delete_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("builtins.open") async def test_init_recreate( self, mock_open, mock_list_pools, mock_delete_config, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [{"pool": "name"}, {"pool": "another"}] mock_delete_config.return_value = None @@ -174,16 +173,16 @@ async def test_init_recreate( "name", json.dumps({"genesis_txn": GENESIS_TRANSACTION_PATH}) ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -197,18 +196,18 @@ async def test_aenter_aexit( mock_close_pool.assert_called_once() assert ledger.pool_handle is None - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit_nested_keepalive( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, keepalive=1), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -229,17 +228,17 @@ async def test_aenter_aexit_nested_keepalive( mock_close_pool.assert_called_once() assert ledger.pool_handle is None - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit_close_x( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_close_pool.side_effect = IndyError(ErrorCode.PoolLedgerTimeout) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -250,17 +249,17 @@ async def test_aenter_aexit_close_x( assert ledger.pool_handle == mock_open_ledger.return_value assert ledger.pool.ref_count == 1 - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_submit_pool_closed( self, mock_close_pool, mock_open_ledger, mock_create_config, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -268,12 +267,12 @@ async def test_submit_pool_closed( await ledger._submit("{}") assert "sign and submit request to closed pool" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.sign_and_submit_request") - @async_mock.patch("indy.ledger.multi_sign_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.sign_and_submit_request") + @mock.patch("indy.ledger.multi_sign_request") async def test_submit_signed( self, mock_indy_multi_sign, @@ -286,10 +285,10 @@ async def test_submit_signed( mock_indy_multi_sign.return_value = json.dumps({"endorsed": "content"}) mock_sign_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: async with ledger: @@ -298,7 +297,7 @@ async def test_submit_signed( with self.assertRaises(BadLedgerRequestError): await ledger._submit("{}", True) - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -322,12 +321,12 @@ async def test_submit_signed( taa_accept=False, ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.sign_and_submit_request") - @async_mock.patch("indy.ledger.append_txn_author_agreement_acceptance_to_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.sign_and_submit_request") + @mock.patch("indy.ledger.append_txn_author_agreement_acceptance_to_request") async def test_submit_signed_taa_accept( self, mock_append_taa, @@ -340,16 +339,16 @@ async def test_submit_signed_taa_accept( mock_append_taa.return_value = "{}" mock_sign_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True), self.profile ) - ledger.get_latest_txn_author_acceptance = async_mock.CoroutineMock( + ledger.get_latest_txn_author_acceptance = mock.CoroutineMock( return_value={ "text": "sample", "version": "0.0", @@ -373,11 +372,11 @@ async def test_submit_signed_taa_accept( "{}", "sample", "0.0", "digest", "dummy", "now" ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_unsigned( self, mock_submit, @@ -386,17 +385,17 @@ async def test_submit_unsigned( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -404,11 +403,11 @@ async def test_submit_unsigned( await ledger._submit("{}", False) mock_submit.assert_called_once_with(ledger.pool_handle, "{}") - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_unsigned_ledger_transaction_error( self, mock_submit, @@ -417,16 +416,16 @@ async def test_submit_unsigned_ledger_transaction_error( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "NO-SUCH-OP"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -438,11 +437,11 @@ async def test_submit_unsigned_ledger_transaction_error( await ledger._submit("{}", False) mock_submit.assert_called_once_with(ledger.pool_handle, "{}") - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_rejected( self, mock_submit, @@ -451,17 +450,17 @@ async def test_submit_rejected( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "REQNACK", "reason": "a reason"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -472,10 +471,10 @@ async def test_submit_rejected( mock_submit.return_value = '{"op": "REJECT", "reason": "another reason"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -484,11 +483,11 @@ async def test_submit_rejected( await ledger._submit("{}", False) assert "Ledger rejected transaction request" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.multi_sign_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.multi_sign_request") async def test_txn_endorse( self, mock_indy_multi_sign, @@ -500,10 +499,10 @@ async def test_txn_endorse( mock_indy_multi_sign.return_value = json.dumps({"endorsed": "content"}) mock_indy_open.return_value = 1 - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -521,17 +520,15 @@ async def test_txn_endorse( ) assert json.loads(endorsed_json) == {"endorsed": "content"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("indy.ledger.append_request_endorser") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.ledger.append_request_endorser") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema( self, mock_is_ledger_read_only, @@ -544,11 +541,11 @@ async def test_send_schema( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) issuer.create_schema.return_value = ("schema_issuer_did:name:1.0", "{}") mock_fetch_schema_by_id.return_value = None @@ -558,11 +555,11 @@ async def test_send_schema( r'{"op":"REPLY","result":{"txnMetadata":{"seqNo": 1}}}' ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future async with ledger: @@ -573,7 +570,7 @@ async def test_send_schema( issuer, "schema_name", "schema_version", [1, 2, 3] ) - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -609,15 +606,13 @@ async def test_send_schema( assert schema_id == issuer.create_schema.return_value[0] assert "signed_txn" in signed_txn - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") async def test_send_schema_already_exists( self, mock_build_schema_req, @@ -628,25 +623,23 @@ async def test_send_schema_already_exists( mock_create_config, mock_set_proto, ): - # mock_did = async_mock.CoroutineMock() + # mock_did = mock.CoroutineMock() - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - mock_add_record = async_mock.CoroutineMock() + mock_add_record = mock.CoroutineMock() future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=mock_add_record) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock_add_record)) ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = self.test_did_info @@ -665,16 +658,14 @@ async def test_send_schema_already_exists( mock_add_record.assert_not_called() - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_ledger_transaction_error_already_exists( self, mock_is_ledger_read_only, @@ -686,22 +677,22 @@ async def test_send_schema_ledger_transaction_error_already_exists( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.CoroutineMock( + ledger._submit = mock.CoroutineMock( side_effect=LedgerTransactionError("UnauthorizedClientRequest") ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = self.test_did_info @@ -716,13 +707,11 @@ async def test_send_schema_ledger_transaction_error_already_exists( ) assert schema_id == fetch_schema_id - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") async def test_send_schema_ledger_read_only( self, mock_check_existing, @@ -731,15 +720,15 @@ async def test_send_schema_ledger_read_only( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -755,14 +744,12 @@ async def test_send_schema_ledger_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_issuer_error( self, mock_is_ledger_read_only, @@ -772,16 +759,16 @@ async def test_send_schema_issuer_error( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) - issuer.create_schema = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.create_schema = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -797,15 +784,13 @@ async def test_send_schema_issuer_error( ) assert "dummy error" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") async def test_send_schema_ledger_transaction_error( self, mock_build_schema_req, @@ -816,16 +801,16 @@ async def test_send_schema_ledger_transaction_error( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.CoroutineMock( + ledger._submit = mock.CoroutineMock( side_effect=LedgerTransactionError("Some other error message") ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -840,16 +825,14 @@ async def test_send_schema_ledger_transaction_error( issuer, "schema_name", "schema_version", [1, 2, 3] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_no_seq_no( self, mock_is_ledger_read_only, @@ -861,9 +844,9 @@ async def test_send_schema_no_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) issuer.create_schema.return_value = ("schema_issuer_did:name:1.0", "{}") @@ -873,12 +856,12 @@ async def test_send_schema_no_seq_no( mock_submit.return_value = ( r'{"op":"REPLY","result":{"txnMetadata":{"no": "seqNo"}}}' ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: - mock_wallet.get_public_did = async_mock.CoroutineMock() + mock_wallet.get_public_did = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -888,24 +871,24 @@ async def test_send_schema_no_seq_no( ) assert "schema sequence number" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") async def test_check_existing_schema( self, mock_fetch_schema_by_id, mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_fetch_schema_by_id.return_value = {"attrNames": ["a", "b", "c"]} ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -925,11 +908,11 @@ async def test_check_existing_schema( attribute_names=["a", "b", "c", "d"], ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema( self, mock_parse_get_schema_resp, @@ -938,17 +921,17 @@ async def test_get_schema( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') mock_submit.return_value = '{"result":{"seqNo":1}}' - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -977,10 +960,10 @@ async def test_get_schema( mock_parse_get_schema_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_schema_request") async def test_get_schema_not_found( self, mock_build_get_schema_req, @@ -988,15 +971,15 @@ async def test_get_schema_not_found( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"seqNo": None}}) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1016,12 +999,12 @@ async def test_get_schema_not_found( assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema_by_seq_no( self, mock_parse_get_schema_resp, @@ -1031,7 +1014,7 @@ async def test_get_schema_by_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') @@ -1057,10 +1040,10 @@ async def test_get_schema_by_seq_no( mock_submit.side_effect = list( submissions ) # becomes list iterator, unsubscriptable, in mock object - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1075,8 +1058,8 @@ async def test_get_schema_by_seq_no( ) mock_submit.assert_has_calls( [ - async_mock.call(mock_build_get_txn_req.return_value), - async_mock.call( + mock.call(mock_build_get_txn_req.return_value), + mock.call( mock_build_get_schema_req.return_value, sign_did=mock_did ), ] @@ -1087,12 +1070,12 @@ async def test_get_schema_by_seq_no( mock_parse_get_schema_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema_by_wrong_seq_no( self, mock_parse_get_schema_resp, @@ -1102,7 +1085,7 @@ async def test_get_schema_by_wrong_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') @@ -1125,27 +1108,27 @@ async def test_get_schema_by_wrong_seq_no( submissions ) # becomes list iterator, unsubscriptable, in mock object ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: with self.assertRaises(LedgerTransactionError): await ledger.get_schema("999") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_credential_definition( self, mock_is_ledger_read_only, @@ -1158,7 +1141,7 @@ async def test_send_credential_definition( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_is_ledger_read_only.return_value = False @@ -1180,7 +1163,7 @@ async def test_send_credential_definition( mock_fetch_cred_def.side_effect = [None, cred_def] - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1192,11 +1175,11 @@ async def test_send_credential_definition( tag = "default" ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future async with ledger: @@ -1225,18 +1208,18 @@ async def test_send_credential_definition( mock_get_schema.assert_called_once_with(schema_id) mock_build_cred_def.assert_called_once_with(mock_did.did, cred_def_json) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") - @async_mock.patch("indy.ledger.append_request_endorser") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("indy.ledger.append_request_endorser") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_credential_definition_endorse_only( self, mock_is_ledger_read_only, @@ -1250,7 +1233,7 @@ async def test_send_credential_definition_endorse_only( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_is_ledger_read_only.return_value = False @@ -1272,7 +1255,7 @@ async def test_send_credential_definition_endorse_only( mock_fetch_cred_def.side_effect = [None, cred_def] - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1282,7 +1265,7 @@ async def test_send_credential_definition_endorse_only( ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -1308,16 +1291,16 @@ async def test_send_credential_definition_endorse_only( ) assert "signed_txn" in signed_txn - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_exists_in_ledger_and_wallet( self, mock_build_cred_def, @@ -1329,7 +1312,7 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1350,7 +1333,7 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_fetch_cred_def.return_value = {"mock": "cred-def"} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1361,11 +1344,11 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( schema_id = "schema_issuer_did:name:1.0" tag = "default" future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = DIDInfo( @@ -1395,43 +1378,43 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_build_cred_def.assert_not_called() mock_get_storage.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") async def test_send_credential_definition_no_such_schema( self, mock_close, mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_offer_exception( self, mock_build_cred_def, @@ -1443,33 +1426,33 @@ async def test_send_credential_definition_offer_exception( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_get_schema.return_value = {"seqNo": 999} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.credential_definition_in_wallet.side_effect = IndyIssuerError( "common IO error" ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_in_wallet_not_ledger( @@ -1479,7 +1462,7 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1498,24 +1481,24 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( @@ -1525,7 +1508,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1544,17 +1527,17 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1562,10 +1545,10 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( ) assert "dummy error" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send_x( @@ -1575,7 +1558,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1594,20 +1577,18 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) + issuer.create_and_store_credential_definition = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1615,10 +1596,10 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send ) assert "dummy error" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_read_only( @@ -1628,7 +1609,7 @@ async def test_send_credential_definition_read_only( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1647,11 +1628,9 @@ async def test_send_credential_definition_read_only( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) + issuer.create_and_store_credential_definition = mock.CoroutineMock( return_value=("cred-def-id", "cred-def-json") ) ledger = IndySdkLedger( @@ -1659,10 +1638,10 @@ async def test_send_credential_definition_read_only( ) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1670,10 +1649,10 @@ async def test_send_credential_definition_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( @@ -1683,7 +1662,7 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1702,33 +1681,31 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_fetch_cred_def.return_value = cred_def - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( - return_value=False - ) + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_on_ledger_in_wallet( self, mock_build_cred_def, @@ -1740,7 +1717,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1761,7 +1738,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_fetch_cred_def.return_value = cred_def - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1770,7 +1747,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: async with ledger: @@ -1802,16 +1779,16 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_build_cred_def.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_create_cred_def_exception( self, mock_build_cred_def, @@ -1823,7 +1800,7 @@ async def test_send_credential_definition_create_cred_def_exception( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1844,14 +1821,14 @@ async def test_send_credential_definition_create_cred_def_exception( mock_fetch_cred_def.return_value = None - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_and_store_credential_definition.side_effect = IndyIssuerError( "invalid structure" ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -1867,11 +1844,11 @@ async def test_send_credential_definition_create_cred_def_exception( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_get_credential_definition( self, mock_parse_get_cred_def_resp, @@ -1880,16 +1857,16 @@ async def test_get_credential_definition( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_cred_def_resp.return_value = ( None, json.dumps({"result": {"seqNo": 1}}), ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), @@ -1918,11 +1895,11 @@ async def test_get_credential_definition( mock_parse_get_cred_def_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_get_credential_definition_ledger_not_found( self, mock_parse_get_cred_def_resp, @@ -1931,13 +1908,13 @@ async def test_get_credential_definition_ledger_not_found( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_cred_def_resp.side_effect = IndyError( error_code=ErrorCode.LedgerNotFound, error_details={"message": "not today"} ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -1960,11 +1937,11 @@ async def test_get_credential_definition_ledger_not_found( assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_fetch_credential_definition_ledger_x( self, mock_parse_get_cred_def_resp, @@ -1973,7 +1950,7 @@ async def test_fetch_credential_definition_ledger_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_parse_get_cred_def_resp.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, @@ -1982,7 +1959,7 @@ async def test_fetch_credential_definition_ledger_x( self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -1991,78 +1968,78 @@ async def test_fetch_credential_definition_ledger_x( await ledger.fetch_credential_definition("cred_def_id") assert "not today" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_key_for_did( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"verkey": self.test_verkey})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_key_for_did(self.test_did) - assert mock_build_get_nym_req.called_once_with( + mock_build_get_nym_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_nym_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response == self.test_verkey - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": {"endpoint": endpoint}})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response == endpoint - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_of_type_profile_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://company.com/masterdata" endpoint_type = EndpointType.PROFILE @@ -2076,7 +2053,7 @@ async def test_get_endpoint_of_type_profile_for_did( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2086,27 +2063,27 @@ async def test_get_endpoint_of_type_profile_for_did( endpoint_type, ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response == endpoint - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_all_endpoints_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) profile_endpoint = "http://company.com/masterdata" default_endpoint = "http://agent.company.com" @@ -2115,129 +2092,129 @@ async def test_get_all_endpoints_for_did( ) mock_submit.return_value = json.dumps({"result": {"data": data_json}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_all_endpoints_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response == json.loads(data_json).get("endpoint") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_all_endpoints_for_did_none( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) profile_endpoint = "http://company.com/masterdata" default_endpoint = "http://agent.company.com" mock_submit.return_value = json.dumps({"result": {"data": None}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_all_endpoints_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did_address_none( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": None})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did_no_endpoint( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"data": None}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_for_did( self, mock_is_ledger_read_only, @@ -2247,7 +2224,7 @@ async def test_update_endpoint_for_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = ["http://old.aries.ca", "http://new.aries.ca"] mock_is_ledger_read_only.return_value = False @@ -2262,7 +2239,7 @@ async def test_update_endpoint_for_did( for i in range(len(endpoint)) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2271,7 +2248,7 @@ async def test_update_endpoint_for_did( self.test_did, endpoint[1] ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2280,17 +2257,17 @@ async def test_update_endpoint_for_did( ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call(mock_build_attrib_req.return_value, True, True), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") @pytest.mark.asyncio async def test_construct_attr_json_with_routing_keys(self, mock_close, mock_open): ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -2309,8 +2286,8 @@ async def test_construct_attr_json_with_routing_keys(self, mock_close, mock_open } ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") @pytest.mark.asyncio async def test_construct_attr_json_with_routing_keys_all_exist_endpoints( self, mock_close, mock_open @@ -2333,12 +2310,12 @@ async def test_construct_attr_json_with_routing_keys_all_exist_endpoints( } ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") @pytest.mark.asyncio async def test_update_endpoint_for_did_calls_attr_json( self, @@ -2350,17 +2327,17 @@ async def test_update_endpoint_for_did_calls_attr_json( mock_open, ): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) mock_is_ledger_read_only.return_value = False async with ledger: - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( ledger, "_construct_attr_json", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=json.dumps( { "endpoint": { @@ -2372,11 +2349,11 @@ async def test_update_endpoint_for_did_calls_attr_json( } ) ), - ) as mock_construct_attr_json, async_mock.patch.object( + ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.CoroutineMock(return_value={}), - ), async_mock.patch.object( + mock.CoroutineMock(return_value={}), + ), mock.patch.object( ledger, "did_to_nym" ): mock_wallet_get_public_did.return_value = self.test_did_info @@ -2390,12 +2367,12 @@ async def test_update_endpoint_for_did_calls_attr_json( "https://url", EndpointType.ENDPOINT, {}, routing_keys ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_for_did_no_prior_endpoints( self, mock_is_ledger_read_only, @@ -2405,25 +2382,25 @@ async def test_update_endpoint_for_did_no_prior_endpoints( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://new.aries.ca" mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: - with async_mock.patch.object( - ledger, "get_all_endpoints_for_did", async_mock.CoroutineMock() + with mock.patch.object( + ledger, "get_all_endpoints_for_did", mock.CoroutineMock() ) as mock_get_all: mock_get_all.return_value = None response = await ledger.update_endpoint_for_did( self.test_did, endpoint ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2432,19 +2409,17 @@ async def test_update_endpoint_for_did_no_prior_endpoints( ) mock_submit.assert_has_calls( [ - async_mock.call( - mock_build_attrib_req.return_value, True, True - ), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_of_type_profile_for_did( self, mock_is_ledger_read_only, @@ -2454,7 +2429,7 @@ async def test_update_endpoint_of_type_profile_for_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = ["http://company.com/oldProfile", "http://company.com/newProfile"] endpoint_type = EndpointType.PROFILE @@ -2472,12 +2447,12 @@ async def test_update_endpoint_of_type_profile_for_did( for i in range(len(endpoint)) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - # ledger = async_mock.patch.object( + # ledger = mock.patch.object( # ledger, # "is_ledger_read_only", - # async_mock.CoroutineMock(return_value=False), + # mock.CoroutineMock(return_value=False), # ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2486,7 +2461,7 @@ async def test_update_endpoint_of_type_profile_for_did( self.test_did, endpoint[1], endpoint_type ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2495,57 +2470,57 @@ async def test_update_endpoint_of_type_profile_for_did( ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call(mock_build_attrib_req.return_value, True, True), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_update_endpoint_for_did_duplicate( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": {"endpoint": endpoint}})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.update_endpoint_for_did(self.test_did, endpoint) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) assert not response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_update_endpoint_for_did_read_only( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( @@ -2554,7 +2529,7 @@ async def test_update_endpoint_for_did_read_only( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2565,11 +2540,11 @@ async def test_update_endpoint_for_did_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym( self, mock_is_ledger_read_only, @@ -2578,14 +2553,14 @@ async def test_register_nym( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" - ) as mock_wallet_get_local_did, async_mock.patch.object( + ) as mock_wallet_get_local_did, mock.patch.object( IndySdkWallet, "replace_local_did_metadata" ) as mock_wallet_replace_local_did_metadata: ledger = IndySdkLedger( @@ -2593,9 +2568,7 @@ async def test_register_nym( ) mock_wallet_get_public_did.return_value = self.test_did_info mock_wallet_get_local_did.return_value = self.test_did_info - mock_wallet_replace_local_did_metadata.return_value = ( - async_mock.CoroutineMock() - ) + mock_wallet_replace_local_did_metadata.return_value = mock.CoroutineMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2603,14 +2576,14 @@ async def test_register_nym( "alias", None, ) - assert mock_build_nym_req.called_once_with( + mock_build_nym_req.assert_called_once_with( self.test_did, self.test_did, self.test_verkey, "alias", None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_nym_req.return_value, True, True, @@ -2624,15 +2597,15 @@ async def test_register_nym( }, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") async def test_register_nym_read_only(self, mock_close, mock_open): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2646,24 +2619,24 @@ async def test_register_nym_read_only(self, mock_close, mock_open): ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_no_public_did( self, mock_is_ledger_read_only, mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock( + mock_wallet = mock.MagicMock( type="indy", - get_local_did=async_mock.CoroutineMock(), - replace_local_did_metadata=async_mock.CoroutineMock(), + get_local_did=mock.CoroutineMock(), + replace_local_did_metadata=mock.CoroutineMock(), ) mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -2676,11 +2649,11 @@ async def test_register_nym_no_public_did( None, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_ledger_x( self, mock_is_ledger_read_only, @@ -2689,7 +2662,7 @@ async def test_register_nym_ledger_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_build_nym_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, @@ -2697,7 +2670,7 @@ async def test_register_nym_ledger_x( mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2710,11 +2683,11 @@ async def test_register_nym_ledger_x( None, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_steward_register_others_did( self, mock_is_ledger_read_only, @@ -2723,22 +2696,20 @@ async def test_register_nym_steward_register_others_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" - ) as mock_wallet_get_local_did, async_mock.patch.object( + ) as mock_wallet_get_local_did, mock.patch.object( IndySdkWallet, "replace_local_did_metadata" ) as mock_wallet_replace_local_did_metadata: mock_wallet_get_public_did.return_value = self.test_did_info mock_wallet_get_local_did.side_effect = WalletNotFoundError() - mock_wallet_replace_local_did_metadata.return_value = ( - async_mock.CoroutineMock() - ) + mock_wallet_replace_local_did_metadata.return_value = mock.CoroutineMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2746,14 +2717,14 @@ async def test_register_nym_steward_register_others_did( "alias", None, ) - assert mock_build_nym_req.called_once_with( + mock_build_nym_req.assert_called_once_with( self.test_did, self.test_did, self.test_verkey, "alias", None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_nym_req.return_value, True, True, @@ -2761,14 +2732,14 @@ async def test_register_nym_steward_register_others_did( ) mock_wallet_replace_local_did_metadata.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_nym_role( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( { @@ -2809,32 +2780,32 @@ async def test_get_nym_role( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: assert await ledger.get_nym_role(self.test_did) == Role.ENDORSER - assert mock_build_get_nym_req.called_once_with( + mock_build_get_nym_req.assert_called_once_with( self.test_did, self.test_did, ) - assert mock_submit.called_once_with(mock_build_get_nym_req.return_value) + mock_submit.assert_called_once_with(mock_build_get_nym_req.return_value) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") async def test_get_nym_role_indy_x( self, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_build_get_nym_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2843,14 +2814,14 @@ async def test_get_nym_role_indy_x( await ledger.get_nym_role(self.test_did) assert "not today" in context.exception.message - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_nym_role_did_not_public_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( { @@ -2882,7 +2853,7 @@ async def test_get_nym_role_did_not_public_x( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2890,12 +2861,12 @@ async def test_get_nym_role_did_not_public_x( with self.assertRaises(BadLedgerRequestError): await ledger.get_nym_role(self.test_did) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair( self, mock_submit, @@ -2905,7 +2876,7 @@ async def test_rotate_public_did_keypair( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.side_effect = [ json.dumps({"result": {"data": json.dumps({"seqNo": 1234})}}), @@ -2918,11 +2889,11 @@ async def test_rotate_public_did_keypair( ), ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2931,23 +2902,23 @@ async def test_rotate_public_did_keypair( async with ledger: await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair_no_nym( self, mock_submit, mock_build_get_nym_request, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"data": json.dumps(None)}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2957,12 +2928,12 @@ async def test_rotate_public_did_keypair_no_nym( with self.assertRaises(BadLedgerRequestError): await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair_corrupt_nym_txn( self, mock_submit, @@ -2972,18 +2943,18 @@ async def test_rotate_public_did_keypair_corrupt_nym_txn( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.side_effect = [ json.dumps({"result": {"data": json.dumps({"seqNo": 1234})}}), json.dumps({"result": {"data": None}}), ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2993,11 +2964,11 @@ async def test_rotate_public_did_keypair_corrupt_nym_txn( with self.assertRaises(BadLedgerRequestError): await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_def_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_def_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_def_response") async def test_get_revoc_reg_def( self, mock_indy_parse_get_rrdef_resp, @@ -3006,7 +2977,7 @@ async def test_get_revoc_reg_def( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rrdef_resp.return_value = ( "rr-id", @@ -3017,7 +2988,7 @@ async def test_get_revoc_reg_def( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3025,14 +2996,14 @@ async def test_get_revoc_reg_def( result = await ledger.get_revoc_reg_def("rr-id") assert result == {"...": "...", "txnTime": 1234567890} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_def_request") async def test_get_revoc_reg_def_indy_x( self, mock_indy_build_get_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_indy_build_get_rrdef_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, @@ -3041,7 +3012,7 @@ async def test_get_revoc_reg_def_indy_x( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3050,11 +3021,11 @@ async def test_get_revoc_reg_def_indy_x( await ledger.get_revoc_reg_def("rr-id") assert "not today" in context.exception.message - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_response") async def test_get_revoc_reg_entry( self, mock_indy_parse_get_rr_resp, @@ -3063,7 +3034,7 @@ async def test_get_revoc_reg_entry( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rr_resp.return_value = ( "rr-id", @@ -3074,7 +3045,7 @@ async def test_get_revoc_reg_entry( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3082,11 +3053,11 @@ async def test_get_revoc_reg_entry( (result, _) = await ledger.get_revoc_reg_entry("rr-id", 1234567890) assert result == {"hello": "world"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_response") async def test_get_revoc_reg_entry_x( self, mock_indy_parse_get_rr_resp, @@ -3095,7 +3066,7 @@ async def test_get_revoc_reg_entry_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rr_resp.side_effect = IndyError( error_code=ErrorCode.PoolLedgerTimeout, @@ -3104,7 +3075,7 @@ async def test_get_revoc_reg_entry_x( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3112,11 +3083,11 @@ async def test_get_revoc_reg_entry_x( async with ledger: await ledger.get_revoc_reg_entry("rr-id", 1234567890) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_delta_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_delta_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_delta_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_delta_response") async def test_get_revoc_reg_delta( self, mock_indy_parse_get_rrd_resp, @@ -3125,7 +3096,7 @@ async def test_get_revoc_reg_delta( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rrd_resp.return_value = ( "rr-id", @@ -3136,7 +3107,7 @@ async def test_get_revoc_reg_delta( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3144,23 +3115,23 @@ async def test_get_revoc_reg_delta( (result, _) = await ledger.get_revoc_reg_delta("rr-id") assert result == {"hello": "world"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_public_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3175,21 +3146,21 @@ async def test_send_revoc_reg_def_public_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_local_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = self.test_did_info @@ -3206,21 +3177,21 @@ async def test_send_revoc_reg_def_local_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_x_no_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = None @@ -3234,23 +3205,23 @@ async def test_send_revoc_reg_def_x_no_did( context.exception ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_public_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3267,21 +3238,21 @@ async def test_send_revoc_reg_entry_public_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_local_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = self.test_did_info @@ -3300,21 +3271,21 @@ async def test_send_revoc_reg_entry_local_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_x_no_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = None @@ -3330,17 +3301,17 @@ async def test_send_revoc_reg_entry_x_no_did( context.exception ) - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_taa_digest_bad_value( self, mock_close_pool, mock_open_ledger, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3348,11 +3319,11 @@ async def test_taa_digest_bad_value( with self.assertRaises(ValueError): await ledger.taa_digest(None, None) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_acceptance_mechanisms_request") - @async_mock.patch("indy.ledger.build_get_txn_author_agreement_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_acceptance_mechanisms_request") + @mock.patch("indy.ledger.build_get_txn_author_agreement_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_txn_author_agreement( self, mock_submit, @@ -3361,34 +3332,34 @@ async def test_get_txn_author_agreement( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) txn_result_data = {"text": "text", "version": "1.0"} mock_submit.side_effect = [ json.dumps({"result": {"data": txn_result_data}}) for i in range(2) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: response = await ledger.get_txn_author_agreement(reload=True) - assert mock_build_get_acc_mech_req.called_once_with( + mock_build_get_acc_mech_req.assert_called_once_with( self.test_did, None, None ) - assert mock_build_get_taa_req.called_once_with( + mock_build_get_taa_req.assert_called_once_with( self.test_did, None, ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_acc_mech_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call( + mock.call( mock_build_get_taa_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), @@ -3405,14 +3376,14 @@ async def test_get_txn_author_agreement( "taa_required": True, } - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") async def test_accept_and_get_latest_txn_author_agreement( self, mock_find_all_records, mock_add_record, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile @@ -3439,7 +3410,7 @@ async def test_accept_and_get_latest_txn_author_agreement( {"pool_name": ledger.pool_name}, ) ] - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3455,20 +3426,20 @@ async def test_accept_and_get_latest_txn_author_agreement( response = await ledger.get_latest_txn_author_acceptance() assert response == acceptance - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") async def test_get_latest_txn_author_agreement_none( self, mock_find_all_records, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile ) mock_find_all_records.return_value = [] - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3479,13 +3450,13 @@ async def test_get_latest_txn_author_agreement_none( response = await ledger.get_latest_txn_author_acceptance() assert response == {} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") async def test_credential_definition_id2schema_id( self, mock_get_schema, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) S_ID = f"{self.test_did}:2:favourite_drink:1.0" SEQ_NO = "9999" @@ -3494,7 +3465,7 @@ async def test_credential_definition_id2schema_id( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info diff --git a/aries_cloudagent/ledger/tests/test_indy_vdr.py b/aries_cloudagent/ledger/tests/test_indy_vdr.py index 335c856efb..6ad326c8cd 100644 --- a/aries_cloudagent/ledger/tests/test_indy_vdr.py +++ b/aries_cloudagent/ledger/tests/test_indy_vdr.py @@ -2,7 +2,7 @@ import indy_vdr import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile @@ -40,15 +40,15 @@ def ledger(): ledger = IndyVdrLedger(IndyVdrLedgerPool("test-ledger"), profile) async def open(): - ledger.pool.handle = async_mock.MagicMock(indy_vdr.Pool) + ledger.pool.handle = mock.MagicMock(indy_vdr.Pool) async def close(): ledger.pool.handle = None - with async_mock.patch.object(ledger.pool, "open", open), async_mock.patch.object( + with mock.patch.object(ledger.pool, "open", open), mock.patch.object( ledger.pool, "close", close - ), async_mock.patch.object( - ledger, "is_ledger_read_only", async_mock.CoroutineMock(return_value=False) + ), mock.patch.object( + ledger, "is_ledger_read_only", mock.CoroutineMock(return_value=False) ): yield ledger @@ -101,10 +101,10 @@ async def test_fetch_txn_author_agreement( ledger: IndyVdrLedger, ): async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.CoroutineMock( + mock.CoroutineMock( side_effect=[ {"data": {"aml": ".."}}, {"data": {"text": "text", "version": "1.0"}}, @@ -210,7 +210,7 @@ async def test_send_schema( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -224,10 +224,10 @@ async def test_send_schema( "txnMetadata": {"seqNo": 1} } - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=None), + mock.CoroutineMock(return_value=None), ): schema_id, schema_def = await ledger.create_and_send_schema( issuer, "schema_name", "9.1", ["a", "b"] @@ -260,7 +260,7 @@ async def test_send_schema_no_public_did( self, ledger: IndyVdrLedger, ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -274,7 +274,7 @@ async def test_send_schema_already_exists( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -284,10 +284,10 @@ async def test_send_schema_already_exists( ) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( issuer.create_schema.return_value[0], {"schema": "result"}, @@ -307,7 +307,7 @@ async def test_send_schema_ledger_read_only( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -318,14 +318,14 @@ async def test_send_schema_ledger_read_only( async with ledger: ledger.pool.read_only = True - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=False), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=False), + ), mock.patch.object( ledger, "is_ledger_read_only", - async_mock.CoroutineMock(return_value=True), + mock.CoroutineMock(return_value=True), ): with pytest.raises(LedgerError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -339,7 +339,7 @@ async def test_send_schema_ledger_transaction_error( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -351,10 +351,10 @@ async def test_send_schema_ledger_transaction_error( async with ledger: ledger.pool_handle.submit_request.side_effect = VdrError(99, "message") - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=False), + mock.CoroutineMock(return_value=False), ): with pytest.raises(LedgerTransactionError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -366,7 +366,7 @@ async def test_send_schema_no_indy_did( self, ledger: IndyVdrLedger, ): - wallet = async_mock.MagicMock((await ledger.profile.session()).wallet) + wallet = mock.MagicMock((await ledger.profile.session()).wallet) wallet.create_public_did.return_value = { "result": { "did": "did:web:doma.in", @@ -376,7 +376,7 @@ async def test_send_schema_no_indy_did( "method": WEB.method_name, } } - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -443,7 +443,7 @@ async def test_send_credential_definition( } }, } - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.credential_definition_in_wallet.return_value = False issuer.create_and_store_credential_definition.return_value = ( @@ -480,7 +480,7 @@ async def test_send_credential_definition_no_public_did( self, ledger: IndyVdrLedger, ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): await ledger.create_and_send_credential_definition( @@ -491,7 +491,7 @@ async def test_send_credential_definition_no_public_did( async def test_send_credential_definition_no_such_schema( self, ledger: IndyVdrLedger ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: ledger.pool_handle.submit_request.return_value = {} with pytest.raises(BadLedgerRequestError): @@ -501,7 +501,7 @@ async def test_send_credential_definition_no_such_schema( @pytest.mark.asyncio async def test_send_credential_definition_read_only(self, ledger: IndyVdrLedger): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: ledger.pool.read_only = True with pytest.raises(LedgerError): @@ -574,7 +574,7 @@ async def test_get_key_for_did_non_sov_public_did( ledger: IndyVdrLedger, ): async with ledger: - wallet = async_mock.MagicMock((await ledger.profile.session()).wallet) + wallet = mock.MagicMock((await ledger.profile.session()).wallet) wallet.get_public_did.return_value = DIDInfo( "did:web:doma.in", "verkey", @@ -740,10 +740,10 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg test_did = await wallet.create_public_did(SOV, ED25519) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "_construct_attr_json", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=json.dumps( { "endpoint": { @@ -755,10 +755,10 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg } ) ), - ) as mock_construct_attr_json, async_mock.patch.object( + ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.CoroutineMock(return_value={}), + mock.CoroutineMock(return_value={}), ): await ledger.update_endpoint_for_did( test_did.did, @@ -1008,10 +1008,10 @@ async def test_credential_definition_id2schema_id(self, ledger: IndyVdrLedger): SEQ_NO = "9999" async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "get_schema", - async_mock.CoroutineMock(return_value={"id": S_ID}), + mock.CoroutineMock(return_value={"id": S_ID}), ) as mock_get_schema: s_id_short = await ledger.credential_definition_id2schema_id( f"55GkHamhTU1ZbTbV2ab9DE:3:CL:{SEQ_NO}:tag" @@ -1031,10 +1031,10 @@ async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.CoroutineMock( + mock.CoroutineMock( side_effect=[ {"data": json.dumps({"seqNo": 1234})}, {"data": {"txn": {"data": {"role": "101", "alias": "Billy"}}}}, diff --git a/aries_cloudagent/ledger/tests/test_routes.py b/aries_cloudagent/ledger/tests/test_routes.py index a04add9e3a..4347823376 100644 --- a/aries_cloudagent/ledger/tests/test_routes.py +++ b/aries_cloudagent/ledger/tests/test_routes.py @@ -1,7 +1,7 @@ from typing import Tuple from unittest import IsolatedAsyncioTestCase -import mock as async_mock +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -22,7 +22,7 @@ class TestLedgerRoutes(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.create_autospec(BaseLedger) + self.ledger = mock.create_autospec(BaseLedger) self.ledger.pool_name = "pool.0" self.profile = InMemoryProfile.test_profile() self.context = self.profile.context @@ -30,9 +30,9 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -48,10 +48,8 @@ def setUp(self): async def test_missing_ledger(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.profile.context.injector.clear_binding(BaseLedger) @@ -83,15 +81,15 @@ async def test_missing_ledger(self): async def test_get_verkey_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -103,15 +101,15 @@ async def test_get_verkey_a(self): async def test_get_verkey_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -126,15 +124,15 @@ async def test_get_verkey_b(self): async def test_get_verkey_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -154,8 +152,8 @@ async def test_get_verkey_no_did(self): async def test_get_verkey_did_not_public(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -168,8 +166,8 @@ async def test_get_verkey_did_not_public(self): async def test_get_verkey_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -182,15 +180,15 @@ async def test_get_verkey_x(self): async def test_get_endpoint(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = self.test_endpoint result = await test_module.get_did_endpoint(self.request) @@ -202,15 +200,15 @@ async def test_get_endpoint(self): async def test_get_endpoint_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = self.test_endpoint result = await test_module.get_did_endpoint(self.request) @@ -225,8 +223,8 @@ async def test_get_endpoint_multitenant(self): async def test_get_endpoint_of_type_profile(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -235,8 +233,8 @@ async def test_get_endpoint_of_type_profile(self): "did": self.test_did, "endpoint_type": self.test_endpoint_type.w3c, } - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = ( self.test_endpoint_type_profile @@ -258,8 +256,8 @@ async def test_get_endpoint_no_did(self): async def test_get_endpoint_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -275,8 +273,8 @@ async def test_register_nym(self): "verkey": self.test_verkey, "role": "reset", } - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: success: bool = True txn: dict = None @@ -326,22 +324,22 @@ async def test_register_nym_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -370,22 +368,22 @@ async def test_register_nym_create_transaction_for_endorser_no_public_did(self): } self.profile.context.settings["endorser.author"] = True - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -413,18 +411,16 @@ async def test_register_nym_create_transaction_for_endorser_storage_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -449,8 +445,8 @@ async def test_register_nym_create_transaction_for_endorser_not_found_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -471,8 +467,8 @@ async def test_register_nym_create_transaction_for_endorser_base_model_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -495,11 +491,11 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_info_x( "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) self.ledger.register_nym.return_value: Tuple[bool, dict] = ( True, @@ -519,11 +515,11 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_did_x(se "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -540,16 +536,16 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_did_x(se async def test_get_nym_role_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -559,16 +555,16 @@ async def test_get_nym_role_a(self): async def test_get_nym_role_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -580,16 +576,16 @@ async def test_get_nym_role_b(self): async def test_get_nym_role_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -606,8 +602,8 @@ async def test_get_nym_role_bad_request(self): async def test_get_nym_role_ledger_txn_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -622,8 +618,8 @@ async def test_get_nym_role_ledger_txn_error(self): async def test_get_nym_role_bad_ledger_req(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -638,8 +634,8 @@ async def test_get_nym_role_bad_ledger_req(self): async def test_get_nym_role_ledger_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -650,19 +646,19 @@ async def test_get_nym_role_ledger_error(self): await test_module.get_nym_role(self.request) async def test_rotate_public_did_keypair(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = async_mock.AsyncMock() + self.ledger.rotate_public_did_keypair = mock.CoroutineMock() await test_module.rotate_public_did_keypair(self.request) json_response.assert_called_once_with({}) async def test_rotate_public_did_keypair_public_wallet_x(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = async_mock.AsyncMock( + self.ledger.rotate_public_did_keypair = mock.CoroutineMock( side_effect=test_module.WalletError("Exception") ) @@ -670,8 +666,8 @@ async def test_rotate_public_did_keypair_public_wallet_x(self): await test_module.rotate_public_did_keypair(self.request) async def test_get_taa(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = {"taa_required": False} self.ledger.get_latest_txn_author_acceptance.return_value = None @@ -688,8 +684,8 @@ async def test_get_taa_required(self): } taa_info = {"taa_required": True} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = taa_info self.ledger.get_latest_txn_author_acceptance.return_value = accepted @@ -705,7 +701,7 @@ async def test_get_taa_x(self): await test_module.ledger_get_taa(self.request) async def test_taa_accept_not_required(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -718,7 +714,7 @@ async def test_taa_accept_not_required(self): await test_module.ledger_accept_taa(self.request) async def test_accept_taa(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -726,8 +722,8 @@ async def test_accept_taa(self): } ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = { "taa_record": {"text": "text"}, @@ -746,7 +742,7 @@ async def test_accept_taa(self): assert result is json_response.return_value async def test_accept_taa_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -762,28 +758,28 @@ async def test_accept_taa_x(self): await test_module.ledger_accept_taa(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] async def test_get_write_ledger(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_ledger_id_by_ledger_pool_name=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_id_by_ledger_pool_name=mock.CoroutineMock( return_value="test_ledger_id" ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_write_ledger(self.request) json_response.assert_called_once_with( @@ -794,8 +790,8 @@ async def test_get_write_ledger(self): assert result is json_response.return_value async def test_get_write_ledger_single_ledger(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_write_ledger(self.request) json_response.assert_called_once_with( @@ -808,18 +804,18 @@ async def test_get_write_ledger_single_ledger(self): async def test_get_ledger_config(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_prod_ledgers=async_mock.AsyncMock( + mock.MagicMock( + get_prod_ledgers=mock.CoroutineMock( return_value={ - "test_1": async_mock.MagicMock(), - "test_2": async_mock.MagicMock(), - "test_5": async_mock.MagicMock(), + "test_1": mock.MagicMock(), + "test_2": mock.MagicMock(), + "test_5": mock.MagicMock(), } ), - get_nonprod_ledgers=async_mock.AsyncMock( + get_nonprod_ledgers=mock.CoroutineMock( return_value={ - "test_3": async_mock.MagicMock(), - "test_4": async_mock.MagicMock(), + "test_3": mock.MagicMock(), + "test_4": mock.MagicMock(), } ), ), @@ -830,8 +826,8 @@ async def test_get_ledger_config(self): {"id": "test_3", "genesis_transactions": "..."}, {"id": "test_4", "genesis_transactions": "..."}, ] - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_ledger_config(self.request) json_response.assert_called_once_with( diff --git a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py index 3a0cccb1b2..4b941f3795 100644 --- a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py +++ b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -20,32 +20,32 @@ CRED_DEF_ID = "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag" -class TestCredentialDefinitionRoutes(AsyncTestCase): +class TestCredentialDefinitionRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.create_and_send_credential_definition = mock.CoroutineMock( return_value=( CRED_DEF_ID, {"cred": "def", "signed_txn": "..."}, True, ) ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"cred": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) - self.issuer = async_mock.create_autospec(IndyIssuer) + self.issuer = mock.create_autospec(IndyIssuer) self.profile_injector.bind_instance(IndyIssuer, self.issuer) - self.storage = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.CoroutineMock( - return_value=[async_mock.MagicMock(value=CRED_DEF_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.CoroutineMock( + return_value=[mock.MagicMock(value=CRED_DEF_ID)] ) self.session_inject[BaseStorage] = self.storage @@ -54,9 +54,9 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -64,7 +64,7 @@ def setUp(self): ) async def test_send_credential_definition(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -74,7 +74,7 @@ async def test_send_credential_definition(self): self.request.query = {"create_transaction_for_endorser": "false"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = ( await test_module.credential_definitions_send_credential_definition( self.request @@ -89,7 +89,7 @@ async def test_send_credential_definition(self): ) async def test_send_credential_definition_create_transaction_for_endorser(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -102,22 +102,22 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -140,7 +140,7 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): async def test_send_credential_definition_create_transaction_for_endorser_storage_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -153,23 +153,21 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), } ) ) - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -180,7 +178,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag async def test_send_credential_definition_create_transaction_for_endorser_not_found_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -193,8 +191,8 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,7 +204,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo async def test_send_credential_definition_create_transaction_for_endorser_base_model_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -219,8 +217,8 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -232,7 +230,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_info_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -245,11 +243,11 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_definitions_send_credential_definition( @@ -259,7 +257,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_did_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -272,11 +270,11 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -288,7 +286,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end ) async def test_send_credential_definition_no_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -304,7 +302,7 @@ async def test_send_credential_definition_no_ledger(self): ) async def test_send_credential_definition_ledger_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -314,7 +312,7 @@ async def test_send_credential_definition_ledger_x(self): self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.__aenter__ = async_mock.CoroutineMock( + self.ledger.__aenter__ = mock.CoroutineMock( side_effect=test_module.LedgerError("oops") ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -325,7 +323,7 @@ async def test_send_credential_definition_ledger_x(self): async def test_created(self): self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_created(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -335,14 +333,14 @@ async def test_created(self): async def test_get_credential_definition(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request ) @@ -357,14 +355,14 @@ async def test_get_credential_definition(self): async def test_get_credential_definition_multitenant(self): self.profile_injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request ) @@ -379,10 +377,8 @@ async def test_get_credential_definition_multitenant(self): async def test_get_credential_definition_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} @@ -394,13 +390,13 @@ async def test_get_credential_definition_no_ledger(self): ) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py index de863ca4b9..e6028978dc 100644 --- a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py +++ b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....wallet.key_type import ED25519 from ....core.in_memory import InMemoryProfile @@ -9,7 +9,7 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestSignatureDecorator(AsyncTestCase): +class TestSignatureDecorator(IsolatedAsyncioTestCase): async def test_init(self): decorator = SignatureDecorator() assert decorator.signature_type is None diff --git a/aries_cloudagent/messaging/jsonld/tests/test_credential.py b/aries_cloudagent/messaging/jsonld/tests/test_credential.py index 85f0eb2a26..46ff019838 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_credential.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_credential.py @@ -3,7 +3,8 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....vc.ld_proofs import DocumentLoader @@ -27,7 +28,7 @@ from .document_loader import custom_document_loader -class TestCredential(AsyncTestCase): +class TestCredential(IsolatedAsyncioTestCase): async def test_did_key(self): did_key = test_module.did_key(TEST_VERKEY) assert did_key.startswith("did:key:z") @@ -52,8 +53,8 @@ async def test_verify_jws_header(self): ) -class TestOps(AsyncTestCase): - async def setUp(self): +class TestOps(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.wallet = InMemoryWallet(InMemoryProfile.test_profile()) await self.wallet.create_signing_key(ED25519, TEST_SEED) @@ -63,7 +64,7 @@ async def setUp(self): setattr( self.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) self.context.injector.bind_instance(DocumentLoader, custom_document_loader) diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index ec41daf578..b36a21b162 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -2,8 +2,8 @@ import json from aiohttp import web -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from pyld import jsonld import pytest @@ -59,15 +59,15 @@ def did_doc(): @pytest.fixture def mock_resolver(did_doc): - did_resolver = DIDResolver(async_mock.MagicMock()) - did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + did_resolver = DIDResolver(mock.MagicMock()) + did_resolver.resolve = mock.CoroutineMock(return_value=did_doc) yield did_resolver @pytest.fixture def mock_sign_credential(): temp = test_module.sign_credential - sign_credential = async_mock.CoroutineMock(return_value="fake_signage") + sign_credential = mock.CoroutineMock(return_value="fake_signage") test_module.sign_credential = sign_credential yield test_module.sign_credential test_module.sign_credential = temp @@ -76,7 +76,7 @@ def mock_sign_credential(): @pytest.fixture def mock_verify_credential(): temp = test_module.verify_credential - verify_credential = async_mock.CoroutineMock(return_value="fake_verify") + verify_credential = mock.CoroutineMock(return_value="fake_verify") test_module.verify_credential = verify_credential yield test_module.verify_credential test_module.verify_credential = temp @@ -85,15 +85,15 @@ def mock_verify_credential(): @pytest.fixture def mock_sign_request(mock_sign_credential): context = AdminRequestContext.test_context() - outbound_message_router = async_mock.CoroutineMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.CoroutineMock( + json=mock.CoroutineMock( return_value={ "verkey": "fake_verkey", "doc": {}, @@ -138,15 +138,15 @@ def request_body(): def mock_verify_request(mock_verify_credential, mock_resolver, request_body): def _mock_verify_request(request_body=request_body): context = AdminRequestContext.test_context({DIDResolver: mock_resolver}) - outbound_message_router = async_mock.CoroutineMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.CoroutineMock(return_value=request_body), + json=mock.CoroutineMock(return_value=request_body), __getitem__=lambda _, k: request_dict[k], ) return request @@ -156,7 +156,7 @@ def _mock_verify_request(request_body=request_body): @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -175,7 +175,7 @@ async def test_sign(mock_sign_request, mock_response): ) @pytest.mark.asyncio async def test_sign_bad_req_error(mock_sign_request, mock_response, error): - test_module.sign_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.sign_credential = mock.CoroutineMock(side_effect=error()) await test_module.sign(mock_sign_request) assert "error" in mock_response.call_args[0][0] @@ -183,7 +183,7 @@ async def test_sign_bad_req_error(mock_sign_request, mock_response, error): @pytest.mark.parametrize("error", [WalletError]) @pytest.mark.asyncio async def test_sign_bad_req_http_error(mock_sign_request, mock_response, error): - test_module.sign_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.sign_credential = mock.CoroutineMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.sign(mock_sign_request) @@ -206,7 +206,7 @@ async def test_verify(mock_verify_request, mock_response): ) @pytest.mark.asyncio async def test_verify_bad_req_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.verify_credential = mock.CoroutineMock(side_effect=error()) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -220,7 +220,7 @@ async def test_verify_bad_req_error(mock_verify_request, mock_response, error): ) @pytest.mark.asyncio async def test_verify_bad_req_http_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.verify_credential = mock.CoroutineMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.verify(mock_verify_request()) @@ -229,7 +229,7 @@ async def test_verify_bad_req_http_error(mock_verify_request, mock_response, err async def test_verify_bad_ver_meth_deref_req_error( mock_resolver, mock_verify_request, mock_response ): - mock_resolver.dereference = async_mock.CoroutineMock(side_effect=ResolverError) + mock_resolver.dereference = mock.CoroutineMock(side_effect=ResolverError) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -256,20 +256,20 @@ async def test_verify_bad_vmethod_unsupported( @pytest.mark.asyncio async def test_register(): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() def test_post_process_routes(): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] -class TestJSONLDRoutes(AsyncTestCase): - async def setUp(self): +class TestJSONLDRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = AdminRequestContext.test_context() self.context.profile.context.injector.bind_instance( DocumentLoader, custom_document_loader @@ -280,9 +280,9 @@ async def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -333,22 +333,22 @@ async def test_verify_credential(self): }, } - self.request.json = async_mock.CoroutineMock(return_value=POSTED_REQUEST) + self.request.json = mock.CoroutineMock(return_value=POSTED_REQUEST) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.verify(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with({"valid": True}) # expected response # compact, expand take a LONG TIME: do them once above, mock for error cases - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = { "@context": "...", "id": "...", @@ -376,14 +376,14 @@ async def test_verify_credential(self): result = await test_module.verify(self.request) assert "error" in json.loads(result) - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = { "@context": "...", "id": "...", @@ -468,9 +468,9 @@ async def test_sign_credential(self): }, }, } - self.request.json = async_mock.CoroutineMock(return_value=POSTED_REQUEST) + self.request.json = mock.CoroutineMock(return_value=POSTED_REQUEST) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.sign(self.request) assert result == mock_response.return_value mock_response.assert_called_once() @@ -481,9 +481,9 @@ async def test_sign_credential(self): posted_request_x = deepcopy(POSTED_REQUEST) posted_request_x["doc"]["options"].pop("verificationMethod") posted_request_x["doc"]["options"].pop("creator") - self.request.json = async_mock.CoroutineMock(return_value=posted_request_x) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + self.request.json = mock.CoroutineMock(return_value=posted_request_x) + with mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_response.side_effect = lambda x: json.dumps(x) result = await test_module.sign(self.request) @@ -491,15 +491,15 @@ async def test_sign_credential(self): # compact, expand take a LONG TIME: do them once above, mock for error cases posted_request = deepcopy(POSTED_REQUEST) - self.request.json = async_mock.CoroutineMock(return_value=posted_request) - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + self.request.json = mock.CoroutineMock(return_value=posted_request) + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = {} # drop all attributes mock_response.side_effect = lambda x: json.dumps(x) result = await test_module.sign(self.request) @@ -510,8 +510,8 @@ async def test_sign_credential(self): await test_module.sign(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() diff --git a/aries_cloudagent/messaging/models/tests/test_base.py b/aries_cloudagent/messaging/models/tests/test_base.py index 9cc6eaf868..b627227a0d 100644 --- a/aries_cloudagent/messaging/models/tests/test_base.py +++ b/aries_cloudagent/messaging/models/tests/test_base.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, INCLUDE, fields, validates_schema, ValidationError @@ -68,7 +69,7 @@ def validate_fields(self, data, **kwargs): raise ValidationError("") -class TestBase(AsyncTestCase): +class TestBase(IsolatedAsyncioTestCase): def test_model_validate_fails(self): model = ModelImpl(attr="string") with self.assertRaises(ValidationError): @@ -81,12 +82,12 @@ def test_model_validate_succeeds(self): def test_ser_x(self): model = ModelImpl(attr="hello world") - with async_mock.patch.object( - model, "_get_schema_class", async_mock.MagicMock() + with mock.patch.object( + model, "_get_schema_class", mock.MagicMock() ) as mock_get_schema_class: - mock_get_schema_class.return_value = async_mock.MagicMock( - return_value=async_mock.MagicMock( - dump=async_mock.MagicMock(side_effect=ValidationError("error")) + mock_get_schema_class.return_value = mock.MagicMock( + return_value=mock.MagicMock( + dump=mock.MagicMock(side_effect=ValidationError("error")) ) ) with self.assertRaises(BaseModelError): diff --git a/aries_cloudagent/messaging/models/tests/test_base_record.py b/aries_cloudagent/messaging/models/tests/test_base_record.py index 803c16e023..23148bf2ca 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -1,6 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields from ....cache.base import BaseCache @@ -65,7 +66,7 @@ class UnencTestImpl(BaseRecord): TAG_NAMES = {"~a", "~b", "c"} -class TestBaseRecord(AsyncTestCase): +class TestBaseRecord(IsolatedAsyncioTestCase): def test_init_undef(self): with self.assertRaises(TypeError): BaseRecord() @@ -84,29 +85,25 @@ def test_from_storage_values(self): async def test_post_save_new(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock() - mock_storage.add_record = async_mock.CoroutineMock() + mock_storage = mock.MagicMock() + mock_storage.add_record = mock.CoroutineMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() - with async_mock.patch.object( - record, "post_save", async_mock.CoroutineMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.CoroutineMock()) as post_save: await record.save(session, reason="reason", event=True) post_save.assert_called_once_with(session, True, None, True) mock_storage.add_record.assert_called_once() async def test_post_save_exist(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock() - mock_storage.update_record = async_mock.CoroutineMock() + mock_storage = mock.MagicMock() + mock_storage.update_record = mock.CoroutineMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() last_state = "last_state" record._last_state = last_state record._id = "id" - with async_mock.patch.object( - record, "post_save", async_mock.CoroutineMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.CoroutineMock()) as post_save: await record.save(session, reason="reason", event=False) post_save.assert_called_once_with(session, False, last_state, False) mock_storage.update_record.assert_called_once() @@ -116,7 +113,7 @@ async def test_cache(self): await BaseRecordImpl.set_cached_key(None, None, None) await BaseRecordImpl.clear_cached_key(None, None) session = InMemoryProfile.test_session() - mock_cache = async_mock.MagicMock(BaseCache, autospec=True) + mock_cache = mock.MagicMock(BaseCache, autospec=True) session.context.injector.bind_instance(BaseCache, mock_cache) record = BaseRecordImpl() cache_key = "cache_key" @@ -147,11 +144,9 @@ async def test_retrieve_by_tag_filter_multi_x_delete(self): async def test_save_x(self): session = InMemoryProfile.test_session() rec = ARecordImpl(a="1", b="0", code="one") - with async_mock.patch.object( - session, "inject", async_mock.MagicMock() - ) as mock_inject: - mock_inject.return_value = async_mock.MagicMock( - add_record=async_mock.CoroutineMock(side_effect=ZeroDivisionError()) + with mock.patch.object(session, "inject", mock.MagicMock()) as mock_inject: + mock_inject.return_value = mock.MagicMock( + add_record=mock.CoroutineMock(side_effect=ZeroDivisionError()) ) with self.assertRaises(ZeroDivisionError): await rec.save(session) @@ -163,7 +158,7 @@ async def test_neq(self): async def test_query(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" record_value = {"created_at": time_now(), "updated_at": time_now()} @@ -183,7 +178,7 @@ async def test_query(self): async def test_query_x(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" record_value = {"created_at": time_now(), "updated_at": time_now()} @@ -193,17 +188,17 @@ async def test_query_x(self): ) mock_storage.find_all_records.return_value = [stored] - with async_mock.patch.object( + with mock.patch.object( BaseRecordImpl, "from_storage", - async_mock.MagicMock(side_effect=BaseModelError), + mock.MagicMock(side_effect=BaseModelError), ): with self.assertRaises(BaseModelError): await BaseRecordImpl.query(session, tag_filter) async def test_query_post_filter(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" a_record = ARecordImpl(ident=record_id, a="one", b="two", code="red") @@ -259,21 +254,19 @@ async def test_query_post_filter(self): ) assert not result - @async_mock.patch("builtins.print") + @mock.patch("builtins.print") def test_log_state(self, mock_print): test_param = "test.log" - with async_mock.patch.object( - BaseRecordImpl, "LOG_STATE_FLAG", test_param - ) as cls: + with mock.patch.object(BaseRecordImpl, "LOG_STATE_FLAG", test_param) as cls: record = BaseRecordImpl() record.log_state( msg="state", params={"a": "1", "b": "2"}, - settings=async_mock.MagicMock(get={test_param: 1}.get), + settings=mock.MagicMock(get={test_param: 1}.get), ) mock_print.assert_called_once() - @async_mock.patch("builtins.print") + @mock.patch("builtins.print") def test_skip_log(self, mock_print): record = BaseRecordImpl() record.log_state("state", settings=None) diff --git a/aries_cloudagent/messaging/schemas/tests/test_routes.py b/aries_cloudagent/messaging/schemas/tests/test_routes.py index f5347a6b2b..baf6ae26e0 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -19,27 +19,27 @@ SCHEMA_ID = "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0" -class TestSchemaRoutes(AsyncTestCase): +class TestSchemaRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.create_and_send_schema = async_mock.CoroutineMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.create_and_send_schema = mock.CoroutineMock( return_value=(SCHEMA_ID, {"schema": "def", "signed_txn": "..."}) ) - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock( return_value={"schema": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) - self.issuer = async_mock.create_autospec(IndyIssuer) + self.issuer = mock.create_autospec(IndyIssuer) self.profile_injector.bind_instance(IndyIssuer, self.issuer) - self.storage = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.CoroutineMock( - return_value=[async_mock.MagicMock(value=SCHEMA_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.CoroutineMock( + return_value=[mock.MagicMock(value=SCHEMA_ID)] ) self.session_inject[BaseStorage] = self.storage self.context = AdminRequestContext.test_context( @@ -47,9 +47,9 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -57,7 +57,7 @@ def setUp(self): ) async def test_send_schema(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -67,7 +67,7 @@ async def test_send_schema(self): self.request.query = {"create_transaction_for_endorser": "false"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_send_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -88,7 +88,7 @@ async def test_send_schema(self): ) async def test_send_schema_create_transaction_for_endorser(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -101,22 +101,22 @@ async def test_send_schema_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -139,7 +139,7 @@ async def test_send_schema_create_transaction_for_endorser(self): ) async def test_send_schema_create_transaction_for_endorser_storage_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -152,18 +152,16 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -175,7 +173,7 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_not_found_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -188,8 +186,8 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -197,7 +195,7 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_base_model_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -210,8 +208,8 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -219,7 +217,7 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -232,17 +230,17 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(se "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -255,11 +253,11 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -269,7 +267,7 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel await test_module.schemas_send_schema(self.request) async def test_send_schema_no_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -282,7 +280,7 @@ async def test_send_schema_no_ledger(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_x_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -290,7 +288,7 @@ async def test_send_schema_x_ledger(self): } ) self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.create_and_send_schema = async_mock.CoroutineMock( + self.ledger.create_and_send_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -300,7 +298,7 @@ async def test_send_schema_x_ledger(self): async def test_created(self): self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_created(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with({"schema_ids": [SCHEMA_ID]}) @@ -308,14 +306,14 @@ async def test_created(self): async def test_get_schema(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -328,14 +326,14 @@ async def test_get_schema(self): async def test_get_schema_multitenant(self): self.profile_injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -348,14 +346,14 @@ async def test_get_schema_multitenant(self): async def test_get_schema_on_seq_no(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": "12345"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -365,14 +363,12 @@ async def test_get_schema_on_seq_no(self): async def test_get_schema_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -383,14 +379,14 @@ async def test_get_schema_no_ledger(self): async def test_get_schema_x_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -398,13 +394,13 @@ async def test_get_schema_x_ledger(self): await test_module.schemas_get_schema(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/messaging/tests/test_agent_message.py b/aries_cloudagent/messaging/tests/test_agent_message.py index bafe0c2703..12105fcbfe 100644 --- a/aries_cloudagent/messaging/tests/test_agent_message.py +++ b/aries_cloudagent/messaging/tests/test_agent_message.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields @@ -48,7 +48,7 @@ class Meta: message_type = "basic-message" -class TestAgentMessage(AsyncTestCase): +class TestAgentMessage(IsolatedAsyncioTestCase): """Tests agent message.""" def test_init(self): @@ -194,7 +194,7 @@ async def test_add_tracing(self): assert msg._trace -class TestAgentMessageSchema(AsyncTestCase): +class TestAgentMessageSchema(IsolatedAsyncioTestCase): """Tests agent message schema.""" def test_init_x(self): diff --git a/aries_cloudagent/multitenant/admin/tests/test_routes.py b/aries_cloudagent/multitenant/admin/tests/test_routes.py index 312997c4b6..2d24d902ee 100644 --- a/aries_cloudagent/multitenant/admin/tests/test_routes.py +++ b/aries_cloudagent/multitenant/admin/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from marshmallow.exceptions import ValidationError from ...base import BaseMultitenantManager, MultitenantManagerError @@ -11,12 +11,12 @@ from .. import routes as test_module -class TestMultitenantRoutes(AsyncTestCase): - async def setUp(self): - self.mock_multitenant_mgr = async_mock.MagicMock( - __aexit__=async_mock.CoroutineMock(), autospec=True +class TestMultitenantRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): + self.mock_multitenant_mgr = mock.MagicMock( + __aexit__=mock.CoroutineMock(), autospec=True ) - self.mock_multitenant_mgr.__aenter__ = async_mock.CoroutineMock( + self.mock_multitenant_mgr.__aenter__ = mock.CoroutineMock( return_value=self.mock_multitenant_mgr ) @@ -27,9 +27,9 @@ async def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -48,14 +48,14 @@ async def test_format_wallet_record_removes_wallet_key(self): assert "wallet.key" not in formatted["settings"] async def test_wallets_list(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True - ) as mock_wallet_record, async_mock.patch.object( + ) as mock_wallet_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: wallets = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567890", @@ -63,8 +63,8 @@ async def test_wallets_list(self): } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567891", @@ -72,8 +72,8 @@ async def test_wallets_list(self): } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567892", @@ -82,7 +82,7 @@ async def test_wallets_list(self): ) ), ] - mock_wallet_record.query = async_mock.CoroutineMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.return_value = [wallets[2], wallets[0], wallets[1]] await test_module.wallets_list(self.request) @@ -91,10 +91,10 @@ async def test_wallets_list(self): ) async def test_wallets_list_x(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True ) as mock_wallet_record: - mock_wallet_record.query = async_mock.CoroutineMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.side_effect = StorageError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -107,14 +107,14 @@ async def test_wallets_list_x(self): async def test_wallets_list_query(self): self.request.query = {"wallet_name": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True - ) as mock_wallet_record, async_mock.patch.object( + ) as mock_wallet_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: wallets = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567890", @@ -123,7 +123,7 @@ async def test_wallets_list_query(self): ) ), ] - mock_wallet_record.query = async_mock.CoroutineMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.return_value = wallets await test_module.wallets_list(self.request) @@ -154,11 +154,11 @@ async def test_wallet_create_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test", "settings": {}, @@ -166,11 +166,11 @@ async def test_wallet_create_tenant_settings(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) print(self.request["context"]) @@ -206,11 +206,11 @@ async def test_wallet_create(self): "wallet_webhook_urls": [], "wallet_dispatch_type": "base", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test", "settings": {}, @@ -218,11 +218,11 @@ async def test_wallet_create(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) print(self.request["context"]) @@ -247,7 +247,7 @@ async def test_wallet_create(self): async def test_wallet_create_x(self): body = {} - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.mock_multitenant_mgr.create_wallet.side_effect = MultitenantManagerError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -270,11 +270,13 @@ async def test_wallet_create_optional_default_fields(self): "label": "my_test_label", "image_url": "https://image.com", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock() + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( + return_value=mock.MagicMock() + ) + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -297,11 +299,13 @@ async def test_wallet_create_raw_key_derivation(self): "wallet_key": "test", "wallet_key_derivation": "RAW", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock() + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( + return_value=mock.MagicMock() + ) + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -329,9 +333,9 @@ async def test_wallet_update_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": body["wallet_webhook_urls"], "wallet.dispatch_type": body["wallet_dispatch_type"], @@ -341,15 +345,15 @@ async def test_wallet_update_tenant_settings(self): "debug.invite_public": True, "public_invites": True, } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -371,24 +375,24 @@ async def test_wallet_update(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": body["wallet_webhook_urls"], "wallet.dispatch_type": body["wallet_dispatch_type"], "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -408,22 +412,22 @@ async def test_wallet_update_no_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -444,24 +448,24 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": [], "wallet.dispatch_type": "base", "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -482,10 +486,10 @@ async def test_wallet_update_wallet_settings_x(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( side_effect=test_module.WalletSettingsError("bad settings") ) @@ -496,7 +500,7 @@ async def test_wallet_update_wallet_settings_x(self): async def test_wallet_update_no_params(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {} - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_update(self.request) @@ -504,8 +508,8 @@ async def test_wallet_update_no_params(self): async def test_wallet_update_not_found(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {"label": "test-label"} - self.request.json = async_mock.CoroutineMock(return_value=body) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock(return_value=body) + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -514,14 +518,14 @@ async def test_wallet_update_not_found(self): async def test_wallet_get(self): self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -534,8 +538,8 @@ async def test_wallet_get(self): async def test_wallet_get_not_found(self): self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.side_effect = StorageNotFoundError() @@ -544,13 +548,13 @@ async def test_wallet_get_not_found(self): async def test_wallet_get_x(self): self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -560,19 +564,19 @@ async def test_wallet_get_x(self): async def test_wallet_create_token_managed(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) @@ -585,22 +589,20 @@ async def test_wallet_create_token_managed(self): async def test_wallet_create_token_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( - return_value={"wallet_key": "dummy_key"} - ) - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) @@ -613,17 +615,15 @@ async def test_wallet_create_token_unmanaged(self): async def test_wallet_create_token_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( - return_value={"wallet_key": "dummy_key"} - ) - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) mock_wallet_record.requires_external_key = False - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -634,10 +634,10 @@ async def test_wallet_create_token_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: - mock_wallet_record_retrieve_by_id.return_value = async_mock.MagicMock() + mock_wallet_record_retrieve_by_id.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPUnauthorized): mock_wallet_record_retrieve_by_id.side_effect = ( @@ -655,12 +655,12 @@ async def test_wallet_remove_managed(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() await test_module.wallet_remove(self.request) @@ -671,16 +671,14 @@ async def test_wallet_remove_managed(self): async def test_wallet_remove_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( - return_value={"wallet_key": "dummy_key"} - ) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() await test_module.wallet_remove(self.request) @@ -691,15 +689,13 @@ async def test_wallet_remove_unmanaged(self): async def test_wallet_remove_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( - return_value={"wallet_key": "dummy_key"} - ) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) - mock_wallet_record = async_mock.MagicMock() + mock_wallet_record = mock.MagicMock() mock_wallet_record.requires_external_key = False - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -710,10 +706,10 @@ async def test_wallet_remove_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): with self.assertRaises(test_module.web.HTTPUnauthorized): self.mock_multitenant_mgr.remove_wallet.side_effect = ( @@ -728,13 +724,13 @@ async def test_wallet_remove_x(self): await test_module.wallet_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 5e2c8c1384..2070f835ab 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -1,7 +1,7 @@ import asyncio -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -10,14 +10,14 @@ from ..askar_profile_manager import AskarProfileMultitenantManager -class TestAskarProfileMultitenantManager(AsyncTestCase): +class TestAskarProfileMultitenantManager(IsolatedAsyncioTestCase): DEFAULT_MULTIENANT_WALLET_NAME = "multitenant_sub_wallet" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = AskarProfileMultitenantManager(self.profile) @@ -41,9 +41,9 @@ async def test_get_wallet_profile_should_open_store_and_return_profile_with_wall }, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.wallet_config" - ) as wallet_config, async_mock.patch( + ) as wallet_config, mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile", ) as AskarProfile: sub_wallet_profile_context = InjectionContext() @@ -104,7 +104,7 @@ async def test_get_wallet_profile_should_create_profile(self): create_profile_stub = asyncio.Future() create_profile_stub.set_result("") - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) @@ -127,10 +127,10 @@ async def test_get_wallet_profile_should_use_custom_subwallet_name(self): {"multitenant.wallet_name": multitenant_sub_wallet_name} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.wallet_config" ) as wallet_config: - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) @@ -154,7 +154,7 @@ def side_effect(context, provision): async def test_remove_wallet_profile(self): test_profile = InMemoryProfile.test_profile({"wallet.id": "test"}) - with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + with mock.patch.object(InMemoryProfile, "remove") as profile_remove: await self.manager.remove_wallet_profile(test_profile) profile_remove.assert_called_once_with() @@ -163,7 +163,7 @@ async def test_open_profiles(self): create_profile_stub = asyncio.Future() create_profile_stub.set_result("") - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index b908b6b0a1..4d572c9a83 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -1,7 +1,7 @@ from datetime import datetime -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock import jwt from .. import base as test_module @@ -44,12 +44,12 @@ def open_profiles(self): """Do nothing.""" -class TestBaseMultitenantManager(AsyncTestCase): - async def setUp(self): +class TestBaseMultitenantManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MockMultitenantManager(self.profile) @@ -59,7 +59,7 @@ async def test_init_throws_no_profile(self): MockMultitenantManager(None) async def test_get_default_mediator(self): - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator" ) as get_default_mediator: mediaton_record = MediationRecord() @@ -142,7 +142,7 @@ async def test_wallet_exists_false(self): async def test_get_wallet_by_key_routing_record_does_not_exist(self): recipient_key = "test" - with async_mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: + with mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: wallet = await self.manager._get_wallet_by_key(recipient_key) assert wallet is None @@ -178,7 +178,7 @@ async def test_get_wallet_by_key(self): assert isinstance(wallet, WalletRecord) async def test_create_wallet_removes_key_only_unmanaged_mode(self): - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: get_wallet_profile.return_value = InMemoryProfile.test_profile() @@ -194,7 +194,7 @@ async def test_create_wallet_removes_key_only_unmanaged_mode(self): assert managed_wallet_record.settings.get("wallet.key") == "test_key" async def test_create_wallet_fails_if_wallet_name_exists(self): - with async_mock.patch.object( + with mock.patch.object( self.manager, "_wallet_name_exists" ) as _wallet_name_exists: _wallet_name_exists.return_value = True @@ -208,13 +208,13 @@ async def test_create_wallet_fails_if_wallet_name_exists(self): ) async def test_create_wallet_saves_wallet_record_creates_profile(self): - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.CoroutineMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "save" - ) as wallet_record_save, async_mock.patch.object( + ) as wallet_record_save, mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: get_wallet_profile.return_value = InMemoryProfile.test_profile() @@ -246,14 +246,14 @@ async def test_create_wallet_adds_wallet_route(self): key_type=ED25519, ) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.CoroutineMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "save" - ) as wallet_record_save, async_mock.patch.object( + ) as wallet_record_save, mock.patch.object( self.manager, "get_wallet_profile" - ) as get_wallet_profile, async_mock.patch.object( + ) as get_wallet_profile, mock.patch.object( InMemoryWallet, "get_public_did" ) as get_public_did: get_wallet_profile.return_value = InMemoryProfile.test_profile( @@ -283,9 +283,9 @@ async def test_create_wallet_adds_wallet_route(self): assert wallet_record.wallet_key == "test_key" async def test_update_wallet(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( WalletRecord, "save" ) as wallet_record_save: wallet_id = "test-wallet-id" @@ -310,7 +310,7 @@ async def test_update_wallet(self): assert wallet_record.wallet_dispatch_type == "default" async def test_remove_wallet_fails_no_wallet_key_but_required(self): - with async_mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: + with mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: retrieve_by_id.return_value = WalletRecord( wallet_id="test", key_management_mode=WalletRecord.MODE_UNMANAGED, @@ -321,15 +321,15 @@ async def test_remove_wallet_fails_no_wallet_key_but_required(self): await self.manager.remove_wallet("test") async def test_remove_wallet_removes_profile_wallet_storage_records(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( self.manager, "get_wallet_profile" - ) as get_wallet_profile, async_mock.patch.object( + ) as get_wallet_profile, mock.patch.object( self.manager, "remove_wallet_profile" - ) as remove_wallet_profile, async_mock.patch.object( + ) as remove_wallet_profile, mock.patch.object( WalletRecord, "delete_record" - ) as wallet_delete_record, async_mock.patch.object( + ) as wallet_delete_record, mock.patch.object( InMemoryStorage, "delete_all_records" ) as delete_all_records: wallet_record = WalletRecord( @@ -366,12 +366,12 @@ async def test_create_auth_token_fails_no_wallet_key_but_required(self): async def test_create_auth_token_managed(self): self.profile.settings["multitenant.jwt_secret"] = "very_secret_jwt" - wallet_record = async_mock.MagicMock( + wallet_record = mock.MagicMock( wallet_id="test_wallet", key_management_mode=WalletRecord.MODE_MANAGED, requires_external_key=False, settings={}, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -381,7 +381,7 @@ async def test_create_auth_token_managed(self): {"wallet_id": wallet_record.wallet_id, "iat": iat}, "very_secret_jwt" ) - with async_mock.patch.object(test_module, "datetime") as mock_datetime: + with mock.patch.object(test_module, "datetime") as mock_datetime: mock_datetime.utcnow.return_value = utc_now token = await self.manager.create_auth_token(wallet_record) @@ -390,12 +390,12 @@ async def test_create_auth_token_managed(self): async def test_create_auth_token_unmanaged(self): self.profile.settings["multitenant.jwt_secret"] = "very_secret_jwt" - wallet_record = async_mock.MagicMock( + wallet_record = mock.MagicMock( wallet_id="test_wallet", key_management_mode=WalletRecord.MODE_UNMANAGED, requires_external_key=True, settings={"wallet.type": "indy"}, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -410,7 +410,7 @@ async def test_create_auth_token_unmanaged(self): "very_secret_jwt", ) - with async_mock.patch.object(test_module, "datetime") as mock_datetime: + with mock.patch.object(test_module, "datetime") as mock_datetime: mock_datetime.utcnow.return_value = utc_now token = await self.manager.create_auth_token(wallet_record, "test_key") @@ -463,7 +463,7 @@ async def test_get_wallet_and_profile(self): session = await self.profile.session() await wallet_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -512,7 +512,7 @@ async def test_get_profile_for_token_managed_wallet_no_iat(self): {"wallet_id": wallet_record.wallet_id}, "very_secret_jwt", algorithm="HS256" ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -549,7 +549,7 @@ async def test_get_profile_for_token_managed_wallet_iat(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -587,7 +587,7 @@ async def test_get_profile_for_token_managed_wallet_x_iat_no_match(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile, self.assertRaises( MultitenantManagerError, msg="Token not valid" @@ -623,7 +623,7 @@ async def test_get_profile_for_token_unmanaged_wallet(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -649,10 +649,10 @@ async def test_get_wallets_by_message_missing_wire_format_raises(self): await self.manager.get_wallets_by_message({}) async def test_get_wallets_by_message(self): - message_body = async_mock.MagicMock() + message_body = mock.MagicMock() recipient_keys = ["1", "2", "3", "4"] - mock_wire_format = async_mock.MagicMock( + mock_wire_format = mock.MagicMock( get_recipient_keys=lambda mesage_body: recipient_keys ) @@ -663,9 +663,7 @@ async def test_get_wallets_by_message(self): WalletRecord(settings={}), ] - with async_mock.patch.object( - self.manager, "_get_wallet_by_key" - ) as get_wallet_by_key: + with mock.patch.object(self.manager, "_get_wallet_by_key") as get_wallet_by_key: get_wallet_by_key.side_effect = return_wallets wallets = await self.manager.get_wallets_by_message( @@ -678,14 +676,14 @@ async def test_get_wallets_by_message(self): assert get_wallet_by_key.call_count == 4 async def test_get_profile_for_key(self): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_wallet.requires_external_key = False - with async_mock.patch.object( + with mock.patch.object( self.manager, "_get_wallet_by_key", - async_mock.CoroutineMock(return_value=mock_wallet), - ), async_mock.patch.object( - self.manager, "get_wallet_profile", async_mock.CoroutineMock() + mock.CoroutineMock(return_value=mock_wallet), + ), mock.patch.object( + self.manager, "get_wallet_profile", mock.CoroutineMock() ) as mock_get_wallet_profile: profile = await self.manager.get_profile_for_key( self.context, "test-verkey" diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index 8a8dcafe3e..17bd7f0331 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...messaging.responder import BaseResponder @@ -7,12 +7,12 @@ from ..manager import MultitenantManager -class TestMultitenantManager(AsyncTestCase): - async def setUp(self): +class TestMultitenantManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MultitenantManager(self.profile) @@ -21,7 +21,7 @@ async def test_get_wallet_profile_returns_from_cache(self): wallet_record = WalletRecord(wallet_id="test") self.manager._profiles.put("test", InMemoryProfile.test_profile()) - with async_mock.patch( + with mock.patch( "aries_cloudagent.config.wallet.wallet_config" ) as wallet_config: profile = await self.manager.get_wallet_profile( @@ -37,7 +37,7 @@ async def test_get_wallet_profile_not_in_cache(self): {"admin.webhook_urls": ["http://localhost:8020"]} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.config.wallet.wallet_config" ) as wallet_config: profile = await self.manager.get_wallet_profile( @@ -78,7 +78,7 @@ def side_effect(context, provision): settings=wallet_record_settings, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: wallet_config.side_effect = side_effect @@ -98,7 +98,7 @@ async def test_get_wallet_profile_settings_reset(self): settings={}, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: @@ -151,7 +151,7 @@ async def test_get_wallet_profile_settings_reset_overwrite(self): }, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: @@ -175,9 +175,9 @@ def side_effect(context, provision): assert profile.settings.get("mediation.clear") is True async def test_update_wallet_update_wallet_profile(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( WalletRecord, "save" ) as wallet_record_save: wallet_id = "test-wallet-id" @@ -213,7 +213,7 @@ async def test_remove_wallet_profile(self): ) self.manager._profiles.put("test", test_profile) - with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + with mock.patch.object(InMemoryProfile, "remove") as profile_remove: await self.manager.remove_wallet_profile(test_profile) assert not self.manager._profiles.has("test") profile_remove.assert_called_once_with() diff --git a/aries_cloudagent/multitenant/tests/test_manager_provider.py b/aries_cloudagent/multitenant/tests/test_manager_provider.py index 8a22a7da6e..bacf0c18e6 100644 --- a/aries_cloudagent/multitenant/tests/test_manager_provider.py +++ b/aries_cloudagent/multitenant/tests/test_manager_provider.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...config.base import InjectionError @@ -6,7 +6,7 @@ from ...core.in_memory import InMemoryProfile -class TestProfileManagerProvider(AsyncTestCase): +class TestProfileManagerProvider(IsolatedAsyncioTestCase): async def test_provide_manager(self): profile = InMemoryProfile.test_profile() provider = MultitenantManagerProvider(profile) diff --git a/aries_cloudagent/multitenant/tests/test_route_manager.py b/aries_cloudagent/multitenant/tests/test_route_manager.py index 2aebc0b2e9..771b4a81fd 100644 --- a/aries_cloudagent/multitenant/tests/test_route_manager.py +++ b/aries_cloudagent/multitenant/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from asynctest import mock +from aries_cloudagent.tests import mock import pytest from ...core.in_memory import InMemoryProfile diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py index 082dfab66a..4034bf5ea0 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,13 +7,13 @@ from .. import menu_handler as handler -class TestMenuHandler(AsyncTestCase): +class TestMenuHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" - handler.save_connection_menu = async_mock.CoroutineMock() + handler.save_connection_menu = mock.CoroutineMock() responder = MockResponder() request_context.message = handler.Menu() diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py index dcf578581f..30d97e65f4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,23 +7,21 @@ from .. import menu_request_handler as handler -class TestMenuRequestHandler(AsyncTestCase): - async def setUp(self): +class TestMenuRequestHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.CoroutineMock( - return_value="menu" - ) + self.menu_service.get_active_menu = mock.CoroutineMock(return_value="menu") handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) @@ -37,16 +33,16 @@ async def test_called(self): assert target == {} async def test_called_no_active_menu(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.CoroutineMock(return_value=None) + self.menu_service.get_active_menu = mock.CoroutineMock(return_value=None) handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py index 76d3b38d04..a8decf96ab 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,21 +7,21 @@ from .. import perform_handler as handler -class TestPerformHandler(AsyncTestCase): - async def setUp(self): +class TestPerformHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.CoroutineMock( + self.menu_service.perform_menu_action = mock.CoroutineMock( return_value="perform" ) @@ -37,18 +35,16 @@ async def test_called(self): assert target == {} async def test_called_no_active_menu(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.CoroutineMock( - return_value=None - ) + self.menu_service.perform_menu_action = mock.CoroutineMock(return_value=None) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py index 2e1094b4fb..50e6fc4f0d 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py index 69ce582851..f79d2119b4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py index 404925e403..6268229faf 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index 533e506f26..46072e2f3e 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,23 +1,23 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....core.in_memory import InMemoryProfile from .....messaging.request_context import RequestContext from .. import controller as test_module -class TestActionMenuController(AsyncTestCase): - async def setUp(self): +class TestActionMenuController(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.context = RequestContext(self.session.profile) async def test_controller(self): - MenuService = async_mock.MagicMock(test_module.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(test_module.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance( test_module.BaseMenuService, self.menu_service ) - self.context.inject = async_mock.CoroutineMock(return_value=self.menu_service) + self.context.inject = mock.CoroutineMock(return_value=self.menu_service) controller = test_module.Controller("protocol") diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index f766d9a77f..0d157842e8 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -7,15 +7,15 @@ from .. import routes as test_module -class TestActionMenuRoutes(AsyncTestCase): +class TestActionMenuRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -23,22 +23,22 @@ def setUp(self): ) async def test_actionmenu_close(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock() - test_module.save_connection_menu = async_mock.CoroutineMock() + test_module.retrieve_connection_menu = mock.CoroutineMock() + test_module.save_connection_menu = mock.CoroutineMock() - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_close(self.request) mock_response.assert_called_once_with({}) async def test_actionmenu_close_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock() - test_module.save_connection_menu = async_mock.CoroutineMock( + test_module.retrieve_connection_menu = mock.CoroutineMock() + test_module.save_connection_menu = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -46,39 +46,35 @@ async def test_actionmenu_close_x(self): await test_module.actionmenu_close(self.request) async def test_actionmenu_close_not_found(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock( - return_value=None - ) + test_module.retrieve_connection_menu = mock.CoroutineMock(return_value=None) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.actionmenu_close(self.request) async def test_actionmenu_fetch(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock( - return_value=None - ) + test_module.retrieve_connection_menu = mock.CoroutineMock(return_value=None) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_fetch(self.request) mock_response.assert_called_once_with({"result": None}) async def test_actionmenu_perform(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True - ) as mock_perform, async_mock.patch.object( + ) as mock_perform, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.actionmenu_perform(self.request) mock_response.assert_called_once_with({}) @@ -88,16 +84,16 @@ async def test_actionmenu_perform(self): ) async def test_actionmenu_perform_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -105,33 +101,33 @@ async def test_actionmenu_perform_no_conn_record(self): await test_module.actionmenu_perform(self.request) async def test_actionmenu_perform_conn_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_perform(self.request) async def test_actionmenu_request(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "MenuRequest", autospec=True - ) as menu_request, async_mock.patch.object( + ) as menu_request, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.actionmenu_request(self.request) mock_response.assert_called_once_with({}) @@ -141,16 +137,16 @@ async def test_actionmenu_request(self): ) async def test_actionmenu_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -158,34 +154,34 @@ async def test_actionmenu_request_no_conn_record(self): await test_module.actionmenu_request(self.request) async def test_actionmenu_request_conn_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_request(self.request) async def test_actionmenu_send(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True - ) as mock_menu, async_mock.patch.object( + ) as mock_menu, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() - mock_menu.deserialize = async_mock.MagicMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() + mock_menu.deserialize = mock.MagicMock() res = await test_module.actionmenu_send(self.request) mock_response.assert_called_once_with({}) @@ -195,16 +191,16 @@ async def test_actionmenu_send(self): ) async def test_actionmenu_send_deserialize_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() - mock_menu.deserialize = async_mock.MagicMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock() + mock_menu.deserialize = mock.MagicMock( side_effect=test_module.BaseModelError("cannot deserialize") ) @@ -212,18 +208,18 @@ async def test_actionmenu_send_deserialize_x(self): await test_module.actionmenu_send(self.request) async def test_actionmenu_send_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_menu.deserialize = async_mock.MagicMock() + mock_menu.deserialize = mock.MagicMock() # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -231,31 +227,31 @@ async def test_actionmenu_send_no_conn_record(self): await test_module.actionmenu_send(self.request) async def test_actionmenu_send_conn_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_menu.deserialize = async_mock.MagicMock() + mock_menu.deserialize = mock.MagicMock() # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_send(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py index 4573997115..af20c24af4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from .....core.event_bus import EventBus, MockEventBus from .....core.in_memory import InMemoryProfile @@ -8,8 +8,8 @@ from .. import driver_service as test_module -class TestActionMenuService(AsyncTestCase): - async def setUp(self): +class TestActionMenuService(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.context = RequestContext(self.session.profile) @@ -21,7 +21,7 @@ async def test_get_active_menu(self): self.context ) - connection = async_mock.MagicMock() + connection = mock.MagicMock() connection.connection_id = "connid" thread_id = "thid" @@ -47,7 +47,7 @@ async def test_perform_menu_action(self): action_name = "action" action_params = {"a": 1, "b": 2} - connection = async_mock.MagicMock() + connection = mock.MagicMock() connection.connection_id = "connid" thread_id = "thid" diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py index 370d88e621..89f54a1b42 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....core.event_bus import EventBus, MockEventBus from .....admin.request_context import AdminRequestContext @@ -9,7 +9,7 @@ from ..models.menu_option import MenuOption -class TestActionMenuUtil(AsyncTestCase): +class TestActionMenuUtil(IsolatedAsyncioTestCase): async def test_save_retrieve_delete_connection_menu(self): context = AdminRequestContext.test_context() diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py index fa602a21d1..bb0fcf6f2e 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -46,7 +47,7 @@ def test_serialize(self, mock_basic_message_schema_load): assert msg_dict is mock_basic_message_schema_load.return_value -class TestBasicMessageSchema(AsyncTestCase): +class TestBasicMessageSchema(IsolatedAsyncioTestCase): """Test basic message schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py index ca730021b0..de3373f053 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -7,15 +7,15 @@ from .. import routes as test_module -class TestBasicMessageRoutes(AsyncTestCase): - async def setUp(self): +class TestBasicMessageRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -24,33 +24,33 @@ async def setUp(self): self.test_conn_id = "connection-id" async def test_connections_send_message(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True - ) as mock_basic_message, async_mock.patch.object( + ) as mock_basic_message, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.connections_send_message(self.request) mock_response.assert_called_once_with({}) mock_basic_message.assert_called_once() async def test_connections_send_message_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -58,29 +58,29 @@ async def test_connections_send_message_no_conn_record(self): await test_module.connections_send_message(self.request) async def test_connections_send_message_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate connection not ready - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False await test_module.connections_send_message(self.request) mock_basic_message.assert_not_called() async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] 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 7fa1d3ab31..1820a71820 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 @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......core.profile import ProfileSession from ......connections.models import connection_target @@ -75,9 +75,9 @@ def did_doc(): class TestRequestHandler: @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -88,14 +88,14 @@ async def test_called(self, mock_conn_mgr, request_context): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called_with_auto_response(self, mock_conn_mgr, request_context): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -109,21 +109,21 @@ async def test_called_with_auto_response(self, mock_conn_mgr, request_context): assert responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_connection_record_with_mediation_metadata_auto_response( self, mock_conn_mgr, request_context, connection_record ): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() request_context.message = ConnectionRequest() - with async_mock.patch.object( + with mock.patch.object( connection_record, "metadata_get", - async_mock.CoroutineMock(return_value={"id": "test-mediation-id"}), + mock.CoroutineMock(return_value={"id": "test-mediation-id"}), ): handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -135,17 +135,17 @@ async def test_connection_record_with_mediation_metadata_auto_response( assert responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_connection_record_without_mediation_metadata( self, mock_conn_mgr, request_context, session, connection_record ): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = ConnectionRequest() storage: BaseStorage = session.inject(BaseStorage) - with async_mock.patch.object( + with mock.patch.object( storage, "find_record", - async_mock.CoroutineMock(raises=StorageNotFoundError), + mock.CoroutineMock(raises=StorageNotFoundError), ) as mock_storage_find_record: handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -157,9 +157,9 @@ async def test_connection_record_without_mediation_metadata( assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) @@ -177,16 +177,16 @@ async def test_problem_report(self, mock_conn_mgr, request_context): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) request_context.message = ConnectionRequest( @@ -207,16 +207,16 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=ConnectionManagerError("no targets") ) request_context.message = ConnectionRequest( diff --git a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py index e0fc85ab73..f5a08522ae 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -67,9 +67,9 @@ def did_doc(): class TestResponseHandler: @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -80,10 +80,10 @@ async def test_called(self, mock_conn_mgr, request_context): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called_auto_ping(self, mock_conn_mgr, request_context): request_context.update_settings({"auto_ping_connection": True}) - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -97,9 +97,9 @@ async def test_called_auto_ping(self, mock_conn_mgr, request_context): assert isinstance(result, Ping) @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED ) @@ -117,16 +117,16 @@ async def test_problem_report(self, mock_conn_mgr, request_context): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) request_context.message = ConnectionResponse( @@ -145,16 +145,16 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=ConnectionManagerError("no target") ) request_context.message = ConnectionResponse( diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py index b35bf95e1a..f325f34c71 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py index 51b77702e5..9ae14e169c 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import ( DIDDoc, @@ -104,7 +105,7 @@ def test_serialize(self, mock_connection_request_schema_dump): ) -class TestConnectionRequestSchema(AsyncTestCase, TestConfig): +class TestConnectionRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test connection request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py index 0fadf94ff4..3522895da8 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......wallet.key_type import ED25519 from ......connections.models.diddoc import ( @@ -100,7 +101,7 @@ def test_serialize(self, mock_connection_response_schema_dump): ) -class TestConnectionResponseSchema(AsyncTestCase, TestConfig): +class TestConnectionResponseSchema(IsolatedAsyncioTestCase, TestConfig): async def test_make_model(self): connection_response = ConnectionResponse( connection=ConnectionDetail(did=self.test_did, did_doc=self.make_did_doc()) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index ee8bfd1a66..fe09ae8d8f 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache @@ -28,7 +29,7 @@ from ..models.connection_detail import ConnectionDetail -class TestConnectionManager(AsyncTestCase): +class TestConnectionManager(IsolatedAsyncioTestCase): def make_did_doc(self, did, verkey): doc = DIDDoc(did=did) controller = did @@ -46,7 +47,7 @@ def make_did_doc(self, did, verkey): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.test_seed = "testseed000000000000000000000001" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" @@ -57,14 +58,14 @@ async def setUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.CoroutineMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = mock.CoroutineMock( return_value=None ) self.resolver = DIDResolver() @@ -89,7 +90,7 @@ async def setUp(self): ) self.context = self.profile.context - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) @@ -129,14 +130,14 @@ async def test_create_invitation_non_multi_use_invitation_fails_on_reuse(self): ) # requestB fails because the invitation was not set to multi-use - rr_awaitable = self.manager.receive_request(requestB, receipt) - await self.assertAsyncRaises(ConnectionManagerError, rr_awaitable) + with self.assertRaises(ConnectionManagerError): + await self.manager.receive_request(requestB, receipt) async def test_create_invitation_public(self): self.context.update_settings({"public_invites": True}) - self.route_manager.route_verkey = async_mock.CoroutineMock() - with async_mock.patch.object( + self.route_manager.route_verkey = mock.CoroutineMock() + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -167,7 +168,7 @@ async def test_create_invitation_public_no_public_invites(self): async def test_create_invitation_public_no_public_did(self): self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -265,7 +266,7 @@ async def test_create_invitation_multi_use_metadata_transfers_to_connection(self assert await new_conn_rec.metadata_get_all(session) == {"test": "value"} async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -277,7 +278,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator", ) as mock_get_default_mediator: @@ -291,7 +292,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) mock_get_default_mediator.assert_not_called() async def test_create_invitation_mediation_using_default(self): - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -303,10 +304,10 @@ async def test_create_invitation_mediation_using_default(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.route_manager, "mediation_record_if_id", - async_mock.CoroutineMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ): _, invite = await self.manager.create_invitation( routing_keys=[self.test_verkey], @@ -355,9 +356,7 @@ async def test_receive_invitation_with_did(self): assert ConnRecord.State.get(invitee_record.state) is ConnRecord.State.REQUEST async def test_receive_invitation_mediation_passes_id_when_auto_accept(self): - with async_mock.patch.object( - ConnectionManager, "create_request" - ) as create_request: + with mock.patch.object(ConnectionManager, "create_request") as create_request: record, connect_invite = await self.manager.create_invitation( my_endpoint="testendpoint" ) @@ -423,14 +422,14 @@ async def test_create_request_multitenant(self): endpoint=self.test_mediator_endpoint, ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -476,14 +475,14 @@ async def test_create_request_mediation_id(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -527,14 +526,14 @@ async def test_create_request_default_mediator(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -558,10 +557,10 @@ async def test_create_request_default_mediator(self): async def test_receive_request_public_did_oob_invite(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -575,18 +574,18 @@ async def test_receive_request_public_did_oob_invite(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -598,10 +597,10 @@ async def test_receive_request_public_did_oob_invite(self): async def test_receive_request_public_did_unsolicited_fails(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -615,28 +614,28 @@ async def test_receive_request_public_did_unsolicited_fails(self): ) self.context.update_settings({"public_invites": True}) - with self.assertRaises(ConnectionManagerError), async_mock.patch.object( + with self.assertRaises(ConnectionManagerError), mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) async def test_receive_request_public_did_conn_invite(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -649,35 +648,35 @@ async def test_receive_request_public_did_conn_invite(self): did=self.test_did, ) - mock_connection_record = async_mock.MagicMock() - mock_connection_record.save = async_mock.CoroutineMock() - mock_connection_record.attach_request = async_mock.CoroutineMock() + mock_connection_record = mock.MagicMock() + mock_connection_record.save = mock.CoroutineMock() + mock_connection_record.attach_request = mock.CoroutineMock() self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "retrieve_by_invitation_msg_id", - async_mock.CoroutineMock(return_value=mock_connection_record), + mock.CoroutineMock(return_value=mock_connection_record), ) as mock_conn_retrieve_by_invitation_msg_id: conn_rec = await self.manager.receive_request(mock_request, receipt) assert conn_rec async def test_receive_request_public_did_unsolicited(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -692,18 +691,18 @@ async def test_receive_request_public_did_unsolicited(self): self.context.update_settings({"public_invites": True}) self.context.update_settings({"requests_through_public_did": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -711,8 +710,8 @@ async def test_receive_request_public_did_unsolicited(self): async def test_receive_request_public_did_no_did_doc(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did mock_request.connection.did_doc = None @@ -727,13 +726,13 @@ async def test_receive_request_public_did_no_did_doc(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): @@ -741,10 +740,10 @@ async def test_receive_request_public_did_no_did_doc(self): async def test_receive_request_public_did_wrong_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = "dummy" receipt = MessageReceipt( @@ -758,23 +757,23 @@ async def test_receive_request_public_did_wrong_did(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): await self.manager.receive_request(mock_request, receipt) async def test_receive_request_public_did_no_public_invites(self): - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) @@ -787,13 +786,13 @@ async def test_receive_request_public_did_no_public_invites(self): ) self.context.update_settings({"public_invites": False}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): @@ -801,10 +800,10 @@ async def test_receive_request_public_did_no_public_invites(self): async def test_receive_request_public_did_no_auto_accept(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -820,16 +819,16 @@ async def test_receive_request_public_did_no_auto_accept(self): self.context.update_settings( {"public_invites": True, "debug.auto_accept_requests": False} ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -841,16 +840,16 @@ async def test_receive_request_public_did_no_auto_accept(self): async def test_create_response(self): conn_rec = ConnRecord(state=ConnRecord.State.REQUEST.rfc160) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.CoroutineMock() + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.CoroutineMock() ): await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -868,24 +867,22 @@ async def test_create_response_multitenant(self): endpoint=self.test_mediator_endpoint, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ), async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( - ConnRecord, "metadata_get", async_mock.CoroutineMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + ConnRecord, "metadata_get", mock.CoroutineMock(return_value=False) + ), mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -942,23 +939,21 @@ async def test_create_response_mediation(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ), async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + record, "metadata_get", mock.CoroutineMock(return_value=False) + ), mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=[mediation_record]), + ), mock.patch.object( record, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnectionResponse, "sign_field", autospec=True ): did_info = DIDInfo( @@ -989,16 +984,16 @@ async def test_create_response_auto_send_mediation_request(self): ) conn_rec.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.CoroutineMock(return_value=True) + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.CoroutineMock(return_value=True) ): await self.manager.create_response(conn_rec) @@ -1008,30 +1003,30 @@ async def test_create_response_auto_send_mediation_request(self): assert target["connection_id"] == conn_rec.connection_id async def test_accept_response_find_by_thread_id(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = mock.CoroutineMock( return_value="sig_verkey" ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.CoroutineMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1040,34 +1035,34 @@ async def test_accept_response_find_by_thread_id(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.RESPONSE async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = mock.CoroutineMock( return_value="sig_verkey" ) receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + MediationManager, "get_default_mediator", mock.CoroutineMock() ): mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=False), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=False), connection_id="test-conn-id", invitation_key="test-invitation-id", ) @@ -1079,21 +1074,21 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel assert not self.responder.messages async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1102,21 +1097,21 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_bad_state(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 ) @@ -1124,22 +1119,22 @@ async def test_accept_response_find_by_thread_id_bad_state(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = None receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, ) @@ -1147,23 +1142,23 @@ async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_did_mismatch(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, ) @@ -1171,30 +1166,28 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_verify_invitation_key_sign_failure(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( - side_effect=ValueError - ) + mock_response.verify_signed_field = mock.CoroutineMock(side_effect=ValueError) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.CoroutineMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1202,30 +1195,30 @@ async def test_accept_response_verify_invitation_key_sign_failure(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_auto_send_mediation_request(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = mock.CoroutineMock( return_value="sig_verkey" ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.CoroutineMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=True), connection_id="test-conn-id", invitation_key="test-invitation-key", ) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index bed4e604bf..3328c9adbe 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -1,8 +1,8 @@ import json from unittest.mock import ANY -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -13,15 +13,15 @@ from .. import routes as test_module -class TestConnectionRoutes(AsyncTestCase): - async def setUp(self): +class TestConnectionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -42,16 +42,16 @@ async def test_connections_list(self): STATE_INVITATION = ConnRecord.State.INVITATION STATE_ABANDONED = ConnRecord.State.ABANDONED ROLE_REQUESTER = ConnRecord.Role.REQUESTER - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.query = async_mock.CoroutineMock() + mock_conn_rec.query = mock.CoroutineMock() mock_conn_rec.Role = ConnRecord.Role - mock_conn_rec.State = async_mock.MagicMock( + mock_conn_rec.State = mock.MagicMock( COMPLETED=STATE_COMPLETED, INVITATION=STATE_INVITATION, ABANDONED=STATE_ABANDONED, - get=async_mock.MagicMock( + get=mock.MagicMock( side_effect=[ ConnRecord.State.ABANDONED, ConnRecord.State.COMPLETED, @@ -60,24 +60,24 @@ async def test_connections_list(self): ), ) conns = [ # in ascending order here - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.COMPLETED.rfc23, "created_at": "1234567890", } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.INVITATION.rfc23, "created_at": "1234567890", } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.ABANDONED.rfc23, "created_at": "1234567890", @@ -87,9 +87,7 @@ async def test_connections_list(self): ] mock_conn_rec.query.return_value = [conns[2], conns[0], conns[1]] # jumbled - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.connections_list(self.request) mock_conn_rec.query.assert_called_once_with( ANY, @@ -126,15 +124,15 @@ async def test_connections_list_x(self): STATE_COMPLETED = ConnRecord.State.COMPLETED ROLE_REQUESTER = ConnRecord.Role.REQUESTER - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.Role = async_mock.MagicMock(return_value=ROLE_REQUESTER) - mock_conn_rec.State = async_mock.MagicMock( + mock_conn_rec.Role = mock.MagicMock(return_value=ROLE_REQUESTER) + mock_conn_rec.State = mock.MagicMock( COMPLETED=STATE_COMPLETED, - get=async_mock.MagicMock(return_value=ConnRecord.State.COMPLETED), + get=mock.MagicMock(return_value=ConnRecord.State.COMPLETED), ) - mock_conn_rec.query = async_mock.CoroutineMock( + mock_conn_rec.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -143,12 +141,12 @@ async def test_connections_list_x(self): async def test_connections_retrieve(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock(return_value={"hello": "world"}) + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -158,15 +156,15 @@ async def test_connections_retrieve(self): async def test_connections_endpoints(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr_cls, async_mock.patch.object( + ) as mock_conn_mgr_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.CoroutineMock( return_value=("localhost:8080", "1.2.3.4:8081") ) ) @@ -180,26 +178,22 @@ async def test_connections_endpoints(self): async def test_connections_endpoints_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr_cls, async_mock.patch.object( + ) as mock_conn_mgr_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( - side_effect=StorageNotFoundError() - ) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.CoroutineMock(side_effect=StorageNotFoundError()) ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_endpoints(self.request) - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( - side_effect=test_module.WalletError() - ) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.CoroutineMock(side_effect=test_module.WalletError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -207,13 +201,13 @@ async def test_connections_endpoints_x(self): async def test_connections_metadata(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() + ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -225,16 +219,16 @@ async def test_connections_metadata(self): async def test_connections_metadata_get_single(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() self.request.query = {"key": "test"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_get", async_mock.CoroutineMock() - ) as mock_metadata_get, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_get", mock.CoroutineMock() + ) as mock_metadata_get, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -246,13 +240,13 @@ async def test_connections_metadata_get_single(self): async def test_connections_metadata_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() + ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -267,18 +261,18 @@ async def test_connections_metadata_x(self): async def test_connections_metadata_set(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - self.request.json = async_mock.CoroutineMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.CoroutineMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.CoroutineMock() + ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -290,18 +284,18 @@ async def test_connections_metadata_set(self): async def test_connections_metadata_set_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - self.request.json = async_mock.CoroutineMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.CoroutineMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.CoroutineMock() + ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -317,8 +311,8 @@ async def test_connections_metadata_set_x(self): async def test_connections_retrieve_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -327,13 +321,13 @@ async def test_connections_retrieve_not_found(self): async def test_connections_retrieve_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -349,7 +343,7 @@ async def test_connections_create_invitation(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -357,19 +351,19 @@ async def test_connections_create_invitation(self): "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( return_value=( - async_mock.MagicMock( # connection record + mock.MagicMock( # connection record connection_id="dummy", alias="conn-alias" ), - async_mock.MagicMock( # invitation - serialize=async_mock.MagicMock(return_value={"a": "value"}), - to_url=async_mock.MagicMock(return_value="http://endpoint.ca"), + mock.MagicMock( # invitation + serialize=mock.MagicMock(return_value={"a": "value"}), + to_url=mock.MagicMock(return_value="http://endpoint.ca"), ), ) ) @@ -398,7 +392,7 @@ async def test_connections_create_invitation(self): async def test_connections_create_invitation_x(self): self.context.update_settings({"public_invites": True}) - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -406,10 +400,10 @@ async def test_connections_create_invitation_x(self): "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -425,17 +419,17 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", "public": "true", "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -443,7 +437,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): async def test_connections_create_invitation_public_forbidden(self): self.context.update_settings({"public_invites": False}) - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -455,23 +449,23 @@ async def test_connections_create_invitation_public_forbidden(self): await test_module.connections_create_invitation(self.request) async def test_connections_receive_invitation(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=mock_conn_rec ) @@ -479,18 +473,18 @@ async def test_connections_receive_invitation(self): mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) async def test_connections_receive_invitation_bad(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: mock_inv_deser.side_effect = test_module.BaseModelError() @@ -505,22 +499,22 @@ async def test_connections_receive_invitation_forbidden(self): await test_module.connections_receive_invitation(self.request) async def test_connections_receive_invitation_x_bad_mediation_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", "mediation_id": "some-id", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -534,18 +528,18 @@ async def test_connections_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_request = mock.CoroutineMock() await test_module.connections_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -553,8 +547,8 @@ async def test_connections_accept_invitation(self): async def test_connections_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -564,12 +558,12 @@ async def test_connections_accept_invitation_not_found(self): async def test_connections_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -580,12 +574,12 @@ async def test_connections_accept_invitation_x_bad_mediation_id(self): self.request.match_info = {"conn_id": "dummy"} self.request.query["mediation_id"] = "some-id" - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_request = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -598,18 +592,18 @@ async def test_connections_accept_request(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() await test_module.connections_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -617,8 +611,8 @@ async def test_connections_accept_request(self): async def test_connections_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -628,14 +622,14 @@ async def test_connections_accept_request_not_found(self): async def test_connections_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_response = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -644,12 +638,12 @@ async def test_connections_accept_request_x(self): async def test_connections_remove(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.CoroutineMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.CoroutineMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -663,12 +657,12 @@ async def test_connections_remove_cache_key(self): await cache.set("conn_rec_state::dummy", "active") profile.context.injector.bind_instance(BaseCache, cache) self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.CoroutineMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.CoroutineMock() assert (await cache.get("conn_rec_state::dummy")) == "active" - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -680,10 +674,10 @@ async def test_connections_remove_cache_key(self): async def test_connections_remove_not_found(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -692,14 +686,12 @@ async def test_connections_remove_not_found(self): async def test_connections_remove_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + mock_conn_rec = mock.MagicMock( + delete_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -707,7 +699,7 @@ async def test_connections_remove_x(self): await test_module.connections_remove(self.request) async def test_connections_create_static(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -725,24 +717,22 @@ async def test_connections_create_static(self): } self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() - mock_my_info = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() + mock_my_info = mock.MagicMock() mock_my_info.did = "my_did" mock_my_info.verkey = "my_verkey" - mock_their_info = async_mock.MagicMock() + mock_their_info = mock.MagicMock() mock_their_info.did = "their_did" mock_their_info.verkey = "their_verkey" - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_static_connection = ( - async_mock.CoroutineMock( - return_value=(mock_my_info, mock_their_info, mock_conn_rec) - ) + mock_conn_mgr.return_value.create_static_connection = mock.CoroutineMock( + return_value=(mock_my_info, mock_their_info, mock_conn_rec) ) await test_module.connections_create_static(self.request) @@ -758,7 +748,7 @@ async def test_connections_create_static(self): ) async def test_connections_create_static_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -776,33 +766,33 @@ async def test_connections_create_static_x(self): } self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() - mock_my_info = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() + mock_my_info = mock.MagicMock() mock_my_info.did = "my_did" mock_my_info.verkey = "my_verkey" - mock_their_info = async_mock.MagicMock() + mock_their_info = mock.MagicMock() mock_their_info.did = "their_did" mock_their_info.verkey = "their_verkey" - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_static_connection = ( - async_mock.CoroutineMock(side_effect=test_module.WalletError()) + mock_conn_mgr.return_value.create_static_connection = mock.CoroutineMock( + side_effect=test_module.WalletError() ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_create_static(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py index 064c06dd4e..9fb4e64433 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py @@ -1,6 +1,6 @@ """Test handler for keylist-query message.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -20,10 +20,10 @@ TEST_VERKEY_DIDKEY = "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL" -class TestKeylistQueryHandler(AsyncTestCase): +class TestKeylistQueryHandler(IsolatedAsyncioTestCase): """Test handler for keylist-query message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py index f2a6830e5d..922ef80b98 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py @@ -1,6 +1,6 @@ """Test handler for keylist-update message.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -19,10 +19,10 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestKeylistUpdateHandler(AsyncTestCase): +class TestKeylistUpdateHandler(IsolatedAsyncioTestCase): """Test handler for keylist-update message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py index b5774c5723..2b57a90bb6 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py @@ -3,8 +3,8 @@ from functools import partial from typing import AsyncGenerator import pytest -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ......connections.models.conn_record import ConnRecord @@ -26,10 +26,10 @@ TEST_ROUTE_VERKEY = "did:key:z6MknxTj6Zj1VrDWc1ofaZtmCVv2zNXpD58Xup4ijDGoQhya" -class TestKeylistUpdateResponseHandler(AsyncTestCase): +class TestKeylistUpdateResponseHandler(IsolatedAsyncioTestCase): """Test handler for keylist-update-response message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.updated = [ @@ -60,9 +60,9 @@ async def test_handler_no_active_connection(self): async def test_handler(self): handler, responder = KeylistUpdateResponseHandler(), MockResponder() - with async_mock.patch.object( + with mock.patch.object( MediationManager, "store_update_results" - ) as mock_store, async_mock.patch.object( + ) as mock_store, mock.patch.object( handler, "notify_keylist_updated" ) as mock_notify: await handler.handle(self.context, responder) @@ -84,7 +84,7 @@ async def _retrieve_by_invitation_key( ): return await generator.__anext__() - with async_mock.patch.object( + with mock.patch.object( self.route_manager, "connection_from_recipient_key", partial(_retrieve_by_invitation_key, _result_generator()), diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py index 08a8b42c97..6437002428 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py @@ -1,6 +1,6 @@ """Test mediate deny message handler.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -13,10 +13,10 @@ TEST_CONN_ID = "conn-id" -class TestMediationDenyHandler(AsyncTestCase): +class TestMediationDenyHandler(IsolatedAsyncioTestCase): """Test mediate deny message handler.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py index d3a39dbebb..5234713869 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py @@ -1,7 +1,7 @@ """Test mediate grant message handler.""" import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from aries_cloudagent.core.profile import ProfileSession @@ -81,11 +81,11 @@ async def test_handler_connection_has_set_to_default_meta( handler, responder = MediationGrantHandler(), MockResponder() record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object( + with mock.patch.object( context.connection_record, "metadata_get", - async_mock.CoroutineMock(return_value=True), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=True), + ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: await handler.handle(context, responder) @@ -96,25 +96,25 @@ async def test_handler_connection_has_set_to_default_meta( async def test_handler_multitenant_base_mediation( self, session: ProfileSession, context: RequestContext ): - handler, responder = MediationGrantHandler(), async_mock.CoroutineMock() - responder.send = async_mock.CoroutineMock() + handler, responder = MediationGrantHandler(), mock.CoroutineMock() + responder.send = mock.CoroutineMock() profile = context.profile profile.context.update_settings( {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - multitenant_mgr = async_mock.CoroutineMock() + multitenant_mgr = mock.CoroutineMock() profile.context.injector.bind_instance(BaseMultitenantManager, multitenant_mgr) default_base_mediator = MediationRecord(routing_keys=["key1", "key2"]) - multitenant_mgr.get_default_mediator = async_mock.CoroutineMock() + multitenant_mgr.get_default_mediator = mock.CoroutineMock() multitenant_mgr.get_default_mediator.return_value = default_base_mediator record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object(MediationManager, "add_key") as add_key: - keylist_updates = async_mock.MagicMock() + with mock.patch.object(MediationManager, "add_key") as add_key: + keylist_updates = mock.MagicMock() add_key.return_value = keylist_updates await handler.handle(context, responder) @@ -130,11 +130,11 @@ async def test_handler_connection_no_set_to_default( handler, responder = MediationGrantHandler(), MockResponder() record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object( + with mock.patch.object( context.connection_record, "metadata_get", - async_mock.CoroutineMock(return_value=False), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=False), + ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: await handler.handle(context, responder) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py index d3c342ec07..e32fe4f9da 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py @@ -1,6 +1,6 @@ """Test mediate request message handler.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -19,10 +19,10 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestMediationRequestHandler(AsyncTestCase): +class TestMediationRequestHandler(IsolatedAsyncioTestCase): """Test mediate request message handler.""" - async def setUp(self): + async def asyncSetUp(self): """setup dependencies of messaging""" self.context = RequestContext.test_context() self.context.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py index 6cf8857a9f..03b0e1cdda 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py @@ -1,6 +1,6 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from unittest import TestCase -from asynctest import mock as async_mock +from unittest import mock from aries_cloudagent.protocols.coordinate_mediation.mediation_invite_store import ( MediationInviteStore, @@ -47,9 +47,9 @@ def test_unused_should_create_unused_record(self): assert not MediationInviteRecord.unused("some_other_invite").used -class TestMediationInviteStore(AsyncTestCase): +class TestMediationInviteStore(IsolatedAsyncioTestCase): def setUp(self): - self.storage = async_mock.MagicMock(spec=BaseStorage) + self.storage = mock.MagicMock(spec=BaseStorage) self.mediation_invite_store = MediationInviteStore(self.storage) async def test_store_create_record_to_store_mediation_invite_when_no_record_exists( diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py index 5848c59063..8f013fe177 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py @@ -2,7 +2,7 @@ import logging from typing import AsyncIterable, Iterable -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock import pytest from .. import manager as test_module @@ -251,8 +251,8 @@ async def test_set_set_get_default_mediator_id( assert await manager.get_default_mediator_id() == "updated" async def test_set_default_mediator_by_id(self, manager: MediationManager): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: await manager.set_default_mediator_by_id("test") @@ -404,23 +404,23 @@ async def test_store_update_results( ), ] - with async_mock.patch.object( - RouteRecord, "query", async_mock.CoroutineMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.CoroutineMock() + ) as mock_route_rec_query, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.side_effect = StorageNotFoundError("no record") await manager.store_update_results(TEST_CONN_ID, results) mock_logger_error.assert_called_once() - with async_mock.patch.object( - RouteRecord, "query", async_mock.CoroutineMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.CoroutineMock() + ) as mock_route_rec_query, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.return_value = [ - async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) + mock.MagicMock(delete_record=mock.CoroutineMock()) ] * 2 await manager.store_update_results(TEST_CONN_ID, results) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py index f543efe386..ac23e8c4ef 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from asynctest import mock +from aries_cloudagent.tests import mock import pytest from .....connections.models.conn_record import ConnRecord diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py index d4b3a83c99..bdf9911c32 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -9,23 +10,23 @@ from .....wallet.did_method import DIDMethods -class TestCoordinateMediationRoutes(AsyncTestCase): +class TestCoordinateMediationRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.context = AdminRequestContext.test_context(profile=self.profile) - self.outbound_message_router = async_mock.CoroutineMock() + self.outbound_message_router = mock.CoroutineMock() self.request_dict = { "context": self.context, "outbound_message_router": self.outbound_message_router, } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( match_info={ "mediation_id": "test-mediation-id", "conn_id": "test-conn-id", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: self.request_dict[k], ) serialized = { @@ -37,10 +38,10 @@ def setUp(self): "endpoint": "http://192.168.1.13:3005", "created_at": "1234567890", } - self.mock_record = async_mock.MagicMock( + self.mock_record = mock.MagicMock( **serialized, - serialize=async_mock.MagicMock(return_value=serialized), - save=async_mock.CoroutineMock() + serialize=mock.MagicMock(return_value=serialized), + save=mock.CoroutineMock() ) def test_mediation_sort_key(self): @@ -65,16 +66,16 @@ def test_mediation_sort_key(self): async def test_list_mediation_requests(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "query", - async_mock.CoroutineMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.CoroutineMock(return_value=[self.mock_record]), + ) as mock_query, mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=InMemoryProfile.test_session()), + mock.MagicMock(return_value=InMemoryProfile.test_session()), ) as session: await test_module.list_mediation_requests(self.request) json_response.assert_called_once_with( @@ -87,16 +88,16 @@ async def test_list_mediation_requests_filters(self): "state": MediationRecord.STATE_GRANTED, "conn_id": "test-conn-id", } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "query", - async_mock.CoroutineMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.CoroutineMock(return_value=[self.mock_record]), + ) as mock_query, mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=InMemoryProfile.test_session()), + mock.MagicMock(return_value=InMemoryProfile.test_session()), ) as session: await test_module.list_mediation_requests(self.request) json_response.assert_called_once_with( @@ -111,31 +112,31 @@ async def test_list_mediation_requests_filters(self): ) async def test_list_mediation_requests_x(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationRecord", - async_mock.MagicMock( - query=async_mock.CoroutineMock(side_effect=test_module.StorageError()) + mock.MagicMock( + query=mock.CoroutineMock(side_effect=test_module.StorageError()) ), ) as mock_med_rec: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.list_mediation_requests(self.request) async def test_list_mediation_requests_no_records(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationRecord", - async_mock.MagicMock(query=async_mock.CoroutineMock(return_value=[])), - ) as mock_med_rec, async_mock.patch.object( + mock.MagicMock(query=mock.CoroutineMock(return_value=[])), + ) as mock_med_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.list_mediation_requests(self.request) mock_response.assert_called_once_with({"results": []}) async def test_retrieve_mediation_request(self): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_mediation_record_retrieve.return_value = self.mock_record @@ -146,11 +147,11 @@ async def test_retrieve_mediation_request(self): mock_mediation_record_retrieve.assert_called() async def test_retrieve_mediation_request_x_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPNotFound @@ -158,11 +159,11 @@ async def test_retrieve_mediation_request_x_not_found(self): await test_module.retrieve_mediation_request(self.request) async def test_retrieve_mediation_request_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPBadRequest @@ -170,11 +171,11 @@ async def test_retrieve_mediation_request_x_storage_error(self): await test_module.retrieve_mediation_request(self.request) async def test_delete_mediation_request(self): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( - self.mock_record, "delete_record", async_mock.CoroutineMock() - ) as mock_delete_record, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_mediation_record_retrieve, mock.patch.object( + self.mock_record, "delete_record", mock.CoroutineMock() + ) as mock_delete_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_mediation_record_retrieve.return_value = self.mock_record @@ -186,11 +187,11 @@ async def test_delete_mediation_request(self): mock_delete_record.assert_called() async def test_delete_mediation_request_x_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPNotFound @@ -198,11 +199,11 @@ async def test_delete_mediation_request_x_not_found(self): await test_module.delete_mediation_request(self.request) async def test_delete_mediation_request_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPBadRequest @@ -212,22 +213,22 @@ async def test_delete_mediation_request_x_storage_error(self): async def test_request_mediation(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", autospec=True - ) as mock_med_mgr, async_mock.patch.object( + ) as mock_med_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.CoroutineMock(return_value=False), - ) as mock_mediation_record_exists, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + mock.CoroutineMock(return_value=False), + ) as mock_mediation_record_exists, mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: - mock_med_mgr.return_value.prepare_request = async_mock.CoroutineMock( + mock_med_mgr.return_value.prepare_request = mock.CoroutineMock( return_value=( self.mock_record, - async_mock.MagicMock( # mediation request - serialize=async_mock.MagicMock(return_value={"a": "value"}), + mock.MagicMock( # mediation request + serialize=mock.MagicMock(return_value={"a": "value"}), ), ) ) @@ -240,10 +241,10 @@ async def test_request_mediation(self): async def test_request_mediation_x_conn_not_ready(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=async_mock.MagicMock(is_ready=False)), + mock.CoroutineMock(return_value=mock.MagicMock(is_ready=False)), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -253,12 +254,12 @@ async def test_request_mediation_x_conn_not_ready(self): async def test_request_mediation_x_already_exists(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.CoroutineMock(return_value=True), + mock.CoroutineMock(return_value=True), ) as mock_exists_for_conn, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -268,10 +269,10 @@ async def test_request_mediation_x_already_exists(self): async def test_request_mediation_x_conn_not_found(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPNotFound ): @@ -280,10 +281,10 @@ async def test_request_mediation_x_conn_not_found(self): async def test_request_mediation_x_storage_error(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ): @@ -291,11 +292,11 @@ async def test_request_mediation_x_storage_error(self): async def test_mediation_request_grant_role_server(self): self.mock_record.role = MediationRecord.ROLE_SERVER - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(return_value=self.mock_record), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.mediation_request_grant(self.request) @@ -306,36 +307,36 @@ async def test_mediation_request_grant_role_server(self): async def test_mediation_request_grant_role_client_x(self): self.mock_record.role = MediationRecord.ROLE_CLIENT - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) async def test_mediation_request_grant_x_rec_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_grant(self.request) async def test_mediation_request_grant_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) async def test_mediation_request_deny_role_server(self): self.mock_record.role = MediationRecord.ROLE_SERVER - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.CoroutineMock(return_value=self.mock_record), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.mediation_request_deny(self.request) @@ -346,30 +347,30 @@ async def test_mediation_request_deny_role_server(self): async def test_mediation_request_deny_role_client_x(self): self.mock_record.role = MediationRecord.ROLE_CLIENT - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ): - mock_mediation_record_retrieve.return_value = async_mock.MagicMock( + mock_mediation_record_retrieve.return_value = mock.MagicMock( role=MediationRecord.ROLE_CLIENT ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) async def test_mediation_request_deny_x_rec_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_deny(self.request) async def test_mediation_request_deny_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) @@ -379,22 +380,20 @@ async def test_get_keylist(self): self.request.query["conn_id"] = "test-id" query_results = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"serialized": "route record"} - ) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"serialized": "route record"}) ) ] - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(return_value=query_results), - ) as mock_query, async_mock.patch.object( + mock.CoroutineMock(return_value=query_results), + ) as mock_query, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=session), - ) as mock_session, async_mock.patch.object( + mock.MagicMock(return_value=session), + ) as mock_session, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.get_keylist(self.request) @@ -408,15 +407,15 @@ async def test_get_keylist(self): async def test_get_keylist_no_matching_records(self): session = await self.profile.session() - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(return_value=[]), - ) as mock_query, async_mock.patch.object( + mock.CoroutineMock(return_value=[]), + ) as mock_query, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=session), - ) as mock_session, async_mock.patch.object( + mock.MagicMock(return_value=session), + ) as mock_session, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.get_keylist(self.request) @@ -424,10 +423,10 @@ async def test_get_keylist_no_matching_records(self): mock_response.assert_called_once_with({"results": []}, status=200) async def test_get_keylist_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(side_effect=test_module.StorageError), + mock.CoroutineMock(side_effect=test_module.StorageError), ) as mock_query, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_keylist(self.request) @@ -459,18 +458,18 @@ async def test_send_keylist_update(self): self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( state=MediationRecord.STATE_GRANTED, connection_id="test-conn-id" ) ), - ) as mock_retrieve_by_id, async_mock.patch.object( + ) as mock_retrieve_by_id, mock.patch.object( test_module.web, "json_response", - async_mock.MagicMock( + mock.MagicMock( side_effect=lambda *args, **kwargs: [*args, *kwargs.values()] ), ) as mock_response: @@ -501,11 +500,11 @@ async def test_send_keylist_update_bad_mediation_state(self): ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( state=MediationRecord.STATE_DENIED, connection_id="test-conn-id" ) ), @@ -526,10 +525,10 @@ async def test_send_keylist_update_x_no_mediation_rec(self): }, ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_update(self.request) @@ -543,26 +542,26 @@ async def test_send_keylist_update_x_storage_error(self): ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_update(self.request) - @async_mock.patch.object(test_module, "MediationManager", autospec=True) + @mock.patch.object(test_module, "MediationManager", autospec=True) async def test_send_keylist_query(self, mock_manager): self.request.json.return_value = {"filter": {"test": "filter"}} self.request.query = {"paginate_limit": 10, "paginate_offset": 20} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), - ) as mock_retrieve_by_id, async_mock.patch.object( + mock.CoroutineMock(return_value=self.mock_record), + ) as mock_retrieve_by_id, mock.patch.object( mock_manager.return_value, "prepare_keylist_query", - async_mock.CoroutineMock(), - ) as mock_prepare_keylist_query, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_prepare_keylist_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.send_keylist_query(self.request) @@ -576,29 +575,29 @@ async def test_send_keylist_query(self, mock_manager): ) async def test_send_keylist_query_x_no_mediation_record(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_query(self.request) async def test_send_keylist_query_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_query(self.request) async def test_get_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -608,12 +607,12 @@ async def test_get_default_mediator(self): async def test_get_empty_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -623,12 +622,12 @@ async def test_get_empty_default_mediator(self): async def test_get_default_mediator_storage_error(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mgr_get_default_record: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_default_mediator(self.request) @@ -638,15 +637,15 @@ async def test_set_default_mediator(self): "mediation_id": "fake_id", } self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.CoroutineMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.CoroutineMock(), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.set_default_mediator(self.request) @@ -660,15 +659,15 @@ async def test_set_default_mediator_storage_error(self): "mediation_id": "bad_id", } self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageError()), + ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -676,15 +675,15 @@ async def test_set_default_mediator_storage_error(self): async def test_clear_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.CoroutineMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.CoroutineMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.clear_default_mediator(self.request) @@ -695,15 +694,15 @@ async def test_clear_default_mediator(self): async def test_clear_default_mediator_storage_error(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.CoroutineMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.CoroutineMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -715,17 +714,17 @@ async def test_update_keylist_for_connection(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.update_keylist_for_connection(self.request) @@ -737,18 +736,18 @@ async def test_update_keylist_for_connection_not_found(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPNotFound): await test_module.update_keylist_for_connection(self.request) @@ -759,30 +758,30 @@ async def test_update_keylist_for_connection_storage_error(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageError), + mock.CoroutineMock(side_effect=StorageError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.update_keylist_for_connection(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py index 945a6de809..55971a2fda 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -25,9 +25,9 @@ class TestDIDXCompleteHandler: """Class unit testing complete handler.""" @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_complete = mock.CoroutineMock() request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() @@ -38,21 +38,19 @@ async def test_called(self, mock_conn_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") - async def test_x(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.CoroutineMock( + @mock.patch.object(test_module, "DIDXManager") + async def test_x( + self, mock_conn_mgr, request_context, caplog: pytest.LogCaptureFixture + ): + mock_conn_mgr.return_value.accept_complete = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value ) ) - mock_conn_mgr.return_value._logger = async_mock.MagicMock( - exception=async_mock.MagicMock() - ) + mock_conn_mgr.return_value._logger = mock.MagicMock(exception=mock.MagicMock()) request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() - await handler_inst.handle(request_context, responder) - - assert mock_conn_mgr.return_value._logger.exception.called_once_( - "Error receiving connection complete" - ) + with caplog.at_level("ERROR"): + await handler_inst.handle(request_context, responder) + assert "Error receiving connection complete" in caplog.text diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py index e851c2d8c7..72382fefe1 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,4 +1,4 @@ -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock import pytest from .. import problem_report_handler as test_module @@ -19,21 +19,21 @@ class TestDIDXProblemReportHandler: """Unit test problem report handler.""" @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.CoroutineMock() + manager.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = DIDXProblemReport() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() await handler_inst.handle(request_context, responder) assert not responder.messages - assert manager.return_value.receive_problem_report.called_once() + manager.return_value.receive_problem_report.assert_called_once() @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_no_conn(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.CoroutineMock() + manager.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = DIDXProblemReport() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() @@ -41,15 +41,15 @@ async def test_called_no_conn(self, manager, request_context): await handler_inst.handle(request_context, responder) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_unrecognized_report_exception( self, manager, request_context, caplog ): - manager.return_value.receive_problem_report = async_mock.CoroutineMock( + manager.return_value.receive_problem_report = mock.CoroutineMock( side_effect=DIDXManagerError() ) request_context.message = DIDXProblemReport() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() await handler_inst.handle(request_context, responder) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py index dada5723a3..c956b5f8c8 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py @@ -1,5 +1,5 @@ -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......connections.models import conn_record, connection_target from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service @@ -22,7 +22,7 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestDIDXRequestHandler(AsyncTestCase): +class TestDIDXRequestHandler(IsolatedAsyncioTestCase): """Class unit testing request handler.""" def did_doc(self): @@ -52,7 +52,7 @@ def did_doc(self): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.ctx = RequestContext.test_context() self.ctx.message_receipt = MessageReceipt( recipient_did="dummy", @@ -91,9 +91,9 @@ async def setUp(self): did_doc_attach=self.did_doc_attach, ) - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -106,15 +106,15 @@ async def test_called(self, mock_didx_mgr): ) assert not responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_with_auto_response(self, mock_didx_mgr): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = conn_record.ConnRecord.ACCEPT_AUTO - mock_conn_rec.save = async_mock.CoroutineMock() - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_rec.save = mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -130,7 +130,7 @@ async def test_called_with_auto_response(self, mock_didx_mgr): ) assert responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_connection_record_with_mediation_metadata_auto_response( self, mock_didx_mgr ): @@ -141,15 +141,15 @@ async def test_connection_record_with_mediation_metadata_auto_response( invitation_msg_id="12345678-1234-5678-1234-567812345678", their_role=conn_record.ConnRecord.Role.REQUESTER, ) - test_exist_conn.metadata_get = async_mock.CoroutineMock( + test_exist_conn.metadata_get = mock.CoroutineMock( return_value={"id": "mediation-test-id"} ) test_exist_conn.accept = conn_record.ConnRecord.ACCEPT_AUTO - test_exist_conn.save = async_mock.CoroutineMock() - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + test_exist_conn.save = mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=test_exist_conn ) - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() test_ctx = RequestContext.test_context() test_ctx.message = DIDXRequest() test_ctx.message_receipt = MessageReceipt() @@ -162,9 +162,9 @@ async def test_connection_record_with_mediation_metadata_auto_response( ) assert responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) @@ -186,15 +186,15 @@ async def test_problem_report(self, mock_didx_mgr): ) assert target == {"target_list": None} - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc(self, mock_conn_target, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) self.ctx.message = DIDXRequest( @@ -218,19 +218,19 @@ async def test_problem_report_did_doc(self, mock_conn_target, mock_didx_mgr): ) assert target == {"target_list": [mock_conn_target]} - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=DIDXManagerError("no targets") ) self.ctx.message = DIDXRequest( diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py index fa4fe5ad12..af9fd617ee 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -30,7 +30,7 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestDIDXResponseHandler(AsyncTestCase): +class TestDIDXResponseHandler(IsolatedAsyncioTestCase): def did_doc(self): doc = DIDDoc(did=TEST_DID) controller = TEST_DID @@ -58,7 +58,7 @@ def did_doc(self): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.ctx = RequestContext.test_context() self.ctx.message_receipt = MessageReceipt() @@ -78,9 +78,9 @@ async def setUp(self): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -92,10 +92,10 @@ async def test_called(self, mock_didx_mgr): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_auto_ping(self, mock_didx_mgr): self.ctx.update_settings({"auto_ping_connection": True}) - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -110,9 +110,9 @@ async def test_called_auto_ping(self, mock_didx_mgr): assert isinstance(result, Ping) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) @@ -135,19 +135,19 @@ async def test_problem_report(self, mock_didx_mgr): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) self.ctx.message = DIDXResponse( @@ -171,19 +171,19 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=DIDXManagerError("no target") ) self.ctx.message = DIDXResponse( diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py index 3b769d56c4..835b7afcb3 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile @@ -49,8 +49,8 @@ def make_did_doc(self): return doc -class TestDIDXRequest(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDIDXRequest(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet @@ -123,10 +123,10 @@ def test_method_other_than_indy(self): assert request.serialize() == new_request.serialize() -class TestDIDXRequestSchema(AsyncTestCase, TestConfig): +class TestDIDXRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test request schema.""" - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py index 3be60ca51e..b13711e078 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile @@ -46,8 +46,8 @@ def make_did_doc(self): return doc -class TestDIDXResponse(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDIDXResponse(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet @@ -101,10 +101,10 @@ def test_serialize(self, mock_response_schema_dump): assert response_dict is mock_response_schema_dump.return_value -class TestDIDXResponseSchema(AsyncTestCase, TestConfig): +class TestDIDXResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test response schema.""" - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index 4372ca4296..d6511ee48a 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from pydid import DIDDocument from .. import manager as test_module @@ -68,22 +68,22 @@ def make_did_doc(self, did, verkey): return doc -class TestDidExchangeManager(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDidExchangeManager(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.CoroutineMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = mock.CoroutineMock( return_value=None ) - self.route_manager.mediation_record_for_connection = async_mock.CoroutineMock( + self.route_manager.mediation_record_for_connection = mock.CoroutineMock( return_value=None ) @@ -112,26 +112,26 @@ async def setUp(self): key_type=ED25519, ) - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.get_endpoint_for_did = async_mock.CoroutineMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.get_endpoint_for_did = mock.CoroutineMock( return_value=TestConfig.test_endpoint ) self.context.injector.bind_instance(BaseLedger, self.ledger) - self.resolver = async_mock.MagicMock() + self.resolver = mock.MagicMock() did_doc = DIDDocument.deserialize(DOC) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) assert did_doc.verification_method - self.resolver.dereference_verification_method = async_mock.CoroutineMock( + self.resolver.dereference_verification_method = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) - self.multitenant_mgr.get_default_mediator = async_mock.CoroutineMock( + self.multitenant_mgr.get_default_mediator = mock.CoroutineMock( return_value=None ) @@ -176,9 +176,9 @@ async def test_receive_invitation(self): ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -187,9 +187,9 @@ async def test_receive_invitation(self): hs_protos=[HSProto.RFC23], ) invi_msg = invi_rec.invitation - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) invitee_record = await self.manager.receive_invitation(invi_msg) @@ -204,9 +204,9 @@ async def test_receive_invitation_oob_public_did(self): ED25519, ) public_did_info = await session.wallet.get_public_did() - with async_mock.patch.object( + with mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = None @@ -216,9 +216,9 @@ async def test_receive_invitation_oob_public_did(self): ) invi_msg = invi_rec.invitation invi_msg.services = [public_did_info.did] - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) invitee_record = await self.manager.receive_invitation( @@ -236,7 +236,7 @@ async def test_receive_invitation_no_auto_accept(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -279,14 +279,14 @@ async def test_create_request_implicit(self): ) await mediation_record.save(session) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( + with mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) conn_rec = await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -356,8 +356,8 @@ async def test_create_request_implicit_x_public_already_connected(self): SOV, ED25519, ) - with self.assertRaises(DIDXManagerError) as context, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + with self.assertRaises(DIDXManagerError) as context, mock.patch.object( + test_module.ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve_by_did: await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -371,25 +371,25 @@ async def test_create_request_implicit_x_public_already_connected(self): assert "Connection already exists for their_did" in str(context.exception) async def test_create_request(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=self.did_info.did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.CoroutineMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + with mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request(mock_conn_rec) @@ -400,15 +400,15 @@ async def test_create_request_multitenant(self): {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_wallet_create_local_did.return_value = DIDInfo( TestConfig.test_did, @@ -417,25 +417,25 @@ async def test_create_request_multitenant(self): method=SOV, key_type=ED25519, ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) await self.manager.create_request( - async_mock.MagicMock( + mock.MagicMock( invitation_key=TestConfig.test_verkey, their_label="Hello", their_role=ConnRecord.Role.RESPONDER.rfc160, alias="Bob", my_did=None, - retrieve_invitation=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.CoroutineMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) ) @@ -471,11 +471,11 @@ async def test_create_request_mediation_id(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + with mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request( @@ -488,7 +488,7 @@ async def test_create_request_mediation_id(self): self.route_manager.route_connection_as_invitee.assert_called_once() async def test_create_request_my_endpoint(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=None, their_did=TestConfig.test_target_did, @@ -497,19 +497,19 @@ async def test_create_request_my_endpoint(self): invitation_key=TestConfig.test_verkey, state=ConnRecord.State.REQUEST.rfc23, alias="Bob", - retrieve_invitation=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.CoroutineMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + with mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request( @@ -519,18 +519,18 @@ async def test_create_request_my_endpoint(self): assert didx_req async def test_create_request_public_did(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=self.did_info.did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.CoroutineMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) request = await self.manager.create_request(mock_conn_rec, use_public_did=True) @@ -538,16 +538,16 @@ async def test_create_request_public_did(self): async def test_receive_request_explicit_public_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( @@ -569,72 +569,70 @@ async def test_receive_request_explicit_public_did(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_mediation_mgr_prep_req.return_value = ( mediation_record, mock_request, ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) - ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -652,10 +650,10 @@ async def test_receive_request_explicit_public_did(self): async def test_receive_request_invi_not_found(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="explicit-not-a-did"), + _thread=mock.MagicMock(pthid="explicit-not-a-did"), ) await session.wallet.create_local_did( @@ -665,10 +663,10 @@ async def test_receive_request_invi_not_found(self): did=TestConfig.test_did, ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError) as context: @@ -684,10 +682,10 @@ async def test_receive_request_invi_not_found(self): async def test_receive_request_public_did_no_did_doc_attachment(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( @@ -709,74 +707,72 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() - ), async_mock.patch.object( + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( + self.manager, "record_did", mock.CoroutineMock() + ), mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_mediation_mgr_prep_req.return_value = ( mediation_record, mock_request, ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST - ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -794,10 +790,10 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=None, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -810,36 +806,34 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture: - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST - ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -856,17 +850,17 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): async def test_receive_request_public_did_x_not_public(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -878,10 +872,10 @@ async def test_receive_request_public_did_x_not_public(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture: - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.WALLET_ONLY ) @@ -899,16 +893,16 @@ async def test_receive_request_public_did_x_not_public(self): async def test_receive_request_public_did_x_wrong_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -920,35 +914,33 @@ async def test_receive_request_public_did_x_wrong_did(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( - test_module.DIDDoc, "from_json", async_mock.MagicMock() - ) as mock_did_doc_from_json, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( + test_module.DIDDoc, "from_json", mock.MagicMock() + ) as mock_did_doc_from_json, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + mock.CoroutineMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) - ) - mock_did_doc_from_json.return_value = async_mock.MagicMock( - did="wrong-did" + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) + mock_did_doc_from_json.return_value = mock.MagicMock(did="wrong-did") - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -966,16 +958,16 @@ async def test_receive_request_public_did_x_wrong_did(self): async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -987,30 +979,30 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(side_effect=DIDXManagerError), + mock.CoroutineMock(side_effect=DIDXManagerError), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -1026,17 +1018,17 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): async def test_receive_request_public_did_no_public_invites(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -1047,18 +1039,18 @@ async def test_receive_request_public_did_no_public_invites(self): ) self.profile.context.update_settings({"public_invites": False}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( - test_module.DIDDoc, "from_json", async_mock.MagicMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( + test_module.DIDDoc, "from_json", mock.MagicMock() ) as mock_did_doc_from_json: - mock_did_doc_from_json.return_value = async_mock.MagicMock( + mock_did_doc_from_json.return_value = mock.MagicMock( did=TestConfig.test_did ) with self.assertRaises(DIDXManagerError) as context: @@ -1074,16 +1066,16 @@ async def test_receive_request_public_did_no_public_invites(self): async def test_receive_request_public_did_no_auto_accept(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -1097,43 +1089,43 @@ async def test_receive_request_public_did_no_auto_accept(self): {"public_invites": True, "debug.auto_accept_requests": False} ) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=mock_conn_record ) - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) conn_rec = await self.manager.receive_request( request=mock_request, @@ -1150,17 +1142,17 @@ async def test_receive_request_public_did_no_auto_accept(self): async def test_receive_request_implicit_public_did_not_enabled(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1180,25 +1172,25 @@ async def test_receive_request_implicit_public_did_not_enabled(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=None) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=None ) with self.assertRaises(DIDXManagerError) as context: @@ -1213,17 +1205,17 @@ async def test_receive_request_implicit_public_did_not_enabled(self): async def test_receive_request_implicit_public_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1246,36 +1238,36 @@ async def test_receive_request_implicit_public_did(self): ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO STATE_REQUEST = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=None) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( + return_value=None ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record @@ -1295,19 +1287,19 @@ async def test_receive_request_implicit_public_did(self): async def test_receive_request_peer_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="dummy-pthid"), + _thread=mock.MagicMock(pthid="dummy-pthid"), ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=TestConfig.test_did, their_did=TestConfig.test_target_did, invitation_key=TestConfig.test_verkey, @@ -1315,12 +1307,10 @@ async def test_receive_request_peer_did(self): is_multiuse_invitation=True, state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.REQUESTER.rfc23, - save=async_mock.CoroutineMock(), - attach_request=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), accept=ConnRecord.ACCEPT_MANUAL, - metadata_get_all=async_mock.CoroutineMock( - return_value={"test": "value"} - ), + metadata_get_all=mock.CoroutineMock(return_value={"test": "value"}), ) mock_conn_rec_state_request = ConnRecord.State.REQUEST @@ -1332,42 +1322,42 @@ async def test_receive_request_peer_did(self): ) self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( return_value=mock_conn ) - mock_conn_rec_cls.return_value = async_mock.MagicMock( + mock_conn_rec_cls.return_value = mock.MagicMock( accept=ConnRecord.ACCEPT_AUTO, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), - metadata_set=async_mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -1385,17 +1375,17 @@ async def test_receive_request_peer_did(self): async def test_receive_request_peer_did_not_found_x(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="dummy-pthid"), + _thread=mock.MagicMock(pthid="dummy-pthid"), ) await session.wallet.create_local_did( @@ -1405,10 +1395,10 @@ async def test_receive_request_peer_did_not_found_x(self): did=TestConfig.test_did, ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError): @@ -1426,25 +1416,25 @@ async def test_create_response(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) @@ -1481,20 +1471,20 @@ async def test_create_response_mediation_id(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) - ), async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.CoroutineMock(return_value=False) + ), mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) await self.manager.create_response( @@ -1533,14 +1523,14 @@ async def test_create_response_mediation_id_invalid_conn_state(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.CoroutineMock(return_value=False) ): with self.assertRaises(DIDXManagerError) as context: await self.manager.create_response( @@ -1560,15 +1550,13 @@ async def test_create_response_multitenant(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_request" - ), async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() - ), async_mock.patch.object( + ), mock.patch.object(conn_rec, "save", mock.CoroutineMock()), mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1578,12 +1566,12 @@ async def test_create_response_multitenant(self): method=SOV, key_type=ED25519, ) - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) @@ -1597,28 +1585,28 @@ async def test_create_response_conn_rec_my_did(self): state=ConnRecord.State.REQUEST.rfc23, ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() - ) as mock_create_did_doc, async_mock.patch.object( - InMemoryWallet, "get_local_did", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() + ) as mock_create_did_doc, mock.patch.object( + InMemoryWallet, "get_local_did", mock.CoroutineMock() ) as mock_get_loc_did: mock_get_loc_did.return_value = self.did_info - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) @@ -1647,25 +1635,25 @@ async def test_create_response_use_public_did(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) @@ -1678,25 +1666,25 @@ async def test_create_response_use_public_did_x_no_public_did(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) @@ -1707,16 +1695,14 @@ async def test_create_response_use_public_did_x_no_public_did(self): assert "No public DID configured" in str(context.exception) async def test_accept_response_find_by_thread_id(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1726,38 +1712,38 @@ async def test_accept_response_find_by_thread_id(self): recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1765,16 +1751,14 @@ async def test_accept_response_find_by_thread_id(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_find_by_thread_id_auto_disclose_features(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1785,40 +1769,40 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): ) self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1827,50 +1811,48 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): mock_proactive_disclose_features.assert_called_once() async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=False), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=False), connection_id="test-conn-id", ) @@ -1879,28 +1861,26 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1909,28 +1889,26 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_bad_state(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 ) @@ -1938,8 +1916,8 @@ async def test_accept_response_find_by_thread_id_bad_state(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = None @@ -1948,30 +1926,30 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + self.manager, "record_did", mock.CoroutineMock() ): - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1979,8 +1957,8 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = None mock_response.did_doc_attach = None @@ -1989,30 +1967,30 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + self.manager, "record_did", mock.CoroutineMock() ): - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) with self.assertRaises(DIDXManagerError) as context: @@ -2020,88 +1998,84 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self assert "No DID in response" in str(context.exception) async def test_accept_response_find_by_thread_id_did_mismatch(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( - did=TestConfig.test_did - ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock(did=TestConfig.test_did) + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.CoroutineMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) with self.assertRaises(DIDXManagerError): await self.manager.accept_response(mock_response, receipt) async def test_accept_complete(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.CoroutineMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.CoroutineMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_complete_with_disclose(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.CoroutineMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.CoroutineMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED mock_proactive_disclose_features.assert_called_once() async def test_accept_complete_x_not_found(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() with self.assertRaises(DIDXManagerError): @@ -2115,7 +2089,7 @@ async def test_reject_invited(self): state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() reason = "He doesn't like you!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2128,7 +2102,7 @@ async def test_reject_requested(self): state=ConnRecord.State.REQUEST.rfc23, their_role=ConnRecord.Role.REQUESTER, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() reason = "I don't like you either! You just watch yourself!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2140,20 +2114,20 @@ async def test_reject_invalid(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() reason = "I'll be careful." with self.assertRaises(DIDXManagerError) as context: await self.manager.reject(mock_conn, reason=reason) assert "Cannot reject connection in state" in str(context.exception) async def test_receive_problem_report(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport( description={ "code": ProblemReportReason.REQUEST_NOT_ACCEPTED.value, @@ -2161,29 +2135,29 @@ async def test_receive_problem_report(self): } ) await self.manager.receive_problem_report(mock_conn, report) - assert mock_conn.abandon.called_once() + mock_conn.abandon.assert_called_once() async def test_receive_problem_report_x_missing_description(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport() with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) assert "Missing description" in str(context.exception) async def test_receive_problem_report_x_unrecognized_code(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport(description={"code": "something random"}) with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2258,10 +2232,10 @@ async def test_resolve_did_document_error(self): ED25519, ) public_did_info = await session.wallet.get_public_did() - with async_mock.patch.object( + with mock.patch.object( self.resolver, "resolve", - async_mock.CoroutineMock(side_effect=ResolverError()), + mock.CoroutineMock(side_effect=ResolverError()), ): with self.assertRaises(DIDXManagerError) as ctx: await self.manager.get_resolved_did_document(public_did_info.did) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py index ff5ad5c52c..6a3926b5b3 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -7,24 +7,22 @@ from ....coordinate_mediation.v1_0.route_manager import RouteManager -class TestDIDExchangeConnRoutes(AsyncTestCase): - async def setUp(self): +class TestDIDExchangeConnRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, __getitem__=lambda _, k: self.request_dict[k], ) - self.profile.context.injector.bind_instance( - RouteManager, async_mock.MagicMock() - ) + self.profile.context.injector.bind_instance(RouteManager, mock.MagicMock()) async def test_didx_accept_invitation(self): self.request.match_info = {"conn_id": "dummy"} @@ -33,18 +31,18 @@ async def test_didx_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock(save=async_mock.CoroutineMock()) - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock(save=mock.CoroutineMock()) + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_class, async_mock.patch.object( + ) as mock_conn_rec_class, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_class.retrieve_by_id.return_value = mock_conn_rec - mock_didx_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_request = mock.CoroutineMock() await test_module.didx_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -52,8 +50,8 @@ async def test_didx_accept_invitation(self): async def test_didx_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -63,12 +61,12 @@ async def test_didx_accept_invitation_not_found(self): async def test_didx_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr: - mock_didx_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) @@ -83,18 +81,14 @@ async def test_didx_create_request_implicit(self): "mediator_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value="mock serialization" - ) - ) + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="mock serialization") ) ) @@ -109,13 +103,13 @@ async def test_didx_create_request_implicit_not_found_x(self): "mediator_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock(side_effect=StorageNotFoundError("not found")) + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( + side_effect=StorageNotFoundError("not found") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -129,15 +123,13 @@ async def test_didx_create_request_implicit_wallet_x(self): "my_endpoint": "http://endpoint.ca", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock( - side_effect=test_module.WalletError("wallet error") - ) + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( + side_effect=test_module.WalletError("wallet error") ) with self.assertRaises(test_module.web.HTTPBadRequest) as context: @@ -150,19 +142,19 @@ async def test_didx_receive_request_implicit(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) @@ -175,16 +167,16 @@ async def test_didx_receive_request_implicit_not_found_x(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=StorageNotFoundError("tricorder must be broken") ) @@ -198,13 +190,13 @@ async def test_didx_receive_request_implicit_bad_request_x(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_didx_req_deser.side_effect = test_module.BaseModelError("bad bits") @@ -218,18 +210,18 @@ async def test_didx_accept_request(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() await test_module.didx_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -237,8 +229,8 @@ async def test_didx_accept_request(self): async def test_didx_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -248,14 +240,14 @@ async def test_didx_accept_request_not_found(self): async def test_didx_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.create_response = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) @@ -264,25 +256,25 @@ async def test_didx_accept_request_x(self): async def test_didx_reject(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.CoroutineMock() + mock_didx_mgr.return_value.reject = mock.CoroutineMock() await test_module.didx_reject(self.request) async def test_didx_reject_x_not_found(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -291,16 +283,16 @@ async def test_didx_reject_x_not_found(self): async def test_didx_reject_x_bad_conn_state(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.CoroutineMock( + mock_didx_mgr.return_value.reject = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) @@ -308,13 +300,13 @@ async def test_didx_reject_x_bad_conn_state(self): await test_module.didx_reject(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py index e6786435eb..10cc70d019 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.base_handler import HandlerException @@ -22,7 +22,7 @@ def request_context() -> RequestContext: ctx = RequestContext.test_context() ctx.connection_ready = True - ctx.connection_record = async_mock.MagicMock(connection_id="test123") + ctx.connection_record = mock.MagicMock(connection_id="test123") yield ctx @@ -53,10 +53,10 @@ async def test_disclose(self, request_context): handler = DiscloseHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py index 98bf973cec..10ab3af132 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.request_context import RequestContext @@ -67,10 +67,10 @@ async def test_receive_query_process_disclosed(self, request_context): request_context.message = query_msg handler = QueryHandler() responder = MockResponder() - with async_mock.patch.object( - ProtocolRegistry, "protocols_matching_query", async_mock.CoroutineMock() - ) as mock_query_match, async_mock.patch.object( - ProtocolRegistry, "prepare_disclosed", async_mock.CoroutineMock() + with mock.patch.object( + ProtocolRegistry, "protocols_matching_query", mock.MagicMock() + ) as mock_query_match, mock.patch.object( + ProtocolRegistry, "prepare_disclosed", mock.CoroutineMock() ) as mock_prepare_disclosed: mock_prepare_disclosed.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py index 84e02cf12e..5c33b88bf2 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py +++ b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py index 18af3b6ba7..c691f6a65f 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py +++ b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py index 9e3f0401e6..6580b2b1e9 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......storage.error import StorageDuplicateError, StorageNotFoundError @@ -11,7 +12,7 @@ from ..discovery_record import V10DiscoveryExchangeRecord -class TestV10DiscoveryExchangeRecord(AsyncTestCase): +class TestV10DiscoveryExchangeRecord(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_record(self): @@ -89,10 +90,10 @@ async def test_exists_for_connection_id(self): async def test_exists_for_connection_id_not_found(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( @@ -102,10 +103,10 @@ async def test_exists_for_connection_id_not_found(self): async def test_exists_for_connection_id_duplicate(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py index 8864a31e15..f11d271356 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py @@ -2,7 +2,8 @@ import logging import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....storage.error import StorageNotFoundError @@ -20,18 +21,16 @@ ) -class TestV10DiscoveryManager(AsyncTestCase): +class TestV10DiscoveryManager(IsolatedAsyncioTestCase): @pytest.fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) self.manager = V10DiscoveryMgr(self.profile) self.disclose = Disclose( protocols=[ @@ -52,10 +51,10 @@ async def setUp(self): async def test_receive_disclosure(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as save_ex, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -71,18 +70,18 @@ async def test_receive_disclosure(self): async def test_receive_disclosure_retreive_by_conn(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = True @@ -100,14 +99,14 @@ async def test_receive_disclosure_retreive_by_conn(self): async def test_receive_disclosure_retreive_by_conn_not_found(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -123,14 +122,14 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): async def test_receive_disclosure_retreive_new_ex_rec(self): test_conn_id = "test123" - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -144,10 +143,10 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) async def test_check_if_disclosure_received(self): - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V10DiscoveryExchangeRecord(), @@ -157,22 +156,22 @@ async def test_check_if_disclosure_received(self): async def test_create_and_send_query_with_connection(self): return_ex_rec = V10DiscoveryExchangeRecord(query_msg=Query(query="*")) - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V10DiscoveryExchangeRecord() @@ -185,16 +184,16 @@ async def test_create_and_send_query_with_connection(self): async def test_create_and_send_query_with_connection_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -206,10 +205,10 @@ async def test_create_and_send_query_with_connection_no_responder(self): assert "Unable to send discover-features v1" in self._caplog.text async def test_create_and_send_query_with_no_connection(self): - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclose() received_ex_rec = await self.manager.create_and_send_query(query="*") diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py index 7dfed0bb20..ce4a4a34e6 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext @@ -11,16 +11,16 @@ from ..models.discovery_record import V10DiscoveryExchangeRecord -class TestDiscoveryRoutes(AsyncTestCase): - async def setUp(self): +class TestDiscoveryRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def setUp(self): ) async def test_query_features(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query": "*"} @@ -36,9 +36,9 @@ async def test_query_features(self): discovery_exchange_id="3fa85f64-5717-4562-b3fc-2c963f66afa6", query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V10DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -46,7 +46,7 @@ async def test_query_features(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_features_with_connection(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query": "*", "connection_id": "test", "comment": "test"} @@ -55,9 +55,9 @@ async def test_query_features_with_connection(self): query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V10DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -65,7 +65,7 @@ async def test_query_features_with_connection(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_records(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -74,9 +74,9 @@ async def test_query_records(self): query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.return_value = test_rec @@ -84,13 +84,13 @@ async def test_query_records(self): mock_response.assert_called_once_with({"results": [test_rec.serialize()]}) async def test_query_records_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.side_effect = StorageError @@ -98,7 +98,7 @@ async def test_query_records_x(self): await test_module.query_records(self.request) async def test_query_records_all(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() test_recs = [ V10DiscoveryExchangeRecord( @@ -111,9 +111,9 @@ async def test_query_records_all(self): ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.return_value = test_recs @@ -123,11 +123,11 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.side_effect = StorageError @@ -135,13 +135,13 @@ async def test_query_records_connection_x(self): await test_module.query_records(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py index 5808a40dae..6e190148b8 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from aries_cloudagent.storage.error import StorageNotFoundError @@ -24,7 +24,7 @@ def request_context() -> RequestContext: ctx = RequestContext.test_context() ctx.connection_ready = True - ctx.connection_record = async_mock.MagicMock(connection_id="test123") + ctx.connection_record = mock.MagicMock(connection_id="test123") yield ctx @@ -61,10 +61,10 @@ async def test_disclosures(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -101,14 +101,14 @@ async def test_disclosures_connection_id_no_thid(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.CoroutineMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -139,14 +139,14 @@ async def test_disclosures_no_conn_id_no_thid(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.CoroutineMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py index cb503650ad..1998a973e0 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......core.goal_code_registry import GoalCodeRegistry @@ -131,10 +131,10 @@ async def test_receive_query_process_disclosed(self, request_context): request_context.message = queries_msg handler = QueriesHandler() responder = MockResponder() - with async_mock.patch.object( - V20DiscoveryMgr, "execute_protocol_query", async_mock.CoroutineMock() - ) as mock_exec_protocol_query, async_mock.patch.object( - V20DiscoveryMgr, "execute_goal_code_query", async_mock.CoroutineMock() + with mock.patch.object( + V20DiscoveryMgr, "execute_protocol_query", mock.CoroutineMock() + ) as mock_exec_protocol_query, mock.patch.object( + V20DiscoveryMgr, "execute_goal_code_query", mock.CoroutineMock() ) as mock_goal_code_protocol_query: mock_exec_protocol_query.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py index 3621d35151..c6440d72eb 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py +++ b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py index e5624a33df..2089c94692 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py +++ b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py index 478acc8d2b..64e0e82689 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......storage.error import StorageDuplicateError, StorageNotFoundError @@ -11,7 +12,7 @@ from ..discovery_record import V20DiscoveryExchangeRecord -class TestV20DiscoveryExchangeRecord(AsyncTestCase): +class TestV20DiscoveryExchangeRecord(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_record(self): @@ -146,10 +147,10 @@ async def test_exists_for_connection_id(self): async def test_exists_for_connection_id_not_found(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( @@ -159,10 +160,10 @@ async def test_exists_for_connection_id_not_found(self): async def test_exists_for_connection_id_duplicate(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py index 7d4a47f155..badaa637b4 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py @@ -2,7 +2,8 @@ import logging import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....storage.error import StorageNotFoundError @@ -20,18 +21,16 @@ ) -class TestV20DiscoveryManager(AsyncTestCase): +class TestV20DiscoveryManager(IsolatedAsyncioTestCase): @pytest.fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) self.disclosures = Disclosures( disclosures=[ { @@ -58,10 +57,10 @@ async def setUp(self): async def test_receive_disclosure(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as save_ex, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -77,17 +76,17 @@ async def test_receive_disclosure(self): async def test_receive_disclosure_retreive_by_conn(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError @@ -106,13 +105,13 @@ async def test_receive_disclosure_retreive_by_conn(self): async def test_receive_disclosure_retreive_by_conn_not_found(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError @@ -129,14 +128,14 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): async def test_receive_disclosure_retreive_new_ex_rec(self): test_conn_id = "test123" - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -150,12 +149,12 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) async def test_proactive_disclosure(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_receive_query.return_value = Disclosures() await self.manager.proactive_disclose_features("test123") @@ -163,12 +162,12 @@ async def test_proactive_disclosure(self): async def test_proactive_disclosure_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.CoroutineMock() ) as mock_send: self._caplog.set_level(logging.WARNING) mock_receive_query.return_value = Disclosures() @@ -178,10 +177,10 @@ async def test_proactive_disclosure_no_responder(self): ) async def test_check_if_disclosure_received(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V20DiscoveryExchangeRecord(), @@ -203,22 +202,22 @@ async def test_create_and_send_query_with_connection(self): ] ) ) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V20DiscoveryExchangeRecord() @@ -231,16 +230,16 @@ async def test_create_and_send_query_with_connection(self): async def test_create_and_send_query_with_connection_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -263,10 +262,10 @@ async def test_create_and_send_query_with_connection_no_responder(self): ) async def test_create_and_send_query_with_no_connection(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclosures() received_ex_rec = await self.manager.create_and_send_query( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py index 61efeef9ce..d6c5ecd2f6 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext @@ -11,16 +11,16 @@ from ..models.discovery_record import V20DiscoveryExchangeRecord -class TestDiscoveryRoutes(AsyncTestCase): - async def setUp(self): +class TestDiscoveryRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def setUp(self): ) async def test_query_features(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query_protocol": "*"} @@ -42,9 +42,9 @@ async def test_query_features(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -52,7 +52,7 @@ async def test_query_features(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_features_with_connection(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = { "query_protocol": "*", @@ -70,9 +70,9 @@ async def test_query_features_with_connection(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -80,7 +80,7 @@ async def test_query_features_with_connection(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_records(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -94,9 +94,9 @@ async def test_query_records(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.return_value = test_rec @@ -104,13 +104,13 @@ async def test_query_records(self): mock_response.assert_called_once_with({"results": [test_rec.serialize()]}) async def test_query_records_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.side_effect = StorageError @@ -118,7 +118,7 @@ async def test_query_records_x(self): await test_module.query_records(self.request) async def test_query_records_all(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() test_recs = [ V20DiscoveryExchangeRecord( @@ -141,9 +141,9 @@ async def test_query_records_all(self): ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.return_value = test_recs @@ -153,11 +153,11 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.side_effect = StorageError @@ -165,13 +165,13 @@ async def test_query_records_connection_x(self): await test_module.query_records(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py index d6f8fe5ca6..5a33ffdb02 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,18 +9,16 @@ from ...messages.endorsed_transaction_response import EndorsedTransactionResponse -class TestEndorsedTransactionResponseHandler(AsyncTestCase): +class TestEndorsedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() @@ -37,14 +33,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = False handler = test_module.EndorsedTransactionResponseHandler() @@ -57,15 +51,13 @@ async def test_called_not_ready(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py index 33f00c5da5..b2d8558cac 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,18 +9,16 @@ from ...messages.refused_transaction_response import RefusedTransactionResponse -class TestRefusedTransactionResponseHandler(AsyncTestCase): +class TestRefusedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = True handler = test_module.RefusedTransactionResponseHandler() @@ -37,14 +33,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = False handler = test_module.RefusedTransactionResponseHandler() @@ -57,15 +51,13 @@ async def test_called_not_ready(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = RefusedTransactionResponse() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py index ed4a864727..dc92327ef9 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.request_context import RequestContext @@ -12,16 +10,16 @@ from ...messages.transaction_acknowledgement import TransactionAcknowledgement -class TestTransactionAcknowledgementHandler(AsyncTestCase): +class TestTransactionAcknowledgementHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.CoroutineMock() + mock.CoroutineMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( @@ -40,13 +38,13 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.CoroutineMock() + mock.CoroutineMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_ready = False @@ -61,13 +59,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock.CoroutineMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py index bc144c16d6..1fd36bed57 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,17 +10,15 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionCancelHandler(AsyncTestCase): +class TestTransactionCancelHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock() request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -40,14 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock() request_context.message = CancelTransaction() request_context.connection_ready = False handler = test_module.TransactionCancelHandler() @@ -61,13 +55,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py index 41c66d4a78..8bb0867548 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,18 +9,16 @@ from ...messages.transaction_job_to_send import TransactionJobToSend -class TestTransactionJobToSendHandler(AsyncTestCase): +class TestTransactionJobToSendHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.set_transaction_their_job = mock.CoroutineMock() request_context.message = TransactionJobToSend() request_context.connection_ready = True handler = test_module.TransactionJobToSendHandler() @@ -37,15 +33,13 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.set_transaction_their_job = mock.CoroutineMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionJobToSend() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py index 61c525e5f5..10d5c7975e 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,15 +10,15 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionRequestHandler(AsyncTestCase): +class TestTransactionRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = TransactionRequest() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -38,12 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = TransactionRequest() request_context.connection_ready = False handler = test_module.TransactionRequestHandler() @@ -57,10 +55,10 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionRequest() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py index e0e9ccbcde..1cb00b198b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,17 +10,15 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionResendHandler(AsyncTestCase): +class TestTransactionResendHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock() request_context.message = TransactionResend() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -40,14 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock() request_context.message = TransactionResend() request_context.connection_ready = False handler = test_module.TransactionResendHandler() @@ -61,13 +55,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionResend() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py index a233649b62..1ae989233f 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +65,7 @@ def test_serialize(self, mock_cancel_transaction_schema_dump): ) -class TestCancelTransactionSchema(AsyncTestCase, TestConfig): +class TestCancelTransactionSchema(IsolatedAsyncioTestCase, TestConfig): """Test cancel transaction schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py index 9ca343c73c..44ecbd3ada 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -96,7 +97,7 @@ def test_serialize(self, mock_endorsed_transaction_response_schema_dump): ) -class TestEndorsedTransactionResponseSchema(AsyncTestCase, TestConfig): +class TestEndorsedTransactionResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test endorsed transaction response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py index 111376b0d2..4e8b7e4c0b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py index 071668d371..72ab421091 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -90,7 +91,7 @@ def test_serialize(self, mock_refused_transaction_response_schema_dump): ) -class TestRefusedTransactionResponseSchema(AsyncTestCase, TestConfig): +class TestRefusedTransactionResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test refused transaction response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py index 09bc6b0a1e..c949370ee0 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py @@ -1,5 +1,6 @@ -from asynctest import TestCase as AsyncTestCase -from unittest import mock, TestCase +from unittest import IsolatedAsyncioTestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix @@ -65,7 +66,7 @@ def test_serialize(self, mock_transaction_acknowledgement_schema_dump): ) -class TestTransactionAcknowledgementSchema(AsyncTestCase, TestConfig): +class TestTransactionAcknowledgementSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction acknowledgement schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py index bfd1ae18e7..99d4fb094a 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +65,7 @@ def test_serialize(self, mock_transaction_job_to_send_schema_dump): ) -class TestTransactionJobToSendSchema(AsyncTestCase, TestConfig): +class TestTransactionJobToSendSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction job to send schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py index 8bbb69ae12..938e07f3c6 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -108,7 +109,7 @@ def test_serialize(self, mock_transaction_request_schema_dump): ) -class TestTransactionRequestSchema(AsyncTestCase, TestConfig): +class TestTransactionRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py index 666a52435c..a7db7be9b4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +65,7 @@ def test_serialize(self, mock_transaction_resend_schema_dump): ) -class TestTransactionResendSchema(AsyncTestCase, TestConfig): +class TestTransactionResendSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction resend schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index df10ffe4ee..82902dfe93 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -2,8 +2,8 @@ import json import uuid -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -25,8 +25,8 @@ CRED_DEF_ID = f"{TEST_DID}:3:CL:12:tag1" -class TestTransactionManager(AsyncTestCase): - async def setUp(self): +class TestTransactionManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): sigs = [ ( "2iNTeFy44WK9zpsPfcwfu489aHWroYh3v8mme9tPyNKn" @@ -102,11 +102,11 @@ async def setUp(self): self.test_endorser_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" self.test_refuser_did = "AGDEjaMunDtFtBVrn1qPKQ" - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.txn_endorse = async_mock.CoroutineMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.txn_endorse = mock.CoroutineMock( return_value=self.test_endorsed_message ) - self.ledger.register_nym = async_mock.CoroutineMock(return_value=(True, {})) + self.ledger.register_nym = mock.CoroutineMock(return_value=(True, {})) self.context = AdminRequestContext.test_context() self.profile = self.context.profile @@ -134,9 +134,7 @@ async def test_transaction_jobs(self): assert author != endorser async def test_create_record(self): - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.create_record( messages_attach=self.test_messages_attach, connection_id=self.test_connection_id, @@ -194,9 +192,7 @@ async def test_create_request(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -234,9 +230,7 @@ async def test_create_request_author_did(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -271,7 +265,7 @@ async def test_create_request_author_did(self): ) async def test_recieve_request(self): - mock_request = async_mock.MagicMock() + mock_request = mock.MagicMock() mock_request.transaction_id = self.test_author_transaction_id mock_request.signature_request = { "context": TransactionRecord.SIGNATURE_CONTEXT, @@ -287,9 +281,7 @@ async def test_recieve_request(self): } mock_request.timing = {"expires_time": self.test_expires_time} - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_request( mock_request, self.test_receivers_connection_id ) @@ -328,9 +320,7 @@ async def test_create_endorse_response(self): transaction_record.state = TransactionRecord.STATE_REQUEST_RECEIVED transaction_record.thread_id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, endorsed_transaction_response, @@ -381,9 +371,7 @@ async def test_create_endorse_response_author_did(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -406,9 +394,7 @@ async def test_create_endorse_response_author_did(self): } ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, endorsed_transaction_response, @@ -431,7 +417,7 @@ async def test_receive_endorse_response(self): ) self.test_author_transaction_id = transaction_record._id - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.transaction_id = self.test_author_transaction_id mock_response.thread_id = self.test_endorser_transaction_id mock_response.signature_response = { @@ -445,9 +431,7 @@ async def test_receive_endorse_response(self): mock_response.state = TransactionRecord.STATE_TRANSACTION_ENDORSED mock_response.endorser_did = self.test_endorser_did - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_endorse_response( mock_response ) @@ -475,12 +459,10 @@ async def test_complete_transaction(self): ) future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.CoroutineMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.CoroutineMock())) ) self.ledger.get_indy_storage = future - self.ledger.txn_submit = async_mock.CoroutineMock( + self.ledger.txn_submit = mock.CoroutineMock( return_value=json.dumps( { "result": { @@ -491,13 +473,13 @@ async def test_complete_transaction(self): ) ) - with async_mock.patch.object( + with mock.patch.object( TransactionRecord, "save", autospec=True - ) as save_record, async_mock.patch.object( + ) as save_record, mock.patch.object( ConnRecord, "retrieve_by_id" ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( TransactionJob.TRANSACTION_ENDORSER.name @@ -537,9 +519,7 @@ async def test_create_refuse_response(self): transaction_record.state = TransactionRecord.STATE_REQUEST_RECEIVED transaction_record.thread_id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, refused_transaction_response, @@ -584,7 +564,7 @@ async def test_receive_refuse_response(self): ) self.test_author_transaction_id = transaction_record._id - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.transaction_id = self.test_author_transaction_id mock_response.thread_id = self.test_endorser_transaction_id mock_response.signature_response = { @@ -596,9 +576,7 @@ async def test_receive_refuse_response(self): mock_response.state = TransactionRecord.STATE_TRANSACTION_REFUSED mock_response.endorser_did = self.test_refuser_did - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_refuse_response( mock_response ) @@ -636,9 +614,7 @@ async def test_cancel_transaction(self): transaction_record.thread_id = self.test_endorser_transaction_id transaction_record._id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, cancelled_transaction_response, @@ -671,13 +647,11 @@ async def test_receive_cancel_transaction(self): author_transaction_request, self.test_receivers_connection_id ) - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.state = TransactionRecord.STATE_TRANSACTION_CANCELLED mock_response.thread_id = author_transaction_record._id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: endorser_transaction_record = await self.manager.receive_cancel_transaction( mock_response, self.test_receivers_connection_id ) @@ -710,9 +684,7 @@ async def test_transaction_resend(self): transaction_record.thread_id = self.test_endorser_transaction_id transaction_record._id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, resend_transaction_response, @@ -743,13 +715,11 @@ async def test_receive_transaction_resend(self): author_transaction_request, self.test_receivers_connection_id ) - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.state = TransactionRecord.STATE_TRANSACTION_RESENT_RECEIEVED mock_response.thread_id = author_transaction_record._id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: endorser_transaction_record = await self.manager.receive_transaction_resend( mock_response, self.test_receivers_connection_id ) @@ -761,45 +731,45 @@ async def test_receive_transaction_resend(self): ) async def test_set_transaction_my_job(self): - conn_record = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + conn_record = mock.MagicMock( + metadata_get=mock.CoroutineMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) for i in range(2): await self.manager.set_transaction_my_job(conn_record, "Hello") async def test_set_transaction_their_job(self): - mock_job = async_mock.MagicMock() - mock_receipt = async_mock.MagicMock() + mock_job = mock.MagicMock() + mock_receipt = mock.MagicMock() - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve: - mock_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) for i in range(2): await self.manager.set_transaction_their_job(mock_job, mock_receipt) async def test_set_transaction_their_job_conn_not_found(self): - mock_job = async_mock.MagicMock() - mock_receipt = async_mock.MagicMock() + mock_job = mock.MagicMock() + mock_receipt = mock.MagicMock() - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index 4d6e3b0897..ad79131aa4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -1,8 +1,8 @@ import asyncio import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -21,8 +21,8 @@ CRED_DEF_ID = f"{TEST_DID}:3:CL:12:tag1" -class TestEndorseTransactionRoutes(AsyncTestCase): - async def setUp(self): +class TestEndorseTransactionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) @@ -32,15 +32,13 @@ async def setUp(self): setattr( self.profile, "session", - async_mock.MagicMock(return_value=self.profile_session), + mock.MagicMock(return_value=self.profile_session), ) - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.txn_endorse = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.txn_submit = async_mock.CoroutineMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.txn_endorse = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.txn_submit = mock.CoroutineMock( return_value=json.dumps( { "result": { @@ -52,21 +50,19 @@ async def setUp(self): ) future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.CoroutineMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.CoroutineMock())) ) self.ledger.get_indy_storage = future - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock( return_value={"id": SCHEMA_ID, "...": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -76,24 +72,22 @@ async def setUp(self): self.test_did = "sample-did" async def test_transactions_list(self): - with async_mock.patch.object( - TransactionRecord, "query", async_mock.CoroutineMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.CoroutineMock() + ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_query.return_value = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) - ) + mock.MagicMock(serialize=mock.MagicMock(return_value={"...": "..."})) ] await test_module.transactions_list(self.request) mock_response.assert_called_once_with({"results": [{"...": "..."}]}) async def test_transactions_list_x(self): - with async_mock.patch.object( - TransactionRecord, "query", async_mock.CoroutineMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.CoroutineMock() + ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_query.side_effect = test_module.StorageError() @@ -104,13 +98,13 @@ async def test_transactions_list_x(self): async def test_transactions_retrieve(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transactions_retrieve(self.request) @@ -119,8 +113,8 @@ async def test_transactions_retrieve(self): async def test_transactions_retrieve_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError() @@ -130,8 +124,8 @@ async def test_transactions_retrieve_not_found_x(self): async def test_transactions_retrieve_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.BaseModelError() @@ -142,32 +136,32 @@ async def test_transaction_create_request(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -178,8 +172,8 @@ async def test_transaction_create_request(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transaction_create_request(self.request) @@ -189,13 +183,13 @@ async def test_transaction_create_request_not_found_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,18 +200,18 @@ async def test_transaction_create_request_base_model_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -237,33 +231,33 @@ async def test_transaction_create_request_no_jobs_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -273,30 +267,30 @@ async def test_transaction_create_request_no_my_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -304,8 +298,8 @@ async def test_transaction_create_request_no_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -315,30 +309,30 @@ async def test_transaction_create_request_no_their_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -346,8 +340,8 @@ async def test_transaction_create_request_no_their_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -357,18 +351,18 @@ async def test_transaction_create_request_my_wrong_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -377,8 +371,8 @@ async def test_transaction_create_request_my_wrong_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -388,25 +382,25 @@ async def test_transaction_create_request_mgr_create_request_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -417,8 +411,8 @@ async def test_transaction_create_request_mgr_create_request_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -428,8 +422,8 @@ async def test_endorse_transaction_response(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -441,31 +435,31 @@ async def test_endorse_transaction_response(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -473,8 +467,8 @@ async def test_endorse_transaction_response(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.endorse_transaction_response(self.request) @@ -490,14 +484,12 @@ async def skip_test_endorse_transaction_response_no_endorser_did_info_x(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None) - ), + mock.MagicMock(get_public_did=mock.CoroutineMock(return_value=None)), ) - with async_mock.patch.object( + with mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: with self.assertRaises(test_module.web.HTTPForbidden): await test_module.endorse_transaction_response(self.request) @@ -507,8 +499,8 @@ async def test_endorse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -520,12 +512,12 @@ async def test_endorse_transaction_response_not_found_x(self): ), ) - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -536,8 +528,8 @@ async def test_endorse_transaction_response_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -549,18 +541,18 @@ async def test_endorse_transaction_response_base_model_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -571,8 +563,8 @@ async def test_endorse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -584,20 +576,20 @@ async def test_endorse_transaction_response_no_jobs_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -608,8 +600,8 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): self.context.injector.clear_binding(BaseLedger) self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -621,29 +613,29 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -651,8 +643,8 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -663,8 +655,8 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -676,17 +668,17 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -694,8 +686,8 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -706,8 +698,8 @@ async def skip_test_endorse_transaction_response_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -718,33 +710,33 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ), ) - self.ledger.txn_endorse = async_mock.CoroutineMock( + self.ledger.txn_endorse = mock.CoroutineMock( side_effect=test_module.LedgerError() ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.CoroutineMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -752,8 +744,8 @@ async def skip_test_endorse_transaction_response_ledger_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -764,8 +756,8 @@ async def test_endorse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -777,26 +769,26 @@ async def test_endorse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -804,8 +796,8 @@ async def test_endorse_transaction_response_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -816,8 +808,8 @@ async def test_refuse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -829,32 +821,32 @@ async def test_refuse_transaction_response(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.CoroutineMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -862,8 +854,8 @@ async def test_refuse_transaction_response(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.refuse_transaction_response(self.request) @@ -874,8 +866,8 @@ async def test_refuse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -887,12 +879,12 @@ async def test_refuse_transaction_response_not_found_x(self): ), ) - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -904,8 +896,8 @@ async def test_refuse_transaction_response_conn_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -917,18 +909,18 @@ async def test_refuse_transaction_response_conn_base_model_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -939,8 +931,8 @@ async def test_refuse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -952,20 +944,20 @@ async def test_refuse_transaction_response_no_jobs_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -976,8 +968,8 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -989,17 +981,17 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1007,8 +999,8 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1019,8 +1011,8 @@ async def test_refuse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + mock.MagicMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -1032,26 +1024,26 @@ async def test_refuse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1059,8 +1051,8 @@ async def test_refuse_transaction_response_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1069,28 +1061,28 @@ async def test_refuse_transaction_response_txn_mgr_x(self): async def test_cancel_transaction(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.CoroutineMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1098,8 +1090,8 @@ async def test_cancel_transaction(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.cancel_transaction(self.request) @@ -1108,8 +1100,8 @@ async def test_cancel_transaction(self): async def test_cancel_transaction_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1119,14 +1111,14 @@ async def test_cancel_transaction_not_found_x(self): async def test_cancel_transaction_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1135,16 +1127,16 @@ async def test_cancel_transaction_conn_rec_base_model_x(self): async def test_cancel_transaction_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1153,13 +1145,13 @@ async def test_cancel_transaction_no_jobs_x(self): async def test_cancel_transaction_wrong_my_job_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1167,8 +1159,8 @@ async def test_cancel_transaction_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1177,22 +1169,22 @@ async def test_cancel_transaction_wrong_my_job_x(self): async def test_cancel_transaction_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1200,8 +1192,8 @@ async def test_cancel_transaction_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1210,28 +1202,28 @@ async def test_cancel_transaction_txn_mgr_x(self): async def test_transaction_resend(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.CoroutineMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1239,8 +1231,8 @@ async def test_transaction_resend(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transaction_resend(self.request) @@ -1249,8 +1241,8 @@ async def test_transaction_resend(self): async def test_transaction_resend_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1260,14 +1252,14 @@ async def test_transaction_resend_not_found_x(self): async def test_transaction_resend_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1276,16 +1268,16 @@ async def test_transaction_resend_conn_rec_base_model_x(self): async def test_transaction_resend_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1294,13 +1286,13 @@ async def test_transaction_resend_no_jobs_x(self): async def test_transaction_resend_my_wrong_job_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1309,8 +1301,8 @@ async def test_transaction_resend_my_wrong_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1319,22 +1311,22 @@ async def test_transaction_resend_my_wrong_job_x(self): async def test_transaction_resend_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1342,8 +1334,8 @@ async def test_transaction_resend_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1352,18 +1344,18 @@ async def test_transaction_resend_txn_mgr_x(self): async def test_set_endorser_role(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - set_transaction_my_job=async_mock.CoroutineMock() + mock_txn_mgr.return_value = mock.MagicMock( + set_transaction_my_job=mock.CoroutineMock() ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1380,8 +1372,8 @@ async def test_set_endorser_role(self): async def test_set_endorser_role_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1391,8 +1383,8 @@ async def test_set_endorser_role_not_found_x(self): async def test_set_endorser_role_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1402,13 +1394,13 @@ async def test_set_endorser_role_base_model_x(self): async def test_set_endorser_info(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1418,7 +1410,7 @@ async def test_set_endorser_info(self): ), } ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) await test_module.set_endorser_info(self.request) @@ -1434,13 +1426,13 @@ async def test_set_endorser_info(self): async def test_set_endorser_info_no_prior_value(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( side_effect=[ { "transaction_my_job": ( @@ -1457,7 +1449,7 @@ async def test_set_endorser_info_no_prior_value(self): }, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) await test_module.set_endorser_info(self.request) @@ -1472,8 +1464,8 @@ async def test_set_endorser_info_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1484,8 +1476,8 @@ async def test_set_endorser_info_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1496,11 +1488,11 @@ async def test_set_endorser_info_no_transaction_jobs_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.set_endorser_info(self.request) @@ -1509,11 +1501,11 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1527,11 +1519,11 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): async def test_set_endorser_info_my_wrong_job_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1546,24 +1538,24 @@ async def test_set_endorser_info_my_wrong_job_x(self): async def test_transaction_write_schema_txn(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value.complete_transaction = async_mock.CoroutineMock() + mock_txn_mgr.return_value.complete_transaction = mock.CoroutineMock() mock_txn_mgr.return_value.complete_transaction.return_value = ( - async_mock.CoroutineMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.CoroutineMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(), state=TransactionRecord.STATE_TRANSACTION_ENDORSED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1575,8 +1567,8 @@ async def test_transaction_write_schema_txn(self): async def test_transaction_write_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1586,8 +1578,8 @@ async def test_transaction_write_not_found_x(self): async def test_transaction_write_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1596,11 +1588,11 @@ async def test_transaction_write_base_model_x(self): async def test_transaction_write_wrong_state_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}), state=TransactionRecord.STATE_TRANSACTION_CREATED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1612,19 +1604,19 @@ async def test_transaction_write_wrong_state_x(self): async def test_transaction_write_schema_txn_complete_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - complete_transaction=async_mock.CoroutineMock( + mock_txn_mgr.return_value = mock.MagicMock( + complete_transaction=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}), state=TransactionRecord.STATE_TRANSACTION_ENDORSED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1635,14 +1627,14 @@ async def test_transaction_write_schema_txn_complete_x(self): await test_module.transaction_write(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {"paths": {}}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {"paths": {}}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py index bb19cea6de..3049526ed3 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -21,8 +21,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestForwardInvitationHandler(AsyncTestCase): - async def setUp(self): +class TestForwardInvitationHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True @@ -42,10 +42,10 @@ async def test_handle(self): handler = test_module.ForwardInvitationHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=ConnRecord(connection_id="dummy") ) @@ -56,10 +56,10 @@ async def test_handle_x(self): handler = test_module.ForwardInvitationHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError("oops") ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py index 7e92953531..301b5ce77e 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -20,8 +20,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestInvitationHandler(AsyncTestCase): - async def setUp(self): +class TestInvitationHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = Invitation( @@ -35,26 +35,27 @@ async def setUp(self): ), message="Hello World", ) - self.context.connection_record = async_mock.MagicMock(connection_id="dummy") + self.context.connection_record = mock.MagicMock(connection_id="dummy") async def test_handle(self): handler = test_module.InvitationHandler() - mock_conn_rec = async_mock.MagicMock(connection_id="dummy") + mock_conn_rec = mock.MagicMock(connection_id="dummy") responder = MockResponder() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: - mock_ctx_inject.return_value = async_mock.MagicMock( - return_invitation=async_mock.CoroutineMock() + mock_ctx_inject.return_value = mock.MagicMock( + return_invitation=mock.CoroutineMock() ) await handler.handle(self.context, responder) - assert mock_ctx_inject.return_value.return_invitation.called_once_with( + mock_ctx_inject.return_value.return_invitation.assert_called_once_with( self.context.connection_record.connection_id, self.context.message, + mock.ANY, responder.send, ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py index 3bf7fe259d..ad0a06da0a 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -21,8 +21,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestInvitationRequestHandler(AsyncTestCase): - async def setUp(self): +class TestInvitationRequestHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = InvitationRequest( @@ -37,7 +37,7 @@ async def test_handle(self): responder = MockResponder() inv_req = InvitationRequest(responder=responder, message="Hello") - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: await handler.handle(self.context, responder) @@ -54,18 +54,18 @@ async def test_handle_auto_accept(self): routing_keys=[TEST_ROUTE_VERKEY], image_url=TEST_IMAGE_URL, ) - mock_conn_rec = async_mock.MagicMock(connection_id="dummy") + mock_conn_rec = mock.MagicMock(connection_id="dummy") responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.create_invitation = mock.CoroutineMock( return_value=(mock_conn_rec, conn_invitation) ) await handler.handle(self.context, responder) - assert mock_mgr.return_value.create_invitation.called_once_with() + mock_mgr.return_value.create_invitation.assert_called_once_with() messages = responder.messages assert len(messages) == 1 diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py index e4b3c26f37..2cb11623e6 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.v1_0.messages.connection_invitation import ConnectionInvitation from .....didcomm_prefix import DIDCommPrefix @@ -68,7 +69,7 @@ def test_serialize(self, mock_invitation_schema_dump): assert invitation_dict is mock_invitation_schema_dump.return_value -class TestForwardInvitationSchema(AsyncTestCase, TestConfig): +class TestForwardInvitationSchema(IsolatedAsyncioTestCase, TestConfig): """Test forward invitation schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py index 1e5b848ba9..b3aaa7cbd0 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.v1_0.messages.connection_invitation import ConnectionInvitation @@ -8,7 +8,7 @@ from ...message_types import PROTOCOL_PACKAGE -class TestInvitation(AsyncTestCase): +class TestInvitation(IsolatedAsyncioTestCase): def setUp(self): self.label = "Label" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py index 8d4513014d..b0224c6c58 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py @@ -1,6 +1,7 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix @@ -57,7 +58,7 @@ def test_serialize(self, mock_invitation_schema_dump): assert request_dict is mock_invitation_schema_dump.return_value -class TestInvitationRequestSchema(AsyncTestCase, TestConfig): +class TestInvitationRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test invitation request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py index 0aacbb20d5..9ace9b497a 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py @@ -1,19 +1,20 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext from .. import routes as test_module -class TestIntroductionRoutes(AsyncTestCase): - async def setUp(self): +class TestIntroductionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -21,7 +22,7 @@ async def setUp(self): ) async def test_introduction_start_no_service(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -43,7 +44,7 @@ async def test_introduction_start_no_service(self): await test_module.introduction_start(self.request) async def test_introduction_start(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -60,16 +61,16 @@ async def test_introduction_start(self): "target_connection_id": "dummy", "message": "Hello", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() - ) as mock_ctx_inject, async_mock.patch.object( + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() + ) as mock_ctx_inject, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.CoroutineMock() + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.CoroutineMock() ) await test_module.introduction_start(self.request) @@ -77,13 +78,13 @@ async def test_introduction_start(self): self.request.match_info["conn_id"], self.request.query["target_connection_id"], self.request.query["message"], - async_mock.ANY, + mock.ANY, self.request["outbound_message_router"], ) mock_response.assert_called_once_with({}) async def test_introduction_start_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -100,14 +101,14 @@ async def test_introduction_start_x(self): "target_connection_id": "dummy", "message": "Hello", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: - mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.CoroutineMock( + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.CoroutineMock( side_effect=test_module.IntroductionError() ) ) @@ -116,13 +117,13 @@ async def test_introduction_start_x(self): await test_module.introduction_start(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py index ea758821a8..1d791b551f 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -23,7 +23,7 @@ TEST_ENDPOINT = "http://localhost" -class TestIntroductionService(AsyncTestCase): +class TestIntroductionService(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = RequestContext(self.profile) diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py index ae0c31f0e6..aed4264e6b 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -11,26 +12,24 @@ from .. import credential_ack_handler as test_module -class TestCredentialAckHandler(AsyncTestCase): +class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = True handler = test_module.CredentialAckHandler() @@ -49,14 +48,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() @@ -71,20 +68,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py index 0f831927a1..c0c6e46ce5 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,24 +11,24 @@ from .. import credential_issue_handler as test_module -class TestCredentialIssueHandler(AsyncTestCase): +class TestCredentialIssueHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() request_context.connection_ready = True handler = test_module.CredentialIssueHandler() @@ -47,25 +48,25 @@ async def test_called_auto_store(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock(), - store_credential=async_mock.CoroutineMock(), - send_credential_ack=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.CoroutineMock(), + store_credential=mock.CoroutineMock(), + send_credential_ack=mock.CoroutineMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), ) @@ -88,31 +89,29 @@ async def test_called_auto_store_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - store_credential=async_mock.CoroutineMock( + store_credential=mock.CoroutineMock( side_effect=test_module.IndyHolderError() ), - send_credential_ack=async_mock.CoroutineMock( + send_credential_ack=mock.CoroutineMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), ) @@ -122,10 +121,10 @@ async def test_called_auto_store_x(self): handler = test_module.CredentialIssueHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -133,12 +132,12 @@ async def test_called_auto_store_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() request_context.connection_ready = False handler = test_module.CredentialIssueHandler() @@ -153,18 +152,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() handler = test_module.CredentialIssueHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py index a9aedbb0a9..65f7ca1541 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,24 +11,24 @@ from .. import credential_offer_handler as test_module -class TestCredentialOfferHandler(AsyncTestCase): +class TestCredentialOfferHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = True handler = test_module.CredentialOfferHandler() @@ -47,21 +48,21 @@ async def test_called_auto_request(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( return_value=(None, "credential_request_message") ) request_context.message = CredentialOffer() @@ -87,25 +88,23 @@ async def test_called_auto_request_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -114,10 +113,10 @@ async def test_called_auto_request_x(self): handler = test_module.CredentialOfferHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -125,12 +124,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() @@ -148,18 +147,18 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py index 2187e6258c..ef9253a439 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,19 +13,17 @@ from .. import credential_problem_report_handler as test_module -class TestCredentialProblemReportHandler(AsyncTestCase): +class TestCredentialProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = CredentialProblemReport( description={ "en": "Change of plans", @@ -44,16 +43,14 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = CredentialProblemReport( description={ @@ -74,7 +71,7 @@ async def test_called_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_ready = False request_context.message = CredentialProblemReport( diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py index 911f056d43..47637ccfce 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,17 +10,17 @@ from .. import credential_proposal_handler as test_module -class TestCredentialProposalHandler(AsyncTestCase): +class TestCredentialProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = CredentialProposal() @@ -37,16 +38,16 @@ async def test_called(self): async def test_called_auto_offer(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( return_value=(None, "credential_offer_message") ) request_context.message = CredentialProposal() @@ -68,18 +69,16 @@ async def test_called_auto_offer(self): async def test_called_auto_offer_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -88,10 +87,10 @@ async def test_called_auto_offer_x(self): handler = test_module.CredentialProposalHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -99,12 +98,12 @@ async def test_called_auto_offer_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = CredentialProposal() request_context.connection_ready = False handler = test_module.CredentialProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py index b74bf445ef..bc4b5ea21d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -14,25 +15,25 @@ CD_ID = "LjgpST2rjsoxYegQDRm7EL:3:CL:18:tag" -class TestCredentialRequestHandler(AsyncTestCase): +class TestCredentialRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = CredentialRequest() @@ -53,11 +54,11 @@ async def test_called(self): async def test_called_auto_issue(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) @@ -73,14 +74,14 @@ async def test_called_auto_issue(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "credential_issue_message") ) request_context.message = CredentialRequest() @@ -108,11 +109,11 @@ async def test_called_auto_issue(self): async def test_called_auto_issue_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) @@ -128,16 +129,16 @@ async def test_called_auto_issue_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.CoroutineMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.CoroutineMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -146,10 +147,10 @@ async def test_called_auto_issue_x(self): handler = test_module.CredentialRequestHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -157,11 +158,11 @@ async def test_called_auto_issue_x(self): async def test_called_auto_issue_no_preview(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) @@ -171,14 +172,14 @@ async def test_called_auto_issue_no_preview(self): credential_proposal_dict={"cred_def_id": CD_ID} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "credential_issue_message") ) @@ -201,12 +202,12 @@ async def test_called_auto_issue_no_preview(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = CredentialRequest() request_context.connection_ready = False handler = test_module.CredentialRequestHandler() @@ -224,18 +225,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = CredentialRequest() handler = test_module.CredentialRequestHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py index ab29df0191..b6c44ad524 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py index ff408a1458..5221bea457 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py index 87a820c64c..150329ac3d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py index fc87a911fa..d4e76821e6 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py @@ -1,7 +1,8 @@ import logging import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py index d8ddce8f49..b3ae1e2203 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py index d1df7d7f71..042f9e3d19 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -29,7 +30,7 @@ ) -class TestV10CredentialExchange(AsyncTestCase): +class TestV10CredentialExchange(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_serde(self): @@ -77,10 +78,10 @@ async def test_save_error_state(self): record.state = V10CredentialExchange.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="test") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py index 66cf6315a5..5beb1b48ff 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -3,7 +3,8 @@ from copy import deepcopy from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....cache.base import BaseCache @@ -49,36 +50,30 @@ ) -class TestCredentialManager(AsyncTestCase): - async def setUp(self): +class TestCredentialManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) - setattr( - self.profile, "transaction", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) + setattr(self.profile, "transaction", mock.MagicMock(return_value=self.session)) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -135,10 +130,10 @@ async def test_prepare_send(self): proposal = CredentialProposal( credential_proposal=preview, cred_def_id=CRED_DEF_ID, schema_id=SCHEMA_ID ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "create_offer", autospec=True ) as create_offer: - create_offer.return_value = (async_mock.MagicMock(), async_mock.MagicMock()) + create_offer.return_value = (mock.MagicMock(), mock.MagicMock()) ret_exchange, ret_cred_offer = await self.manager.prepare_send( connection_id, proposal ) @@ -163,13 +158,11 @@ async def test_create_proposal(self): ) ) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: exchange: V10CredentialExchange = await self.manager.create_proposal( connection_id, auto_offer=True, @@ -201,13 +194,11 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: exchange: V10CredentialExchange = await self.manager.create_proposal( connection_id, auto_offer=True, @@ -239,9 +230,7 @@ async def test_receive_proposal(self): ) ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: proposal = CredentialProposal( credential_proposal=preview, cred_def_id=CRED_DEF_ID, schema_id=None ) @@ -292,14 +281,12 @@ async def test_create_free_offer(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -370,18 +357,16 @@ async def test_create_free_offer_attr_mismatch(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -430,16 +415,16 @@ async def test_create_bound_offer(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "get_cached_key", autospec=True - ) as get_cached_key, async_mock.patch.object( + ) as get_cached_key, mock.patch.object( V10CredentialExchange, "set_cached_key", autospec=True ) as set_cached_key: get_cached_key.return_value = None - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -501,18 +486,16 @@ async def test_create_bound_offer_no_cred_def(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "get_cached_key", autospec=True - ) as get_cached_key, async_mock.patch.object( + ) as get_cached_key, mock.patch.object( V10CredentialExchange, "set_cached_key", autospec=True ) as set_cached_key: get_cached_key.return_value = None - issuer = async_mock.MagicMock() - issuer.create_credential_offer = async_mock.CoroutineMock( - return_value=INDY_OFFER - ) + issuer = mock.MagicMock() + issuer.create_credential_offer = mock.CoroutineMock(return_value=INDY_OFFER) self.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(CredentialManagerError): @@ -555,12 +538,12 @@ async def test_receive_offer_proposed(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -591,15 +574,15 @@ async def test_receive_free_offer(self): offers_attach=[CredentialOffer.wrap_indy_offer(INDY_OFFER)], ) self.context.message = offer - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = connection_id - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -641,17 +624,15 @@ async def test_create_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.CoroutineMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -708,21 +689,19 @@ async def test_create_request_no_cache(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.CoroutineMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -764,7 +743,7 @@ async def test_create_request_bad_state(self): await self.manager.create_request(stored_exchange, holder_did) async def test_receive_request(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_exchange = V10CredentialExchange( credential_exchange_id="dummy-cxid", @@ -780,12 +759,12 @@ async def test_receive_request(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_request(request, mock_conn, None) @@ -815,17 +794,17 @@ async def test_receive_request_no_connection_cred_request(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="test_conn_id", ) - mock_oob = async_mock.MagicMock() + mock_oob = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_exchange cx_rec = await self.manager.receive_request(request, mock_conn, mock_oob) @@ -856,16 +835,16 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="test_conn_id", ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = (StorageNotFoundError(),) with self.assertRaises(CredentialManagerError): @@ -906,28 +885,28 @@ async def test_issue_credential_revocable(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1000" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", - get_or_fetch_local_tails_path=async_mock.CoroutineMock(), + get_or_fetch_local_tails_path=mock.CoroutineMock(), max_creds=10, ), ) @@ -971,7 +950,7 @@ async def test_issue_credential_non_revocable(self): thread_id = "thread-id" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) stored_exchange = V10CredentialExchange( credential_exchange_id="dummy-cxid", @@ -994,28 +973,28 @@ async def test_issue_credential_non_revocable(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), None) ) self.context.injector.bind_instance(IndyIssuer, issuer) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=CRED_DEF_NR ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) self.context.injector.clear_binding(BaseLedger) self.context.injector.bind_instance(BaseLedger, self.ledger) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ): (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1065,38 +1044,36 @@ async def test_issue_credential_fills_rr(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), stored_exchange.revocation_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value = async_mock.MagicMock( + revoc.return_value = mock.MagicMock( get_or_create_active_registry=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=mock.CoroutineMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", max_creds=1000, - get_or_fetch_local_tails_path=( - async_mock.CoroutineMock() - ), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ) ) ), - handle_full_registry=async_mock.CoroutineMock(), + handle_full_registry=mock.CoroutineMock(), ) (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1168,35 +1145,33 @@ async def test_issue_credential_no_active_rr_no_retries(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( side_effect=[ None, ( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=mock.CoroutineMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ), ] @@ -1234,25 +1209,23 @@ async def test_issue_credential_no_active_rr_retry(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=None ) with self.assertRaises(CredentialManagerError) as context: @@ -1278,12 +1251,12 @@ async def test_receive_credential(self): credentials_attach=[CredentialIssue.wrap_indy_credential(INDY_CRED)] ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_credential(issue, connection_id) @@ -1334,30 +1307,30 @@ async def test_store_credential(self): await stored_exchange.save(self.session) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) - holder.get_credential = async_mock.CoroutineMock( + holder = mock.MagicMock() + holder.store_credential = mock.CoroutineMock(return_value=cred_id) + holder.get_credential = mock.CoroutineMock( return_value=json.dumps(INDY_CRED_INFO) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationRegistry", autospec=True - ) as mock_rev_reg, async_mock.patch.object( + ) as mock_rev_reg, mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True ) as delete_ex: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) ret_exchange = await self.manager.store_credential( @@ -1413,7 +1386,7 @@ async def test_store_credential_no_preview(self): thread_id = "thread-id" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) cred_no_rev = {**INDY_CRED} cred_no_rev["rev_reg_id"] = None @@ -1437,29 +1410,29 @@ async def test_store_credential_no_preview(self): ) await stored_exchange.save(self.session) - cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) - holder.get_credential = async_mock.CoroutineMock( + holder = mock.MagicMock() + holder.store_credential = mock.CoroutineMock(return_value=cred_id) + holder.get_credential = mock.CoroutineMock( return_value=json.dumps(cred_info_no_rev) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True ) as delete_ex: ret_exchange = await self.manager.store_credential(stored_exchange) @@ -1507,21 +1480,21 @@ async def test_store_credential_holder_store_indy_error(self): ) await stored_exchange.save(self.session) - cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock( + holder = mock.MagicMock() + holder.store_credential = mock.CoroutineMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1547,14 +1520,14 @@ async def test_send_credential_ack(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save_ex, async_mock.patch.object( + ) as mock_save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True - ) as mock_delete_ex, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_log_exception, async_mock.patch.object( - test_module.LOGGER, "warning", async_mock.MagicMock() + ) as mock_delete_ex, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_log_exception, mock.patch.object( + test_module.LOGGER, "warning", mock.MagicMock() ) as mock_log_warning: mock_delete_ex.side_effect = test_module.StorageError() (exch, ack) = await self.manager.send_credential_ack(stored_exchange) @@ -1582,14 +1555,14 @@ async def test_receive_credential_ack(self): ack = CredentialAck() - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True - ) as delete_ex, async_mock.patch.object( + ) as delete_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange ret_exchange = await self.manager.receive_credential_ack(ack, connection_id) @@ -1623,12 +1596,12 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1651,10 +1624,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py index 129f7eceb1..e100a50a58 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext from .....wallet.base import BaseWallet @@ -8,15 +9,15 @@ from . import CRED_DEF_ID -class TestCredentialRoutes(AsyncTestCase): - async def setUp(self): +class TestCredentialRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -31,17 +32,15 @@ async def test_credential_exchange_list(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.query = async_mock.CoroutineMock() + mock_cred_ex.query = mock.CoroutineMock() mock_cred_ex.query.return_value = [mock_cred_ex] - mock_cred_ex.serialize = async_mock.MagicMock() + mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_list(self.request) mock_response.assert_called_once_with( {"results": [mock_cred_ex.serialize.return_value]} @@ -55,12 +54,12 @@ async def test_credential_exchange_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.query = async_mock.CoroutineMock( + mock_cred_ex.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -69,19 +68,17 @@ async def test_credential_exchange_list_x(self): async def test_credential_exchange_retrieve(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.serialize = async_mock.MagicMock() + mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( mock_cred_ex.serialize.return_value @@ -90,12 +87,12 @@ async def test_credential_exchange_retrieve(self): async def test_credential_exchange_retrieve_not_found(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -104,42 +101,40 @@ async def test_credential_exchange_retrieve_not_found(self): async def test_credential_exchange_retrieve_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.serialize = async_mock.MagicMock( + mock_cred_ex.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_retrieve(self.request) async def test_credential_exchange_create(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.return_value = ( mock_cred_ex_record, @@ -153,28 +148,26 @@ async def test_credential_exchange_create(self): ) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.side_effect = ( test_module.StorageError() @@ -186,37 +179,33 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.CoroutineMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.CoroutineMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_create(self.request) assert "credential_proposal" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.return_value = ( mock_cred_ex_record, @@ -232,9 +221,7 @@ async def test_credential_exchange_send(self): async def test_credential_exchange_send_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.CoroutineMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.CoroutineMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send(self.request) @@ -244,23 +231,23 @@ async def test_credential_exchange_send_no_conn_record(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -270,52 +257,50 @@ async def test_credential_exchange_send_not_ready(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate connection not ready mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ): - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_cred_offer = async_mock.MagicMock() + mock_cred_offer = mock.MagicMock() - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.CoroutineMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), - prepare_send=async_mock.CoroutineMock( + prepare_send=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -330,18 +315,18 @@ async def test_credential_exchange_send_proposal(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record ) @@ -355,22 +340,22 @@ async def test_credential_exchange_send_proposal(self): ) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) mock_credential_manager.return_value.create_proposal.return_value = ( - async_mock.MagicMock() + mock.MagicMock() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -380,11 +365,11 @@ async def test_credential_exchange_send_proposal_deser_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deser: mock_preview_deser.side_effect = test_module.BaseModelError() @@ -392,21 +377,21 @@ async def test_credential_exchange_send_proposal_deser_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_proposal.return_value = ( - async_mock.MagicMock() + mock.MagicMock() ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -416,20 +401,18 @@ async def test_credential_exchange_send_proposal_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record @@ -439,7 +422,7 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -451,20 +434,18 @@ async def test_credential_exchange_create_free_offer(self): self.context.update_settings({"debug.auto_respond_credential_offer": True}) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_create_free_offer(self.request) @@ -474,7 +455,7 @@ async def test_credential_exchange_create_free_offer(self): ) async def test_credential_exchange_create_free_offer_no_cred_def_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -487,14 +468,14 @@ async def test_credential_exchange_create_free_offer_no_cred_def_id(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_preview(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = {"comment": "comment", "cred_def_id": "dummy"} with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -505,15 +486,15 @@ async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(se ) self.context.update_settings({"default_endpoint": "http://1.2.3.4:8081"}) - self.session_inject[BaseWallet] = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), + self.session_inject[BaseWallet] = mock.MagicMock( + get_public_did=mock.CoroutineMock(return_value=None), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_deser_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -523,15 +504,13 @@ async def test_credential_exchange_create_free_offer_deser_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.side_effect = ( test_module.BaseModelError() ) @@ -540,7 +519,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -550,22 +529,22 @@ async def test_credential_exchange_create_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.CoroutineMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -573,7 +552,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -583,22 +562,20 @@ async def test_credential_exchange_send_free_offer(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_offer(self.request) @@ -608,7 +585,7 @@ async def test_credential_exchange_send_free_offer(self): ) async def test_credential_exchange_send_free_offer_no_cred_def_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = { "comment": "comment", "credential_preview": "dummy", @@ -618,7 +595,7 @@ async def test_credential_exchange_send_free_offer_no_cred_def_id(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_preview(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = { "comment": "comment", "cred_def_id": CRED_DEF_ID, @@ -628,7 +605,7 @@ async def test_credential_exchange_send_free_offer_no_preview(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -636,53 +613,49 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value["auto_issue"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -692,25 +665,23 @@ async def test_credential_exchange_send_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.CoroutineMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -719,32 +690,30 @@ async def test_credential_exchange_send_free_offer_x(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_bound_offer(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_offer(self.request) @@ -754,69 +723,67 @@ async def test_credential_exchange_send_bound_offer(self): ) async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_ACKED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) @@ -824,61 +791,59 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_not_ready(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_request(self.request) @@ -888,36 +853,36 @@ async def test_credential_exchange_send_request(self): ) async def test_credential_exchange_send_request_no_conn(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "OobRecord", autospec=True - ) as mock_oob_rec, async_mock.patch.object( + ) as mock_oob_rec, mock.patch.object( test_module, "default_did_from_verkey", autospec=True - ) as mock_default_did_from_verkey, async_mock.patch.object( + ) as mock_default_did_from_verkey, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.CoroutineMock( + return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) mock_cred_ex.retrieve_by_id.return_value.connection_id = None - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_request(self.request) @@ -931,111 +896,107 @@ async def test_credential_exchange_send_request_no_conn(self): mock_default_did_from_verkey.assert_called_once_with("our-recipient_key") async def test_credential_exchange_send_request_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() - mock_cred_ex.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() + mock_cred_ex.retrieve_by_id.return_value = mock.MagicMock( state=mock_cred_ex.STATE_OFFER_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_issue(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.issue_credential.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_issue(self.request) @@ -1045,113 +1006,109 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: mock_cred_ex_rec.state = mock_cred_ex_cls.STATE_REQUEST_RECEIVED - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.issue_credential = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.issue_credential = mock.CoroutineMock() mock_credential_manager.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.issue_credential = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.issue_credential = mock.CoroutineMock() mock_credential_manager.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: mock_cred_ex_cls.state = mock_cred_ex_cls.STATE_REQUEST_RECEIVED - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.CoroutineMock( + mock_issue_cred = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) mock_credential_manager.return_value.issue_credential = mock_issue_cred @@ -1160,29 +1117,29 @@ async def test_credential_exchange_issue_rev_reg_full(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) - mock_credential_manager.return_value = async_mock.MagicMock( - issue_credential=async_mock.CoroutineMock( + mock_credential_manager.return_value = mock.MagicMock( + issue_credential=mock.CoroutineMock( return_value=( mock_cred_ex_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -1190,31 +1147,31 @@ async def test_credential_exchange_issue_deser_x(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_store(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.store_credential.return_value = ( mock_cred_ex_record ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1224,33 +1181,33 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.store_credential.return_value = ( mock_cred_ex_record ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1260,42 +1217,42 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) async def test_credential_exchange_store_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1304,67 +1261,63 @@ async def test_credential_exchange_store_no_conn_record(self): ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex, - async_mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex_cls, async_mock.patch.object( + ) as mock_cred_ex_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock( + mock_cred_ex_record = mock.MagicMock( state=mock_cred_ex_cls.STATE_CREDENTIAL_RECEIVED, - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock() ) - mock_credential_manager.return_value = async_mock.MagicMock( - store_credential=async_mock.CoroutineMock( - return_value=mock_cred_ex_record - ), - send_credential_ack=async_mock.CoroutineMock( - return_value=(mock_cred_ex_record, async_mock.MagicMock()) + mock_credential_manager.return_value = mock.MagicMock( + store_credential=mock.CoroutineMock(return_value=mock_cred_ex_record), + send_credential_ack=mock.CoroutineMock( + return_value=(mock_cred_ex_record, mock.MagicMock()) ), ) @@ -1374,29 +1327,28 @@ async def test_credential_exchange_store_x(self): async def test_credential_exchange_remove(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.delete_record = async_mock.CoroutineMock() + mock_cred_ex.delete_record = mock.CoroutineMock() await test_module.credential_exchange_remove(self.request) mock_response.assert_called_once_with({}) async def test_credential_exchange_remove_bad_cred_ex_id(self): - mock = async_mock.MagicMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1404,47 +1356,40 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_remove_x(self): - mock = async_mock.MagicMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) - mock_rec = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) - ) - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=mock_rec + mock_rec = mock.MagicMock( + delete_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock(return_value=mock_rec) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1457,15 +1402,15 @@ async def test_credential_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_credential_exchange_problem_report_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1473,21 +1418,21 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): await test_module.credential_exchange_problem_report(self.request) async def test_credential_exchange_problem_report_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( + save_error_state=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1497,13 +1442,13 @@ async def test_credential_exchange_problem_report_x(self): await test_module.credential_exchange_problem_report(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py index 66ac360d3e..77abf110c3 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py @@ -1,8 +1,8 @@ from copy import deepcopy from time import time import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from marshmallow import ValidationError from .. import handler as test_module @@ -193,34 +193,30 @@ } -class TestV20IndyCredFormatHandler(AsyncTestCase): - async def setUp(self): +class TestV20IndyCredFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Ledger - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -230,11 +226,11 @@ async def setUp(self): self.context.injector.bind_instance(BaseCache, self.cache) # Issuer - self.issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + self.issuer = mock.MagicMock(IndyIssuer, autospec=True) self.context.injector.bind_instance(IndyIssuer, self.issuer) # Holder - self.holder = async_mock.MagicMock(IndyHolder, autospec=True) + self.holder = mock.MagicMock(IndyHolder, autospec=True) self.context.injector.bind_instance(IndyHolder, self.holder) self.handler = IndyCredFormatHandler(self.profile) @@ -288,33 +284,33 @@ async def test_get_indy_detail_record(self): await details_indy[0].save(self.session) await details_indy[1].save(self.session) # exercise logger warning on get() - with async_mock.patch.object( - INDY_LOGGER, "warning", async_mock.MagicMock() + with mock.patch.object( + INDY_LOGGER, "warning", mock.MagicMock() ) as mock_warning: assert await self.handler.get_detail_record(cred_ex_id) in details_indy mock_warning.assert_called_once() async def test_check_uniqueness(self): - with async_mock.patch.object( + with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_indy_query: mock_indy_query.return_value = [] await self.handler._check_uniqueness("dummy-cx-id") - with async_mock.patch.object( + with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_indy_query: - mock_indy_query.return_value = [async_mock.MagicMock()] + mock_indy_query.return_value = [mock.MagicMock()] with self.assertRaises(V20CredFormatError) as context: await self.handler._check_uniqueness("dummy-cx-id") assert "detail record already exists" in str(context.exception) async def test_create_proposal(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() proposal_data = {"schema_id": SCHEMA_ID} (cred_format, attachment) = await self.handler.create_proposal( @@ -331,7 +327,7 @@ async def test_create_proposal(self): assert attachment.data.base64 async def test_create_proposal_none(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() proposal_data = None (cred_format, attachment) = await self.handler.create_proposal( @@ -342,8 +338,8 @@ async def test_create_proposal_none(self): assert attachment.content == {} async def test_receive_proposal(self): - cred_ex_record = async_mock.MagicMock() - cred_proposal_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_proposal_message = mock.MagicMock() # Not much to assert. Receive proposal doesn't do anything await self.handler.receive_proposal(cred_ex_record, cred_proposal_message) @@ -389,7 +385,7 @@ async def test_create_offer(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -455,7 +451,7 @@ async def test_create_offer_no_cache(self): await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -499,7 +495,7 @@ async def test_create_offer_attr_mismatch(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) cred_def_record = StorageRecord( @@ -517,13 +513,13 @@ async def test_create_offer_attr_mismatch(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): with self.assertRaises(V20CredFormatError): await self.handler.create_offer(cred_proposal) @@ -541,7 +537,7 @@ async def test_create_offer_no_matching_sent_cred_def(self): filters_attach=[AttachDecorator.data_base64({}, ident="0")], ) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -550,8 +546,8 @@ async def test_create_offer_no_matching_sent_cred_def(self): assert "Issuer has no operable cred def" in str(context.exception) async def test_receive_offer(self): - cred_ex_record = async_mock.MagicMock() - cred_offer_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_offer_message = mock.MagicMock() # Not much to assert. Receive offer doesn't do anything await self.handler.receive_offer(cred_ex_record, cred_offer_message) @@ -577,12 +573,12 @@ async def test_create_request(self): ) cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_req_meta = {} - self.holder.create_credential_request = async_mock.CoroutineMock( + self.holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) @@ -612,12 +608,12 @@ async def test_create_request(self): cred_ex_record._id = "dummy-id3" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): await self.handler.create_request( cred_ex_record, {"holder_did": holder_did} @@ -645,8 +641,8 @@ async def test_create_request_bad_state(self): async def test_create_request_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_OFFER_RECEIVED) - with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.CoroutineMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.CoroutineMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -658,15 +654,15 @@ async def test_create_request_not_unique_x(self): assert "indy detail record already exists" in str(context.exception) async def test_receive_request(self): - cred_ex_record = async_mock.MagicMock() - cred_request_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_request_message = mock.MagicMock() # Not much to assert. Receive request doesn't do anything await self.handler.receive_request(cred_ex_record, cred_request_message) async def test_receive_request_no_offer(self): - cred_ex_record = async_mock.MagicMock(cred_offer=None) - cred_request_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock(cred_offer=None) + cred_request_message = mock.MagicMock() with self.assertRaises(V20CredFormatError) as context: await self.handler.receive_request(cred_ex_record, cred_request_message) @@ -721,21 +717,19 @@ async def test_issue_credential_revocable(self): ) cred_rev_id = "1000" - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), max_creds=10, ), ) @@ -809,20 +803,20 @@ async def test_issue_credential_non_revocable(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), None) ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=CRED_DEF_NR ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ): (cred_format, attachment) = await self.handler.issue_credential( cred_ex_record, retries=0 @@ -849,8 +843,8 @@ async def test_issue_credential_non_revocable(self): async def test_issue_credential_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_REQUEST_RECEIVED) - with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.CoroutineMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.CoroutineMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -907,14 +901,12 @@ async def test_issue_credential_no_active_rr_no_retries(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=() ) with self.assertRaises(V20CredFormatError) as context: @@ -967,24 +959,22 @@ async def test_issue_credential_no_active_rr_retry(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( side_effect=[ None, ( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=mock.CoroutineMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ), ] @@ -1040,21 +1030,19 @@ async def test_issue_credential_rr_full(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerRevocationRegistryFullError("Nope") ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=mock.CoroutineMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ) ) @@ -1064,8 +1052,8 @@ async def test_issue_credential_rr_full(self): assert "has no active revocation registry" in str(context.exception) async def test_receive_credential(self): - cred_ex_record = async_mock.MagicMock() - cred_issue_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_issue_message = mock.MagicMock() # Not much to assert. Receive credential doesn't do anything await self.handler.receive_credential(cred_ex_record, cred_issue_message) @@ -1138,18 +1126,18 @@ async def test_store_credential(self): cred_id = "cred-id" - self.holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) + self.holder.store_credential = mock.CoroutineMock(return_value=cred_id) stored_cred = {"stored": "cred"} - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps(stored_cred) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationRegistry", autospec=True ) as mock_rev_reg: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) with self.assertRaises(V20CredFormatError) as context: @@ -1157,25 +1145,25 @@ async def test_store_credential(self): assert "No credential exchange " in str(context.exception) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( test_module, "RevocationRegistry", autospec=True - ) as mock_rev_reg, async_mock.patch.object( + ) as mock_rev_reg, mock.patch.object( test_module.IndyCredFormatHandler, "get_detail_record", autospec=True ) as mock_get_detail_record: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) - mock_get_detail_record.return_value = async_mock.MagicMock( + mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) self.ledger.get_credential_definition.reset_mock() @@ -1259,21 +1247,21 @@ async def test_store_credential_holder_store_indy_error(self): ) cred_id = "cred-id" - self.holder.store_credential = async_mock.CoroutineMock( + self.holder.store_credential = mock.CoroutineMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) - with async_mock.patch.object( + with mock.patch.object( test_module.IndyCredFormatHandler, "get_detail_record", autospec=True - ) as mock_get_detail_record, async_mock.patch.object( - test_module.RevocationRegistry, "from_definition", async_mock.MagicMock() + ) as mock_get_detail_record, mock.patch.object( + test_module.RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_rev_reg: - mock_get_detail_record.return_value = async_mock.MagicMock( + mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) - mock_rev_reg.return_value = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + mock_rev_reg.return_value = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() ) with self.assertRaises(test_module.IndyHolderError) as context: await self.handler.store_credential(stored_cx_rec, cred_id) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index f17202fd31..bc868d08ca 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,7 +1,7 @@ from copy import deepcopy from .......vc.ld_proofs.error import LinkedDataProofException -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from unittest.mock import patch from marshmallow import ValidationError @@ -131,19 +131,17 @@ } -class TestV20LDProofCredFormatHandler(AsyncTestCase): - async def setUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) +class TestV20LDProofCredFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): + self.holder = mock.MagicMock() + self.wallet = mock.MagicMock(BaseWallet, autospec=True) self.session = InMemoryProfile.test_session( bind={VCHolder: self.holder, BaseWallet: self.wallet} ) self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Set custom document loader self.context.injector.bind_instance(DocumentLoader, custom_document_loader) @@ -213,8 +211,8 @@ async def test_get_ld_proof_detail_record(self): await details_ld_proof[0].save(self.session) await details_ld_proof[1].save(self.session) # exercise logger warning on get() - with async_mock.patch.object( - LD_PROOF_LOGGER, "warning", async_mock.MagicMock() + with mock.patch.object( + LD_PROOF_LOGGER, "warning", mock.MagicMock() ) as mock_warning: assert await self.handler.get_detail_record(cred_ex_id) in details_ld_proof mock_warning.assert_called_once() @@ -237,10 +235,10 @@ async def test_assert_can_issue_with_id_and_proof_type(self): context.exception ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did=TEST_DID_SOV, @@ -279,7 +277,7 @@ async def test_assert_can_issue_with_id_and_proof_type(self): assert "Issuer did did:key:notfound not found" in str(context.exception) async def test_get_did_info_for_did_sov(self): - self.wallet.get_local_did = async_mock.CoroutineMock() + self.wallet.get_local_did = mock.CoroutineMock() did_info = await self.handler._did_info_for_did(TEST_DID_SOV) self.wallet.get_local_did.assert_called_once_with( @@ -297,14 +295,14 @@ async def test_get_did_info_for_did_key(self): async def test_get_suite_for_detail(self): detail: LDProofVCDetail = LDProofVCDetail.deserialize(LD_PROOF_VC_DETAIL) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), - ) as mock_can_issue, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_can_issue, mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_did_info: suite = await self.handler._get_suite_for_detail(detail) @@ -321,8 +319,8 @@ async def test_get_suite_for_detail(self): mock_did_info.assert_called_once_with(detail.credential.issuer_id) async def test_get_suite(self): - proof = async_mock.MagicMock() - did_info = async_mock.MagicMock() + proof = mock.MagicMock() + did_info = mock.MagicMock() suite = await self.handler._get_suite( proof_type=BbsBlsSignature2020.signature_type, @@ -407,7 +405,7 @@ async def test_prepare_detail_ed25519_2020(self): assert SECURITY_CONTEXT_ED25519_2020_URL in detail.credential.context_urls async def test_create_proposal(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL) @@ -423,7 +421,7 @@ async def test_create_proposal(self): assert attachment.data.base64 async def test_create_proposal_adds_bbs_context(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL_BBS) @@ -433,7 +431,7 @@ async def test_create_proposal_adds_bbs_context(self): assert SECURITY_CONTEXT_BBS_URL in attachment.content["credential"]["@context"] async def test_create_proposal_adds_ed25519_2020_context(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL_ED25519_2020) @@ -446,17 +444,17 @@ async def test_create_proposal_adds_ed25519_2020_context(self): ) async def test_receive_proposal(self): - cred_ex_record = async_mock.MagicMock() - cred_proposal_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_proposal_message = mock.MagicMock() # Not much to assert. Receive proposal doesn't do anything await self.handler.receive_proposal(cred_ex_record, cred_proposal_message) async def test_create_offer(self): - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_can_issue, patch.object( test_module, "get_properties_without_context", return_value=[] ): @@ -493,10 +491,10 @@ async def test_create_offer_adds_bbs_context(self): ], ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -518,10 +516,10 @@ async def test_create_offer_adds_ed25519_2020_context(self): ], ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -540,10 +538,10 @@ async def test_create_offer_x_no_proposal(self): async def test_create_offer_x_wrong_attributes(self): missing_properties = ["foo"] - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ), patch.object( test_module, "get_properties_without_context", @@ -560,8 +558,8 @@ async def test_create_offer_x_wrong_attributes(self): ) async def test_receive_offer(self): - cred_ex_record = async_mock.MagicMock() - cred_offer_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_offer_message = mock.MagicMock() # Not much to assert. Receive offer doesn't do anything await self.handler.receive_offer(cred_ex_record, cred_offer_message) @@ -624,9 +622,9 @@ async def test_create_request_x_no_data(self): ) async def test_receive_request_no_offer(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() cred_ex_record.cred_offer = None - cred_request_message = async_mock.MagicMock() + cred_request_message = mock.MagicMock() # Not much to assert. Receive request doesn't do anything if no prior offer await self.handler.receive_request(cred_ex_record, cred_request_message) @@ -789,13 +787,13 @@ async def test_issue_credential(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -842,13 +840,13 @@ async def test_issue_credential_adds_bbs_context(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -886,13 +884,13 @@ async def test_issue_credential_adds_ed25519_2020_context(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -1143,19 +1141,17 @@ async def test_store_credential(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.CoroutineMock() + self.holder.store_credential = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.CoroutineMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.CoroutineMock( - return_value=DocumentVerificationResult(verified=True) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.CoroutineMock(return_value=DocumentVerificationResult(verified=True)), + ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -1206,19 +1202,17 @@ async def test_store_credential_x_not_verified(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.CoroutineMock() + self.holder.store_credential = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.CoroutineMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.CoroutineMock( - return_value=DocumentVerificationResult(verified=False) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.CoroutineMock(return_value=DocumentVerificationResult(verified=False)), + ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose, self.assertRaises( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py index f4283168fa..146588ad08 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,25 +11,23 @@ from .. import cred_ack_handler as test_module -class TestCredentialAckHandler(AsyncTestCase): +class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = V20CredAck() request_context.connection_ready = True handler = test_module.V20CredAckHandler() @@ -48,12 +47,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_cred_ack = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_cred_ack = mock.CoroutineMock() request_context.message = V20CredAck() request_context.connection_ready = False handler = test_module.V20CredAckHandler() @@ -70,8 +69,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py index 2a47af1d5d..6bf6d4db8b 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,24 +11,24 @@ from .. import cred_issue_handler as test_module -class TestCredentialIssueHandler(AsyncTestCase): +class TestCredentialIssueHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = V20CredIssue() request_context.connection_ready = True handler_inst = test_module.V20CredIssueHandler() @@ -47,22 +48,22 @@ async def test_called_auto_store(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock(), - store_credential=async_mock.CoroutineMock(), - send_cred_ack=async_mock.CoroutineMock(return_value="cred_ack_message"), + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.CoroutineMock(), + store_credential=mock.CoroutineMock(), + send_cred_ack=mock.CoroutineMock(return_value="cred_ack_message"), ) request_context.message = V20CredIssue() request_context.connection_ready = True @@ -83,31 +84,29 @@ async def test_called_auto_store_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - store_credential=async_mock.CoroutineMock( + store_credential=mock.CoroutineMock( side_effect=[ test_module.IndyHolderError, test_module.StorageError(), ] ), - send_cred_ack=async_mock.CoroutineMock(), + send_cred_ack=mock.CoroutineMock(), ) request_context.message = V20CredIssue() @@ -122,12 +121,12 @@ async def test_called_auto_store_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = V20CredIssue() request_context.connection_ready = False handler_inst = test_module.V20CredIssueHandler() @@ -142,8 +141,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py index 66e295ce34..5b9368285f 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,24 +11,24 @@ from .. import cred_offer_handler as test_module -class TestV20CredOfferHandler(AsyncTestCase): +class TestV20CredOfferHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = V20CredOffer() request_context.connection_ready = True handler_inst = test_module.V20CredOfferHandler() @@ -47,21 +48,21 @@ async def test_called_auto_request(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( return_value=(None, "cred_request_message") ) request_context.message = V20CredOffer() @@ -87,25 +88,23 @@ async def test_called_auto_request_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -114,10 +113,10 @@ async def test_called_auto_request_x(self): handler = test_module.V20CredOfferHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -125,12 +124,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = V20CredOffer() request_context.connection_ready = False handler_inst = test_module.V20CredOfferHandler() @@ -148,8 +147,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py index fa5195fce9..df1df7cf58 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,18 +10,16 @@ from .. import cred_problem_report_handler as test_module -class TestCredProblemReportHandler(AsyncTestCase): +class TestCredProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.connection_ready = True request_context.message = V20CredProblemReport( description={ @@ -41,16 +40,14 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = V20CredProblemReport( description={ @@ -71,7 +68,7 @@ async def test_called_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_ready = False request_context.message = V20CredProblemReport( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py index daaf4c0d79..e49d5e8a4c 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,17 +10,17 @@ from .. import cred_proposal_handler as test_module -class TestV20CredProposalHandler(AsyncTestCase): +class TestV20CredProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = V20CredProposal() @@ -37,16 +38,16 @@ async def test_called(self): async def test_called_auto_offer(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( return_value=(None, "cred_offer_message") ) request_context.message = V20CredProposal() @@ -68,18 +69,16 @@ async def test_called_auto_offer(self): async def test_called_auto_offer_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -88,10 +87,10 @@ async def test_called_auto_offer_x(self): handler = test_module.V20CredProposalHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -99,12 +98,12 @@ async def test_called_auto_offer_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = V20CredProposal() request_context.connection_ready = False handler_inst = test_module.V20CredProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py index 25edba8b36..3c1d654244 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -13,25 +14,25 @@ CD_ID = "LjgpST2rjsoxYegQDRm7EL:3:CL:18:tag" -class TestV20CredRequestHandler(AsyncTestCase): +class TestV20CredRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = V20CredRequest() @@ -49,11 +50,11 @@ async def test_called(self): async def test_called_auto_issue(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) @@ -61,14 +62,14 @@ async def test_called_auto_issue(self): cred_ex_rec = V20CredExRecord() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "cred_issue_message") ) request_context.message = V20CredRequest() @@ -93,28 +94,28 @@ async def test_called_auto_issue(self): async def test_called_auto_issue_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() cred_ex_rec = V20CredExRecord() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.CoroutineMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.CoroutineMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -123,10 +124,10 @@ async def test_called_auto_issue_x(self): handler = test_module.V20CredRequestHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + with mock.patch.object( + responder, "send_reply", mock.CoroutineMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -134,12 +135,12 @@ async def test_called_auto_issue_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = V20CredRequest() request_context.connection_ready = False handler = test_module.V20CredRequestHandler() @@ -157,8 +158,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py index ec4e33c4bf..a2b363edcf 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -8,7 +9,7 @@ from ..cred_ack import V20CredAck -class TestV20CredAck(AsyncTestCase): +class TestV20CredAck(IsolatedAsyncioTestCase): """Credential ack tests.""" async def test_init_type(self): @@ -21,8 +22,8 @@ async def test_deserialize(self): """Test deserialization.""" obj = V20CredAck() - with async_mock.patch.object( - test_module.V20CredAckSchema, "load", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredAckSchema, "load", mock.MagicMock() ) as mock_load: cred_ack = V20CredAck.deserialize(obj) mock_load.assert_called_once_with(obj) @@ -33,8 +34,8 @@ async def test_serialize(self): """Test serialization.""" obj = V20CredAck() - with async_mock.patch.object( - test_module.V20CredAckSchema, "dump", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredAckSchema, "dump", mock.MagicMock() ) as mock_dump: cred_ack_dict = obj.serialize() mock_dump.assert_called_once_with(obj) @@ -42,7 +43,7 @@ async def test_serialize(self): assert cred_ack_dict is mock_dump.return_value -class TestCredentialAckSchema(AsyncTestCase): +class TestCredentialAckSchema(IsolatedAsyncioTestCase): """Test credential ack schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py index a0f2d70639..8e4428943a 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -12,7 +13,7 @@ from ..cred_issue import V20CredIssue -class TestV20CredIssue(AsyncTestCase): +class TestV20CredIssue(IsolatedAsyncioTestCase): """Credential issue tests""" INDY_CRED = { @@ -160,8 +161,8 @@ async def test_serialize(self): """Test serialization.""" obj = TestV20CredIssue.CRED_ISSUE - with async_mock.patch.object( - test_module.V20CredIssueSchema, "dump", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredIssueSchema, "dump", mock.MagicMock() ) as mock_dump: cred_issue_dict = obj.serialize() mock_dump.assert_called_once_with(obj) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py index 3334aa5c59..73a7db3831 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -12,7 +12,7 @@ from ..inner.cred_preview import V20CredAttrSpec, V20CredPreview -class TestV20CredOffer(AsyncTestCase): +class TestV20CredOffer(IsolatedAsyncioTestCase): """Credential offer tests""" indy_offer = { @@ -132,7 +132,7 @@ async def test_serde(self): V20CredOffer.deserialize(obj) -class TestV20CredOfferSchema(AsyncTestCase): +class TestV20CredOfferSchema(IsolatedAsyncioTestCase): """Test credential cred offer schema""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py index 2389668065..0d302f5a77 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py @@ -1,7 +1,8 @@ import logging import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py index e45778f008..6dafd7027b 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -25,7 +25,7 @@ } -class TestV20CredProposal(AsyncTestCase): +class TestV20CredProposal(IsolatedAsyncioTestCase): """Credential proposal tests.""" async def test_init(self): @@ -234,7 +234,7 @@ async def test_serialize_minimal(self): } -class TestV20CredProposalSchema(AsyncTestCase): +class TestV20CredProposalSchema(IsolatedAsyncioTestCase): """Test credential proposal schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py index 607a3ff445..d813d9cc35 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -11,7 +11,7 @@ from ..cred_request import V20CredRequest -class TestV20CredRequest(AsyncTestCase): +class TestV20CredRequest(IsolatedAsyncioTestCase): """Credential request tests""" indy_cred_req = { @@ -137,7 +137,7 @@ async def test_serde(self): V20CredRequest.deserialize(obj) -class TestV20CredRequestSchema(AsyncTestCase): +class TestV20CredRequestSchema(IsolatedAsyncioTestCase): """Test credential request schema""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py index 94510d1e06..1045f49003 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..indy import V20CredExRecordIndy -class TestV20CredExRecordIndy(AsyncTestCase): +class TestV20CredExRecordIndy(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecordIndy( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py index 0c6e1ad2a1..ed9cb903f1 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..ld_proof import V20CredExRecordLDProof -class TestV20CredExRecordLDProof(AsyncTestCase): +class TestV20CredExRecordLDProof(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecordLDProof(cred_ex_ld_proof_id="dummy-0", cred_ex_id="abc") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py index d46fd498d7..ad4c449601 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator @@ -36,7 +37,7 @@ } -class TestV20CredExRecord(AsyncTestCase): +class TestV20CredExRecord(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecord( @@ -125,10 +126,10 @@ async def test_save_error_state(self): record.state = V20CredExRecord.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="test") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py index b1ed8216ea..ba3c0c38fb 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py @@ -1,7 +1,8 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache @@ -78,26 +79,22 @@ ) -class TestV20CredManager(AsyncTestCase): - async def setUp(self): +class TestV20CredManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) @@ -130,10 +127,10 @@ async def test_prepare_send(self): ) ], ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "create_offer", autospec=True ) as create_offer: - create_offer.return_value = (async_mock.MagicMock(), async_mock.MagicMock()) + create_offer.return_value = (mock.MagicMock(), mock.MagicMock()) ret_cred_ex_rec, ret_cred_offer = await self.manager.prepare_send( connection_id, cred_proposal, replacement_id="123" ) @@ -157,12 +154,12 @@ async def test_create_proposal(self): ) ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.CoroutineMock( + mock_handler.return_value.create_proposal = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -200,12 +197,12 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.CoroutineMock( + mock_handler.return_value.create_proposal = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -251,12 +248,12 @@ async def test_receive_proposal(self): ) ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_proposal = async_mock.CoroutineMock() + mock_handler.return_value.receive_proposal = mock.CoroutineMock() cred_proposal = V20CredProposal( credential_preview=cred_preview, @@ -324,12 +321,12 @@ async def test_create_free_offer(self): cred_proposal=cred_proposal, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.CoroutineMock( + mock_handler.return_value.create_offer = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -400,12 +397,12 @@ async def test_create_bound_offer(self): cred_proposal=cred_proposal, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.CoroutineMock( + mock_handler.return_value.create_offer = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -510,16 +507,16 @@ async def test_receive_offer_proposed(self): thread_id=thread_id, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(return_value=stored_cx_rec), - ) as mock_retrieve, async_mock.patch.object( + mock.CoroutineMock(return_value=stored_cx_rec), + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.CoroutineMock() + mock_handler.return_value.receive_offer = mock.CoroutineMock() cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -564,17 +561,17 @@ async def test_receive_free_offer(self): cred_offer.assign_thread_id(thread_id) self.context.message = cred_offer - self.context.conn_record = async_mock.MagicMock() + self.context.conn_record = mock.MagicMock() self.context.conn_record.connection_id = connection_id - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.CoroutineMock() + mock_handler.return_value.receive_offer = mock.CoroutineMock() mock_retrieve.side_effect = (StorageNotFoundError(),) cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -620,12 +617,12 @@ async def test_create_bound_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.CoroutineMock( + mock_handler.return_value.create_request = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -707,12 +704,12 @@ async def test_create_free_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.CoroutineMock( + mock_handler.return_value.create_request = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -759,7 +756,7 @@ async def test_create_request_bad_state(self): assert " state " in str(context.exception) async def test_receive_request(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_cx_rec = V20CredExRecord( cred_ex_id="dummy-cxid", connection_id=mock_conn.connection_id, @@ -779,15 +776,15 @@ async def test_receive_request(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() # mock_retrieve.return_value = stored_cx_rec cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -826,18 +823,18 @@ async def test_receive_request_no_connection_cred_request(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") - mock_oob = async_mock.MagicMock() + mock_conn = mock.MagicMock(connection_id="test_conn_id") + mock_oob = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.return_value = stored_cx_rec - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() cx_rec = await self.manager.receive_request( cred_request, mock_conn, mock_oob @@ -858,7 +855,7 @@ async def test_receive_request_no_connection_cred_request(self): assert cx_rec.connection_id == "test_conn_id" async def test_receive_request_no_cred_ex_with_offer_found(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_cx_rec = V20CredExRecord( cred_ex_id="dummy-cxid", initiator=V20CredExRecord.INITIATOR_EXTERNAL, @@ -878,15 +875,15 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -970,19 +967,19 @@ async def test_issue_credential(self): thread_id=thread_id, ) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred_rev_id = "1000" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.issue_credential = async_mock.CoroutineMock( + mock_handler.return_value.issue_credential = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -1085,16 +1082,16 @@ async def test_receive_cred(self): credentials_attach=[AttachDecorator.data_base64(INDY_CRED, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_credential = async_mock.CoroutineMock() + mock_handler.return_value.receive_credential = mock.CoroutineMock() mock_retrieve.return_value = stored_cx_rec ret_cx_rec = await self.manager.receive_credential( cred_issue, @@ -1155,10 +1152,10 @@ async def test_receive_cred_x_extra_formats(self): credentials_attach=[AttachDecorator.data_base64(LD_PROOF_VC, ident="1")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1193,10 +1190,10 @@ async def test_receive_cred_x_no_formats(self): credentials_attach=[AttachDecorator.data_base64(LD_PROOF_VC, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1234,14 +1231,14 @@ async def test_store_credential(self): thread_id=thread_id, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True - ) as mock_delete, async_mock.patch.object( + ) as mock_delete, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.store_credential = async_mock.CoroutineMock() + mock_handler.return_value.store_credential = mock.CoroutineMock() ret_cx_rec = await self.manager.store_credential( stored_cx_rec, cred_id=cred_id @@ -1281,14 +1278,14 @@ async def test_send_cred_ack(self): auto_remove=True, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save_ex, async_mock.patch.object( + ) as mock_save_ex, mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete_ex, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_log_exception, async_mock.patch.object( - test_module.LOGGER, "warning", async_mock.MagicMock() + ) as mock_delete_ex, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_log_exception, mock.patch.object( + test_module.LOGGER, "warning", mock.MagicMock() ) as mock_log_warning: mock_delete_ex.side_effect = test_module.StorageError() (_, ack) = await self.manager.send_cred_ack(stored_exchange) @@ -1313,13 +1310,13 @@ async def test_receive_cred_ack(self): ack = V20CredAck() - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True ) as mock_delete: mock_retrieve.return_value = stored_cx_rec @@ -1340,21 +1337,21 @@ async def test_receive_cred_ack(self): mock_delete.assert_called_once() async def test_delete_cred_ex_record(self): - stored_cx_rec = async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) - stored_indy = async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) + stored_cx_rec = mock.MagicMock(delete_record=mock.CoroutineMock()) + stored_indy = mock.MagicMock(delete_record=mock.CoroutineMock()) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( - test_module, "V20CredFormat", async_mock.MagicMock() + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( + test_module, "V20CredFormat", mock.MagicMock() ) as mock_cred_format: mock_retrieve.return_value = stored_cx_rec mock_cred_format.Format = [ - async_mock.MagicMock( - detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.CoroutineMock( + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.CoroutineMock( return_value=[ stored_indy, stored_indy, @@ -1362,9 +1359,9 @@ async def test_delete_cred_ex_record(self): ) ) ), - async_mock.MagicMock( - detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.CoroutineMock(return_value=[]) + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.CoroutineMock(return_value=[]) ) ), ] @@ -1385,12 +1382,12 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1419,10 +1416,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py index 845f21555c..9d7d8dab9c 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py @@ -1,5 +1,6 @@ from .....vc.ld_proofs.error import LinkedDataProofException -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -14,15 +15,15 @@ ) -class TestV20CredRoutes(AsyncTestCase): - async def setUp(self): +class TestV20CredRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -89,17 +90,13 @@ async def test_credential_exchange_list(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.query = async_mock.CoroutineMock(return_value=[mock_cx_rec]) - mock_cx_rec.serialize = async_mock.MagicMock( - return_value={"hello": "world"} - ) + mock_cx_rec.query = mock.CoroutineMock(return_value=[mock_cx_rec]) + mock_cx_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_list(self.request) mock_response.assert_called_once_with( { @@ -121,12 +118,12 @@ async def test_credential_exchange_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.query = async_mock.CoroutineMock( + mock_cx_rec.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -135,30 +132,28 @@ async def test_credential_exchange_list_x(self): async def test_credential_exchange_retrieve(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock() + mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( { @@ -171,32 +166,30 @@ async def test_credential_exchange_retrieve(self): async def test_credential_exchange_retrieve_indy_ld_proof(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock() + mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"in": "dy"}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"in": "dy"}) ), - async_mock.MagicMock( # ld_proof - serialize=async_mock.MagicMock(return_value={"ld": "proof"}) + mock.MagicMock( # ld_proof + serialize=mock.MagicMock(return_value={"ld": "proof"}) ), ] ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( { @@ -209,12 +202,12 @@ async def test_credential_exchange_retrieve_indy_ld_proof(self): async def test_credential_exchange_retrieve_not_found(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -223,20 +216,20 @@ async def test_credential_exchange_retrieve_not_found(self): async def test_credential_exchange_retrieve_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock( + mock_cx_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( return_value=None ) @@ -244,26 +237,26 @@ async def test_credential_exchange_retrieve_x(self): await test_module.credential_exchange_retrieve(self.request) async def test_credential_exchange_create(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_cx_rec = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_cred_mgr.return_value.prepare_send.return_value = ( mock_cx_rec, @@ -275,22 +268,22 @@ async def test_credential_exchange_create(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cred_mgr.return_value.prepare_send.side_effect = ( @@ -303,7 +296,7 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": { @@ -317,26 +310,26 @@ async def test_credential_exchange_create_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) - mock_cx_rec = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_cred_mgr.return_value.prepare_send.return_value = ( mock_cx_rec, @@ -348,36 +341,36 @@ async def test_credential_exchange_send(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_request_no_conn_no_holder_did(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "OobRecord", autospec=True - ) as mock_oob_rec, async_mock.patch.object( + ) as mock_oob_rec, mock.patch.object( test_module, "default_did_from_verkey", autospec=True - ) as mock_default_did_from_verkey, async_mock.patch.object( + ) as mock_default_did_from_verkey, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.CoroutineMock( + return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) mock_cred_ex.retrieve_by_id.return_value.connection_id = None - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_request(self.request) @@ -394,26 +387,26 @@ async def test_credential_exchange_send_no_conn_record(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -423,7 +416,7 @@ async def test_credential_exchange_send_not_ready(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -431,46 +424,44 @@ async def test_credential_exchange_send_not_ready(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_cred_preview_deser: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_cred_offer = async_mock.MagicMock() - mock_cred_mgr.return_value = async_mock.CoroutineMock( - create_offer=async_mock.CoroutineMock( + mock_cred_offer = mock.MagicMock() + mock_cred_mgr.return_value = mock.CoroutineMock( + create_offer=mock.CoroutineMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), - prepare_send=async_mock.CoroutineMock( + prepare_send=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -485,7 +476,7 @@ async def test_credential_exchange_send_proposal(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -493,14 +484,14 @@ async def test_credential_exchange_send_proposal(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec await test_module.credential_exchange_send_proposal(self.request) @@ -511,7 +502,7 @@ async def test_credential_exchange_send_proposal(self): async def test_credential_exchange_send_proposal_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "comment", "connection_id": connection_id, @@ -523,23 +514,21 @@ async def test_credential_exchange_send_proposal_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_proposal.return_value = ( - async_mock.MagicMock() - ) + mock_cred_mgr.return_value.create_proposal.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_proposal(self.request) @@ -548,7 +537,7 @@ async def test_credential_exchange_send_proposal_x(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -556,16 +545,14 @@ async def test_credential_exchange_send_proposal_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec @@ -573,28 +560,26 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_proposal.return_value = ( - async_mock.MagicMock() - ) + mock_cred_mgr.return_value.create_proposal.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -605,18 +590,18 @@ async def test_credential_exchange_create_free_offer(self): ) self.context.update_settings({"debug.auto_respond_credential_offer": True}) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_create_free_offer(self.request) @@ -624,7 +609,7 @@ async def test_credential_exchange_create_free_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_free_offer_no_filter(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -638,7 +623,7 @@ async def test_credential_exchange_create_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -648,22 +633,22 @@ async def test_credential_exchange_create_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_cred_mgr.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + create_offer=mock.CoroutineMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -671,7 +656,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -681,25 +666,25 @@ async def test_credential_exchange_send_free_offer(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_offer(self.request) mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_free_offer_no_filter(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "comment", "credential_preview": { @@ -713,7 +698,7 @@ async def test_credential_exchange_send_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -723,27 +708,27 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": True, "credential_preview": { @@ -753,26 +738,26 @@ async def test_credential_exchange_send_free_offer_not_ready(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -782,24 +767,22 @@ async def test_credential_exchange_send_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_cred_mgr.return_value = async_mock.CoroutineMock( - create_offer=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.CoroutineMock( + create_offer=mock.CoroutineMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -808,30 +791,30 @@ async def test_credential_exchange_send_free_offer_x(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_bound_offer(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_offer(self.request) @@ -839,26 +822,26 @@ async def test_credential_exchange_send_bound_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_bound_offer_linked_data_error(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() exception_message = "ex" mock_cred_mgr.return_value.create_offer.side_effect = ( @@ -870,67 +853,67 @@ async def test_credential_exchange_send_bound_offer_linked_data_error(self): assert exception_message in str(error.exception) async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_DONE, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) @@ -938,59 +921,59 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_not_ready(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_request(self.request) @@ -998,105 +981,105 @@ async def test_credential_exchange_send_request(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_request_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() - mock_cx_rec.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() + mock_cx_rec.retrieve_by_id.return_value = mock.MagicMock( state=mock_cx_rec.STATE_OFFER_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_free_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_request(self.request) @@ -1104,87 +1087,85 @@ async def test_credential_exchange_send_free_request(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_free_request_no_filter(self): - self.request.json = async_mock.CoroutineMock( - return_value={"comment": "comment"} - ) + self.request.json = mock.CoroutineMock(return_value={"comment": "comment"}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send_free_request(self.request) assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() mock_cred_mgr.return_value.create_request.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() mock_cred_mgr.return_value.create_request.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), ] ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() with self.assertRaises(test_module.web.HTTPBadRequest): # ledger error await test_module.credential_exchange_send_free_request(self.request) @@ -1192,30 +1173,30 @@ async def test_credential_exchange_send_free_request_x(self): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_issue(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1223,7 +1204,7 @@ async def test_credential_exchange_issue(self): mock_cred_mgr.return_value.issue_credential.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_issue(self.request) @@ -1237,109 +1218,109 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( conn_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: mock_cx_rec.state = mock_cx_rec_cls.STATE_REQUEST_RECEIVED - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cx_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock() mock_cred_mgr.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock() mock_cred_mgr.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( conn_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: mock_cx_rec.state = mock_cx_rec_cls.STATE_REQUEST_RECEIVED - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cx_rec ) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.CoroutineMock( + mock_issue_cred = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) mock_cred_mgr.return_value.issue_credential = mock_issue_cred @@ -1348,36 +1329,36 @@ async def test_credential_exchange_issue_rev_reg_full(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cx_rec ) - mock_cred_mgr.return_value = async_mock.MagicMock( - issue_credential=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + issue_credential=mock.CoroutineMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_cred_mgr.return_value.get_detail_record = async_mock.CoroutineMock( + mock_cred_mgr.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1387,39 +1368,39 @@ async def test_credential_exchange_issue_deser_x(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_store(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1433,40 +1414,40 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( LDProofCredFormatHandler, "get_detail_record", autospec=True - ) as mock_ld_proof_get_detail_record, async_mock.patch.object( + ) as mock_ld_proof_get_detail_record, mock.patch.object( IndyCredFormatHandler, "get_detail_record", autospec=True ) as mock_indy_get_detail_record: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() - mock_indy_get_detail_record.return_value = async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_indy_get_detail_record.return_value = mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ) mock_ld_proof_get_detail_record.return_value = None # ld_proof mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1480,119 +1461,117 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) async def test_credential_exchange_store_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( state=mock_cx_rec_cls.STATE_CREDENTIAL_RECEIVED, - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock() ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - mock_cred_mgr.return_value = async_mock.MagicMock( - store_credential=async_mock.CoroutineMock(return_value=mock_cx_rec), - send_cred_ack=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + store_credential=mock.CoroutineMock(return_value=mock_cx_rec), + send_cred_ack=mock.CoroutineMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ), ) @@ -1603,13 +1582,13 @@ async def test_credential_exchange_store_x(self): async def test_credential_exchange_remove(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock() + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.CoroutineMock() ) await test_module.credential_exchange_remove(self.request) @@ -1618,11 +1597,11 @@ async def test_credential_exchange_remove(self): async def test_credential_exchange_remove_bad_cred_ex_id(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1633,11 +1612,11 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): async def test_credential_exchange_remove_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1646,25 +1625,23 @@ async def test_credential_exchange_remove_x(self): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cred_ex, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1677,17 +1654,17 @@ async def test_credential_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_credential_exchange_problem_report_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1695,21 +1672,21 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): await test_module.credential_exchange_problem_report(self.request) async def test_credential_exchange_problem_report_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( + save_error_state=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1719,13 +1696,13 @@ async def test_credential_exchange_problem_report_x(self): await test_module.credential_exchange_problem_report(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py index eb63e04b37..2389b5aade 100644 --- a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py +++ b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,11 +10,11 @@ from .. import ack_handler as test_module -class TestNotificationAckHandler(AsyncTestCase): +class TestNotificationAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message = V10Ack(status="OK") handler = test_module.V10AckHandler() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py index c8b69357cb..692f1e48f6 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,7 +1,7 @@ """Test Problem Report Handler.""" import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -36,9 +36,9 @@ async def session(request_context) -> ProfileSession: class TestOOBProblemReportHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = OOBProblemReport( description={ "en": "No such connection", @@ -55,9 +55,9 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_problem_report = mock.CoroutineMock() mock_oob_mgr.return_value.receive_problem_report.side_effect = ( OutOfBandManagerError("error") ) @@ -68,10 +68,10 @@ async def test_exception(self, mock_oob_mgr, request_context, connection_record) } ) handler = test_module.OOBProblemReportMessageHandler() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_exc_logger: responder = MockResponder() await handler.handle(context=request_context, responder=responder) - assert mock_exc_logger.called_once() + mock_exc_logger.assert_called_once() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py index f403a1ce17..905c218f8d 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py @@ -1,7 +1,7 @@ """Test Reuse Accept Message Handler.""" import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -36,11 +36,9 @@ async def session(request_context) -> ProfileSession: class TestHandshakeReuseAcceptHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.CoroutineMock() - ) + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.CoroutineMock() request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() @@ -52,16 +50,21 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") - async def test_exception(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.CoroutineMock() - ) + @mock.patch.object(test_module, "OutOfBandManager") + async def test_exception( + self, + mock_oob_mgr, + request_context, + connection_record, + caplog: pytest.LogCaptureFixture, + ): + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.CoroutineMock() mock_oob_mgr.return_value.receive_reuse_accepted_message.side_effect = ( OutOfBandManagerError("error") ) request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() - await handler.handle(context=request_context, responder=responder) - assert mock_oob_mgr.return_value._logger.exception.called_once_("error") + with caplog.at_level("ERROR"): + await handler.handle(request_context, responder) + assert "Error processing" in caplog.text diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py index d4d94f546c..2e6982aef2 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py @@ -1,7 +1,7 @@ """Test Reuse Message Handler.""" import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -29,9 +29,9 @@ async def session(request_context) -> ProfileSession: class TestHandshakeReuseHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() request_context.connection_record = ConnRecord() @@ -44,9 +44,9 @@ async def test_called(self, mock_oob_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_reuse_accepted(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() reuse_accepted = HandshakeReuseAccept() mock_oob_mgr.return_value.receive_reuse_message.return_value = reuse_accepted request_context.message = HandshakeReuse() @@ -61,9 +61,11 @@ async def test_reuse_accepted(self, mock_oob_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") - async def test_exception(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + @mock.patch.object(test_module, "OutOfBandManager") + async def test_exception( + self, mock_oob_mgr, request_context, caplog: pytest.LogCaptureFixture + ): + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() mock_oob_mgr.return_value.receive_reuse_message.side_effect = ( OutOfBandManagerError("error") ) @@ -71,5 +73,6 @@ async def test_exception(self, mock_oob_mgr, request_context): handler = test_module.HandshakeReuseMessageHandler() request_context.connection_record = ConnRecord() responder = MockResponder() - await handler.handle(request_context, responder) - assert mock_oob_mgr.return_value._logger.exception.called_once_("error") + with caplog.at_level("ERROR"): + await handler.handle(request_context, responder) + assert "Error processing" in caplog.text diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py b/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py index 9581e6a923..aafb44f9c0 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -11,7 +11,7 @@ TEST_DID = "did:sov:55GkHamhTU1ZbTbV2ab9DE" -class TestInvitationRecord(AsyncTestCase): +class TestInvitationRecord(IsolatedAsyncioTestCase): def test_invitation_record(self): """Test invitation record.""" invi_rec = InvitationRecord(invi_msg_id="12345") @@ -28,7 +28,7 @@ def test_invitation_record(self): assert invi_rec != another -class TestInvitationRecordSchema(AsyncTestCase): +class TestInvitationRecordSchema(IsolatedAsyncioTestCase): def test_make_record(self): """Test making record.""" invi = InvitationMessage( diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 25abf93193..62f7db787c 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -6,7 +6,8 @@ from typing import List from unittest.mock import ANY -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord from .....connections.models.connection_target import ConnectionTarget @@ -308,10 +309,10 @@ def make_did_doc(self, did, verkey): return doc -class TestOOBManager(AsyncTestCase, TestConfig): +class TestOOBManager(IsolatedAsyncioTestCase, TestConfig): def setUp(self): self.responder = MockResponder() - self.responder.send = async_mock.CoroutineMock() + self.responder.send = mock.CoroutineMock() self.test_mediator_routing_keys = [ "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR" @@ -319,8 +320,8 @@ def setUp(self): self.test_mediator_conn_id = "mediator-conn-id" self.test_mediator_endpoint = "http://mediator.example.com" - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) @@ -339,39 +340,39 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseResponder, self.responder) self.profile.context.injector.bind_instance( - EventBus, async_mock.MagicMock(notify=async_mock.CoroutineMock()) + EventBus, mock.MagicMock(notify=mock.CoroutineMock()) ) - self.mt_mgr = async_mock.MagicMock() - self.mt_mgr = async_mock.create_autospec(MultitenantManager) + self.mt_mgr = mock.MagicMock() + self.mt_mgr = mock.create_autospec(MultitenantManager) self.profile.context.injector.bind_instance(BaseMultitenantManager, self.mt_mgr) - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.profile.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) self.manager = OutOfBandManager(self.profile) assert self.manager.profile - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], [], ) - self.test_conn_rec = async_mock.MagicMock( + self.test_conn_rec = mock.MagicMock( connection_id="dummy", my_did=TestConfig.test_did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.REQUESTER, state=ConnRecord.State.COMPLETED, their_public_did=self.their_public_did, - save=async_mock.CoroutineMock(), + save=mock.CoroutineMock(), ) async def test_create_invitation_handshake_succeeds(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -405,9 +406,9 @@ async def test_create_invitation_multitenant_local(self): } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_signing_key", autospec=True - ) as mock_wallet_create_signing_key, async_mock.patch.object( + ) as mock_wallet_create_signing_key, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_wallet_create_signing_key.return_value = KeyInfo( @@ -431,7 +432,7 @@ async def test_create_invitation_multitenant_public(self): } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -451,7 +452,7 @@ async def test_create_invitation_multitenant_public(self): async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): async with self.profile.session() as session: - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -461,11 +462,11 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator_id", - ) as mock_get_default_mediator, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() + ) as mock_get_default_mediator, mock.patch.object( + mock_conn_rec, "metadata_set", mock.CoroutineMock() ) as mock_metadata_set: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -502,12 +503,12 @@ async def test_create_invitation_no_handshake_no_attachments_x(self): async def test_create_invitation_attachment_v1_0_cred_offer(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -516,7 +517,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): method=SOV, key_type=ED25519, ) - mock_retrieve_cxid.return_value = async_mock.MagicMock( + mock_retrieve_cxid.return_value = mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 ) invi_rec = await self.manager.create_invitation( @@ -536,12 +537,12 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -550,7 +551,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): method=SOV, key_type=ED25519, ) - mock_retrieve_cxid.return_value = async_mock.MagicMock( + mock_retrieve_cxid.return_value = mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 ) invi_rec = await self.manager.create_invitation( @@ -570,16 +571,16 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): } async def test_create_invitation_attachment_v2_0_cred_offer(self): - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_cxid_v1, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve_cxid_v1, mock.patch.object( test_module.V20CredExRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid_v2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -589,9 +590,9 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): key_type=ED25519, ) mock_retrieve_cxid_v1.side_effect = test_module.StorageNotFoundError() - mock_retrieve_cxid_v2.return_value = async_mock.MagicMock( - cred_offer=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"cred": "offer"}) + mock_retrieve_cxid_v2.return_value = mock.MagicMock( + cred_offer=mock.MagicMock( + serialize=mock.MagicMock(return_value={"cred": "offer"}) ) ) invi_rec = await self.manager.create_invitation( @@ -612,12 +613,12 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): async def test_create_invitation_attachment_present_proof_v1_0(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_pxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -626,7 +627,7 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): method=SOV, key_type=ED25519, ) - mock_retrieve_pxid.return_value = async_mock.MagicMock( + mock_retrieve_pxid.return_value = mock.MagicMock( presentation_request_dict=self.PRES_REQ_V1 ) invi_rec = await self.manager.create_invitation( @@ -647,16 +648,16 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): async def test_create_invitation_attachment_present_proof_v2_0(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), - ) as mock_retrieve_pxid_1, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve_pxid_1, mock.patch.object( test_module.V20PresExRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_pxid_2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -666,7 +667,7 @@ async def test_create_invitation_attachment_present_proof_v2_0(self): key_type=ED25519, ) mock_retrieve_pxid_1.side_effect = StorageNotFoundError() - mock_retrieve_pxid_2.return_value = async_mock.MagicMock( + mock_retrieve_pxid_2.return_value = mock.MagicMock( pres_request=TestConfig.PRES_REQ_V2 ) invi_rec = await self.manager.create_invitation( @@ -725,7 +726,7 @@ async def test_create_invitation_requests_attach_x_multi_use(self): async def test_create_invitation_public_x_no_public_did(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -742,7 +743,7 @@ async def test_create_invitation_public_x_no_public_did(self): async def test_create_invitation_attachment_x(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -778,7 +779,7 @@ async def test_create_invitation_peer_did(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -827,7 +828,7 @@ async def test_create_invitation_metadata_assigned(self): async def test_create_invitation_x_public_metadata(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -850,13 +851,11 @@ async def test_create_invitation_x_public_metadata(self): ) async def test_wait_for_conn_rec_active_retrieve_by_id(self): - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - connection_id="the-retrieved-connection-id" - ) + mock.CoroutineMock( + return_value=mock.MagicMock(connection_id="the-retrieved-connection-id") ), ): conn_rec = await self.manager._wait_for_conn_rec_active("a-connection-id") @@ -865,14 +864,14 @@ async def test_wait_for_conn_rec_active_retrieve_by_id(self): async def test_create_handshake_reuse_msg(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.test_conn_rec), + mock.CoroutineMock(return_value=self.test_conn_rec), ): oob_mgr_fetch_conn.return_value = ConnectionTarget( did=TestConfig.test_did, @@ -907,7 +906,7 @@ async def test_create_handshake_reuse_msg(self): async def test_create_handshake_reuse_msg_catch_exception(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, @@ -915,7 +914,7 @@ async def test_create_handshake_reuse_msg_catch_exception(self): oob_mgr_fetch_conn.side_effect = StorageNotFoundError() with self.assertRaises(OutOfBandManagerError) as context: await self.manager._create_handshake_reuse_message( - async_mock.MagicMock(), self.test_conn_rec, "1.0" + mock.MagicMock(), self.test_conn_rec, "1.0" ) assert "Error on creating and sending a handshake reuse message" in str( context.exception @@ -935,20 +934,20 @@ async def test_receive_reuse_message_existing_found(self): self.test_conn_rec.invitation_msg_id = "test_123" self.test_conn_rec.state = ConnRecord.State.COMPLETED.rfc160 - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True, - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "notify", autospec=True ) as mock_notify: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=False, ) @@ -992,20 +991,20 @@ async def test_receive_reuse_message_existing_found_multi_use(self): self.test_conn_rec.invitation_msg_id = "test_123" self.test_conn_rec.state = ConnRecord.State.COMPLETED.rfc160 - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True, - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "notify", autospec=True ) as mock_notify: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, ) @@ -1046,14 +1045,14 @@ async def test_receive_reuse_accepted(self): reuse_msg_accepted = HandshakeReuseAccept() reuse_msg_accepted.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( self.profile, "notify", autospec=True - ) as mock_notify, async_mock.patch.object( + ) as mock_notify, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), ) await self.manager.receive_reuse_accepted_message( @@ -1083,9 +1082,9 @@ async def test_receive_reuse_accepted_x(self): reuse_msg_accepted = HandshakeReuseAccept() reuse_msg_accepted.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( self.profile, "notify", autospec=True - ) as mock_notify, async_mock.patch.object( + ) as mock_notify, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError,) @@ -1122,13 +1121,13 @@ async def test_receive_problem_report(self): ) problem_report.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), + save=mock.CoroutineMock(), ) await self.manager.receive_problem_report( @@ -1156,7 +1155,7 @@ async def test_receive_problem_report_x(self): ) problem_report.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError(),) @@ -1168,7 +1167,7 @@ async def test_receive_problem_report_x(self): assert "Error processing problem report message " in err.exception.message async def test_receive_invitation_with_valid_mediation(self): - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") async with self.profile.session() as session: self.profile.context.update_settings({"public_invites": True}) @@ -1180,10 +1179,10 @@ async def test_receive_invitation_with_valid_mediation(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( - DIDXManager, "receive_invitation", async_mock.CoroutineMock() - ) as mock_didx_recv_invi, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + with mock.patch.object( + DIDXManager, "receive_invitation", mock.CoroutineMock() + ) as mock_didx_recv_invi, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1207,16 +1206,16 @@ async def test_receive_invitation_with_valid_mediation(self): ) async def test_receive_invitation_with_invalid_mediation(self): - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( DIDXManager, "receive_invitation", - async_mock.CoroutineMock(), - ) as mock_didx_recv_invi, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_didx_recv_invi, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1226,7 +1225,7 @@ async def test_receive_invitation_with_invalid_mediation(self): mock_didx_recv_invi.return_value = mock_conn mock_retrieve_conn_by_id.return_value = mock_conn invi_msg = invite.invitation - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) await self.manager.receive_invitation( @@ -1244,15 +1243,15 @@ async def test_receive_invitation_with_invalid_mediation(self): async def test_receive_invitation_didx_services_with_service_block(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as didx_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as didx_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_conn_by_id: - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) mock_retrieve_conn_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1273,15 +1272,15 @@ async def test_receive_invitation_didx_services_with_service_block(self): async def test_receive_invitation_connection_protocol(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as conn_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ) as conn_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id: - conn_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + conn_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) mock_conn_retrieve_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1364,15 +1363,15 @@ async def test_existing_conn_record_public_did(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), - ) as oob_mgr_find_existing_conn, async_mock.patch.object( - OobRecord, "save", async_mock.CoroutineMock() - ) as oob_record_save, async_mock.patch.object( - OobRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as oob_record_retrieve_by_id, async_mock.patch.object( + mock.CoroutineMock(), + ) as oob_mgr_find_existing_conn, mock.patch.object( + OobRecord, "save", mock.CoroutineMock() + ) as oob_record_save, mock.patch.object( + OobRecord, "retrieve_by_id", mock.CoroutineMock() + ) as oob_record_retrieve_by_id, mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True ) as oob_mgr_fetch_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn @@ -1385,7 +1384,7 @@ async def test_existing_conn_record_public_did(self): requests_attach=[], ) - oob_record_retrieve_by_id.return_value = async_mock.MagicMock( + oob_record_retrieve_by_id.return_value = mock.MagicMock( state=OobRecord.STATE_ACCEPTED ) @@ -1411,18 +1410,18 @@ async def test_receive_invitation_handshake_reuse(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.CoroutineMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.CoroutineMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.CoroutineMock(), - ) as perform_handshake, async_mock.patch.object( + mock.CoroutineMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(return_value=test_exist_conn), + mock.CoroutineMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1432,7 +1431,7 @@ async def test_receive_invitation_handshake_reuse(self): requests_attach=[], ) - handle_handshake_reuse.return_value = async_mock.MagicMock( + handle_handshake_reuse.return_value = mock.MagicMock( state=OobRecord.STATE_ACCEPTED ) @@ -1459,22 +1458,22 @@ async def test_receive_invitation_handshake_reuse_failed(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.CoroutineMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.CoroutineMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.CoroutineMock(), - ) as perform_handshake, async_mock.patch.object( + mock.CoroutineMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(return_value=test_exist_conn), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=test_exist_conn), + ), mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=test_exist_conn), + mock.CoroutineMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1484,13 +1483,13 @@ async def test_receive_invitation_handshake_reuse_failed(self): requests_attach=[], ) - mock_oob = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock(), - emit_event=async_mock.CoroutineMock(), + mock_oob = mock.MagicMock( + delete_record=mock.CoroutineMock(), + emit_event=mock.CoroutineMock(), ) perform_handshake.return_value = mock_oob - handle_handshake_reuse.return_value = async_mock.MagicMock( + handle_handshake_reuse.return_value = mock.MagicMock( state=OobRecord.STATE_NOT_ACCEPTED ) @@ -1521,17 +1520,17 @@ async def test_receive_invitation_handshake_reuse_failed(self): async def test_receive_invitation_services_with_service_did(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy") + mock_conn = mock.MagicMock(connection_id="dummy") - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as didx_mgr_cls, async_mock.patch.object( + ) as didx_mgr_cls, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_conn), + mock.CoroutineMock(return_value=mock_conn), ): - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1549,9 +1548,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = async_mock.MagicMock( - handle_message=async_mock.CoroutineMock() - ) + mock_oob_processor = mock.MagicMock(handle_message=mock.CoroutineMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1560,14 +1557,14 @@ async def test_request_attach_oob_message_processor_connectionless(self): endpoint=self.test_endpoint, recipient_keys=[self.test_verkey] ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_signing_key", - async_mock.CoroutineMock(), - ) as mock_create_signing_key, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_create_signing_key, mock.patch.object( OutOfBandManager, "_service_decorator_from_service", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( verkey="a-verkey", metadata={}, key_type=ED25519 @@ -1612,17 +1609,15 @@ async def test_request_attach_oob_message_processor_connection(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = async_mock.MagicMock( - handle_message=async_mock.CoroutineMock() - ) + mock_oob_processor = mock.MagicMock(handle_message=mock.CoroutineMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn oob_invitation = InvitationMessage( @@ -1655,12 +1650,12 @@ async def test_request_attach_wait_for_conn_rec_active(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "_wait_for_conn_rec_active" - ) as mock_wait_for_conn_rec_active, async_mock.patch.object( + ) as mock_wait_for_conn_rec_active, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn mock_wait_for_conn_rec_active.return_value = None @@ -1686,7 +1681,7 @@ async def test_request_attach_wait_for_conn_rec_active(self): async def test_service_decorator_from_service_did(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -1719,7 +1714,7 @@ async def test_service_decorator_from_service_object(self): async def test_service_decorator_from_service_str_empty_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( "", # empty endpoint [TestConfig.test_verkey], @@ -1733,7 +1728,7 @@ async def test_service_decorator_from_service_str_empty_endpoint(self): async def test_service_decorator_from_service_str_none_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( None, # None endpoint [TestConfig.test_verkey], @@ -1796,10 +1791,10 @@ async def test_delete_stale_connection_by_invitation(self): updated_at=datetime_to_str(older_datetime), ) ] - with async_mock.patch.object( - ConnRecord, "query", async_mock.CoroutineMock() - ) as mock_connrecord_query, async_mock.patch.object( - ConnRecord, "delete_record", async_mock.CoroutineMock() + with mock.patch.object( + ConnRecord, "query", mock.CoroutineMock() + ) as mock_connrecord_query, mock.patch.object( + ConnRecord, "delete_record", mock.CoroutineMock() ) as mock_connrecord_delete: mock_connrecord_query.return_value = records await self.manager.delete_stale_connection_by_invitation("test123") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py index a8127be26c..22bcd06226 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord @@ -7,15 +7,15 @@ from .. import routes as test_module -class TestOutOfBandRoutes(AsyncTestCase): - async def setUp(self): +class TestOutOfBandRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,21 +28,21 @@ async def test_invitation_create(self): "auto_accept": "true", } body = { - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [test_module.HSProto.RFC23.name], "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"abc": "123"}) ) ) @@ -70,22 +70,22 @@ async def test_invitation_create_with_accept(self): "auto_accept": "true", } body = { - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [test_module.HSProto.RFC23.name], "accept": ["didcomm/aip1", "didcomm/aip2;env=rfc19"], "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"abc": "123"}) ) ) @@ -109,20 +109,20 @@ async def test_invitation_create_with_accept(self): async def test_invitation_create_x(self): self.request.query = {"multi_use": "true"} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [23], "use_public_did": True, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=test_module.OutOfBandManagerError() ) @@ -131,17 +131,17 @@ async def test_invitation_create_x(self): mock_json_response.assert_not_called() async def test_invitation_receive(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() expected_connection_record = ConnRecord(connection_id="some-id") - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.InvitationMessage, "deserialize", async_mock.Mock() - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.InvitationMessage, "deserialize", mock.Mock() + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=expected_connection_record ) @@ -156,16 +156,16 @@ async def test_invitation_receive_forbidden_x(self): await test_module.invitation_receive(self.request) async def test_invitation_receive_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.InvitationMessage, "deserialize", async_mock.Mock() - ) as mock_invi_deser, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.InvitationMessage, "deserialize", mock.Mock() + ) as mock_invi_deser, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=test_module.StorageError("cannot write") ) @@ -173,13 +173,13 @@ async def test_invitation_receive_x(self): await test_module.invitation_receive(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py index 055604e6a3..06d844df64 100644 --- a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py @@ -4,7 +4,7 @@ from typing import Sequence from uuid import uuid4 -import mock as async_mock +from aries_cloudagent.tests import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2, ED25519 @@ -1844,7 +1844,7 @@ async def test_reveal_doc_d(self, profile): @pytest.mark.asyncio async def test_credential_subject_as_list(self, profile): dif_pres_exch_handler = DIFPresExchHandler(profile) - with async_mock.patch.object( + with mock.patch.object( dif_pres_exch_handler, "new_credential_builder", autospec=True ) as mock_cred_builder: mock_cred_builder.return_value = {} @@ -2037,10 +2037,10 @@ async def test_get_sign_key_credential_subject_id(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2102,10 +2102,10 @@ async def test_get_sign_key_credential_subject_id_error(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2170,10 +2170,10 @@ async def test_get_sign_key_credential_subject_id_bbsbls(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", @@ -2240,29 +2240,29 @@ async def test_create_vp_no_issuer(self, profile, setup_tuple): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (VC_RECORDS, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1"} @@ -2293,33 +2293,33 @@ async def test_create_vp_with_bbs_suite(self, profile, setup_tuple): profile, proof_type=BbsBlsSignature2020.signature_type ) cred_list, pd_list = setup_tuple - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_create_vp, mock.patch.object( test_module, "sign_presentation", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_sign_vp: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (cred_list, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1", "@context": ["test"]} @@ -2351,33 +2351,33 @@ async def test_create_vp_no_issuer_with_bbs_suite(self, profile, setup_tuple): profile, proof_type=BbsBlsSignature2020.signature_type ) cred_list, pd_list = setup_tuple - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_create_vp, mock.patch.object( DIFPresExchHandler, "get_sign_key_credential_subject_id", - async_mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_sign_key_cred_subject: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (cred_list, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1", "@context": ["test"]} @@ -3290,8 +3290,8 @@ async def test_apply_constraint_received_cred_path_update(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3326,8 +3326,8 @@ async def test_apply_constraint_received_cred_invalid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3344,8 +3344,8 @@ async def test_apply_constraint_received_cred_invalid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3370,8 +3370,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3388,8 +3388,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3416,8 +3416,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3460,8 +3460,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3478,8 +3478,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3496,8 +3496,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3514,8 +3514,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3538,8 +3538,8 @@ async def test_apply_constraint_received_cred_no_sel_disc(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3625,8 +3625,8 @@ async def test_filter_by_field_keyerror(self, profile): "@type": "fhir:resource-types#Patient", "address": {"@id": "urn:bnid:_:c14n1", "city": "Рума"}, } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3650,8 +3650,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:integer", "@value": "10", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3671,8 +3671,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:dateTime", "@value": "2020-09-28T11:00:00+00:00", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3693,8 +3693,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:boolean", "@value": "false", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3710,8 +3710,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:double", "@value": "10.2", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3726,8 +3726,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "@id": "test", "test": "val", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py index db233adc17..ae963a3ef1 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,28 +11,26 @@ from .. import presentation_ack_handler as test_module -class TestPresentationAckHandler(AsyncTestCase): +class TestPresentationAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_presentation_ack = mock.CoroutineMock() request_context.message = PresentationAck() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationAckHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -45,14 +44,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_presentation_ack = mock.CoroutineMock() request_context.message = PresentationAck() request_context.connection_ready = False handler = test_module.PresentationAckHandler() @@ -67,8 +64,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py index 28b4747502..0ce2d5ab5d 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,27 +11,27 @@ from .. import presentation_handler as test_module -class TestPresentationHandler(AsyncTestCase): +class TestPresentationHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = False - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_presentation = mock.CoroutineMock() request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -46,22 +47,22 @@ async def test_called_auto_verify(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.CoroutineMock() - mock_pres_mgr.return_value.verify_presentation = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_presentation = mock.CoroutineMock() + mock_pres_mgr.return_value.verify_presentation = mock.CoroutineMock() request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -77,36 +78,34 @@ async def test_called_auto_verify_x(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value = async_mock.MagicMock( - receive_presentation=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value = mock.MagicMock( + receive_presentation=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - verify_presentation=async_mock.CoroutineMock( + verify_presentation=mock.CoroutineMock( side_effect=test_module.LedgerError() ), ) request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py index a726dc349c..99a756785b 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,19 +13,17 @@ from .. import presentation_problem_report_handler as test_module -class TestPresentationProblemReportHandler(AsyncTestCase): +class TestPresentationProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = PresentationProblemReport( description={ "en": "Change of plans", @@ -44,16 +43,14 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = PresentationProblemReport( description={ diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py index 95c963f704..c3df16088a 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,22 +10,22 @@ from .. import presentation_proposal_handler as test_module -class TestPresentationProposalHandler(AsyncTestCase): +class TestPresentationProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) request_context.message = PresentationProposal() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationProposalHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -37,19 +38,19 @@ async def test_called(self): async def test_called_auto_request(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( return_value=( mock_pres_mgr.return_value.receive_proposal.return_value, "presentation_request_message", @@ -76,21 +77,19 @@ async def test_called_auto_request(self): async def test_called_auto_request_x(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( side_effect=test_module.LedgerError() ) @@ -99,8 +98,8 @@ async def test_called_auto_request_x(self): handler = test_module.PresentationProposalHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -108,12 +107,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = PresentationProposal() request_context.connection_ready = False handler = test_module.PresentationProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py index 83329461a4..68875205b3 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -63,20 +64,20 @@ ) -class TestPresentationRequestHandler(AsyncTestCase): +class TestPresentationRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value=INDY_PROOF_REQ ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -97,17 +98,17 @@ async def test_called(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -126,17 +127,17 @@ async def test_called(self): async def test_called_not_found(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value=INDY_PROOF_REQ ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -157,18 +158,18 @@ async def test_called_not_found(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( side_effect=StorageNotFoundError ) mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -187,10 +188,10 @@ async def test_called_not_found(self): async def test_called_auto_present(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -225,33 +226,33 @@ async def test_called_auto_present(self): auto_present=True, ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.CoroutineMock( + mock_holder = mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.CoroutineMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -274,10 +275,10 @@ async def test_called_auto_present(self): async def test_called_auto_present_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -307,41 +308,39 @@ async def test_called_auto_present_x(self): presentation_proposal = PresentationProposal( comment="Hello World", presentation_proposal=PRES_PREVIEW ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( presentation_proposal_dict=presentation_proposal, auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = mock_px_rec - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -349,18 +348,18 @@ async def test_called_auto_present_x(self): handler = test_module.PresentationRequestHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() async def test_called_auto_present_no_preview(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -389,14 +388,14 @@ async def test_called_auto_present_no_preview(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -407,20 +406,20 @@ async def test_called_auto_present_no_preview(self): request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -443,10 +442,10 @@ async def test_called_auto_present_no_preview(self): async def test_called_auto_present_pred_no_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -469,33 +468,33 @@ async def test_called_auto_present_pred_no_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=[]) + mock.CoroutineMock(return_value=[]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -514,10 +513,10 @@ async def test_called_auto_present_pred_no_match(self): async def test_called_auto_present_pred_single_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -540,14 +539,14 @@ async def test_called_auto_present_pred_single_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[{"cred_info": {"referent": "dummy-0"}}] ) ) @@ -555,20 +554,20 @@ async def test_called_auto_present_pred_single_match(self): request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -591,10 +590,10 @@ async def test_called_auto_present_pred_single_match(self): async def test_called_auto_present_pred_multi_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -617,14 +616,14 @@ async def test_called_auto_present_pred_multi_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -635,20 +634,20 @@ async def test_called_auto_present_pred_multi_match(self): request_context.injector.bind_instance(IndyHolder, mock_holder) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -671,10 +670,10 @@ async def test_called_auto_present_pred_multi_match(self): async def test_called_auto_present_multi_cred_match_reft(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -717,14 +716,14 @@ async def test_called_auto_present_multi_cred_match_reft(self): auto_present=True, ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ { "cred_info": { @@ -766,20 +765,20 @@ async def test_called_auto_present_multi_cred_match_reft(self): request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -802,10 +801,10 @@ async def test_called_auto_present_multi_cred_match_reft(self): async def test_called_auto_present_bait_and_switch(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -839,7 +838,7 @@ async def test_called_auto_present_bait_and_switch(self): auto_present=True, ) - by_reft = async_mock.CoroutineMock( + by_reft = mock.CoroutineMock( return_value=[ { "cred_info": { @@ -867,32 +866,32 @@ async def test_called_auto_present_bait_and_switch(self): }, ] ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=by_reft ) request_context.injector.bind_instance(IndyHolder, mock_holder) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -913,12 +912,12 @@ async def test_called_auto_present_bait_and_switch(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = PresentationRequest() request_context.connection_ready = False handler = test_module.PresentationRequestHandler() @@ -936,8 +935,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py index 60e7cc2387..325bf8cbe5 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py index 0498a89a8e..55577fb6bb 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......indy.models.pres_preview import ( @@ -85,7 +86,7 @@ class Meta: model_class = BasexRecordImpl -class TestRecord(AsyncTestCase): +class TestRecord(IsolatedAsyncioTestCase): async def test_record(self): presentation_proposal = PresentationProposal( comment="Hello World", presentation_proposal=PRES_PREVIEW @@ -129,10 +130,10 @@ async def test_save_error_state(self): record.state = V10PresentationExchange.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="testing") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py index 97f77aac9e..5ff7ee0eeb 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py @@ -2,7 +2,8 @@ from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import ( V10CredentialExchange, @@ -213,20 +214,18 @@ PRES.assign_thread_id("dummy") -class TestPresentationManager(AsyncTestCase): - async def setUp(self): +class TestPresentationManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -242,7 +241,7 @@ async def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -251,7 +250,7 @@ async def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -263,15 +262,15 @@ async def setUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -286,7 +285,7 @@ async def setUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -296,8 +295,8 @@ async def setUp(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -308,9 +307,9 @@ async def setUp(self): ) injector.bind_instance(IndyHolder, self.holder) - Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) + Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.CoroutineMock( + self.verifier.verify_presentation = mock.CoroutineMock( return_value=("true", []) ) injector.bind_instance(IndyVerifier, self.verifier) @@ -353,9 +352,9 @@ async def test_record_eq(self): async def test_create_exchange_for_proposal(self): proposal = PresentationProposal() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( PresentationProposal, "serialize", autospec=True ): exchange = await self.manager.create_exchange_for_proposal( @@ -373,10 +372,10 @@ async def test_create_exchange_for_proposal(self): assert exchange.auto_remove is True async def test_receive_proposal(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) proposal = PresentationProposal() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange = await self.manager.receive_proposal(proposal, connection_record) @@ -392,7 +391,7 @@ async def test_create_bound_request(self): presentation_proposal_dict=proposal.serialize(), role=V10PresentationExchange.ROLE_VERIFIER, ) - exchange.save = async_mock.CoroutineMock() + exchange.save = mock.CoroutineMock() (ret_exchange, pres_req_msg) = await self.manager.create_bound_request( presentation_exchange_record=exchange, name=PROOF_REQ_NAME, @@ -419,7 +418,7 @@ async def test_create_exchange_for_request(self): ] ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange = await self.manager.create_exchange_for_request( @@ -438,7 +437,7 @@ async def test_create_exchange_for_request(self): async def test_receive_request(self): exchange_in = V10PresentationExchange() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.receive_request(exchange_in) @@ -457,21 +456,21 @@ async def test_create_presentation(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -500,21 +499,21 @@ async def test_create_presentation_proof_req_non_revoc_interval_none(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -561,21 +560,21 @@ async def test_create_presentation_self_asserted(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -593,12 +592,10 @@ async def test_create_presentation_self_asserted(self): assert exchange_out.state == V10PresentationExchange.STATE_PRESENTATION_SENT async def test_create_presentation_no_revocation(self): - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -613,9 +610,9 @@ async def test_create_presentation_no_revocation(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -628,7 +625,7 @@ async def test_create_presentation_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -638,17 +635,17 @@ async def test_create_presentation_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( - test_indy_util_module.LOGGER, "info", async_mock.MagicMock() + ) as mock_attach_decorator, mock.patch.object( + test_indy_util_module.LOGGER, "info", mock.MagicMock() ) as mock_log_info: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -679,9 +676,9 @@ async def test_create_presentation_bad_revoc_state(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -695,7 +692,7 @@ async def test_create_presentation_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -705,27 +702,27 @@ async def test_create_presentation_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( side_effect=IndyHolderError("Problem", {"message": "Nope"}) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -747,9 +744,9 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -776,7 +773,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -786,8 +783,8 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -798,21 +795,21 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -837,7 +834,7 @@ async def test_no_matching_creds_for_proof_req(self): nonce=PROOF_REQ_NONCE, profile=self.profile, ) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -845,7 +842,7 @@ async def test_no_matching_creds_for_proof_req(self): indy_proof_req, holder=self.holder ) - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -860,7 +857,7 @@ async def test_no_matching_creds_for_proof_req(self): self.holder.get_credentials_for_presentation_request_by_referent = get_creds async def test_receive_presentation(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange( presentation_proposal_dict={ @@ -949,14 +946,14 @@ async def test_receive_presentation(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [exchange_dummy] exchange_out = await self.manager.receive_presentation( @@ -1063,14 +1060,14 @@ async def test_receive_presentation_oob(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [exchange_dummy] exchange_out = await self.manager.receive_presentation(PRES, None, None) @@ -1084,7 +1081,7 @@ async def test_receive_presentation_oob(self): ) async def test_receive_presentation_bait_and_switch(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange( presentation_proposal_dict={ @@ -1173,9 +1170,9 @@ async def test_receive_presentation_bait_and_switch(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1185,14 +1182,14 @@ async def test_receive_presentation_bait_and_switch(self): async def test_receive_presentation_connectionless(self): exchange_dummy = V10PresentationExchange() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = exchange_dummy exchange_out = await self.manager.receive_presentation(PRES, None, None) @@ -1231,7 +1228,7 @@ async def test_verify_presentation(self): presentation=INDY_PROOF, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.verify_presentation(exchange_in) @@ -1259,7 +1256,7 @@ async def test_verify_presentation_with_revocation(self): ] } - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.verify_presentation(exchange_in) @@ -1284,12 +1281,12 @@ async def test_send_presentation_ack_oob(self): responder = MockResponder() self.profile.context.injector.bind_instance(BaseResponder, responder) - with async_mock.patch.object( + with mock.patch.object( test_module.OobRecord, "retrieve_by_tag_filter" - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: await self.manager.send_presentation_ack(exchange) messages = responder.messages @@ -1305,14 +1302,14 @@ async def test_send_presentation_ack_no_responder(self): await self.manager.send_presentation_ack(exchange) async def test_receive_presentation_ack_a(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange() - message = async_mock.MagicMock() + message = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1326,14 +1323,14 @@ async def test_receive_presentation_ack_a(self): ) async def test_receive_presentation_ack_b(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange() - message = async_mock.MagicMock(_verification_result="true") + message = mock.MagicMock(_verification_result="true") - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1364,16 +1361,16 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.CoroutineMock(), + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = stored_exchange @@ -1406,10 +1403,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py index 77e3ea1ca7..ca3d8e6927 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py @@ -1,6 +1,7 @@ import importlib -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from marshmallow import ValidationError @@ -14,15 +15,15 @@ from .. import routes as test_module -class TestProofRoutes(AsyncTestCase): +class TestProofRoutes(IsolatedAsyncioTestCase): def setUp(self): self.context = AdminRequestContext.test_context() self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -60,7 +61,7 @@ async def test_presentation_exchange_list(self): "state": "dummy", } - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -70,16 +71,14 @@ async def test_presentation_exchange_list(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.CoroutineMock() + mock_presentation_exchange.query = mock.CoroutineMock() mock_presentation_exchange.query.return_value = [mock_presentation_exchange] - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_list(self.request) mock_response.assert_called_once_with( {"results": [mock_presentation_exchange.serialize.return_value]} @@ -93,7 +92,7 @@ async def test_presentation_exchange_list_x(self): "state": "dummy", } - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -103,7 +102,7 @@ async def test_presentation_exchange_list_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.CoroutineMock( + mock_presentation_exchange.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -113,7 +112,7 @@ async def test_presentation_exchange_list_x(self): async def test_presentation_exchange_credentials_list_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -123,7 +122,7 @@ async def test_presentation_exchange_credentials_list_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock() + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_presentation_exchange.retrieve_by_id.side_effect = StorageNotFoundError @@ -140,15 +139,15 @@ async def test_presentation_exchange_credentials_x(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(side_effect=test_module.IndyHolderError()) + mock.CoroutineMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.CoroutineMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.CoroutineMock()) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -173,14 +172,14 @@ async def test_presentation_exchange_credentials_list_single_referent(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.CoroutineMock( + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.CoroutineMock( return_value=returned_credentials ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -190,13 +189,9 @@ async def test_presentation_exchange_credentials_list_single_referent(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.return_value.retrieve_by_id.return_value = ( - mock_presentation_exchange - ) + mock_presentation_exchange.retrieve_by_id.return_value = mock.MagicMock() - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_credentials_list(self.request) mock_response.assert_called_once_with(returned_credentials) @@ -210,14 +205,14 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -227,20 +222,18 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.return_value.retrieve_by_id.return_value = ( - mock_presentation_exchange + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock() ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_credentials_list(self.request) mock_response.assert_called_once_with(returned_credentials) async def test_presentation_exchange_retrieve(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -250,14 +243,12 @@ async def test_presentation_exchange_retrieve(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex.retrieve_by_id = mock.CoroutineMock() mock_pres_ex.retrieve_by_id.return_value = mock_pres_ex - mock_pres_ex.serialize = async_mock.MagicMock() + mock_pres_ex.serialize = mock.MagicMock() mock_pres_ex.serialize.return_value = {"thread_id": "sample-thread-id"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_retrieve(self.request) mock_response.assert_called_once_with( mock_pres_ex.serialize.return_value @@ -266,7 +257,7 @@ async def test_presentation_exchange_retrieve(self): async def test_presentation_exchange_retrieve_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -276,7 +267,7 @@ async def test_presentation_exchange_retrieve_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex.retrieve_by_id.side_effect = StorageNotFoundError @@ -287,12 +278,12 @@ async def test_presentation_exchange_retrieve_not_found(self): async def test_presentation_exchange_retrieve_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - mock_pres_ex_rec = async_mock.MagicMock( + mock_pres_ex_rec = mock.MagicMock( connection_id="abc123", thread_id="thid123", - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -302,10 +293,10 @@ async def test_presentation_exchange_retrieve_x(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock_pres_ex_rec ) - mock_pres_ex_rec.serialize = async_mock.MagicMock( + mock_pres_ex_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) @@ -313,40 +304,38 @@ async def test_presentation_exchange_retrieve_x(self): await test_module.presentation_exchange_retrieve(self.request) async def test_presentation_exchange_send_proposal(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, ) as mock_preview: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock(return_value=mock_presentation_exchange_record) + mock.CoroutineMock(return_value=mock_presentation_exchange_record) ) - mock_preview.return_value.deserialize.return_value = async_mock.MagicMock() + mock_preview.return_value.deserialize.return_value = mock.MagicMock() - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_proposal(self.request) mock_response.assert_called_once_with( mock_presentation_exchange_record.serialize.return_value ) async def test_presentation_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: @@ -354,7 +343,7 @@ async def test_presentation_exchange_send_proposal_no_conn_record(self): importlib.reload(test_module) # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -362,15 +351,15 @@ async def test_presentation_exchange_send_proposal_no_conn_record(self): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch( + ) as mock_preview, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "messages.presentation_proposal.PresentationProposal" @@ -380,36 +369,36 @@ async def test_presentation_exchange_send_proposal_not_ready(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, ) as mock_preview: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -418,95 +407,93 @@ async def test_presentation_exchange_send_proposal_x(self): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_create_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"comment": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_presentation_exchange, async_mock.patch( + ) as mock_presentation_exchange, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, ) as mock_generate_nonce: # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.CoroutineMock() + mock_generate_nonce = mock.CoroutineMock() - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_presentation_exchange ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_create_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_create_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"comment": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_presentation_exchange, async_mock.patch( + ) as mock_presentation_exchange, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, ) as mock_generate_nonce: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -515,7 +502,7 @@ async def test_presentation_exchange_create_request_x(self): await test_module.presentation_exchange_create_request(self.request) async def test_presentation_exchange_send_free_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -523,24 +510,24 @@ async def test_presentation_exchange_send_free_request(self): } ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch( + ) as mock_generate_nonce, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -550,56 +537,52 @@ async def test_presentation_exchange_send_free_request(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_presentation_exchange ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_free_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_free_request_not_found(self): - self.request.json = async_mock.CoroutineMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.CoroutineMock(return_value={"connection_id": "dummy"}) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: @@ -607,7 +590,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): importlib.reload(test_module) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -615,7 +598,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -623,23 +606,23 @@ async def test_presentation_exchange_send_free_request_x(self): } ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -649,24 +632,24 @@ async def test_presentation_exchange_send_free_request_x(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.CoroutineMock() + mock_generate_nonce = mock.CoroutineMock() - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -674,40 +657,40 @@ async def test_presentation_exchange_send_free_request_x(self): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_bound_request(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange", autospec=True, @@ -719,54 +702,52 @@ async def test_presentation_exchange_send_bound_request(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.CoroutineMock( return_value=(mock_presentation_exchange, mock_presentation_request) ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_bound_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_bound_request_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -780,37 +761,37 @@ async def test_presentation_exchange_send_bound_request_not_found(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_not_ready(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -824,12 +805,12 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -837,13 +818,13 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -851,10 +832,10 @@ async def test_presentation_exchange_send_bound_request_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_send_bound_request_bad_state(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -865,8 +846,8 @@ async def test_presentation_exchange_send_bound_request_bad_state(self): importlib.reload(test_module) mock_presentation_exchange.connection_id = "dummy" - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -874,26 +855,26 @@ async def test_presentation_exchange_send_bound_request_bad_state(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_x(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -908,20 +889,20 @@ async def test_presentation_exchange_send_bound_request_x(self): test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) mock_presentation_exchange.connection_id = "abc123" - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id", } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -936,7 +917,7 @@ async def test_presentation_exchange_send_bound_request_x(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_presentation(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -947,27 +928,27 @@ async def test_presentation_exchange_send_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch.object( + ) as mock_presentation_manager, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch( + ) as mock_presentation_proposal, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -981,42 +962,40 @@ async def test_presentation_exchange_send_presentation(self): test_module.V10PresentationExchange.STATE_REQUEST_RECEIVED ) mock_presentation_exchange.connection_id = "dummy" - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.CoroutineMock( - return_value=(mock_presentation_exchange, async_mock.MagicMock()) + mock_mgr = mock.MagicMock( + create_presentation=mock.CoroutineMock( + return_value=(mock_presentation_exchange, mock.MagicMock()) ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_presentation(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1024,26 +1003,26 @@ async def test_presentation_exchange_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_send_presentation_not_found(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1053,14 +1032,14 @@ async def test_presentation_exchange_send_presentation_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -1068,26 +1047,26 @@ async def test_presentation_exchange_send_presentation_not_found(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1097,15 +1076,15 @@ async def test_presentation_exchange_send_presentation_not_ready(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -1113,10 +1092,10 @@ async def test_presentation_exchange_send_presentation_not_ready(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_bad_state(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1126,8 +1105,8 @@ async def test_presentation_exchange_send_presentation_bad_state(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1135,7 +1114,7 @@ async def test_presentation_exchange_send_presentation_bad_state(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -1145,23 +1124,23 @@ async def test_presentation_exchange_send_presentation_x(self): ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1171,22 +1150,22 @@ async def test_presentation_exchange_send_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ), ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + create_presentation=mock.CoroutineMock( side_effect=test_module.LedgerError() ) ) @@ -1198,24 +1177,24 @@ async def test_presentation_exchange_send_presentation_x(self): async def test_presentation_exchange_verify_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch( + ) as mock_generate_nonce, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1225,43 +1204,41 @@ async def test_presentation_exchange_verify_presentation(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", thread_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.CoroutineMock( return_value=mock_presentation_exchange.retrieve_by_id.return_value ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_verify_presentation( self.request ) mock_response.assert_called_once_with({"thread_id": "sample-thread-id"}) async def test_presentation_exchange_verify_presentation_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1271,10 +1248,10 @@ async def test_presentation_exchange_verify_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_verify_presentation_bad_state(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1284,8 +1261,8 @@ async def test_presentation_exchange_verify_presentation_bad_state(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1298,25 +1275,25 @@ async def test_presentation_exchange_verify_presentation_x(self): self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1326,24 +1303,24 @@ async def test_presentation_exchange_verify_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", thread_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1362,31 +1339,29 @@ async def test_presentation_exchange_verify_presentation_x(self): ) async def test_presentation_exchange_problem_report(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_pres_ex, async_mock.patch( + ) as mock_pres_ex, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1396,15 +1371,15 @@ async def test_presentation_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch( + ) as mock_pres_mgr_cls, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1414,7 +1389,7 @@ async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1422,27 +1397,27 @@ async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): await test_module.presentation_exchange_problem_report(self.request) async def test_presentation_exchange_problem_report_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_pres_ex, async_mock.patch( + ) as mock_pres_ex, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -1452,7 +1427,7 @@ async def test_presentation_exchange_problem_report_x(self): async def test_presentation_exchange_remove(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1462,25 +1437,23 @@ async def test_presentation_exchange_remove(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), ) ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_remove(self.request) mock_response.assert_called_once_with({}) async def test_presentation_exchange_remove_not_found(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1491,7 +1464,7 @@ async def test_presentation_exchange_remove_not_found(self): importlib.reload(test_module) # Emulate storage not found (bad pres ex id) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -1501,7 +1474,7 @@ async def test_presentation_exchange_remove_not_found(self): async def test_presentation_exchange_remove_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1511,11 +1484,11 @@ async def test_presentation_exchange_remove_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.CoroutineMock( + delete_record=mock.CoroutineMock( side_effect=test_module.StorageError() ), ) @@ -1525,13 +1498,13 @@ async def test_presentation_exchange_remove_x(self): await test_module.presentation_exchange_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py index 8986ff42ac..3020607be9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py @@ -1,6 +1,6 @@ from copy import deepcopy -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from marshmallow import ValidationError from pyld import jsonld @@ -363,19 +363,17 @@ } -class TestDIFFormatHandler(AsyncTestCase): - async def setUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) +class TestDIFFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): + self.holder = mock.MagicMock() + self.wallet = mock.MagicMock(BaseWallet, autospec=True) self.session = InMemoryProfile.test_session( bind={VCHolder: self.holder, BaseWallet: self.wallet} ) self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Set custom document loader self.context.injector.bind_instance(DocumentLoader, custom_document_loader) @@ -601,10 +599,10 @@ async def test_create_pres(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -644,10 +642,10 @@ async def test_create_pres_pd_schema_uri(self): error_msg="error", ) request_data = {} - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -686,10 +684,10 @@ async def test_create_pres_prover_proof_spec(self): ) request_data = {} request_data["dif"] = dif_pres_spec - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -754,19 +752,19 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -848,19 +846,19 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -931,19 +929,19 @@ async def test_create_pres_one_of_filter(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -981,10 +979,10 @@ async def test_create_pres_no_challenge(self): error_msg="error", ) request_data = {} - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -1022,10 +1020,10 @@ async def test_create_pres_storage_not_found(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1069,10 +1067,10 @@ async def test_create_pres_pd_claim_format_ed255(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1112,10 +1110,10 @@ async def test_create_pres_pd_claim_format_bls12381g2(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1163,20 +1161,20 @@ async def test_verify_pres_sequence(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=PresentationVerificationResult(verified=True) ), ): output = await self.handler.verify_pres(record) assert output.verified - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=PresentationVerificationResult(verified=False) ), ): @@ -1220,10 +1218,10 @@ async def test_verify_pres(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=PresentationVerificationResult(verified=True) ), ) as mock_vr: @@ -1413,10 +1411,10 @@ async def test_create_pres_cred_no_tag_query(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1836,8 +1834,8 @@ async def test_verify_received_limit_disclosure_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -1915,8 +1913,8 @@ async def test_verify_received_limit_disclosure_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -1967,8 +1965,8 @@ async def test_verify_received_pres_invalid_jsonpath(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2020,8 +2018,8 @@ async def test_verify_received_pres_no_match_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2073,8 +2071,8 @@ async def test_verify_received_pres_no_match_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2123,8 +2121,8 @@ async def test_verify_received_pres_limit_disclosure_fail_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2173,8 +2171,8 @@ async def test_verify_received_pres_limit_disclosure_fail_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2263,10 +2261,10 @@ async def test_verify_received_pres_fail_schema_filter(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() - ) as mock_log_err, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() + ) as mock_log_err, mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -2275,9 +2273,7 @@ async def test_verify_received_pres_fail_schema_filter(self): async def test_create_pres_catch_typeerror(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock(side_effect=TypeError) - ), + mock.MagicMock(search_credentials=mock.MagicMock(side_effect=TypeError)), ) test_pd = deepcopy(DIF_PRES_REQUEST_B) dif_pres_request = V20PresRequest( @@ -2332,10 +2328,10 @@ async def test_create_pres_catch_diferror(self): ] self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), @@ -2366,8 +2362,8 @@ async def test_create_pres_catch_diferror(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - DIFPresExchHandler, "create_vp", async_mock.MagicMock() + with mock.patch.object( + DIFPresExchHandler, "create_vp", mock.MagicMock() ) as mock_create_vp: mock_create_vp.side_effect = DIFPresExchError("TEST") await self.handler.create_pres(record) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py index 928a2df6be..57ee46f7ac 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,26 +11,26 @@ from .. import pres_ack_handler as test_module -class TestV20PresAckHandler(AsyncTestCase): +class TestV20PresAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.CoroutineMock() request_context.message = V20PresAck() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresAckHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -43,12 +44,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.CoroutineMock() request_context.message = V20PresAck() request_context.connection_ready = False handler = test_module.V20PresAckHandler() @@ -63,8 +64,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py index b28027c263..03bd117c5d 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,27 +11,27 @@ from .. import pres_handler as test_module -class TestV20PresHandler(AsyncTestCase): +class TestV20PresHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = False - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres = mock.CoroutineMock() request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -46,22 +47,22 @@ async def test_called_auto_verify(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.CoroutineMock() - mock_pres_mgr.return_value.verify_pres = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres = mock.CoroutineMock() + mock_pres_mgr.return_value.verify_pres = mock.CoroutineMock() request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -77,36 +78,32 @@ async def test_called_auto_verify_x(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=oob_record ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value = async_mock.MagicMock( - receive_pres=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) - ), - verify_pres=async_mock.CoroutineMock( - side_effect=test_module.LedgerError() + mock_pres_mgr.return_value = mock.MagicMock( + receive_pres=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), + verify_pres=mock.CoroutineMock(side_effect=test_module.LedgerError()), ) request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py index 170a826e14..2984b2ec9f 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,18 +10,16 @@ from .. import pres_problem_report_handler as test_module -class TestV20PresProblemReportHandler(AsyncTestCase): +class TestV20PresProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = V20PresProblemReport( description={ "en": "Change of plans", @@ -40,15 +39,13 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = V20PresProblemReport( description={ diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py index 033742133e..b8de7f3e55 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,22 +10,22 @@ from .. import pres_proposal_handler as test_module -class TestV20PresProposalHandler(AsyncTestCase): +class TestV20PresProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = False - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( + return_value=mock.MagicMock() ) request_context.message = V20PresProposal() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresProposalHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -37,19 +38,19 @@ async def test_called(self): async def test_called_auto_request(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() - request_context.connection_record = async_mock.MagicMock() + request_context.message = mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( return_value=( mock_pres_mgr.return_value.receive_pres_proposal.return_value, "presentation_request_message", @@ -76,21 +77,19 @@ async def test_called_auto_request(self): async def test_called_auto_request_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() - request_context.message = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( side_effect=test_module.LedgerError() ) @@ -99,8 +98,8 @@ async def test_called_auto_request_x(self): handler = test_module.V20PresProposalHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -108,14 +107,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock() request_context.message = V20PresProposal() request_context.connection_ready = False handler = test_module.V20PresProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py index 786d78bee5..9a493027a7 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......indy.holder import IndyHolder @@ -179,20 +180,20 @@ } -class TestPresRequestHandler(AsyncTestCase): +class TestPresRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=async_mock.MagicMock() + request_context.message.attachment = mock.MagicMock( + return_value=mock.MagicMock() ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -213,17 +214,17 @@ async def test_called(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -241,17 +242,17 @@ async def test_called(self): async def test_called_not_found(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=async_mock.MagicMock() + request_context.message.attachment = mock.MagicMock( + return_value=mock.MagicMock() ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -272,18 +273,18 @@ async def test_called_not_found(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( side_effect=StorageNotFoundError ) mock_px_rec_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -301,12 +302,10 @@ async def test_called_not_found(self): async def test_called_auto_present_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( @@ -320,41 +319,39 @@ async def test_called_auto_present_x(self): AttachDecorator.data_base64(INDY_PROOF_REQ, ident="indy") ], ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -362,25 +359,23 @@ async def test_called_auto_present_x(self): handler = test_module.V20PresRequestHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() async def test_called_auto_present_indy(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -401,29 +396,27 @@ async def test_called_auto_present_indy(self): auto_present=True, ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(mock_px_rec, "pres message") ) @@ -448,7 +441,7 @@ async def test_called_auto_present_indy(self): async def test_called_auto_present_dif(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -458,14 +451,12 @@ async def test_called_auto_present_dif(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=DIF_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=DIF_PROOF_REQ) request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -484,20 +475,20 @@ async def test_called_auto_present_dif(self): pres_proposal=pres_proposal, auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -520,7 +511,7 @@ async def test_called_auto_present_dif(self): async def test_called_auto_present_no_preview(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -530,21 +521,19 @@ async def test_called_auto_present_no_preview(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -554,20 +543,20 @@ async def test_called_auto_present_no_preview(self): ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -590,12 +579,10 @@ async def test_called_auto_present_no_preview(self): async def test_called_auto_present_pred_no_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( formats=[ @@ -608,40 +595,40 @@ async def test_called_auto_present_pred_no_match(self): AttachDecorator.data_base64(INDY_PROOF_REQ, ident="indy") ], ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=[]) + mock.CoroutineMock(return_value=[]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( side_effect=test_indy_handler.V20PresFormatHandlerError ) request_context.connection_ready = True @@ -660,7 +647,7 @@ async def test_called_auto_present_pred_no_match(self): async def test_called_auto_present_pred_single_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -670,42 +657,42 @@ async def test_called_auto_present_pred_single_match(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( + request_context.message.attachment = mock.MagicMock( return_value=INDY_PROOF_REQ_PRED ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[{"cred_info": {"referent": "dummy-0"}}] ) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -728,7 +715,7 @@ async def test_called_auto_present_pred_single_match(self): async def test_called_auto_present_pred_multi_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -738,22 +725,22 @@ async def test_called_auto_present_pred_multi_match(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( + request_context.message.attachment = mock.MagicMock( return_value=INDY_PROOF_REQ_PRED ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -763,20 +750,20 @@ async def test_called_auto_present_pred_multi_match(self): ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -799,7 +786,7 @@ async def test_called_auto_present_pred_multi_match(self): async def test_called_auto_present_multi_cred_match_reft(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -809,9 +796,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( formats=[ @@ -825,16 +810,16 @@ async def test_called_auto_present_multi_cred_match_reft(self): ], ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ { "cred_info": { @@ -879,20 +864,20 @@ async def test_called_auto_present_multi_cred_match_reft(self): pres_proposal=pres_proposal.serialize(), auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -916,12 +901,12 @@ async def test_called_auto_present_multi_cred_match_reft(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock() request_context.message = V20PresRequest() request_context.connection_ready = False handler = test_module.V20PresRequestHandler() @@ -939,8 +924,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py b/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py index 11607756f5..7a026ea628 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py index ba27e20f45..cf72950d84 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator @@ -67,7 +68,7 @@ class Meta: model_class = BasexRecordImpl -class TestRecord(AsyncTestCase): +class TestRecord(IsolatedAsyncioTestCase): async def test_record(self): pres_proposal = V20PresProposal( comment="Hello World", @@ -126,10 +127,10 @@ async def test_save_error_state(self): record.state = V20PresExRecord.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.CoroutineMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="testing") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py index 51da3c6450..0a26daf14a 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py @@ -3,7 +3,8 @@ from copy import deepcopy from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....indy.holder import IndyHolder @@ -381,20 +382,18 @@ } -class TestV20PresManager(AsyncTestCase): - async def setUp(self): +class TestV20PresManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -410,7 +409,7 @@ async def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -419,7 +418,7 @@ async def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -431,16 +430,16 @@ async def setUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -455,7 +454,7 @@ async def setUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -465,8 +464,8 @@ async def setUp(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -477,9 +476,9 @@ async def setUp(self): ) injector.bind_instance(IndyHolder, self.holder) - Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) + Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.CoroutineMock( + self.verifier.verify_presentation = mock.CoroutineMock( return_value=("true", []) ) injector.bind_instance(IndyVerifier, self.verifier) @@ -526,11 +525,9 @@ async def test_create_exchange_for_proposal(self): ] ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V20PresProposal, "serialize", autospec=True - ): + ) as save_ex, mock.patch.object(V20PresProposal, "serialize", autospec=True): px_rec = await self.manager.create_exchange_for_proposal( CONN_ID, proposal, @@ -546,13 +543,13 @@ async def test_create_exchange_for_proposal(self): assert px_rec.auto_remove is True async def test_receive_proposal(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) proposal = V20PresProposal( formats=[ V20PresFormat(attach_id="indy", format_=V20PresFormat.Format.INDY.aries) ] ) - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec = await self.manager.receive_pres_proposal( proposal, connection_record, @@ -581,7 +578,7 @@ async def test_create_bound_request_a(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.CoroutineMock() + px_rec.save = mock.CoroutineMock() request_data = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -615,7 +612,7 @@ async def test_create_bound_request_b(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.CoroutineMock() + px_rec.save = mock.CoroutineMock() (ret_px_rec, pres_req_msg) = await self.manager.create_bound_request( pres_ex_record=px_rec, comment=comment, @@ -673,7 +670,7 @@ async def test_create_pres_catch_diferror(self): ], ).serialize(), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresFormatHandler, "create_pres", autospec=True ) as mock_create_pres: mock_create_pres.return_value = None @@ -688,7 +685,7 @@ async def test_create_pres_catch_diferror(self): ) async def test_receive_pres_catch_diferror(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_x = V20Pres( formats=[ V20PresFormat( @@ -720,9 +717,9 @@ async def test_receive_pres_catch_diferror(self): pres_request=pres_req.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresFormatHandler, "receive_pres", autospec=True - ) as mock_receive_pres, async_mock.patch.object( + ) as mock_receive_pres, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: mock_receive_pres.return_value = False @@ -749,7 +746,7 @@ async def test_create_exchange_for_request(self): ) pres_req.assign_thread_id("dummy") - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec = await self.manager.create_exchange_for_request( CONN_ID, pres_req, @@ -766,7 +763,7 @@ async def test_create_exchange_for_request(self): async def test_receive_pres_request(self): px_rec_in = V20PresExRecord() - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.receive_pres_request(px_rec_in) save_ex.assert_called_once() @@ -787,21 +784,21 @@ async def test_create_pres_indy(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -841,23 +838,23 @@ async def test_create_pres_indy_and_dif(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator_indy, async_mock.patch.object( + ) as mock_attach_decorator_indy, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True - ) as mock_rr, async_mock.patch.object( + ) as mock_rr, mock.patch.object( DIFPresFormatHandler, "create_pres", autospec=True ) as mock_create_pres: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator_indy.data_base64 = async_mock.MagicMock( + mock_attach_decorator_indy.data_base64 = mock.MagicMock( return_value=mock_attach_decorator_indy ) @@ -898,29 +895,29 @@ async def test_create_pres_proof_req_non_revoc_interval_none(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -954,21 +951,21 @@ async def test_create_pres_self_asserted(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -988,12 +985,10 @@ async def test_create_pres_self_asserted(self): assert px_rec_out.state == V20PresExRecord.STATE_PRESENTATION_SENT async def test_create_pres_no_revocation(self): - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -1013,9 +1008,9 @@ async def test_create_pres_no_revocation(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1028,7 +1023,7 @@ async def test_create_pres_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1038,17 +1033,17 @@ async def test_create_pres_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( - test_indy_util_module.LOGGER, "info", async_mock.MagicMock() + ) as mock_attach_decorator, mock.patch.object( + test_indy_util_module.LOGGER, "info", mock.MagicMock() ) as mock_log_info: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -1098,9 +1093,9 @@ async def test_create_pres_bad_revoc_state(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1114,7 +1109,7 @@ async def test_create_pres_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1124,31 +1119,31 @@ async def test_create_pres_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( side_effect=test_indy_util_module.IndyHolderError( "Problem", {"message": "Nope"} ) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True - ) as mock_rr, async_mock.patch.object( - test_indy_util_module.LOGGER, "error", async_mock.MagicMock() + ) as mock_rr, mock.patch.object( + test_indy_util_module.LOGGER, "error", mock.MagicMock() ) as mock_log_error: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) request_data = {} @@ -1171,9 +1166,9 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -1200,7 +1195,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1210,8 +1205,8 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -1222,21 +1217,21 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -1268,7 +1263,7 @@ async def test_no_matching_creds_for_proof_req(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -1276,7 +1271,7 @@ async def test_no_matching_creds_for_proof_req(self): INDY_PROOF_REQ_NAMES, preview=None, holder=self.holder ) - get_creds = async_mock.CoroutineMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1308,15 +1303,15 @@ async def test_no_matching_creds_indy_handler(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True ) as mock_attach_decorator: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) request_data = {} @@ -1329,7 +1324,7 @@ async def test_no_matching_creds_indy_handler(self): assert "No matching Indy" in str(context.exception) async def test_receive_pres(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_proposal = V20PresProposal( formats=[ V20PresFormat( @@ -1380,14 +1375,14 @@ async def test_receive_pres(self): assert by_format.get("pres_proposal").get("indy") == INDY_PROOF_REQ_NAME assert by_format.get("pres_request").get("indy") == INDY_PROOF_REQ_NAME - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1400,7 +1395,7 @@ async def test_receive_pres(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_proposal = V20PresProposal( formats=[ V20PresFormat( @@ -1455,14 +1450,14 @@ async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): assert by_format.get("pres_proposal").get("indy") == INDY_PROOF_REQ_NAME assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1475,7 +1470,7 @@ async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_indy_no_predicate_restrictions(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -1537,14 +1532,14 @@ async def test_receive_pres_indy_no_predicate_restrictions(self): assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1557,7 +1552,7 @@ async def test_receive_pres_indy_no_predicate_restrictions(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_indy_no_attr_restrictions(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -1613,14 +1608,14 @@ async def test_receive_pres_indy_no_attr_restrictions(self): assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1633,7 +1628,7 @@ async def test_receive_pres_indy_no_attr_restrictions(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_bait_and_switch_attr_name(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAME) indy_proof_req["requested_attributes"]["0_screencapture_uuid"]["restrictions"][ 0 @@ -1682,9 +1677,9 @@ async def test_receive_pres_bait_and_switch_attr_name(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1738,9 +1733,9 @@ async def test_receive_pres_bait_and_switch_attr_name(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1749,7 +1744,7 @@ async def test_receive_pres_bait_and_switch_attr_name(self): assert "Presentation referent" in str(context.exception) async def test_receive_pres_bait_and_switch_attr_names(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAMES) indy_proof_req["requested_attributes"]["0_player_uuid"]["restrictions"][0][ "attr::screenCapture::value" @@ -1797,9 +1792,9 @@ async def test_receive_pres_bait_and_switch_attr_names(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1853,9 +1848,9 @@ async def test_receive_pres_bait_and_switch_attr_names(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1864,7 +1859,7 @@ async def test_receive_pres_bait_and_switch_attr_names(self): assert "Presentation referent" in str(context.exception) async def test_receive_pres_bait_and_switch_pred(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAME) indy_proof_req["requested_predicates"] = {} pres_proposal = V20PresProposal( @@ -1910,9 +1905,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1968,9 +1963,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2026,9 +2021,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2084,9 +2079,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2128,13 +2123,13 @@ async def test_verify_pres(self): ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() @@ -2188,34 +2183,34 @@ async def test_verify_pres_indy_and_dif(self): ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() assert px_rec_out.state == (V20PresExRecord.STATE_DONE) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch( + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch( "aries_cloudagent.vc.vc_ld.verify.verify_presentation", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=PresentationVerificationResult(verified=False) ), - ), async_mock.patch.object( + ), mock.patch.object( IndyVerifier, "verify_presentation", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=PresentationVerificationResult(verified=True) ), - ), async_mock.patch.object( + ), mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) @@ -2258,14 +2253,14 @@ async def test_send_pres_ack_no_responder(self): await self.manager.send_pres_ack(px_rec) async def test_receive_pres_ack_a(self): - conn_record = async_mock.MagicMock(connection_id=CONN_ID) + conn_record = mock.MagicMock(connection_id=CONN_ID) px_rec_dummy = V20PresExRecord() - message = async_mock.MagicMock() + message = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2275,14 +2270,14 @@ async def test_receive_pres_ack_a(self): assert px_rec_out.state == V20PresExRecord.STATE_DONE async def test_receive_pres_ack_b(self): - conn_record = async_mock.MagicMock(connection_id=CONN_ID) + conn_record = mock.MagicMock(connection_id=CONN_ID) px_rec_dummy = V20PresExRecord() - message = async_mock.MagicMock(_verification_result="true") + message = mock.MagicMock(_verification_result="true") - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2309,16 +2304,16 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.CoroutineMock(), + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = stored_exchange @@ -2351,10 +2346,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py index 0d13acc826..cbce0e26e9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py @@ -1,6 +1,6 @@ from copy import deepcopy -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from marshmallow import ValidationError from time import time from unittest.mock import ANY @@ -124,21 +124,19 @@ } -class TestPresentProofRoutes(AsyncTestCase): +class TestPresentProofRoutes(IsolatedAsyncioTestCase): def setUp(self): self.context = AdminRequestContext.test_context() self.profile = self.context.profile injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -154,7 +152,7 @@ def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -163,7 +161,7 @@ def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -176,9 +174,9 @@ def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -249,17 +247,15 @@ async def test_present_proof_list(self): "state": "dummy", } - mock_pres_ex_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_pres_ex_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.query = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.query = mock.CoroutineMock( return_value=[mock_pres_ex_rec_inst] ) @@ -276,10 +272,10 @@ async def test_present_proof_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.query = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -289,10 +285,10 @@ async def test_present_proof_list_x(self): async def test_present_proof_credentials_list_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex_rec_cls.retrieve_by_id.side_effect = StorageNotFoundError() @@ -309,18 +305,18 @@ async def test_present_proof_credentials_x(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(side_effect=test_module.IndyHolderError()) + mock.CoroutineMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.CoroutineMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.CoroutineMock()) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec ) @@ -337,20 +333,20 @@ async def test_present_proof_credentials_list_single_referent(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.CoroutineMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.CoroutineMock() ) await test_module.present_proof_credentials_list(self.request) @@ -366,20 +362,20 @@ async def test_present_proof_credentials_list_multiple_referents(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.CoroutineMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.CoroutineMock() ) await test_module.present_proof_credentials_list(self.request) @@ -392,25 +388,23 @@ async def test_present_proof_credentials_list_dif(self): self.request.query = {"extra_query": {}} returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -444,10 +438,10 @@ async def test_present_proof_credentials_list_dif(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -466,29 +460,23 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): self.request.query = {"extra_query": {}} returned_credentials = [ - async_mock.MagicMock( - cred_value={"name": "Credential1"}, record_id="test_1" - ), - async_mock.MagicMock( - cred_value={"name": "Credential2"}, record_id="test_2" - ), + mock.MagicMock(cred_value={"name": "Credential1"}, record_id="test_1"), + mock.MagicMock(cred_value={"name": "Credential2"}, record_id="test_2"), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -532,10 +520,10 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -560,25 +548,23 @@ async def test_present_proof_credentials_dif_no_tag_query(self): "required" ] = False returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -612,10 +598,10 @@ async def test_present_proof_credentials_dif_no_tag_query(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -640,25 +626,23 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): "limit_disclosure" ] returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -692,10 +676,10 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -720,25 +704,23 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): "limit_disclosure" ] returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -772,10 +754,10 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -830,21 +812,21 @@ async def test_present_proof_credentials_single_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -893,21 +875,21 @@ async def test_present_proof_credentials_double_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -953,21 +935,21 @@ async def test_present_proof_credentials_list_limit_disclosure_no_bbs(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1016,21 +998,21 @@ async def test_present_proof_credentials_no_ldp_vp(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1076,34 +1058,32 @@ async def test_present_proof_credentials_list_schema_uri(self): ) returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record await test_module.present_proof_credentials_list(self.request) @@ -1122,18 +1102,18 @@ async def test_present_proof_credentials_list_dif_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + mock.CoroutineMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1169,10 +1149,10 @@ async def test_present_proof_credentials_list_dif_error(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: with self.assertRaises(test_module.web.HTTPBadRequest): mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -1181,14 +1161,14 @@ async def test_present_proof_credentials_list_dif_error(self): async def test_present_proof_retrieve(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ) ) @@ -1200,10 +1180,10 @@ async def test_present_proof_retrieve(self): async def test_present_proof_retrieve_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1213,16 +1193,16 @@ async def test_present_proof_retrieve_not_found(self): async def test_present_proof_retrieve_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - mock_pres_ex_rec_inst = async_mock.MagicMock( + mock_pres_ex_rec_inst = mock.MagicMock( connection_id="abc123", thread_id="thid123", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_pres_ex_rec_inst ) @@ -1230,7 +1210,7 @@ async def test_present_proof_retrieve_x(self): await test_module.present_proof_retrieve(self.request) async def test_present_proof_send_proposal(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy-conn-id", "presentation_proposal": { @@ -1239,21 +1219,21 @@ async def test_present_proof_send_proposal(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(is_ready=True) + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(is_ready=True) ) - mock_px_rec_inst = async_mock.MagicMock() + mock_px_rec_inst = mock.MagicMock() mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock(return_value=mock_px_rec_inst) + mock.CoroutineMock(return_value=mock_px_rec_inst) ) await test_module.present_proof_send_proposal(self.request) @@ -1262,12 +1242,12 @@ async def test_present_proof_send_proposal(self): ) async def test_present_proof_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1275,35 +1255,35 @@ async def test_present_proof_send_proposal_no_conn_record(self): await test_module.present_proof_send_proposal(self.request) async def test_present_proof_send_proposal_not_ready(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresProposal", autospec=True ) as mock_proposal: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(is_ready=False) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.present_proof_send_proposal(self.request) async def test_present_proof_send_proposal_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -1315,27 +1295,25 @@ async def test_present_proof_create_request(self): indy_proof_req = deepcopy(INDY_PROOF_REQ) indy_proof_req.pop("nonce") # exercise _add_nonce() - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: indy_proof_req}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_request, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_px_rec_inst ) ) @@ -1347,28 +1325,28 @@ async def test_present_proof_create_request(self): ) async def test_present_proof_create_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: INDY_PROOF_REQ}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_request, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock() - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock() + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -1378,7 +1356,7 @@ async def test_present_proof_create_request_x(self): await test_module.present_proof_create_request(self.request) async def test_present_proof_send_free_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1386,24 +1364,24 @@ async def test_present_proof_send_free_request(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( + ) as mock_pres_request, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock() - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock({"thread_id": "sample-thread-id"}) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock() + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock({"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_px_rec_inst ) ) @@ -1415,14 +1393,12 @@ async def test_present_proof_send_free_request(self): ) async def test_present_proof_send_free_request_not_found(self): - self.request.json = async_mock.CoroutineMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.CoroutineMock(return_value={"connection_id": "dummy"}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1430,15 +1406,15 @@ async def test_present_proof_send_free_request_not_found(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": "dummy", "proof_request": {}} ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_inst = async_mock.MagicMock(is_ready=False) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) @@ -1446,7 +1422,7 @@ async def test_present_proof_send_free_request_not_ready(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1454,31 +1430,29 @@ async def test_present_proof_send_free_request_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( + ) as mock_pres_request, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_conn_rec_inst = async_mock.MagicMock() - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock() + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -1488,52 +1462,52 @@ async def test_present_proof_send_free_request_x(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_bound_request(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_request = async_mock.MagicMock() + mock_pres_request = mock.MagicMock() - mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.CoroutineMock( return_value=(mock_px_rec_inst, mock_pres_request) ) ) @@ -1545,39 +1519,39 @@ async def test_present_proof_send_bound_request(self): ) async def test_present_proof_send_bound_request_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1585,42 +1559,42 @@ async def test_present_proof_send_bound_request_not_found(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_not_ready(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=False, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) @@ -1628,13 +1602,13 @@ async def test_present_proof_send_bound_request_not_ready(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1642,34 +1616,34 @@ async def test_present_proof_send_bound_request_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_bound_request_bad_state(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -1677,50 +1651,50 @@ async def test_present_proof_send_bound_request_bad_state(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_x(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + mock.MagicMock( + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1730,7 +1704,7 @@ async def test_present_proof_send_bound_request_x(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_presentation(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1745,39 +1719,39 @@ async def test_present_proof_send_presentation(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.CoroutineMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1790,7 +1764,7 @@ async def test_present_proof_send_presentation(self): async def test_present_proof_send_presentation_dif(self): proof_req = deepcopy(DIF_PROOF_REQ) proof_req["issuer_id"] = "test123" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "dif": proof_req, } @@ -1800,39 +1774,39 @@ async def test_present_proof_send_presentation_dif(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.CoroutineMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1843,9 +1817,7 @@ async def test_present_proof_send_presentation_dif(self): ) async def test_present_proof_send_presentation_dif_error(self): - self.request.json = async_mock.CoroutineMock( - return_value={"dif": DIF_PROOF_REQ} - ) + self.request.json = mock.CoroutineMock(return_value={"dif": DIF_PROOF_REQ}) self.request.match_info = { "pres_ex_id": "dummy", } @@ -1879,33 +1851,31 @@ async def test_present_proof_send_presentation_dif_error(self): ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=px_rec_instance ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( - side_effect=test_module.LedgerError() - ) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.CoroutineMock(side_effect=test_module.LedgerError()) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1913,7 +1883,7 @@ async def test_present_proof_send_presentation_dif_error(self): mock_response.assert_called_once_with(px_rec_instance.serialize()) async def test_present_proof_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1927,10 +1897,10 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): "pres_ex_id": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) @@ -1939,7 +1909,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_presentation_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1954,29 +1924,29 @@ async def test_present_proof_send_presentation_not_found(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1984,7 +1954,7 @@ async def test_present_proof_send_presentation_not_found(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1999,37 +1969,37 @@ async def test_present_proof_send_presentation_not_ready(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(is_ready=False) + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(is_ready=False) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_bad_state(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -2043,17 +2013,17 @@ async def test_present_proof_send_presentation_bad_state(self): "pres_ex_id": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id=None, state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -2061,7 +2031,7 @@ async def test_present_proof_send_presentation_bad_state(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -2076,39 +2046,39 @@ async def test_present_proof_send_presentation_x(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + mock.MagicMock( + verify_presentation=mock.CoroutineMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2125,32 +2095,32 @@ async def test_present_proof_send_presentation_x(self): async def test_present_proof_verify_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.CoroutineMock(return_value=mock_px_rec_inst) + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.CoroutineMock(return_value=mock_px_rec_inst) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -2160,10 +2130,10 @@ async def test_present_proof_verify_presentation(self): async def test_present_proof_verify_presentation_px_rec_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) @@ -2174,17 +2144,17 @@ async def test_present_proof_verify_presentation_px_rec_not_found(self): async def test_present_proof_verify_presentation_bad_state(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -2194,33 +2164,33 @@ async def test_present_proof_verify_presentation_bad_state(self): async def test_present_proof_verify_presentation_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.CoroutineMock( + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2235,25 +2205,23 @@ async def test_present_proof_verify_presentation_x(self): await test_module.present_proof_verify_presentation(self.request) async def test_present_proof_problem_report(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec, async_mock.patch.object( + ) as mock_px_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() - ) + mock_px_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -2263,15 +2231,15 @@ async def test_present_proof_problem_report(self): mock_response.assert_called_once_with({}) async def test_present_proof_problem_report_bad_pres_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -2279,19 +2247,19 @@ async def test_present_proof_problem_report_bad_pres_ex_id(self): await test_module.present_proof_problem_report(self.request) async def test_present_proof_problem_report_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -2301,16 +2269,16 @@ async def test_present_proof_problem_report_x(self): async def test_present_proof_remove(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), ) ) @@ -2320,10 +2288,10 @@ async def test_present_proof_remove(self): async def test_present_proof_remove_px_rec_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -2333,14 +2301,14 @@ async def test_present_proof_remove_px_rec_not_found(self): async def test_present_proof_remove_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.CoroutineMock( + delete_record=mock.CoroutineMock( side_effect=test_module.StorageError() ), ) @@ -2350,14 +2318,14 @@ async def test_present_proof_remove_x(self): await test_module.present_proof_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] @@ -2441,7 +2409,7 @@ async def test_retrieve_uri_list_from_schema_filter(self): assert test_one_of_uri_groups == [["test123", "test321"]] async def test_send_presentation_no_specification(self): - self.request.json = async_mock.CoroutineMock(return_value={"comment": "test"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "test"}) self.request.match_info = { "pres_ex_id": "dummy", } diff --git a/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py b/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py index c3240c6d5f..c9f586533e 100644 --- a/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py +++ b/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py index b4805d8059..4e4925cd61 100644 --- a/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from asynctest import mock +from aries_cloudagent.tests import mock import pytest from .. import routes as test_module diff --git a/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py index 6fe38c848b..624f831119 100644 --- a/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from asynctest import mock +from aries_cloudagent.tests import mock import pytest from .. import routes as test_module diff --git a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py index 03e3b2993e..0e4947738c 100644 --- a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py +++ b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock import json from ......connections.models.connection_target import ConnectionTarget @@ -18,8 +18,8 @@ TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" -class TestForwardHandler(AsyncTestCase): - async def setUp(self): +class TestForwardHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = Forward(to="sample-did", msg={"msg": "sample-message"}) @@ -29,18 +29,18 @@ async def test_handle(self): handler = test_module.ForwardHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "RoutingManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_connection_mgr, async_mock.patch.object( + ) as mock_connection_mgr, mock.patch.object( self.context.profile, "notify", autospec=True ) as mock_notify: - mock_mgr.return_value.get_recipient = async_mock.CoroutineMock( + mock_mgr.return_value.get_recipient = mock.CoroutineMock( return_value=RouteRecord(connection_id="dummy") ) mock_connection_mgr.return_value.get_connection_targets = ( - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ ConnectionTarget( recipient_keys=["recip_key"], @@ -77,10 +77,10 @@ async def test_handle_cannot_resolve_recipient(self): handler = test_module.ForwardHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "RoutingManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.get_recipient = async_mock.CoroutineMock( + mock_mgr.return_value.get_recipient = mock.CoroutineMock( side_effect=test_module.RoutingManagerError() ) diff --git a/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py b/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py index 2dea1d988d..833622ebde 100644 --- a/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py +++ b/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py @@ -1,6 +1,7 @@ import json -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py b/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py index 7b650a03d8..22846bcd3d 100644 --- a/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py +++ b/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from marshmallow.exceptions import ValidationError from ..route_record import RouteRecordSchema -class TestConnRecord(AsyncTestCase): +class TestConnRecord(IsolatedAsyncioTestCase): async def test_route_record_validation_fails_no_connection_wallet(self): schema = schema = RouteRecordSchema() diff --git a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py index 047ab6652c..2f6ae835f4 100644 --- a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py +++ b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from marshmallow import ValidationError @@ -18,8 +18,8 @@ TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" -class TestRoutingManager(AsyncTestCase): - async def setUp(self): +class TestRoutingManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.message_receipt = MessageReceipt(sender_verkey=TEST_VERKEY) self.transaction = await self.context.transaction() # for coverage @@ -70,8 +70,8 @@ async def test_get_recipient_no_verkey(self): assert "Must pass non-empty" in str(context.exception) async def test_get_recipient_duplicate_routes(self): - with async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.CoroutineMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageDuplicateError() with self.assertRaises(RouteNotFoundError) as context: @@ -79,8 +79,8 @@ async def test_get_recipient_duplicate_routes(self): assert "More than one route" in str(context.exception) async def test_get_recipient_no_routes(self): - with async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.CoroutineMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(RouteNotFoundError) as context: diff --git a/aries_cloudagent/protocols/tests/test_didcomm_prefix.py b/aries_cloudagent/protocols/tests/test_didcomm_prefix.py index 4328d539d0..daa403a9c9 100644 --- a/aries_cloudagent/protocols/tests/test_didcomm_prefix.py +++ b/aries_cloudagent/protocols/tests/test_didcomm_prefix.py @@ -1,11 +1,11 @@ from os import environ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..didcomm_prefix import DIDCommPrefix -class TestDIDCommPrefix(AsyncTestCase): +class TestDIDCommPrefix(IsolatedAsyncioTestCase): def test_didcomm_prefix(self): DIDCommPrefix.set({}) assert environ.get("DIDCOMM_PREFIX") == DIDCommPrefix.OLD.value diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py index dcb21280a3..92e184bf1d 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -52,7 +53,7 @@ def test_serialize(self, mock_ping_schema_load): assert msg_dict is mock_ping_schema_load.return_value -class TestPingSchema(AsyncTestCase): +class TestPingSchema(IsolatedAsyncioTestCase): """Test ping schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py index b05a8aaf02..3a6bd7cbf6 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py @@ -1,6 +1,7 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -51,7 +52,7 @@ def test_serialize(self, mock_ping_schema_load): assert msg_dict is mock_ping_schema_load.return_value -class TestPingResponseSchema(AsyncTestCase): +class TestPingResponseSchema(IsolatedAsyncioTestCase): """Test ping response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py index 4cded73a3a..97cd67993a 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py @@ -1,20 +1,20 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .. import routes as test_module -class TestTrustpingRoutes(AsyncTestCase): +class TestTrustpingRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -22,62 +22,56 @@ def setUp(self): ) async def test_connections_send_ping(self): - self.request.json = async_mock.CoroutineMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( - test_module, "Ping", async_mock.MagicMock() - ) as mock_ping, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( + test_module, "Ping", mock.MagicMock() + ) as mock_ping, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: - mock_ping.return_value = async_mock.MagicMock(_thread_id="dummy") - mock_retrieve.return_value = async_mock.MagicMock(is_ready=True) + mock_ping.return_value = mock.MagicMock(_thread_id="dummy") + mock_retrieve.return_value = mock.MagicMock(is_ready=True) result = await test_module.connections_send_ping(self.request) json_response.assert_called_once_with({"thread_id": "dummy"}) assert result is json_response.return_value async def test_connections_send_ping_no_conn(self): - self.request.json = async_mock.CoroutineMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: mock_retrieve.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_send_ping(self.request) async def test_connections_send_ping_not_ready(self): - self.request.json = async_mock.CoroutineMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: - mock_retrieve.return_value = async_mock.MagicMock(is_ready=False) + mock_retrieve.return_value = mock.MagicMock(is_ready=False) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_send_ping(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/resolver/default/tests/test_indy.py b/aries_cloudagent/resolver/default/tests/test_indy.py index 424b85658d..d2344a2047 100644 --- a/aries_cloudagent/resolver/default/tests/test_indy.py +++ b/aries_cloudagent/resolver/default/tests/test_indy.py @@ -2,7 +2,7 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -31,14 +31,14 @@ def resolver(): @pytest.fixture def ledger(): """Ledger fixture.""" - ledger = async_mock.MagicMock(spec=BaseLedger) - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( + ledger = mock.MagicMock(spec=BaseLedger) + ledger.get_all_endpoints_for_did = mock.CoroutineMock( return_value={ "endpoint": "https://github.com/", "profile": "https://example.com/profile", } ) - ledger.get_key_for_did = async_mock.CoroutineMock(return_value="key") + ledger.get_key_for_did = mock.CoroutineMock(return_value="key") yield ledger @@ -48,10 +48,8 @@ def profile(ledger): profile = InMemoryProfile.test_profile() profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( - return_value=(None, ledger) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, ledger)) ), ) yield profile @@ -85,12 +83,12 @@ async def test_resolve_multitenant( """Test resolve method.""" profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", ledger)), ): assert await resolver.resolve(profile, TEST_DID0) @@ -101,10 +99,8 @@ async def test_resolve_x_no_ledger( """Test resolve method with no ledger.""" profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) with pytest.raises(ResolverError): @@ -132,9 +128,7 @@ async def test_supports_updated_did_sov_rules( "linked_domains": "https://example.com", } - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( - return_value=example - ) + ledger.get_all_endpoints_for_did = mock.CoroutineMock(return_value=example) assert await resolver.resolve(profile, TEST_DID0) @pytest.mark.asyncio @@ -147,9 +141,7 @@ async def test_supports_updated_did_sov_rules_no_endpoint_url( "types": ["DIDComm", "did-communication", "endpoint"], } - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( - return_value=example - ) + ledger.get_all_endpoints_for_did = mock.CoroutineMock(return_value=example) result = await resolver.resolve(profile, TEST_DID0) assert "service" not in result diff --git a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py index 3f21da0657..2acace6876 100644 --- a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py +++ b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py @@ -1,6 +1,6 @@ """Test LegacyPeerDIDResolver.""" -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock import pydid import pytest @@ -37,9 +37,9 @@ class TestLegacyPeerDIDResolver: @pytest.mark.asyncio async def test_supports(self, resolver: LegacyPeerDIDResolver, profile: Profile): """Test supports.""" - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -51,9 +51,9 @@ async def test_supports_no_cache( ): """Test supports.""" profile.context.injector.clear_binding(BaseCache) - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -71,26 +71,24 @@ async def test_supports_x_unknown_did( self, resolver: LegacyPeerDIDResolver, profile: Profile ): """Test supports returns false for unknown DID.""" - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( - side_effect=StorageNotFoundError - ) + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.CoroutineMock(side_effect=StorageNotFoundError) ) assert not await resolver.supports(profile, TEST_DID2) @pytest.mark.asyncio async def test_resolve(self, resolver: LegacyPeerDIDResolver, profile: Profile): """Test resolve.""" - with async_mock.patch.object( + with mock.patch.object( test_module, "BaseConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "LegacyDocCorrections" ) as mock_corrections: doc = object() - mock_corrections.apply = async_mock.MagicMock(return_value=doc) - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -105,21 +103,19 @@ async def test_resolve_x_not_found( This should be impossible in practice but still. """ - with async_mock.patch.object( + with mock.patch.object( test_module, "BaseConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "LegacyDocCorrections" ) as mock_corrections, pytest.raises( test_module.DIDNotFound ): doc = object - mock_corrections.apply = async_mock.MagicMock(return_value=doc) - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( - side_effect=StorageNotFoundError - ) + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.CoroutineMock(side_effect=StorageNotFoundError) ) - resolver.supports = async_mock.CoroutineMock(return_value=True) + resolver.supports = mock.CoroutineMock(return_value=True) result = await resolver.resolve(profile, TEST_DID0) assert result == doc diff --git a/aries_cloudagent/resolver/default/tests/test_universal.py b/aries_cloudagent/resolver/default/tests/test_universal.py index 96e5d0827f..05f3b89801 100644 --- a/aries_cloudagent/resolver/default/tests/test_universal.py +++ b/aries_cloudagent/resolver/default/tests/test_universal.py @@ -3,7 +3,7 @@ import re from typing import Dict, Union -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock import pytest from ....config.settings import Settings @@ -122,10 +122,10 @@ async def test_fetch_resolver_props(mock_client_session: MockClientSession): @pytest.mark.asyncio async def test_get_supported_did_regex(): props = {"example": {"http": {"pattern": "match a test string"}}} - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_fetch_resolver_props", - async_mock.CoroutineMock(return_value=props), + mock.CoroutineMock(return_value=props), ): pattern = await UniversalResolver()._get_supported_did_regex() assert pattern.fullmatch("match a test string") @@ -147,12 +147,12 @@ async def test_setup_endpoint_regex_set(resolver: UniversalResolver): "resolver.universal.supported": "test", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( test_module, "_compile_supported_did_regex", - async_mock.MagicMock(return_value="pattern"), + mock.MagicMock(return_value="pattern"), ): await resolver.setup(context) @@ -167,12 +167,12 @@ async def test_setup_endpoint_set(resolver: UniversalResolver): "resolver.universal": "http://example.com", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) @@ -187,12 +187,12 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): "resolver.universal": "DEFAULT", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) @@ -203,12 +203,12 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): @pytest.mark.asyncio async def test_setup_endpoint_unset(resolver: UniversalResolver): settings = Settings() - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) diff --git a/aries_cloudagent/resolver/tests/test_base.py b/aries_cloudagent/resolver/tests/test_base.py index 2108468458..5d3a77e159 100644 --- a/aries_cloudagent/resolver/tests/test_base.py +++ b/aries_cloudagent/resolver/tests/test_base.py @@ -3,7 +3,7 @@ import pytest import re -from asynctest import mock as async_mock +from unittest import mock from pydid import DIDDocument from ..base import BaseDIDResolver, DIDMethodNotSupported, ResolverType @@ -40,7 +40,7 @@ def non_native_resolver(): @pytest.fixture def profile(): - yield async_mock.MagicMock() + yield mock.MagicMock() def test_native_on_native(native_resolver): diff --git a/aries_cloudagent/resolver/tests/test_routes.py b/aries_cloudagent/resolver/tests/test_routes.py index 01c213572b..bdb1c2fd73 100644 --- a/aries_cloudagent/resolver/tests/test_routes.py +++ b/aries_cloudagent/resolver/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from pydid import DIDDocument from ...core.in_memory import InMemoryProfile @@ -40,7 +40,7 @@ def resolution_result(did_doc): @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -49,39 +49,39 @@ def mock_response(): @pytest.fixture def mock_resolver(resolution_result): - did_resolver = async_mock.MagicMock() - did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - did_resolver.resolve_with_metadata = async_mock.CoroutineMock( + did_resolver = mock.MagicMock() + did_resolver.resolve = mock.CoroutineMock(return_value=did_doc) + did_resolver.resolve_with_metadata = mock.CoroutineMock( return_value=resolution_result ) yield did_resolver @pytest.mark.asyncio -async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_doc): +async def test_resolver(mock_resolver, mock_response: mock.MagicMock, did_doc): profile = InMemoryProfile.test_profile() context = profile.context setattr(context, "profile", profile) session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = async_mock.CoroutineMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={ "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( context.profile, "session", - async_mock.MagicMock(return_value=session), + mock.MagicMock(return_value=session), ) as mock_session: await test_module.resolve_did(request) mock_response.call_args[0][0] == did_doc.serialize() @@ -98,9 +98,7 @@ async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_ ], ) async def test_resolver_not_found_error(mock_resolver, side_effect, error): - mock_resolver.resolve_with_metadata = async_mock.CoroutineMock( - side_effect=side_effect() - ) + mock_resolver.resolve_with_metadata = mock.CoroutineMock(side_effect=side_effect()) profile = InMemoryProfile.test_profile() context = profile.context @@ -108,23 +106,23 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = async_mock.CoroutineMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={ "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( context.profile, "session", - async_mock.MagicMock(return_value=session), + mock.MagicMock(return_value=session), ) as mock_session: with pytest.raises(error): await test_module.resolve_did(request) @@ -132,14 +130,14 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): @pytest.mark.asyncio async def test_register(): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() @pytest.mark.asyncio async def test_post_process_routes(): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py index ecc19d4b5f..25d756317e 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....storage.base import StorageNotFoundError @@ -10,7 +10,7 @@ REV_REG_ID = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:0" -class TestIssuerCredRevRecord(AsyncTestCase): +class TestIssuerCredRevRecord(IsolatedAsyncioTestCase): def setUp(self): self.session = InMemoryProfile.test_session() diff --git a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py index bc292daeb4..19f4e92e20 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py @@ -4,7 +4,8 @@ from os.path import join from typing import Any, Mapping, Type -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile, InMemoryProfileSession from ....core.profile import Profile, ProfileSession @@ -52,22 +53,22 @@ } -class TestIssuerRevRegRecord(AsyncTestCase): - async def setUp(self): +class TestIssuerRevRegRecord(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile( settings={"tails_server_base_url": "http://1.2.3.4:8088"}, ) self.context = self.profile.context - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.send_revoc_reg_def = async_mock.CoroutineMock() - self.ledger.send_revoc_reg_entry = async_mock.CoroutineMock() + self.ledger.send_revoc_reg_def = mock.CoroutineMock() + self.ledger.send_revoc_reg_entry = mock.CoroutineMock() self.profile.context.injector.bind_instance(BaseLedger, self.ledger) - TailsServer = async_mock.MagicMock(BaseTailsServer, autospec=True) + TailsServer = mock.MagicMock(BaseTailsServer, autospec=True) self.tails_server = TailsServer() - self.tails_server.upload_tails_file = async_mock.CoroutineMock( + self.tails_server.upload_tails_file = mock.CoroutineMock( return_value=(True, "http://1.2.3.4:8088/rev-reg-id") ) self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server) @@ -171,17 +172,17 @@ def __init__( def handle(self): if self.handle_counter == 0: self.handle_counter = self.handle_counter + 1 - return async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.CoroutineMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_cred_def) ) ) ) else: - return async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.CoroutineMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_reg_rev_def_private), ), ) @@ -213,13 +214,13 @@ def handle(self): "ver": "1.0", "value": {"accum": "ACCUM", "issued": [1, 2], "revoked": [3, 4]}, } - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( _test_rev_reg_delta, 1234567890, ) ) - self.ledger.send_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.send_revoc_reg_entry = mock.CoroutineMock( return_value={ "result": {"...": "..."}, }, @@ -229,10 +230,10 @@ def handle(self): ) _test_profile = _test_session.profile _test_profile.context.injector.bind_instance(BaseLedger, self.ledger) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.CoroutineMock( + mock.CoroutineMock( return_value=[ test_module.IssuerCredRevRecord( record_id=test_module.UUID4_EXAMPLE, @@ -243,14 +244,14 @@ def handle(self): ) ] ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(return_value=rec), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=rec), + ), mock.patch.object( test_module, "generate_ledger_rrrecovery_txn", - async_mock.CoroutineMock(return_value=rev_reg_delta), + mock.CoroutineMock(return_value=rev_reg_delta), ): assert ( _test_rev_reg_delta, @@ -273,11 +274,11 @@ async def test_generate_registry_etc(self): cred_def_id=CRED_DEF_ID, revoc_reg_id=REV_REG_ID, ) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( - issuer, "create_and_store_revocation_registry", async_mock.CoroutineMock() + with mock.patch.object( + issuer, "create_and_store_revocation_registry", mock.CoroutineMock() ) as mock_create_store_rr: mock_create_store_rr.side_effect = IndyIssuerError("Not this time") @@ -290,9 +291,7 @@ async def test_generate_registry_etc(self): json.dumps(REV_REG_ENTRY), ) - with async_mock.patch.object( - test_module, "move", async_mock.MagicMock() - ) as mock_move: + with mock.patch.object(test_module, "move", mock.MagicMock()) as mock_move: await rec.generate_registry(self.profile) assert rec.revoc_reg_id == REV_REG_ID @@ -312,7 +311,7 @@ async def test_generate_registry_etc(self): assert rec.state == IssuerRevRegRecord.STATE_POSTED self.ledger.send_revoc_reg_def.assert_called_once() - with async_mock.patch.object(test_module.Path, "is_file", lambda _: True): + with mock.patch.object(test_module.Path, "is_file", lambda _: True): await rec.upload_tails_file(self.profile) assert ( rec.tails_public_uri diff --git a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py index ddba588969..d28d6ac6df 100644 --- a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py +++ b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from copy import deepcopy from pathlib import Path from shutil import rmtree @@ -40,7 +41,7 @@ } -class TestRevocationRegistry(AsyncTestCase): +class TestRevocationRegistry(IsolatedAsyncioTestCase): def tearDown(self): rmtree(TAILS_DIR, ignore_errors=True) @@ -83,7 +84,7 @@ async def test_tails_local_path(self): rev_reg_loc = RevocationRegistry.from_definition(REV_REG_DEF, public_def=False) assert rev_reg_loc.get_receiving_tails_local_path() == TAILS_LOCAL - with async_mock.patch.object(Path, "is_file", autospec=True) as mock_is_file: + with mock.patch.object(Path, "is_file", autospec=True) as mock_is_file: mock_is_file.return_value = True assert await rev_reg_loc.get_or_fetch_local_tails_path() == TAILS_LOCAL @@ -101,14 +102,12 @@ async def test_retrieve_tails(self): rr_def_public["value"]["tailsLocation"] = "http://sample.ca:8088/path" rev_reg = RevocationRegistry.from_definition(rr_def_public, public_def=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( - test_module, "Session", autospec=True - ) as mock_session: - mock_session.return_value.__enter__ = async_mock.MagicMock( + more_magic = mock.MagicMock() + with mock.patch.object(test_module, "Session", autospec=True) as mock_session: + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( + more_magic.get = mock.MagicMock( side_effect=test_module.RequestException("Not this time") ) @@ -118,18 +117,14 @@ async def test_retrieve_tails(self): rmtree(TAILS_DIR, ignore_errors=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( - test_module, "Session", autospec=True - ) as mock_session: - mock_session.return_value.__enter__ = async_mock.MagicMock( + more_magic = mock.MagicMock() + with mock.patch.object(test_module, "Session", autospec=True) as mock_session: + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( - return_value=async_mock.MagicMock( - iter_content=async_mock.MagicMock( - side_effect=[(b"abcd1234",), (b"",)] - ) + more_magic.get = mock.MagicMock( + return_value=mock.MagicMock( + iter_content=mock.MagicMock(side_effect=[(b"abcd1234",), (b"",)]) ) ) @@ -141,28 +136,26 @@ async def test_retrieve_tails(self): rmtree(TAILS_DIR, ignore_errors=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( + more_magic = mock.MagicMock() + with mock.patch.object( test_module, "Session", autospec=True - ) as mock_session, async_mock.patch.object( - base58, "b58encode", async_mock.MagicMock() - ) as mock_b58enc, async_mock.patch.object( + ) as mock_session, mock.patch.object( + base58, "b58encode", mock.MagicMock() + ) as mock_b58enc, mock.patch.object( Path, "is_file", autospec=True ) as mock_is_file: - mock_session.return_value.__enter__ = async_mock.MagicMock( + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( - return_value=async_mock.MagicMock( - iter_content=async_mock.MagicMock( - side_effect=[(b"abcd1234",), (b"",)] - ) + more_magic.get = mock.MagicMock( + return_value=mock.MagicMock( + iter_content=mock.MagicMock(side_effect=[(b"abcd1234",), (b"",)]) ) ) mock_is_file.return_value = False - mock_b58enc.return_value = async_mock.MagicMock( - decode=async_mock.MagicMock(return_value=TAILS_HASH) + mock_b58enc.return_value = mock.MagicMock( + decode=mock.MagicMock(return_value=TAILS_HASH) ) await rev_reg.get_or_fetch_local_tails_path() diff --git a/aries_cloudagent/revocation/tests/test_indy.py b/aries_cloudagent/revocation/tests/test_indy.py index 32c2215dc6..256b80a04e 100644 --- a/aries_cloudagent/revocation/tests/test_indy.py +++ b/aries_cloudagent/revocation/tests/test_indy.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -18,22 +19,22 @@ from ..models.revocation_registry import RevocationRegistry -class TestIndyRevocation(AsyncTestCase): +class TestIndyRevocation(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": True}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock() + self.ledger.get_revoc_reg_def = mock.CoroutineMock() self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + mock.MagicMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -55,12 +56,12 @@ async def test_init_issuer_registry(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): result = await self.revoc.init_issuer_registry(CRED_DEF_ID) assert result.cred_def_id == CRED_DEF_ID @@ -73,9 +74,7 @@ async def test_init_issuer_registry_no_cred_def(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( - return_value=None - ) + self.ledger.get_credential_definition = mock.CoroutineMock(return_value=None) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) with self.assertRaises(RevocationNotSupportedError) as x_revo: @@ -86,7 +85,7 @@ async def test_init_issuer_registry_bad_size(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": "..."}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -119,7 +118,7 @@ async def test_init_issuer_registry_no_revocation(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -133,10 +132,10 @@ async def test_get_issuer_rev_reg_record(self): rec = await self.revoc.init_issuer_registry(CRED_DEF_ID) rec.revoc_reg_id = "dummy" - rec.generate_registry = async_mock.CoroutineMock() + rec.generate_registry = mock.CoroutineMock() - with async_mock.patch.object( - IssuerRevRegRecord, "retrieve_by_revoc_reg_id", async_mock.CoroutineMock() + with mock.patch.object( + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", mock.CoroutineMock() ) as mock_retrieve_by_rr_id: mock_retrieve_by_rr_id.return_value = rec await rec.generate_registry(self.profile, None) @@ -223,8 +222,8 @@ async def test_decommission_issuer_registries(self): async def test_get_ledger_registry(self): CRED_DEF_ID = "{self.test_did}:3:CL:1234:default" - with async_mock.patch.object( - RevocationRegistry, "from_definition", async_mock.MagicMock() + with mock.patch.object( + RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_from_def: result = await self.revoc.get_ledger_registry("dummy") assert result == mock_from_def.return_value @@ -238,14 +237,14 @@ async def test_get_ledger_registry(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), - ), async_mock.patch.object( - RevocationRegistry, "from_definition", async_mock.MagicMock() + mock.CoroutineMock(return_value=(None, self.ledger)), + ), mock.patch.object( + RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_from_def: result = await self.revoc.get_ledger_registry("dummy2") assert result == mock_from_def.return_value diff --git a/aries_cloudagent/revocation/tests/test_manager.py b/aries_cloudagent/revocation/tests/test_manager.py index b987913c97..f48cb70693 100644 --- a/aries_cloudagent/revocation/tests/test_manager.py +++ b/aries_cloudagent/revocation/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from aries_cloudagent.revocation.models.issuer_cred_rev_record import ( IssuerCredRevRecord, @@ -30,23 +30,23 @@ TAILS_LOCAL = f"{TAILS_DIR}/{TAILS_HASH}" -class TestRevocationManager(AsyncTestCase): - async def setUp(self): +class TestRevocationManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.manager = RevocationManager(self.profile) async def test_revoke_credential_publish(self): CRED_EX_ID = "dummy-cxid" CRED_REV_ID = "1" - mock_issuer_rev_reg_record = async_mock.MagicMock( + mock_issuer_rev_reg_record = mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), pending_pub=["2"], ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.revoke_credentials = mock.CoroutineMock( return_value=( json.dumps( { @@ -63,27 +63,27 @@ async def test_revoke_credential_publish(self): ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): - mock_retrieve.return_value = async_mock.MagicMock( + mock_retrieve.return_value = mock.MagicMock( rev_reg_id="dummy-rr-id", cred_rev_id=CRED_REV_ID ) - mock_rev_reg = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + mock_rev_reg = mock.MagicMock( + get_or_fetch_local_tails_path=mock.CoroutineMock() ) - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=mock_issuer_rev_reg_record ) - revoc.return_value.get_ledger_registry = async_mock.CoroutineMock( + revoc.return_value.get_ledger_registry = mock.CoroutineMock( return_value=mock_rev_reg ) @@ -99,14 +99,14 @@ async def test_revoke_credential_publish(self): async def test_revoke_cred_by_cxid_not_found(self): CRED_EX_ID = "dummy-cxid" - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(RevocationManagerError): @@ -122,14 +122,12 @@ async def test_revoke_credential_no_rev_reg_rec(self): revoc_reg_id=REV_REG_ID, ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=None ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(RevocationManagerError): @@ -137,28 +135,26 @@ async def test_revoke_credential_no_rev_reg_rec(self): async def test_revoke_credential_pend(self): CRED_REV_ID = "1" - mock_issuer_rev_reg_record = async_mock.MagicMock( - mark_pending=async_mock.CoroutineMock() - ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + mock_issuer_rev_reg_record = mock.MagicMock(mark_pending=mock.CoroutineMock()) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), - ) as session, async_mock.patch.object( + mock.MagicMock(return_value=self.profile.session()), + ) as session, mock.patch.object( self.profile, "transaction", - async_mock.MagicMock(return_value=session.return_value), - ) as session, async_mock.patch.object( + mock.MagicMock(return_value=session.return_value), + ) as session, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=mock_issuer_rev_reg_record ) @@ -185,28 +181,28 @@ async def test_publish_pending_revocations_basic(self): }, ] - mock_issuer_rev_reg_record = async_mock.MagicMock( + mock_issuer_rev_reg_record = mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=[mock_issuer_rev_reg_record]), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=[mock_issuer_rev_reg_record]), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -232,40 +228,40 @@ async def test_publish_pending_revocations_1_rev_reg_all(self): ] mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( record_id=0, revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), - async_mock.MagicMock( + mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock( + mock.CoroutineMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -292,40 +288,40 @@ async def test_publish_pending_revocations_1_rev_reg_some(self): ] mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( record_id=0, revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), - async_mock.MagicMock( + mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock( + mock.CoroutineMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -337,46 +333,46 @@ async def test_publish_pending_revocations_1_rev_reg_some(self): async def test_clear_pending(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations() assert result == {} async def test_clear_pending_1_rev_reg_all(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: None}) assert result == { @@ -386,23 +382,23 @@ async def test_clear_pending_1_rev_reg_all(self): async def test_clear_pending_1_rev_reg_some(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["99"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: ["9"]}) assert result == { diff --git a/aries_cloudagent/revocation/tests/test_routes.py b/aries_cloudagent/revocation/tests/test_routes.py index b715d59970..45bfa0e4c9 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -1,10 +1,10 @@ import os +import pytest import shutil -import unittest from aiohttp.web import HTTPBadRequest, HTTPNotFound -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.revocation.error import RevocationError @@ -13,16 +13,16 @@ from .. import routes as test_module -class TestRevocationRoutes(AsyncTestCase): +class TestRevocationRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -75,7 +75,7 @@ async def test_validate_cred_rev_rec_qs_and_revoke_req(self): ) async def test_revoke(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -83,38 +83,38 @@ async def test_revoke(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock() + mock_mgr.return_value.revoke_credential = mock.CoroutineMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_by_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "cred_ex_id": "dummy-cxid", "publish": "false", } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock() + mock_mgr.return_value.revoke_credential = mock.CoroutineMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -122,12 +122,12 @@ async def test_revoke_not_found(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock( + mock_mgr.return_value.revoke_credential = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -135,14 +135,14 @@ async def test_revoke_not_found(self): await test_module.revoke(self.request) async def test_publish_revocations(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - pub_pending = async_mock.CoroutineMock() + pub_pending = mock.CoroutineMock() mock_mgr.return_value.publish_pending_revocations = pub_pending await test_module.publish_revocations(self.request) @@ -152,28 +152,26 @@ async def test_publish_revocations(self): ) async def test_publish_revocations_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr: - pub_pending = async_mock.CoroutineMock( - side_effect=test_module.RevocationError() - ) + pub_pending = mock.CoroutineMock(side_effect=test_module.RevocationError()) mock_mgr.return_value.publish_pending_revocations = pub_pending with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.publish_revocations(self.request) async def test_clear_pending_revocations(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.CoroutineMock() + clear_pending = mock.CoroutineMock() mock_mgr.return_value.clear_pending_revocations = clear_pending await test_module.clear_pending_revocations(self.request) @@ -183,16 +181,14 @@ async def test_clear_pending_revocations(self): ) async def test_clear_pending_revocations_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = mock.CoroutineMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + clear_pending = mock.CoroutineMock(side_effect=test_module.StorageError()) mock_mgr.return_value.clear_pending_revocations = clear_pending with self.assertRaises(test_module.web.HTTPBadRequest): @@ -200,26 +196,26 @@ async def test_clear_pending_revocations_x(self): async def test_create_rev_reg(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( + ) as mock_find, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find.return_value = True - mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - generate_registry=async_mock.CoroutineMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.CoroutineMock( + return_value=mock.MagicMock( + generate_registry=mock.CoroutineMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -230,17 +226,17 @@ async def test_create_rev_reg(self): async def test_create_rev_reg_no_such_cred_def(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_find, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find.return_value = False @@ -250,23 +246,23 @@ async def test_create_rev_reg_no_such_cred_def(self): async def test_create_rev_reg_no_revo_support(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( + ) as mock_find, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find = True - mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.CoroutineMock( side_effect=test_module.RevocationNotSupportedError( error_code="dummy" ) @@ -285,12 +281,12 @@ async def test_rev_regs_created(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( - test_module.IssuerRevRegRecord, "query", async_mock.CoroutineMock() - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.IssuerRevRegRecord, "query", mock.CoroutineMock() + ) as mock_query, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_query.return_value = [async_mock.MagicMock(revoc_reg_id="dummy")] + mock_query.return_value = [mock.MagicMock(revoc_reg_id="dummy")] result = await test_module.rev_regs_created(self.request) mock_json_response.assert_called_once_with({"rev_reg_ids": ["dummy"]}) @@ -302,15 +298,15 @@ async def test_get_rev_reg(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -325,13 +321,13 @@ async def test_get_rev_reg_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -346,16 +342,16 @@ async def test_get_rev_reg_issued(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.CoroutineMock(), - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(), + ) as mock_query, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_query.return_value = return_value = [{"...": "..."}, {"...": "..."}] result = await test_module.get_rev_reg_issued_count(self.request) @@ -369,10 +365,10 @@ async def test_get_rev_reg_issued_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -390,15 +386,15 @@ async def test_get_cred_rev_record(self): "cred_rev_id": CRED_REV_ID, } - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.CoroutineMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) result = await test_module.get_cred_rev_record(self.request) @@ -410,15 +406,15 @@ async def test_get_cred_rev_record_by_cred_ex_id(self): self.request.query = {"cred_ex_id": CRED_EX_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.CoroutineMock(), + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) result = await test_module.get_cred_rev_record(self.request) @@ -431,17 +427,17 @@ async def test_get_cred_rev_record_not_found(self): ) CRED_REV_ID = "1" - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": REV_REG_ID, "cred_rev_id": CRED_REV_ID, } ) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") with self.assertRaises(test_module.web.HTTPNotFound): @@ -451,15 +447,15 @@ async def test_get_active_rev_reg(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_active_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -472,13 +468,13 @@ async def test_get_active_rev_reg_not_found(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_active_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -493,14 +489,14 @@ async def test_get_tails_file(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock(tails_local_path="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock(tails_local_path="dummy") ) ) @@ -514,13 +510,13 @@ async def test_get_tails_file_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -535,15 +531,15 @@ async def test_upload_tails_file_basic(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_upload = async_mock.CoroutineMock() - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_upload = mock.CoroutineMock() + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -561,12 +557,12 @@ async def test_upload_tails_file_no_local_tails_file(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=False, ) @@ -582,13 +578,13 @@ async def test_upload_tails_file_fail(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_upload = async_mock.CoroutineMock(side_effect=RevocationError("test")) - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( + mock_upload = mock.CoroutineMock(side_effect=RevocationError("test")) + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -605,17 +601,17 @@ async def test_send_rev_reg_def(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - send_def=async_mock.CoroutineMock(), - send_entry=async_mock.CoroutineMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + send_def=mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -630,13 +626,13 @@ async def test_send_rev_reg_def_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -651,13 +647,13 @@ async def test_send_rev_reg_def_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - send_def=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + send_def=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -673,16 +669,16 @@ async def test_send_rev_reg_entry(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.CoroutineMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + send_entry=mock.CoroutineMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -697,13 +693,13 @@ async def test_send_rev_reg_entry_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -718,13 +714,13 @@ async def test_send_rev_reg_entry_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + send_entry=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -739,23 +735,23 @@ async def test_update_rev_reg(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.CoroutineMock(), + save=mock.CoroutineMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -769,19 +765,19 @@ async def test_update_rev_reg_not_found(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -795,19 +791,19 @@ async def test_update_rev_reg_x(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -822,7 +818,7 @@ async def test_set_rev_reg_state(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", } @@ -831,17 +827,17 @@ async def test_set_rev_reg_state(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - set_state=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( + return_value=mock.MagicMock( + set_state=mock.CoroutineMock(), + save=mock.CoroutineMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -855,7 +851,7 @@ async def test_set_rev_reg_state_not_found(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", } @@ -864,13 +860,13 @@ async def test_set_rev_reg_state_not_found(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -880,14 +876,14 @@ async def test_set_rev_reg_state_not_found(self): mock_json_response.assert_not_called() async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock( + mock_app = mock.MagicMock( _state={ "swagger_dict": { "paths": { @@ -906,7 +902,7 @@ async def test_post_process_routes(self): assert "tags" in mock_app._state["swagger_dict"] -class TestDeleteTails(unittest.TestCase): +class TestDeleteTails(IsolatedAsyncioTestCase): def setUp(self): self.rev_reg_id = "rev_reg_id_123" self.cred_def_id = "cred_def_id_456" @@ -917,6 +913,7 @@ def setUp(self): os.makedirs(self.main_dir_rev) open(self.tails_path, "w").close() + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_by_rev_reg_id(self): # Setup rev_reg_id = self.rev_reg_id @@ -930,6 +927,7 @@ async def test_delete_tails_by_rev_reg_id(self): self.assertEqual(result, {"message": "All files deleted successfully"}) self.assertFalse(os.path.exists(self.tails_path)) + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_by_cred_def_id(self): # Setup cred_def_id = self.cred_def_id @@ -948,6 +946,7 @@ async def test_delete_tails_by_cred_def_id(self): self.assertFalse(os.path.exists(cred_dir)) self.assertTrue(os.path.exists(main_dir_cred)) + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_not_found(self): # Setup cred_def_id = "invalid_cred_def_id" @@ -961,6 +960,6 @@ async def test_delete_tails_not_found(self): self.assertEqual(result, {"message": "No such file or directory"}) self.assertTrue(os.path.exists(self.main_dir_rev)) - async def tearDown(self): + def tearDown(self): if os.path.exists(self.main_dir_rev): shutil.rmtree(self.main_dir_rev) diff --git a/aries_cloudagent/settings/tests/test_routes.py b/aries_cloudagent/settings/tests/test_routes.py index b17774c050..4c103bf2ba 100644 --- a/aries_cloudagent/settings/tests/test_routes.py +++ b/aries_cloudagent/settings/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ...admin.request_context import AdminRequestContext from ...core.in_memory import InMemoryProfile @@ -15,7 +15,7 @@ @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -41,9 +41,9 @@ async def test_get_profile_settings(mock_response): profile=profile, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.CoroutineMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) await test_module.get_profile_settings(request) @@ -71,16 +71,16 @@ async def test_get_profile_settings(mock_response): }, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.CoroutineMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( multi_tenant_manager, "get_wallet_and_profile" ) as get_wallet_and_profile: get_wallet_and_profile.return_value = ( - async_mock.MagicMock( + mock.MagicMock( settings={ "admin.admin_client_max_request_size": 1, "debug.auto_respond_credential_offer": True, @@ -120,9 +120,9 @@ async def test_update_profile_settings(mock_response): profile=profile, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.CoroutineMock( + json=mock.CoroutineMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -161,9 +161,9 @@ async def test_update_profile_settings(mock_response): }, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.CoroutineMock( + json=mock.CoroutineMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -176,13 +176,13 @@ async def test_update_profile_settings(mock_response): ), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( multi_tenant_manager, "update_wallet" - ) as update_wallet, async_mock.patch.object( + ) as update_wallet, mock.patch.object( multi_tenant_manager, "get_wallet_and_profile" ) as get_wallet_and_profile: get_wallet_and_profile.return_value = ( - async_mock.MagicMock( + mock.MagicMock( settings={ "admin.admin_client_max_request_size": 1, "debug.auto_respond_credential_offer": True, @@ -198,7 +198,7 @@ async def test_update_profile_settings(mock_response): ), profile, ) - update_wallet.return_value = async_mock.MagicMock( + update_wallet.return_value = mock.MagicMock( settings={ "public_invites": False, "debug.invite_public": False, diff --git a/aries_cloudagent/storage/tests/conftest.py b/aries_cloudagent/storage/tests/conftest.py new file mode 100644 index 0000000000..ea37361764 --- /dev/null +++ b/aries_cloudagent/storage/tests/conftest.py @@ -0,0 +1,15 @@ +import pytest +from ...storage.record import StorageRecord + + +@pytest.fixture +def record_factory(): + def _test_record(tags={}): + return StorageRecord(type="TYPE", value="TEST", tags=tags) + + yield _test_record + + +@pytest.fixture +def missing(): + yield StorageRecord(type="__MISSING__", value="000000000") diff --git a/aries_cloudagent/storage/tests/test_askar_storage.py b/aries_cloudagent/storage/tests/test_askar_storage.py index b1a146a45d..a7d9883273 100644 --- a/aries_cloudagent/storage/tests/test_askar_storage.py +++ b/aries_cloudagent/storage/tests/test_askar_storage.py @@ -2,9 +2,9 @@ import pytest import os -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...askar.profile import AskarProfileManager from ...config.injection_context import InjectionContext @@ -49,16 +49,16 @@ class TestAskarStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.skip @pytest.mark.asyncio async def test_record(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -148,8 +148,8 @@ async def test_record(self): with pytest.raises(StorageError): await storage.get_record("connection", None) - with async_mock.patch.object( - test_module.non_secrets, "get_wallet_record", async_mock.CoroutineMock() + with mock.patch.object( + test_module.non_secrets, "get_wallet_record", mock.CoroutineMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -157,18 +157,18 @@ async def test_record(self): with pytest.raises(test_module.StorageError): await storage.get_record("connection", "dummy-id") - with async_mock.patch.object( + with mock.patch.object( test_module.non_secrets, "update_wallet_record_value", - async_mock.CoroutineMock(), - ) as mock_update_value, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_update_value, mock.patch.object( test_module.non_secrets, "update_wallet_record_tags", - async_mock.CoroutineMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_update_tags, mock.patch.object( test_module.non_secrets, "delete_wallet_record", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -212,16 +212,16 @@ async def test_record(self): @pytest.mark.skip @pytest.mark.asyncio async def test_storage_search_x(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -249,10 +249,10 @@ async def test_storage_search_x(self): with pytest.raises(StorageSearchError): await search.fetch(10) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -260,14 +260,14 @@ async def test_storage_search_x(self): await search.open() await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.CoroutineMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -276,10 +276,10 @@ async def test_storage_search_x(self): await search.fetch(10) await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -357,16 +357,14 @@ async def test_postgres_wallet_storage_works(self): await postgres_wallet.remove() -class TestAskarStorageSearchSession(AsyncTestCase): +class TestAskarStorageSearchSession(IsolatedAsyncioTestCase): @pytest.mark.asyncio async def test_askar_storage_search_session(self): profile = "profileId" - with async_mock.patch( - "aries_cloudagent.storage.askar.AskarProfile" - ) as AskarProfile: + with mock.patch("aries_cloudagent.storage.askar.AskarProfile") as AskarProfile: askar_profile = AskarProfile(None, True) - askar_profile_scan = async_mock.MagicMock() + askar_profile_scan = mock.MagicMock() askar_profile.store.scan.return_value = askar_profile_scan askar_profile.settings.get.return_value = profile diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index db0366c830..3d32a16930 100644 --- a/aries_cloudagent/storage/tests/test_in_memory_storage.py +++ b/aries_cloudagent/storage/tests/test_in_memory_storage.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...storage.error import ( @@ -29,14 +29,6 @@ def store_search(): yield InMemoryStorage(profile) -def test_record(tags={}): - return StorageRecord(type="TYPE", value="TEST", tags=tags) - - -def test_missing_record(tags={}): - return StorageRecord(type="__MISSING__", value="000000000") - - class TestInMemoryStorage: def test_repr(self, store): assert store.__class__.__name__ in str(store) @@ -47,20 +39,19 @@ async def test_add_required(self, store): await store.add_record(None) @pytest.mark.asyncio - async def test_add_id_required(self, store): - record = test_record()._replace(id=None) + async def test_add_id_required(self, store, record_factory): + record = record_factory()._replace(id=None) with pytest.raises(StorageError): await store.add_record(record) @pytest.mark.asyncio - async def test_retrieve_missing(self, store): - missing = test_missing_record() + async def test_retrieve_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.get_record(missing.type, missing.id) @pytest.mark.asyncio - async def test_add_retrieve(self, store): - record = test_record() + async def test_add_retrieve(self, store, record_factory): + record = record_factory() await store.add_record(record) result = await store.get_record(record.type, record.id) assert result @@ -73,26 +64,25 @@ async def test_add_retrieve(self, store): await store.add_record(record) @pytest.mark.asyncio - async def test_delete(self, store): - record = test_record() + async def test_delete(self, store, record_factory): + record = record_factory() await store.add_record(record) await store.delete_record(record) with pytest.raises(StorageNotFoundError): await store.get_record(record.type, record.id) @pytest.mark.asyncio - async def test_delete_missing(self, store): - missing = test_missing_record() + async def test_delete_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.delete_record(missing) @pytest.mark.asyncio - async def test_update_record(self, store): + async def test_update_record(self, store, record_factory): init_value = "a" init_tags = {"a": "a", "b": "b"} upd_value = "b" upd_tags = {"a": "A", "c": "C"} - record = test_record(init_tags)._replace(value=init_value) + record = record_factory(init_tags)._replace(value=init_value) await store.add_record(record) assert record.value == init_value assert record.tags == init_tags @@ -102,14 +92,13 @@ async def test_update_record(self, store): assert result.tags == upd_tags @pytest.mark.asyncio - async def test_update_missing(self, store): - missing = test_missing_record() + async def test_update_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.update_record(missing, missing.value, {}) @pytest.mark.asyncio - async def test_find_record(self, store): - record = test_record() + async def test_find_record(self, store, record_factory): + record = record_factory() await store.add_record(record) # search with find_record @@ -125,14 +114,14 @@ async def test_find_record(self, store): _ = await store.find_record("NOT-MY-TYPE", {}, None) # search again with find_row on multiple rows - record = test_record() + record = record_factory() await store.add_record(record) with pytest.raises(StorageDuplicateError): await store.find_record(record.type, {}, None) @pytest.mark.asyncio - async def test_find_all(self, store): - record = test_record() + async def test_find_all(self, store, record_factory): + record = record_factory() await store.add_record(record) # search @@ -145,8 +134,8 @@ async def test_find_all(self, store): assert found.tags == record.tags @pytest.mark.asyncio - async def test_delete_all(self, store): - record = test_record({"tag": "one"}) + async def test_delete_all(self, store, record_factory): + record = record_factory({"tag": "one"}) await store.add_record(record) await store.delete_all_records(record.type, {"tag": "two"}) @@ -159,8 +148,8 @@ async def test_delete_all(self, store): class TestInMemoryStorageSearch: @pytest.mark.asyncio - async def test_search(self, store_search): - record = test_record() + async def test_search(self, store_search, record_factory): + record = record_factory() await store_search.add_record(record) # search @@ -182,18 +171,16 @@ async def test_search(self, store_search): # search again with with iterator mystery error search = store_search.search_records(record.type, {}, None) - with async_mock.patch.object( - search, "fetch", async_mock.CoroutineMock() - ) as mock_fetch: - mock_fetch.return_value = async_mock.MagicMock( - pop=async_mock.MagicMock(side_effect=IndexError()) + with mock.patch.object(search, "fetch", mock.CoroutineMock()) as mock_fetch: + mock_fetch.return_value = mock.MagicMock( + pop=mock.MagicMock(side_effect=IndexError()) ) async for row in search: pytest.fail("Should not arrive here") @pytest.mark.asyncio - async def test_iter_search(self, store_search): - record = test_record() + async def test_iter_search(self, store_search, record_factory): + record = record_factory() await store_search.add_record(record) count = 0 search = store_search.search_records(record.type, {}, None) @@ -215,9 +202,9 @@ async def test_closed_search(self, store_search): class TestInMemoryTagQuery: @pytest.mark.asyncio - async def test_tag_value_match(self, store): + async def test_tag_value_match(self, store, record_factory): TAGS = {"a": "aardvark", "b": "bear", "z": "0"} - record = test_record(TAGS) + record = record_factory(TAGS) await store.add_record(record) assert not tag_value_match(None, {"$neq": "octopus"}) @@ -245,9 +232,9 @@ async def test_tag_value_match(self, store): assert "Unsupported match operator" in str(excinfo.value) @pytest.mark.asyncio - async def test_tag_query_match(self, store): + async def test_tag_query_match(self, store, record_factory): TAGS = {"a": "aardvark", "b": "bear", "z": "0"} - record = test_record(TAGS) + record = record_factory(TAGS) await store.add_record(record) assert tag_query_match(None, None) diff --git a/aries_cloudagent/storage/tests/test_indy_storage.py b/aries_cloudagent/storage/tests/test_indy_storage.py index ff1092cf61..77e4c8f3e2 100644 --- a/aries_cloudagent/storage/tests/test_indy_storage.py +++ b/aries_cloudagent/storage/tests/test_indy_storage.py @@ -9,7 +9,7 @@ import indy.wallet from indy.error import ErrorCode -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ...config.injection_context import InjectionContext from ...indy.sdk.profile import IndySdkProfileManager, IndySdkProfile @@ -28,7 +28,7 @@ async def make_profile(): key = await IndySdkWallet.generate_wallet_key() context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): return await IndySdkProfileManager().provision( context, { @@ -63,20 +63,20 @@ class TestIndySdkStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.asyncio async def test_record(self): - with async_mock.patch( + with mock.patch( "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): config = { @@ -171,8 +171,8 @@ async def test_record(self): with pytest.raises(StorageError): await storage.get_record("connection", None) - with async_mock.patch.object( - indy.non_secrets, "get_wallet_record", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "get_wallet_record", mock.CoroutineMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -180,18 +180,18 @@ async def test_record(self): with pytest.raises(test_module.StorageError): await storage.get_record("connection", "dummy-id") - with async_mock.patch.object( + with mock.patch.object( indy.non_secrets, "update_wallet_record_value", - async_mock.CoroutineMock(), - ) as mock_update_value, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_update_value, mock.patch.object( indy.non_secrets, "update_wallet_record_tags", - async_mock.CoroutineMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.CoroutineMock(), + ) as mock_update_tags, mock.patch.object( indy.non_secrets, "delete_wallet_record", - async_mock.CoroutineMock(), + mock.CoroutineMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -234,20 +234,20 @@ async def test_record(self): @pytest.mark.asyncio async def test_storage_search_x(self): - with async_mock.patch( + with mock.patch( "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): context = InjectionContext() @@ -279,10 +279,10 @@ async def test_storage_search_x(self): with pytest.raises(StorageSearchError): await search.fetch(10) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -290,14 +290,14 @@ async def test_storage_search_x(self): await search.fetch() await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.CoroutineMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + mock.CoroutineMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -305,10 +305,10 @@ async def test_storage_search_x(self): await search.fetch(10) await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -317,17 +317,17 @@ async def test_storage_search_x(self): @pytest.mark.asyncio async def test_storage_del_close(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() - ) as mock_delete, async_mock.patch.object( + with mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): context = InjectionContext() @@ -345,10 +345,10 @@ async def test_storage_del_close(self): session = await fake_profile.session() storage = session.inject(BaseStorage) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.return_value = 1 search = storage.search_records("connection") @@ -363,10 +363,10 @@ async def test_storage_del_close(self): c += 1 mock_indy_close_search.assert_awaited_with(1) - with async_mock.patch.object( # error on close - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + with mock.patch.object( # error on close + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") mock_indy_open_search.return_value = 1 @@ -375,18 +375,18 @@ async def test_storage_del_close(self): with pytest.raises(StorageSearchError): await search.close() - with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_close_search, async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + with mock.patch.object( # run on event loop until complete + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() + ) as mock_indy_close_search, mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: coros = [] - mock_get_event_loop.return_value = async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( create_task=lambda c: coros.append(c), - is_running=async_mock.MagicMock(return_value=False), - run_until_complete=async_mock.MagicMock(), + is_running=mock.MagicMock(return_value=False), + run_until_complete=mock.MagicMock(), ) mock_indy_open_search.return_value = 1 search = storage.search_records("connection") @@ -401,18 +401,18 @@ async def test_storage_del_close(self): for coro in coros: await coro - with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() - ) as mock_indy_close_search, async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + with mock.patch.object( # run on event loop until complete + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() + ) as mock_indy_close_search, mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: coros = [] - mock_get_event_loop.return_value = async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( create_task=lambda c: coros.append(c), - is_running=async_mock.MagicMock(return_value=False), - run_until_complete=async_mock.MagicMock(), + is_running=mock.MagicMock(return_value=False), + run_until_complete=mock.MagicMock(), ) mock_indy_open_search.return_value = 1 mock_indy_close_search.side_effect = ValueError("Dave's not here") diff --git a/aries_cloudagent/storage/vc_holder/tests/conftest.py b/aries_cloudagent/storage/vc_holder/tests/conftest.py new file mode 100644 index 0000000000..62ed6f92f6 --- /dev/null +++ b/aries_cloudagent/storage/vc_holder/tests/conftest.py @@ -0,0 +1,56 @@ +"""Fixtures for vc holder tests.""" + +import pytest +from ..vc_record import VCRecord + +VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" +VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" +VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" +VC_PROOF_TYPE = "Ed25519Signature2018" +VC_ISSUER_ID = "https://example.edu/issuers/14" +VC_SCHEMA_ID = "https://example.org/examples/degree.json" +VC_GIVEN_ID = "http://example.edu/credentials/3732" + + +@pytest.fixture +def record(): + yield VCRecord( + contexts=[ + VC_CONTEXT, + "https://www.w3.org/2018/credentials/examples/v1", + ], + expanded_types=[ + VC_TYPE, + "https://example.org/examples#UniversityDegreeCredential", + ], + schema_ids=[VC_SCHEMA_ID], + issuer_id=VC_ISSUER_ID, + subject_ids=[VC_SUBJECT_ID], + proof_types=[VC_PROOF_TYPE], + given_id=VC_GIVEN_ID, + cred_tags={"tag": "value"}, + cred_value={ + "@context": [ + VC_CONTEXT, + "https://www.w3.org/2018/credentials/examples/v1", + ], + "id": VC_GIVEN_ID, + "type": ["VerifiableCredential", "UniversityDegreeCredential"], + "issuer": VC_ISSUER_ID, + "identifier": "83627467", + "name": "University Degree", + "issuanceDate": "2010-01-01T19:53:24Z", + "credentialSubject": { + "id": VC_SUBJECT_ID, + "givenName": "Cai", + "familyName": "Leblanc", + }, + "proof": { + "type": "Ed25519Signature2018", + "verificationMethod": "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", + "created": "2021-05-07T08:50:17.626625", + "proofPurpose": "assertionMethod", + "jws": "eyJhbGciOiAiRWREU0EiLCAiYjY0IjogZmFsc2UsICJjcml0IjogWyJiNjQiXX0..rubQvgig7cN-F6cYn_AJF1BCSaMpkoR517Ot_4pqwdJnQ-JwKXq6d6cNos5JR73E9WkwYISXapY0fYTIG9-fBA", + }, + }, + ) diff --git a/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py index c36fa9b4b3..315a20f553 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py @@ -10,15 +10,6 @@ from . import test_in_memory_vc_holder as in_memory -VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" -VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" -VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" -VC_PROOF_TYPE = "Ed25519Signature2018" -VC_ISSUER_ID = "https://example.edu/issuers/14" -VC_SCHEMA_ID = "https://example.org/examples/degree.json" -VC_GIVEN_ID = "http://example.edu/credentials/3732" - - async def make_profile(): context = InjectionContext() profile = await AskarProfileManager().provision( @@ -41,55 +32,11 @@ async def holder(): await profile.close() -def test_record() -> VCRecord: - return VCRecord( - contexts=[ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - expanded_types=[ - VC_TYPE, - "https://example.org/examples#UniversityDegreeCredential", - ], - schema_ids=[VC_SCHEMA_ID], - issuer_id=VC_ISSUER_ID, - subject_ids=[VC_SUBJECT_ID], - proof_types=[VC_PROOF_TYPE], - given_id=VC_GIVEN_ID, - cred_tags={"tag": "value"}, - cred_value={ - "@context": [ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - "id": VC_GIVEN_ID, - "type": ["VerifiableCredential", "UniversityDegreeCredential"], - "issuer": VC_ISSUER_ID, - "identifier": "83627467", - "name": "University Degree", - "issuanceDate": "2010-01-01T19:53:24Z", - "credentialSubject": { - "id": VC_SUBJECT_ID, - "givenName": "Cai", - "familyName": "Leblanc", - }, - "proof": { - "type": "Ed25519Signature2018", - "verificationMethod": "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - "created": "2021-05-07T08:50:17.626625", - "proofPurpose": "assertionMethod", - "jws": "eyJhbGciOiAiRWREU0EiLCAiYjY0IjogZmFsc2UsICJjcml0IjogWyJiNjQiXX0..rubQvgig7cN-F6cYn_AJF1BCSaMpkoR517Ot_4pqwdJnQ-JwKXq6d6cNos5JR73E9WkwYISXapY0fYTIG9-fBA", - }, - }, - ) - - -@pytest.mark.indy class TestAskarVCHolder(in_memory.TestInMemoryVCHolder): # run same test suite with different holder fixture @pytest.mark.asyncio - async def test_tag_query(self, holder: VCHolder): + async def test_tag_query(self, holder: VCHolder, record: VCRecord): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential", @@ -119,7 +66,6 @@ async def test_tag_query(self, holder: VCHolder): }, ] } - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) diff --git a/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py index 2c3309d010..ca465b642c 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py @@ -22,8 +22,9 @@ def holder(): yield profile.inject(VCHolder) -def test_record() -> VCRecord: - return VCRecord( +@pytest.fixture +def record(): + yield VCRecord( contexts=[ VC_CONTEXT, "https://www.w3.org/2018/credentials/examples/v1", @@ -70,7 +71,7 @@ def test_repr(self, holder): assert holder.__class__.__name__ in str(holder) @pytest.mark.asyncio - async def test_tag_query(self, holder: VCHolder): + async def test_tag_query(self, holder: VCHolder, record: VCRecord): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential", @@ -100,7 +101,6 @@ async def test_tag_query(self, holder: VCHolder): }, ] } - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) @@ -286,12 +286,13 @@ async def test_sorting_vcrecord(self, holder: VCHolder): assert rows == expected @pytest.mark.asyncio - async def test_tag_query_valid_and_operator(self, holder: VCHolder): + async def test_tag_query_valid_and_operator( + self, holder: VCHolder, record: VCRecord + ): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential2", ] - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) @@ -299,8 +300,7 @@ async def test_tag_query_valid_and_operator(self, holder: VCHolder): assert rows == [] @pytest.mark.asyncio - async def test_store_retrieve(self, holder: VCHolder): - record = test_record() + async def test_store_retrieve(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) result = await holder.retrieve_credential_by_id(record.record_id) assert result == record @@ -318,16 +318,14 @@ async def test_store_retrieve(self, holder: VCHolder): await holder.retrieve_credential_by_given_id("missing") @pytest.mark.asyncio - async def test_delete(self, holder: VCHolder): - record = test_record() + async def test_delete(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) await holder.delete_credential(record) with pytest.raises(StorageNotFoundError): await holder.retrieve_credential_by_id(record.record_id) @pytest.mark.asyncio - async def test_search(self, holder: VCHolder): - record = test_record() + async def test_search(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) search = holder.search_credentials() diff --git a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py index fa092511b4..3009e61b1e 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock from ....config.injection_context import InjectionContext @@ -8,26 +8,16 @@ from ....wallet.indy import IndySdkWallet from ..base import VCHolder -from ..vc_record import VCRecord from . import test_in_memory_vc_holder as in_memory -VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" -VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" -VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" -VC_PROOF_TYPE = "Ed25519Signature2018" -VC_ISSUER_ID = "https://example.edu/issuers/14" -VC_SCHEMA_ID = "https://example.org/examples/degree.json" -VC_GIVEN_ID = "http://example.edu/credentials/3732" - - async def make_profile(): key = await IndySdkWallet.generate_wallet_key() context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): return await IndySdkProfileManager().provision( context, { @@ -48,26 +38,6 @@ async def holder(): await profile.close() -def test_record() -> VCRecord: - return VCRecord( - contexts=[ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - expanded_types=[ - VC_TYPE, - "https://example.org/examples#UniversityDegreeCredential", - ], - schema_ids=[VC_SCHEMA_ID], - issuer_id=VC_ISSUER_ID, - subject_ids=[VC_SUBJECT_ID], - proof_types=[VC_PROOF_TYPE], - given_id=VC_GIVEN_ID, - cred_tags={"tag": "value"}, - cred_value={"...": "..."}, - ) - - @pytest.mark.indy class TestIndySdkVCHolder(in_memory.TestInMemoryVCHolder): # run same test suite with different holder fixture diff --git a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py index f3d8456f83..33dcd061bb 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py @@ -1,4 +1,6 @@ -from asynctest import TestCase as AsyncTestCase +from typing import Callable + +import pytest from ....messaging.models.base import BaseModelError @@ -120,38 +122,41 @@ CRED_VALUE = {"...": "..."} -def test_record() -> VCRecord: - return VCRecord( - contexts=CONTEXTS, - expanded_types=TYPES, - schema_ids=SCHEMA_IDS, - issuer_id=ISSUER_ID, - subject_ids=SUBJECT_IDS, - proof_types=PROOF_TYPES, - cred_value=CRED_VALUE, - given_id=GIVEN_ID, - cred_tags=CRED_TAGS, - ) +@pytest.fixture +def record(): + def _record(): + return VCRecord( + contexts=CONTEXTS, + expanded_types=TYPES, + schema_ids=SCHEMA_IDS, + issuer_id=ISSUER_ID, + subject_ids=SUBJECT_IDS, + proof_types=PROOF_TYPES, + cred_value=CRED_VALUE, + given_id=GIVEN_ID, + cred_tags=CRED_TAGS, + ) + yield _record -class TestVCRecord(AsyncTestCase): - def test_create(self): - record = test_record() - assert record.contexts == set(CONTEXTS) - assert record.expanded_types == set(TYPES) - assert record.schema_ids == set(SCHEMA_IDS) - assert record.subject_ids == set(SUBJECT_IDS) - assert record.proof_types == set(PROOF_TYPES) - assert record.issuer_id == ISSUER_ID - assert record.given_id == GIVEN_ID - assert record.record_id and isinstance(record.record_id, str) - assert record.cred_tags == CRED_TAGS - assert record.cred_value == CRED_VALUE +class TestVCRecord: + def test_create(self, record: Callable[[], VCRecord]): + record_a = record() + assert record_a.contexts == set(CONTEXTS) + assert record_a.expanded_types == set(TYPES) + assert record_a.schema_ids == set(SCHEMA_IDS) + assert record_a.subject_ids == set(SUBJECT_IDS) + assert record_a.proof_types == set(PROOF_TYPES) + assert record_a.issuer_id == ISSUER_ID + assert record_a.given_id == GIVEN_ID + assert record_a.record_id and isinstance(record_a.record_id, str) + assert record_a.cred_tags == CRED_TAGS + assert record_a.cred_value == CRED_VALUE - def test_eq(self): - record_a = test_record() - record_b = test_record() + def test_eq(self, record: Callable[[], VCRecord]): + record_a = record() + record_b = record() assert record_a != record_b record_b.record_id = record_a.record_id @@ -160,12 +165,12 @@ def test_eq(self): record_b.contexts.clear() assert record_a != record_b - async def test_serde(self): - obj = test_record().serialize() - record = VCRecord.deserialize(obj) - assert type(record) == VCRecord + def test_serde(self, record: Callable[[], VCRecord]): + obj = record().serialize() + rec = VCRecord.deserialize(obj) + assert isinstance(rec, VCRecord) - obj_x = test_record() + obj_x = record() obj_x.cred_tags = -1 # not a dict - with self.assertRaises(BaseModelError): + with pytest.raises(BaseModelError): obj_x.serialize() diff --git a/aries_cloudagent/tails/tests/test_indy.py b/aries_cloudagent/tails/tests/test_indy.py index 082d772955..1bbdcbefe4 100644 --- a/aries_cloudagent/tails/tests/test_indy.py +++ b/aries_cloudagent/tails/tests/test_indy.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -12,7 +13,7 @@ REV_REG_ID = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:0" -class TestIndyTailsServer(AsyncTestCase): +class TestIndyTailsServer(IsolatedAsyncioTestCase): async def test_upload_no_tails_upload_url_x(self): context = InjectionContext(settings={"ledger.genesis_transactions": "dummy"}) indy_tails = test_module.IndyTailsServer() @@ -29,8 +30,8 @@ async def test_upload(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -48,8 +49,8 @@ async def test_upload_indy_sdk(self): profile.settings["tails_server_upload_url"] = "http://1.2.3.4:8088" profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_write_ledgers=async_mock.CoroutineMock( + mock.MagicMock( + get_write_ledgers=mock.CoroutineMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -57,11 +58,11 @@ async def test_upload_indy_sdk(self): ) ), ) - profile.context.injector.bind_instance(BaseLedger, async_mock.MagicMock()) + profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -79,8 +80,8 @@ async def test_upload_indy_vdr(self): profile.settings["tails_server_upload_url"] = "http://1.2.3.4:8088" profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_write_ledgers=async_mock.CoroutineMock( + mock.MagicMock( + get_write_ledgers=mock.CoroutineMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -88,11 +89,11 @@ async def test_upload_indy_vdr(self): ) ), ) - profile.context.injector.bind_instance(BaseLedger, async_mock.MagicMock()) + profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -114,8 +115,8 @@ async def test_upload_x(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() ) as mock_put: mock_put.side_effect = test_module.PutError("Server down for maintenance") diff --git a/aries_cloudagent/tests/mock.py b/aries_cloudagent/tests/mock.py new file mode 100644 index 0000000000..0df4f3bd3b --- /dev/null +++ b/aries_cloudagent/tests/mock.py @@ -0,0 +1,20 @@ +"""Mock utilities.""" +from unittest.mock import AsyncMock, MagicMock, patch, create_autospec, Mock, ANY + + +def CoroutineMock(*args, **kwargs): + """Return an AsyncMock that returns a MagicMock, unless return_value is set.""" + if "return_value" in kwargs: + return AsyncMock(*args, **kwargs) + return AsyncMock(*args, **kwargs, return_value=MagicMock()) + + +__all__ = [ + "CoroutineMock", + "AsyncMock", + "MagicMock", + "patch", + "create_autospec", + "Mock", + "ANY", +] diff --git a/aries_cloudagent/tests/test_main.py b/aries_cloudagent/tests/test_main.py index 5bc72503b8..70c0589d43 100644 --- a/aries_cloudagent/tests/test_main.py +++ b/aries_cloudagent/tests/test_main.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .. import __main__ as test_module diff --git a/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py b/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py index c5f8f19a1e..e60ddcfcea 100644 --- a/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py +++ b/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....connections.models.connection_target import ConnectionTarget from ....transport.outbound.message import OutboundMessage @@ -6,7 +6,7 @@ from ..delivery_queue import DeliveryQueue -class TestDeliveryQueue(AsyncTestCase): +class TestDeliveryQueue(IsolatedAsyncioTestCase): async def test_message_add_and_check(self): queue = DeliveryQueue() diff --git a/aries_cloudagent/transport/inbound/tests/test_http_transport.py b/aries_cloudagent/transport/inbound/tests/test_http_transport.py index aea3f2e740..2d6baaac6c 100644 --- a/aries_cloudagent/transport/inbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ import json from aiohttp.test_utils import AioHTTPTestCase, unused_port -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -61,7 +61,7 @@ def receive_message( message: InboundMessage, can_respond: bool = False, ): - message.wait_processing_complete = async_mock.CoroutineMock() + message.wait_processing_complete = mock.CoroutineMock() self.message_results.append((message.payload, message.receipt, can_respond)) if self.result_event: self.result_event.set() @@ -72,11 +72,11 @@ def get_application(self): return self.transport.make_application() async def test_start_x(self): - with async_mock.patch.object( - test_module.web, "TCPSite", async_mock.MagicMock() + with mock.patch.object( + test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: - mock_site.return_value = async_mock.MagicMock( - start=async_mock.CoroutineMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.CoroutineMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() @@ -113,28 +113,28 @@ async def test_send_message_outliers(self): await self.transport.start() test_message = {"test": "message"} - with async_mock.patch.object( - test_module.HttpTransport, "create_session", async_mock.CoroutineMock() + with mock.patch.object( + test_module.HttpTransport, "create_session", mock.CoroutineMock() ) as mock_session: - mock_session.return_value = async_mock.MagicMock( - receive=async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - receipt=async_mock.MagicMock(direct_response_requested=True), - wait_processing_complete=async_mock.CoroutineMock(), + mock_session.return_value = mock.MagicMock( + receive=mock.CoroutineMock( + return_value=mock.MagicMock( + receipt=mock.MagicMock(direct_response_requested=True), + wait_processing_complete=mock.CoroutineMock(), ) ), can_respond=True, profile=InMemoryProfile.test_profile(), - clear_response=async_mock.MagicMock(), - wait_response=async_mock.CoroutineMock(return_value=b"Hello world"), + clear_response=mock.MagicMock(), + wait_response=mock.CoroutineMock(return_value=b"Hello world"), response_buffer="something", ) async with self.client.post("/", data=test_message) as resp: result = await resp.text() assert result == "Hello world" - mock_session.return_value = async_mock.MagicMock( - receive=async_mock.CoroutineMock( + mock_session.return_value = mock.MagicMock( + receive=mock.CoroutineMock( side_effect=test_module.WireFormatParseError() ), profile=InMemoryProfile.test_profile(), @@ -150,12 +150,12 @@ async def test_send_message_outliers(self): async def test_invite_message_handler(self): await self.transport.start() - request = async_mock.MagicMock(query={"c_i": "dummy"}) + request = mock.MagicMock(query={"c_i": "dummy"}) resp = await self.transport.invite_message_handler(request) assert b"You have received a connection invitation" in resp.body assert resp.status == 200 - request = async_mock.MagicMock(query={}) + request = mock.MagicMock(query={}) resp = await self.transport.invite_message_handler(request) assert resp.body is None assert resp.status == 200 diff --git a/aries_cloudagent/transport/inbound/tests/test_manager.py b/aries_cloudagent/transport/inbound/tests/test_manager.py index 7b0e2f4424..7c9d8c846e 100644 --- a/aries_cloudagent/transport/inbound/tests/test_manager.py +++ b/aries_cloudagent/transport/inbound/tests/test_manager.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -9,7 +10,7 @@ from ..manager import InboundTransportManager -class TestInboundTransportManager(AsyncTestCase): +class TestInboundTransportManager(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() @@ -44,7 +45,7 @@ async def test_setup(self): ) mgr = InboundTransportManager(self.profile, None) - with async_mock.patch.object(mgr, "register") as mock_register: + with mock.patch.object(mgr, "register") as mock_register: await mgr.setup() mock_register.assert_called_once() tcfg: InboundTransportConfiguration = mock_register.call_args[0][0] @@ -57,9 +58,9 @@ async def test_setup(self): assert mgr.undelivered_queue async def test_start_stop(self): - transport = async_mock.MagicMock() - transport.start = async_mock.CoroutineMock() - transport.stop = async_mock.CoroutineMock() + transport = mock.MagicMock() + transport.start = mock.CoroutineMock() + transport.stop = mock.CoroutineMock() mgr = InboundTransportManager(self.profile, None) mgr.register_transport(transport, "transport_cls") @@ -72,10 +73,10 @@ async def test_start_stop(self): transport.stop.assert_awaited_once_with() async def test_create_session(self): - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() self.profile.context.injector.bind_instance(BaseWireFormat, test_wire_format) - test_inbound_handler = async_mock.CoroutineMock() + test_inbound_handler = mock.CoroutineMock() mgr = InboundTransportManager(self.profile, test_inbound_handler) test_transport = "http" test_accept = True @@ -103,14 +104,14 @@ async def test_create_session(self): async def test_return_to_session(self): mgr = InboundTransportManager(self.profile, None) - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() session = await mgr.create_session("http", wire_format=test_wire_format) test_outbound = OutboundMessage(payload=None) test_outbound.reply_session_id = session.session_id - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: assert mgr.return_to_session(test_outbound) is True @@ -119,22 +120,22 @@ async def test_return_to_session(self): test_outbound = OutboundMessage(payload=None) test_outbound.reply_session_id = None - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=False ) as mock_accept: assert mgr.return_to_session(test_outbound) is False mock_accept.assert_called_once_with(test_outbound) - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: assert mgr.return_to_session(test_outbound) is True mock_accept.assert_called_once_with(test_outbound) async def test_close_return(self): - test_return = async_mock.MagicMock() + test_return = mock.MagicMock() mgr = InboundTransportManager(self.profile, None, return_inbound=test_return) - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() session = await mgr.create_session("http", wire_format=test_wire_format) @@ -146,8 +147,8 @@ async def test_close_return(self): async def test_dispatch_complete_undelivered(self): mgr = InboundTransportManager(self.profile, None) - test_wire_format = async_mock.MagicMock( - parse_message=async_mock.CoroutineMock(return_value=("payload", "receipt")) + test_wire_format = mock.MagicMock( + parse_message=mock.CoroutineMock(return_value=("payload", "receipt")) ) session = await mgr.create_session( "http", wire_format=test_wire_format, accept_undelivered=True @@ -157,7 +158,7 @@ async def test_dispatch_complete_undelivered(self): async def test_close_x(self): mgr = InboundTransportManager(self.profile, None) - mock_session = async_mock.MagicMock(response_buffer=async_mock.MagicMock()) + mock_session = mock.MagicMock(response_buffer=mock.MagicMock()) mgr.closed_session(mock_session) async def test_process_undelivered(self): @@ -165,7 +166,7 @@ async def test_process_undelivered(self): {"transport.enable_undelivered_queue": True} ) test_verkey = "test-verkey" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() mgr = InboundTransportManager(self.profile, None) await mgr.setup() @@ -179,7 +180,7 @@ async def test_process_undelivered(self): ) session.add_reply_verkeys(test_verkey) - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: mgr.process_undelivered(session) @@ -191,7 +192,7 @@ async def test_return_undelivered_false(self): {"transport.enable_undelivered_queue": False} ) test_verkey = "test-verkey" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() mgr = InboundTransportManager(self.profile, None) await mgr.setup() diff --git a/aries_cloudagent/transport/inbound/tests/test_message.py b/aries_cloudagent/transport/inbound/tests/test_message.py index 71a8defee8..3472ff300b 100644 --- a/aries_cloudagent/transport/inbound/tests/test_message.py +++ b/aries_cloudagent/transport/inbound/tests/test_message.py @@ -1,12 +1,12 @@ import asyncio -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase from ..message import InboundMessage from ..receipt import MessageReceipt -class TestInboundMessage(TestCase): +class TestInboundMessage(IsolatedAsyncioTestCase): async def test_wait_response(self): message = InboundMessage( payload="test", diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index e1e5fcd9cd..ae6424ed3e 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -1,7 +1,8 @@ import asyncio import pytest -from asynctest import TestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ....admin.server import AdminResponder from ....core.in_memory import InMemoryProfile @@ -17,16 +18,16 @@ from ..session import InboundSession -class TestInboundSession(TestCase): +class TestInboundSession(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() def test_init(self): - test_inbound = async_mock.MagicMock() + test_inbound = mock.MagicMock() test_session_id = "session-id" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() test_client_info = {"client": "info"} - test_close = async_mock.MagicMock() + test_close = mock.MagicMock() test_reply_mode = MessageReceipt.REPLY_MODE_ALL test_reply_thread_ids = {"1", "2"} test_reply_verkeys = {"3", "4"} @@ -53,8 +54,8 @@ def test_init(self): assert "1" in sess.reply_thread_ids assert "3" in sess.reply_verkeys - test_msg = async_mock.MagicMock() - with async_mock.patch.object(sess, "process_inbound") as process: + test_msg = mock.MagicMock() + with mock.patch.object(sess, "process_inbound") as process: sess.receive_inbound(test_msg) process.assert_called_once_with(test_msg) test_inbound.assert_called_once_with( @@ -88,10 +89,10 @@ def test_setters(self): async def test_parse_inbound(self): test_session_id = "session-id" test_transport_type = "transport-type" - test_wire_format = async_mock.MagicMock() - test_wire_format.parse_message = async_mock.CoroutineMock() + test_wire_format = mock.MagicMock() + test_wire_format.parse_message = mock.CoroutineMock() test_parsed = "parsed-payload" - test_receipt = async_mock.MagicMock() + test_receipt = mock.MagicMock() test_wire_format.parse_message.return_value = (test_parsed, test_receipt) sess = InboundSession( profile=self.profile, @@ -102,7 +103,7 @@ async def test_parse_inbound(self): ) session = self.profile.session() - setattr(self.profile, "session", async_mock.MagicMock(return_value=session)) + setattr(self.profile, "session", mock.MagicMock(return_value=session)) test_payload = "{}" result = await sess.parse_inbound(test_payload) @@ -113,18 +114,18 @@ async def test_parse_inbound(self): assert result.transport_type == test_transport_type async def test_receive(self): - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.CoroutineMock( - return_value=[async_mock.MagicMock(is_managed=True)] + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.CoroutineMock( + return_value=[mock.MagicMock(is_managed=True)] ) - self.multitenant_mgr.get_wallet_profile = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallet_profile = mock.CoroutineMock( return_value=self.profile ) self.profile.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) self.profile.context.update_settings({"multitenant.enabled": True}) - self.base_responder = async_mock.MagicMock(AdminResponder, autospec=True) + self.base_responder = mock.MagicMock(AdminResponder, autospec=True) self.profile.context.injector.bind_instance(BaseResponder, self.base_responder) sess = InboundSession( @@ -133,12 +134,12 @@ async def test_receive(self): session_id=None, wire_format=None, ) - test_msg = async_mock.MagicMock() + test_msg = mock.MagicMock() - with async_mock.patch.object( - sess, "parse_inbound", async_mock.CoroutineMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.CoroutineMock() + ) as encode, mock.patch.object( + sess, "receive_inbound", mock.MagicMock() ) as receive: result = await sess.receive(test_msg) encode.assert_awaited_once_with(test_msg) @@ -146,11 +147,11 @@ async def test_receive(self): assert result is encode.return_value async def test_receive_no_wallet_found(self): - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.CoroutineMock( + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.CoroutineMock( side_effect=ValueError("no such wallet") ) - self.multitenant_mgr.get_wallet_profile = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallet_profile = mock.CoroutineMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -164,12 +165,12 @@ async def test_receive_no_wallet_found(self): session_id=None, wire_format=None, ) - test_msg = async_mock.MagicMock() + test_msg = mock.MagicMock() - with async_mock.patch.object( - sess, "parse_inbound", async_mock.CoroutineMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.CoroutineMock() + ) as encode, mock.patch.object( + sess, "receive_inbound", mock.MagicMock() ) as receive: result = await sess.receive(test_msg) encode.assert_awaited_once_with(test_msg) @@ -266,11 +267,9 @@ async def test_wait_response(self): assert sess.response_event.is_set() assert sess.response_buffered - with async_mock.patch.object( - sess, "encode_outbound", async_mock.CoroutineMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.CoroutineMock()) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) - assert encode.awaited_once_with(test_msg) + encode.assert_awaited_once_with(test_msg) assert result is encode.return_value sess.clear_response() @@ -291,9 +290,7 @@ async def test_wait_response_x(self): assert sess.response_event.is_set() assert sess.response_buffered - with async_mock.patch.object( - sess, "encode_outbound", async_mock.CoroutineMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.CoroutineMock()) as encode: encode.side_effect = WireFormatError() with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(sess.wait_response(), 0.1) @@ -304,8 +301,8 @@ async def test_wait_response_x(self): assert await asyncio.wait_for(sess.wait_response(), 0.1) is None async def test_encode_response(self): - test_wire_format = async_mock.MagicMock() - test_wire_format.encode_message = async_mock.CoroutineMock() + test_wire_format = mock.MagicMock() + test_wire_format.encode_message = mock.CoroutineMock() sess = InboundSession( profile=self.profile, inbound_handler=None, @@ -317,7 +314,7 @@ async def test_encode_response(self): test_to_verkey = "to-verkey" session = self.profile.session() - setattr(self.profile, "session", async_mock.MagicMock(return_value=session)) + setattr(self.profile, "session", mock.MagicMock(return_value=session)) with self.assertRaises(WireFormatError): await sess.encode_outbound(test_msg) @@ -346,7 +343,7 @@ async def test_accept_response(self): ) test_msg = OutboundMessage(payload=None) - with async_mock.patch.object(sess, "select_outbound") as selector: + with mock.patch.object(sess, "select_outbound") as selector: selector.return_value = False accepted = sess.accept_response(test_msg) diff --git a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py index 03250fe7f9..52d71e8f90 100644 --- a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py @@ -3,7 +3,7 @@ import pytest from aiohttp.test_utils import AioHTTPTestCase, unused_port -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile @@ -68,11 +68,11 @@ def receive_message( self.result_event.set() async def test_start_x(self): - with async_mock.patch.object( - test_module.web, "TCPSite", async_mock.MagicMock() + with mock.patch.object( + test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: - mock_site.return_value = async_mock.MagicMock( - start=async_mock.CoroutineMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.CoroutineMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() @@ -86,7 +86,7 @@ async def test_message_and_response(self): async with self.client.ws_connect("/") as ws: self.result_event = asyncio.Event() await ws.send_json(test_message) - await asyncio.wait((self.result_event.wait(),), timeout=0.1) + await asyncio.wait_for(self.result_event.wait(), timeout=0.1) assert self.session is not None assert len(self.message_results) == 1 diff --git a/aries_cloudagent/transport/outbound/tests/test_http_transport.py b/aries_cloudagent/transport/outbound/tests/test_http_transport.py index 3dc96d35bc..707d74c05d 100644 --- a/aries_cloudagent/transport/outbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ from aiohttp.test_utils import AioHTTPTestCase from aiohttp import web -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....utils.stats import Collector @@ -129,13 +129,13 @@ async def test_transport_coverage(self): with pytest.raises(OutboundTransportError): await transport.handle_message(None, None, None) - with async_mock.patch.object( - transport, "client_session", async_mock.MagicMock() + with mock.patch.object( + transport, "client_session", mock.MagicMock() ) as mock_session: - mock_response = async_mock.MagicMock(status=404) - mock_session.post = async_mock.MagicMock( - return_value=async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(return_value=mock_response) + mock_response = mock.MagicMock(status=404) + mock_session.post = mock.MagicMock( + return_value=mock.MagicMock( + __aenter__=mock.CoroutineMock(return_value=mock_response) ) ) with pytest.raises(OutboundTransportError): diff --git a/aries_cloudagent/transport/outbound/tests/test_manager.py b/aries_cloudagent/transport/outbound/tests/test_manager.py index 7521173734..d2ea9c945f 100644 --- a/aries_cloudagent/transport/outbound/tests/test_manager.py +++ b/aries_cloudagent/transport/outbound/tests/test_manager.py @@ -1,6 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....connections.models.connection_target import ConnectionTarget @@ -16,7 +17,7 @@ from ..message import OutboundMessage -class TestOutboundTransportManager(AsyncTestCase): +class TestOutboundTransportManager(IsolatedAsyncioTestCase): def test_register_path(self): mgr = OutboundTransportManager(InMemoryProfile.test_profile()) mgr.register("http") @@ -40,7 +41,7 @@ def test_maximum_retry_count(self): async def test_setup(self): profile = InMemoryProfile.test_profile({"transport.outbound_configs": ["http"]}) mgr = OutboundTransportManager(profile) - with async_mock.patch.object(mgr, "register") as mock_register: + with mock.patch.object(mgr, "register") as mock_register: await mgr.setup() mock_register.assert_called_once_with("http") @@ -48,19 +49,19 @@ async def test_send_message(self): profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - transport_cls = async_mock.Mock(spec=[]) + transport_cls = mock.Mock(spec=[]) with self.assertRaises(OutboundTransportRegistrationError): mgr.register_class(transport_cls, "transport_cls") - transport = async_mock.MagicMock() - transport.handle_message = async_mock.CoroutineMock() - transport.wire_format.encode_message = async_mock.CoroutineMock() - transport.start = async_mock.CoroutineMock() - transport.stop = async_mock.CoroutineMock() + transport = mock.MagicMock() + transport.handle_message = mock.CoroutineMock() + transport.wire_format.encode_message = mock.CoroutineMock() + transport.start = mock.CoroutineMock() + transport.stop = mock.CoroutineMock() transport.schemes = ["http"] transport.is_external = False - transport_cls = async_mock.MagicMock() + transport_cls = mock.MagicMock() transport_cls.schemes = ["http"] transport_cls.return_value = transport mgr.register_class(transport_cls, "transport_cls") @@ -82,9 +83,7 @@ async def test_send_message(self): send_session = InMemoryProfile.test_session() send_profile = send_session.profile - setattr( - send_profile, "session", async_mock.MagicMock(return_value=send_session) - ) + setattr(send_profile, "session", mock.MagicMock(return_value=send_session)) await mgr.enqueue_message(send_profile, message) await mgr.flush() @@ -124,8 +123,8 @@ async def test_send_message(self): async def test_stop_cancel(self): profile = InMemoryProfile.test_profile({"transport.outbound_configs": ["http"]}) mgr = OutboundTransportManager(profile) - mgr._process_task = async_mock.MagicMock( - done=async_mock.MagicMock(return_value=False), cancel=async_mock.MagicMock() + mgr._process_task = mock.MagicMock( + done=mock.MagicMock(return_value=False), cancel=mock.MagicMock() ) mgr.running_transports = {} await mgr.stop() @@ -145,15 +144,15 @@ async def test_enqueue_webhook(self): test_topic, test_payload, test_endpoint, max_attempts=test_attempts ) - transport_cls = async_mock.MagicMock() + transport_cls = mock.MagicMock() transport_cls.schemes = ["http"] - transport_cls.return_value = async_mock.MagicMock() + transport_cls.return_value = mock.MagicMock() transport_cls.return_value.schemes = ["http"] - transport_cls.return_value.start = async_mock.CoroutineMock() + transport_cls.return_value.start = mock.CoroutineMock() tid = mgr.register_class(transport_cls, "transport_cls") await mgr.start_transport(tid) - with async_mock.patch.object(mgr, "process_queued") as mock_process: + with mock.patch.object(mgr, "process_queued") as mock_process: mgr.enqueue_webhook( test_topic, test_payload, test_endpoint, max_attempts=test_attempts ) @@ -166,47 +165,47 @@ async def test_enqueue_webhook(self): assert queued.state == QueuedOutboundMessage.STATE_PENDING async def test_process_done_x(self): - mock_task = async_mock.MagicMock( - done=async_mock.MagicMock(return_value=True), - exception=async_mock.MagicMock(return_value=KeyError("No such key")), + mock_task = mock.MagicMock( + done=mock.MagicMock(return_value=True), + exception=mock.MagicMock(return_value=KeyError("No such key")), ) profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - with async_mock.patch.object( - mgr, "_process_task", async_mock.MagicMock() + with mock.patch.object( + mgr, "_process_task", mock.MagicMock() ) as mock_mgr_process: - mock_mgr_process.done = async_mock.MagicMock(return_value=True) + mock_mgr_process.done = mock.MagicMock(return_value=True) mgr._process_done(mock_task) async def test_process_finished_x(self): - mock_queued = async_mock.MagicMock(retries=1) - mock_task = async_mock.MagicMock( + mock_queued = mock.MagicMock(retries=1) + mock_task = mock.MagicMock( exc_info=(KeyError, KeyError("nope"), None), ) profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - with async_mock.patch.object( - mgr, "process_queued", async_mock.MagicMock() + with mock.patch.object( + mgr, "process_queued", mock.MagicMock() ) as mock_mgr_process: mgr.finished_encode(mock_queued, mock_task) mgr.finished_deliver(mock_queued, mock_task) mgr.finished_deliver(mock_queued, mock_task) async def test_process_loop_retry_now(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_RETRY, retry_at=test_module.get_timer() - 1, ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_trace.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -214,18 +213,18 @@ async def test_process_loop_retry_now(self): assert mock_queued.retry_at is None async def test_process_loop_retry_later(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_RETRY, retry_at=test_module.get_timer() + 3600, ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module.asyncio, "sleep", async_mock.CoroutineMock() + with mock.patch.object( + test_module.asyncio, "sleep", mock.CoroutineMock() ) as mock_sleep_x: mock_sleep_x.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -234,21 +233,21 @@ async def test_process_loop_retry_later(self): async def test_process_loop_new(self): profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_new = [ - async_mock.MagicMock( + mock.MagicMock( state=test_module.QueuedOutboundMessage.STATE_NEW, - message=async_mock.MagicMock(enc_payload=b"encr"), + message=mock.MagicMock(enc_payload=b"encr"), ) ] - with async_mock.patch.object( - mgr, "deliver_queued_message", async_mock.MagicMock() - ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + mgr, "deliver_queued_message", mock.MagicMock() + ) as mock_deliver, mock.patch.object( + mgr.outbound_event, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_wait.side_effect = KeyError() # cover state=NEW logic and bail @@ -257,21 +256,21 @@ async def test_process_loop_new(self): async def test_process_loop_new_deliver(self): profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_new = [ - async_mock.MagicMock( + mock.MagicMock( state=test_module.QueuedOutboundMessage.STATE_DELIVER, - message=async_mock.MagicMock(enc_payload=b"encr"), + message=mock.MagicMock(enc_payload=b"encr"), ) ] - with async_mock.patch.object( - mgr, "deliver_queued_message", async_mock.MagicMock() - ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.CoroutineMock() - ) as mock_wait, async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + mgr, "deliver_queued_message", mock.MagicMock() + ) as mock_deliver, mock.patch.object( + mgr.outbound_event, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_wait.side_effect = KeyError() # cover state=DELIVER logic and bail @@ -279,7 +278,7 @@ async def test_process_loop_new_deliver(self): await mgr._process_loop() async def test_process_loop_x(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_DONE, error=KeyError(), endpoint="http://1.2.3.4:8081", @@ -287,30 +286,28 @@ async def test_process_loop_x(self): ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) await mgr._process_loop() async def test_finished_deliver_x_log_debug(self): - mock_queued = async_mock.MagicMock( - state=QueuedOutboundMessage.STATE_DONE, retries=1 - ) - mock_completed_x = async_mock.MagicMock(exc_info=KeyError("an error occurred")) + mock_queued = mock.MagicMock(state=QueuedOutboundMessage.STATE_DONE, retries=1) + mock_completed_x = mock.MagicMock(exc_info=KeyError("an error occurred")) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_logger_exception, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() - ) as mock_logger_error, async_mock.patch.object( - test_module.LOGGER, "isEnabledFor", async_mock.MagicMock() - ) as mock_logger_enabled, async_mock.patch.object( - mgr, "process_queued", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_logger_exception, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() + ) as mock_logger_error, mock.patch.object( + test_module.LOGGER, "isEnabledFor", mock.MagicMock() + ) as mock_logger_enabled, mock.patch.object( + mgr, "process_queued", mock.MagicMock() ) as mock_process: mock_logger_enabled.return_value = True # cover debug logging mgr.finished_deliver(mock_queued, mock_completed_x) @@ -318,13 +315,11 @@ async def test_finished_deliver_x_log_debug(self): async def test_should_encode_outbound_message(self): base_wire_format = BaseWireFormat() encoded_msg = "encoded_message" - base_wire_format.encode_message = async_mock.CoroutineMock( - return_value=encoded_msg - ) + base_wire_format.encode_message = mock.CoroutineMock(return_value=encoded_msg) profile = InMemoryProfile.test_profile(bind={BaseWireFormat: base_wire_format}) - profile.session = async_mock.CoroutineMock(return_value=async_mock.MagicMock()) - outbound = async_mock.MagicMock(payload="payload", enc_payload=None) - target = async_mock.MagicMock() + profile.session = mock.CoroutineMock(return_value=mock.MagicMock()) + outbound = mock.MagicMock(payload="payload", enc_payload=None) + target = mock.MagicMock() mgr = OutboundTransportManager(profile) result = await mgr.encode_outbound_message(profile, outbound, target) @@ -341,8 +336,8 @@ async def test_should_encode_outbound_message(self): async def test_should_not_encode_already_packed_message(self): profile = InMemoryProfile.test_session().profile enc_payload = "enc_payload" - outbound = async_mock.MagicMock(enc_payload=enc_payload) - target = async_mock.MagicMock() + outbound = mock.MagicMock(enc_payload=enc_payload) + target = mock.MagicMock() mgr = OutboundTransportManager(profile) result = await mgr.encode_outbound_message(profile, outbound, target) diff --git a/aries_cloudagent/transport/queue/tests/test_basic_queue.py b/aries_cloudagent/transport/queue/tests/test_basic_queue.py index 53bcf7353b..b417bb1d0a 100644 --- a/aries_cloudagent/transport/queue/tests/test_basic_queue.py +++ b/aries_cloudagent/transport/queue/tests/test_basic_queue.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from .. import basic as test_module from ..basic import BasicMessageQueue @@ -15,7 +16,7 @@ async def collect(queue, count=1): return found -class TestBasicQueue(AsyncTestCase): +class TestBasicQueue(IsolatedAsyncioTestCase): async def test_enqueue_dequeue(self): queue = BasicMessageQueue() @@ -36,26 +37,27 @@ async def test_dequeue_x(self): test_value = "test value" await queue.enqueue(test_value) - with async_mock.patch.object( - test_module.asyncio, "get_event_loop", async_mock.MagicMock() - ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait: + with mock.patch.object( + test_module.asyncio, "get_event_loop", mock.MagicMock() + ) as mock_get_event_loop, mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + queue, "stop_event" + ) as mock_stop_event, mock.patch.object( + queue, "queue" + ): + mock_stop_event.is_set.return_value = False mock_wait.return_value = ( - async_mock.MagicMock(), - [ - async_mock.MagicMock( - done=async_mock.MagicMock(), cancel=async_mock.MagicMock() - ) - ], + mock.MagicMock(), + [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], ) - mock_get_event_loop.return_value = async_mock.MagicMock( - create_task=async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( + create_task=mock.MagicMock( side_effect=[ - async_mock.MagicMock(), # stopped - async_mock.MagicMock( # dequeued - done=async_mock.MagicMock(return_value=True), - exception=async_mock.MagicMock(return_value=KeyError()), + mock.MagicMock(), # stopped + mock.MagicMock( # dequeued + done=mock.MagicMock(return_value=True), + exception=mock.MagicMock(return_value=KeyError()), ), ] ) @@ -68,27 +70,28 @@ async def test_dequeue_none(self): test_value = "test value" await queue.enqueue(test_value) - with async_mock.patch.object( - test_module.asyncio, "get_event_loop", async_mock.MagicMock() - ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() - ) as mock_wait: + with mock.patch.object( + test_module.asyncio, "get_event_loop", mock.MagicMock() + ) as mock_get_event_loop, mock.patch.object( + test_module.asyncio, "wait", mock.CoroutineMock() + ) as mock_wait, mock.patch.object( + queue, "stop_event" + ) as mock_stop_event, mock.patch.object( + queue, "queue" + ): + mock_stop_event.is_set.return_value = False mock_wait.return_value = ( - async_mock.MagicMock(), - [ - async_mock.MagicMock( - done=async_mock.MagicMock(), cancel=async_mock.MagicMock() - ) - ], + mock.MagicMock(), + [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], ) - mock_get_event_loop.return_value = async_mock.MagicMock( - create_task=async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( + create_task=mock.MagicMock( side_effect=[ - async_mock.MagicMock( # stopped - done=async_mock.MagicMock(return_value=True) + mock.MagicMock( # stopped + done=mock.MagicMock(return_value=True) ), - async_mock.MagicMock( # dequeued - done=async_mock.MagicMock(return_value=False) + mock.MagicMock( # dequeued + done=mock.MagicMock(return_value=False) ), ] ) diff --git a/aries_cloudagent/transport/tests/test_pack_format.py b/aries_cloudagent/transport/tests/test_pack_format.py index 764e4a54bf..e1f66fbb15 100644 --- a/aries_cloudagent/transport/tests/test_pack_format.py +++ b/aries_cloudagent/transport/tests/test_pack_format.py @@ -1,8 +1,8 @@ import json from base64 import b64encode -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix @@ -16,7 +16,7 @@ from ..pack_format import PackWireFormat -class TestPackWireFormat(AsyncTestCase): +class TestPackWireFormat(IsolatedAsyncioTestCase): test_message_type = DIDCommPrefix.qualify_current("PROTOCOL/MESSAGE") test_message_id = "MESSAGE_ID" test_content = "CONTENT" @@ -54,8 +54,8 @@ async def test_errors(self): } serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.CoroutineMock() + with mock.patch.object( + serializer, "unpack", mock.CoroutineMock() ) as mock_unpack: mock_unpack.return_value = "{missing-brace" with self.assertRaises(WireFormatParseError) as context: @@ -64,8 +64,8 @@ async def test_errors(self): serializer = PackWireFormat() serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.CoroutineMock() + with mock.patch.object( + serializer, "unpack", mock.CoroutineMock() ) as mock_unpack: mock_unpack.return_value = json.dumps([1, 2, 3]) with self.assertRaises(WireFormatParseError) as context: @@ -92,25 +92,23 @@ async def test_pack_x(self): ["key"], ) - mock_wallet = async_mock.MagicMock( - pack_message=async_mock.CoroutineMock(side_effect=WalletError()) + mock_wallet = mock.MagicMock( + pack_message=mock.CoroutineMock(side_effect=WalletError()) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], None, ["key"]) - mock_wallet = async_mock.MagicMock( - pack_message=async_mock.CoroutineMock( + mock_wallet = mock.MagicMock( + pack_message=mock.CoroutineMock( side_effect=[json.dumps("message").encode("utf-8"), WalletError()] ) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) - with async_mock.patch.object( - test_module, "Forward", async_mock.MagicMock() + with mock.patch.object( + test_module, "Forward", mock.MagicMock() ) as mock_forward: - mock_forward.return_value = async_mock.MagicMock( - to_json=async_mock.MagicMock() - ) + mock_forward.return_value = mock.MagicMock(to_json=mock.MagicMock()) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], ["key"], ["key"]) diff --git a/aries_cloudagent/transport/tests/test_stats.py b/aries_cloudagent/transport/tests/test_stats.py index f2cc267d0c..acddd20d2d 100644 --- a/aries_cloudagent/transport/tests/test_stats.py +++ b/aries_cloudagent/transport/tests/test_stats.py @@ -1,14 +1,15 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock +from unittest import IsolatedAsyncioTestCase from .. import stats as test_module -class TestStatsTracer(AsyncTestCase): +class TestStatsTracer(IsolatedAsyncioTestCase): def setUp(self): - self.context = async_mock.MagicMock( - socket_timer=async_mock.MagicMock( - stop=async_mock.MagicMock(side_effect=AttributeError("wrong")) + self.context = mock.MagicMock( + socket_timer=mock.MagicMock( + stop=mock.MagicMock(side_effect=AttributeError("wrong")) ) ) self.tracer = test_module.StatsTracer(test_module.Collector(), "test") diff --git a/aries_cloudagent/transport/tests/test_wire_format.py b/aries_cloudagent/transport/tests/test_wire_format.py index 48471402a1..c22e403dae 100644 --- a/aries_cloudagent/transport/tests/test_wire_format.py +++ b/aries_cloudagent/transport/tests/test_wire_format.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..wire_format import JsonWireFormat -class TestWireFormat(AsyncTestCase): +class TestWireFormat(IsolatedAsyncioTestCase): async def test_get_recipient_keys(self): serializer = JsonWireFormat() recipient_keys = serializer.get_recipient_keys("message_body") diff --git a/aries_cloudagent/utils/tests/test_classloader.py b/aries_cloudagent/utils/tests/test_classloader.py index b83b0d6755..50583856d2 100644 --- a/aries_cloudagent/utils/tests/test_classloader.py +++ b/aries_cloudagent/utils/tests/test_classloader.py @@ -1,4 +1,5 @@ -from unittest import TestCase, mock +from unittest import TestCase +from unittest import mock from ...core.error import BaseError diff --git a/aries_cloudagent/utils/tests/test_outofband.py b/aries_cloudagent/utils/tests/test_outofband.py index 6e3821ff57..81d5763ca7 100644 --- a/aries_cloudagent/utils/tests/test_outofband.py +++ b/aries_cloudagent/utils/tests/test_outofband.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ...protocols.out_of_band.v1_0.messages.invitation import InvitationMessage from ...wallet.did_info import DIDInfo diff --git a/aries_cloudagent/utils/tests/test_repeat.py b/aries_cloudagent/utils/tests/test_repeat.py index 0056334a8a..f92e8f3c1a 100644 --- a/aries_cloudagent/utils/tests/test_repeat.py +++ b/aries_cloudagent/utils/tests/test_repeat.py @@ -1,9 +1,10 @@ -from asynctest import mock, TestCase +from unittest import IsolatedAsyncioTestCase +from unittest import mock from .. import repeat as test_module -class TestRepeat(TestCase): +class TestRepeat(IsolatedAsyncioTestCase): async def test_iter(self): expect = [5, 7, 11, 17, 25] seq = test_module.RepeatSequence(5, interval=5.0, backoff=0.25) diff --git a/aries_cloudagent/utils/tests/test_stats.py b/aries_cloudagent/utils/tests/test_stats.py index e055192a49..d984b93785 100644 --- a/aries_cloudagent/utils/tests/test_stats.py +++ b/aries_cloudagent/utils/tests/test_stats.py @@ -1,11 +1,11 @@ from tempfile import NamedTemporaryFile -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..stats import Collector -class TestStats(AsyncTestCase): +class TestStats(IsolatedAsyncioTestCase): async def test_fn_decorator(self): stats = Collector() diff --git a/aries_cloudagent/utils/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py index dc0cc559a0..0d1a5cfd88 100644 --- a/aries_cloudagent/utils/tests/test_task_queue.py +++ b/aries_cloudagent/utils/tests/test_task_queue.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from aries_cloudagent.tests import mock +from unittest import IsolatedAsyncioTestCase from ..task_queue import CompletedTask, PendingTask, TaskQueue, task_exc_info @@ -11,7 +12,7 @@ async def retval(val, *, delay=0): return val -class TestTaskQueue(AsyncTestCase): +class TestTaskQueue(IsolatedAsyncioTestCase): async def test_run(self): queue = TaskQueue() task = None @@ -83,7 +84,7 @@ async def test_pending(self): assert pend.cancelled task.cancel() - with async_mock.patch.object(pend, "task_future", autospec=True) as mock_future: + with mock.patch.object(pend, "task_future", autospec=True) as mock_future: mock_future.cancelled.return_value = True pend.task = "a suffusion of yellow" mock_future.set_result.assert_not_called() @@ -105,10 +106,10 @@ def done(complete: CompletedTask): async def noop(): return - with async_mock.patch.object( - queue, "drain", async_mock.MagicMock() - ) as mock_drain, async_mock.patch.object( - queue, "wait_for", async_mock.CoroutineMock() + with mock.patch.object( + queue, "drain", mock.MagicMock() + ) as mock_drain, mock.patch.object( + queue, "wait_for", mock.CoroutineMock() ) as mock_wait_for: mock_drain.side_effect = [queue.loop.create_task(noop()), None] await queue.complete(cleanup=True) @@ -137,7 +138,7 @@ async def test_drain_done(self): queue = TaskQueue(1) queue.add_pending(pend) - with async_mock.patch.object( + with mock.patch.object( queue.pending_tasks[0], "task_future", autospec=True ) as mock_future: mock_future.cancelled.return_value = False diff --git a/aries_cloudagent/utils/tests/test_tracing.py b/aries_cloudagent/utils/tests/test_tracing.py index c27d461dc4..b9c7278383 100644 --- a/aries_cloudagent/utils/tests/test_tracing.py +++ b/aries_cloudagent/utils/tests/test_tracing.py @@ -1,7 +1,7 @@ import json import requests -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...protocols.out_of_band.v1_0.messages.invitation import InvitationMessage from ...protocols.issue_credential.v1_0.models.credential_exchange import ( @@ -16,7 +16,7 @@ from .. import tracing as test_module -class TestTracing(AsyncTestCase): +class TestTracing(IsolatedAsyncioTestCase): test_did = "55GkHamhTU1ZbTbV2ab9DE" def test_get_timer(self): diff --git a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py index d1842d9ac2..e920fb9774 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -1,4 +1,5 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from aries_cloudagent.tests import mock from aries_cloudagent.wallet.key_type import ED25519 @@ -9,8 +10,8 @@ from ..wallet_key_pair import WalletKeyPair -class TestWalletKeyPair(TestCase): - async def setUp(self): +class TestWalletKeyPair(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() async def test_sign_x_no_public_key(self): @@ -27,12 +28,12 @@ async def test_sign(self): key_type=ED25519, public_key_base58=public_key_base58, ) - signed = async_mock.MagicMock() + signed = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "sign_message", - async_mock.CoroutineMock(return_value=signed), + mock.CoroutineMock(return_value=signed), ) as sign_message: singed_ret = await key_pair.sign(b"Message") @@ -56,10 +57,10 @@ async def test_verify(self): public_key_base58=public_key_base58, ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "verify_message", - async_mock.CoroutineMock(return_value=True), + mock.CoroutineMock(return_value=True), ) as verify_message: verified = await key_pair.verify(b"Message", b"signature") diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py index 957c5d56c1..3e6b030c5c 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py @@ -1,12 +1,13 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ...validation_result import PurposeResult from ..controller_proof_purpose import ControllerProofPurpose from ..authentication_proof_purpose import AuthenticationProofPurpose -class TestAuthenticationProofPurpose(TestCase): +class TestAuthenticationProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): date = datetime.now() delta = timedelta(1) @@ -33,18 +34,16 @@ async def test_validate(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) proof = { "challenge": "8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "example.com", } - document = async_mock.MagicMock() - suite = async_mock.MagicMock() + document = mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} - document_loader = async_mock.MagicMock() + document_loader = mock.MagicMock() result = proof_purpose.validate( proof=proof, @@ -67,9 +66,7 @@ async def test_validate_x_challenge_does_not_match(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) result = proof_purpose.validate( @@ -77,10 +74,10 @@ async def test_validate_x_challenge_does_not_match(self): "challenge": "another8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "example.com", }, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid assert "The challenge is not as expected" in str(result.error) @@ -90,9 +87,7 @@ async def test_validate_x_domain_does_not_match(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) result = proof_purpose.validate( @@ -100,10 +95,10 @@ async def test_validate_x_domain_does_not_match(self): "challenge": "8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "anotherexample.com", }, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid assert "The domain is not as expected" in str(result.error) diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py index 8ae1dc33c6..4babb4d91e 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ....tests.data import TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519 from ....tests.document_loader import custom_document_loader @@ -7,7 +8,7 @@ from ..controller_proof_purpose import ControllerProofPurpose -class TestControllerProofPurpose(TestCase): +class TestControllerProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): term = "TestTerm" date = datetime.now() @@ -31,7 +32,7 @@ async def test_validate(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -54,7 +55,7 @@ async def test_validate_controller_invalid_type(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -78,7 +79,7 @@ async def test_validate_x_not_authorized(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -100,15 +101,15 @@ async def test_validate_x_not_authorized(self): async def test_validate_x_super_invalid(self): proof_purpose = ControllerProofPurpose(term="assertionMethod") - with async_mock.patch.object(ProofPurpose, "validate") as validate_mock: - validate_mock.return_value = async_mock.MagicMock(valid=False) + with mock.patch.object(ProofPurpose, "validate") as validate_mock: + validate_mock.return_value = mock.MagicMock(valid=False) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py index 60442b73da..5ca98670b3 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ...validation_result import PurposeResult from ..assertion_proof_purpose import AssertionProofPurpose @@ -8,7 +9,7 @@ from ....tests.document_loader import custom_document_loader -class TestCredentialIssuancePurpose(TestCase): +class TestCredentialIssuancePurpose(IsolatedAsyncioTestCase): async def test_properties(self): date = datetime.now() delta = timedelta(1) @@ -25,15 +26,13 @@ async def test_properties(self): async def test_validate(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": TEST_VC_DOCUMENT_SIGNED_ED25519["issuer"]} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -55,16 +54,14 @@ async def test_validate(self): async def test_validate_x_no_issuer(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": TEST_VC_DOCUMENT_SIGNED_ED25519["issuer"]} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() document.pop("issuer") proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -80,15 +77,13 @@ async def test_validate_x_no_issuer(self): async def test_validate_x_no_match_issuer(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": "random_controller_id"} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -106,17 +101,15 @@ async def test_validate_x_no_match_issuer(self): async def test_validate_x_super_invalid(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: - validate_mock.return_value = async_mock.MagicMock(valid=False) + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: + validate_mock.return_value = mock.MagicMock(valid=False) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py index ffde15d366..ee01358587 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py @@ -1,11 +1,12 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from .....messaging.util import datetime_to_str from ..proof_purpose import ProofPurpose -class TestProofPurpose(TestCase): +class TestProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): term = "TestTerm" date = datetime.now() @@ -24,11 +25,11 @@ async def test_validate(self): proof_purpose = ProofPurpose(term="ProofTerm", date=datetime.now()) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert result.valid @@ -40,10 +41,10 @@ async def test_validate_timestamp_delta(self): result = proof_purpose.validate( proof={"created": datetime_to_str(date + timedelta(5))}, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert result.valid @@ -55,10 +56,10 @@ async def test_validate_timestamp_delta_out_of_rage(self): result = proof_purpose.validate( proof={"created": datetime_to_str(date + timedelta(15))}, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py index a5a141c174..11d7649453 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py @@ -1,4 +1,5 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -24,10 +25,10 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsBlsSignature2020(TestCase): +class TestBbsBlsSignature2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( @@ -138,9 +139,9 @@ async def test_verify_signature_x_invalid_proof_value(self): with self.assertRaises(LinkedDataProofException): await suite.verify_signature( - verify_data=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document=async_mock.MagicMock(), + verify_data=mock.MagicMock(), + verification_method=mock.MagicMock(), + document=mock.MagicMock(), proof={"proofValue": {"not": "a string"}}, - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py index ae217d4b63..54abb9f7e0 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py @@ -1,4 +1,5 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -33,10 +34,10 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsBlsSignatureProof2020(TestCase): +class TestBbsBlsSignatureProof2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( @@ -202,8 +203,8 @@ async def test_derive_proof_x_invalid_proof_type(self): with self.assertRaises(LinkedDataProofException): await suite.derive_proof( - reveal_document=async_mock.MagicMock(), - document=async_mock.MagicMock(), + reveal_document=mock.MagicMock(), + document=mock.MagicMock(), proof={"type": "incorrect type"}, - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py index fdae59d396..e9dfba0d33 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py @@ -1,9 +1,7 @@ -from asynctest import TestCase - -from aries_cloudagent.wallet.key_type import ED25519 - +from unittest import IsolatedAsyncioTestCase from .....did.did_key import DIDKey +from .....wallet.key_type import ED25519 from .....wallet.in_memory import InMemoryWallet from .....core.in_memory import InMemoryProfile @@ -23,10 +21,10 @@ from ..ed25519_signature_2018 import Ed25519Signature2018 -class TestEd25519Signature2018(TestCase): +class TestEd25519Signature2018(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py index c527e3aa48..68950bf3d3 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py @@ -1,6 +1,5 @@ -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.wallet.key_type import ED25519 from ..ed25519_signature_2020 import Ed25519Signature2020 from ...crypto.wallet_key_pair import WalletKeyPair from ...ld_proofs import sign, verify @@ -16,12 +15,13 @@ from .....core.in_memory import InMemoryProfile from .....did.did_key import DIDKey from .....wallet.in_memory import InMemoryWallet +from .....wallet.key_type import ED25519 -class TestEd25519Signature2020(TestCase): +class TestEd25519Signature2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/tests/test_check.py b/aries_cloudagent/vc/ld_proofs/tests/test_check.py index 56573fbde5..ca6ee1668b 100644 --- a/aries_cloudagent/vc/ld_proofs/tests/test_check.py +++ b/aries_cloudagent/vc/ld_proofs/tests/test_check.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ..check import get_properties_without_context from ...tests.document_loader import custom_document_loader diff --git a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py index 26f170793e..9141e48c98 100644 --- a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py +++ b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py @@ -1,8 +1,8 @@ +from unittest import IsolatedAsyncioTestCase import pytest from datetime import datetime, timezone -from asynctest import TestCase from ....wallet.key_type import BLS12381G2, ED25519 from ....did.did_key import DIDKey @@ -36,10 +36,10 @@ ) -class TestLDProofs(TestCase): +class TestLDProofs(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) diff --git a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py index 0fd50ccbc1..d22d432b93 100644 --- a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py +++ b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase import pytest from ...wallet.key_type import BLS12381G2 @@ -31,8 +31,8 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsMattrInterop(TestCase): - async def setUp(self): +class TestBbsMattrInterop(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) diff --git a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py index 26f027d4a6..2c440fc063 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py @@ -1,10 +1,10 @@ -from asynctest import TestCase +from unittest import TestCase from ..validation_result import PresentationVerificationResult class TestValidationResult(TestCase): - async def test_properties(self): + def test_properties(self): result = PresentationVerificationResult(verified=True) result2 = PresentationVerificationResult(verified=True) diff --git a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index d169a1907a..9fec151e35 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py @@ -1,4 +1,5 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from datetime import datetime import pytest @@ -37,10 +38,10 @@ ) -class TestLinkedDataVerifiableCredential(TestCase): +class TestLinkedDataVerifiableCredential(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) @@ -112,8 +113,8 @@ async def test_issue_x_invalid_credential_structure(self): with self.assertRaises(LinkedDataProofException) as context: await issue( credential=credential, - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert "invalid structure" in str(context.exception) @@ -124,9 +125,9 @@ async def test_derive_x_invalid_credential_structure(self): with self.assertRaises(LinkedDataProofException) as context: await derive_credential( credential=credential, - reveal_document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + reveal_document=mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert "invalid structure" in str(context.exception) @@ -163,7 +164,7 @@ async def test_verify_x_invalid_credential_structure(self): result = await verify_credential( credential=credential, suites=[], - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.verified @@ -305,8 +306,8 @@ async def test_sign_presentation_x_no_purpose_challenge(self): with self.assertRaises(LinkedDataProofException) as context: await sign_presentation( presentation=PRESENTATION_UNSIGNED, - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert 'A "challenge" param is required' in str(context.exception) diff --git a/aries_cloudagent/wallet/models/tests/test_wallet_record.py b/aries_cloudagent/wallet/models/tests/test_wallet_record.py index 39ea44b224..bc1b51bdb1 100644 --- a/aries_cloudagent/wallet/models/tests/test_wallet_record.py +++ b/aries_cloudagent/wallet/models/tests/test_wallet_record.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..wallet_record import WalletRecord from ...error import WalletSettingsError -class TestWalletRecord(AsyncTestCase): +class TestWalletRecord(IsolatedAsyncioTestCase): async def test_serde(self): rec = WalletRecord( wallet_id="my-wallet-id", diff --git a/aries_cloudagent/wallet/tests/test_crypto.py b/aries_cloudagent/wallet/tests/test_crypto.py index 43b0d03452..bac2d10cd2 100644 --- a/aries_cloudagent/wallet/tests/test_crypto.py +++ b/aries_cloudagent/wallet/tests/test_crypto.py @@ -1,7 +1,8 @@ import pytest import json -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ..key_type import BLS12381G1, ED25519 from ..error import WalletError diff --git a/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py b/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py index 1d610f53fe..21feeac5ea 100644 --- a/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py +++ b/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py @@ -1,6 +1,6 @@ -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.core.profile import Profile +from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.did.did_key import DIDKey @@ -12,18 +12,25 @@ TEST_DID_KEY = "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL" -class TestDefaultVerificationKeyStrategy(TestCase): +class TestDefaultVerificationKeyStrategy(IsolatedAsyncioTestCase): + async def asyncSetUp(self) -> None: + self.profile = InMemoryProfile.test_profile() + async def test_with_did_sov(self): strategy = DefaultVerificationKeyStrategy() assert ( - await strategy.get_verification_method_id_for_did(TEST_DID_SOV, Profile()) + await strategy.get_verification_method_id_for_did( + TEST_DID_SOV, self.profile + ) == TEST_DID_SOV + "#key-1" ) async def test_with_did_key(self): strategy = DefaultVerificationKeyStrategy() assert ( - await strategy.get_verification_method_id_for_did(TEST_DID_KEY, Profile()) + await strategy.get_verification_method_id_for_did( + TEST_DID_KEY, self.profile + ) == DIDKey.from_did(TEST_DID_KEY).key_id ) @@ -31,7 +38,7 @@ async def test_unsupported_did_method(self): strategy = DefaultVerificationKeyStrategy() assert ( await strategy.get_verification_method_id_for_did( - "did:test:test", Profile() + "did:test:test", self.profile ) is None ) diff --git a/aries_cloudagent/wallet/tests/test_did_posture.py b/aries_cloudagent/wallet/tests/test_did_posture.py index 85aa498d15..d4000ae8db 100644 --- a/aries_cloudagent/wallet/tests/test_did_posture.py +++ b/aries_cloudagent/wallet/tests/test_did_posture.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..did_posture import DIDPosture -class TestDIDPosture(AsyncTestCase): +class TestDIDPosture(IsolatedAsyncioTestCase): async def test_did_posture(self): assert DIDPosture.PUBLIC is DIDPosture.get("PUBLIC") assert DIDPosture.POSTED is DIDPosture.get("POSTED") diff --git a/aries_cloudagent/wallet/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index 47ae72cdec..1da9d7968d 100644 --- a/aries_cloudagent/wallet/tests/test_indy_wallet.py +++ b/aries_cloudagent/wallet/tests/test_indy_wallet.py @@ -7,7 +7,7 @@ import indy.did import indy.wallet import pytest -from asynctest import mock as async_mock +from aries_cloudagent.tests import mock from ...config.injection_context import InjectionContext from ...core.error import ProfileDuplicateError, ProfileError, ProfileNotFoundError @@ -39,7 +39,7 @@ async def wallet(): context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) context.injector.bind_instance(DIDMethods, DIDMethods()) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): profile = cast( IndySdkProfile, await IndySdkProfileManager().provision( @@ -68,8 +68,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): SOV, ED25519, self.test_seed, self.test_sov_did ) - with async_mock.patch.object( - indy.did, "replace_keys_start", async_mock.CoroutineMock() + with mock.patch.object( + indy.did, "replace_keys_start", mock.CoroutineMock() ) as mock_repl_start: mock_repl_start.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -78,8 +78,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): await wallet.rotate_did_keypair_start(self.test_sov_did) assert "outlier" in str(excinfo.value) - with async_mock.patch.object( - indy.did, "replace_keys_apply", async_mock.CoroutineMock() + with mock.patch.object( + indy.did, "replace_keys_apply", mock.CoroutineMock() ) as mock_repl_apply: mock_repl_apply.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -90,8 +90,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_signing_key_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "create_key", async_mock.CoroutineMock() + with mock.patch.object( + indy.crypto, "create_key", mock.CoroutineMock() ) as mock_create_key: mock_create_key.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -102,8 +102,8 @@ async def test_create_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_local_did_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.did, "create_and_store_my_did", async_mock.CoroutineMock() + with mock.patch.object( + indy.did, "create_and_store_my_did", mock.CoroutineMock() ) as mock_create: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -114,8 +114,8 @@ async def test_create_local_did_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_set_did_endpoint_ledger(self, wallet: IndySdkWallet): - mock_ledger = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did( SOV, @@ -142,8 +142,8 @@ async def test_set_did_endpoint_ledger_with_routing_keys( self, wallet: IndySdkWallet ): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] - mock_ledger = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did(SOV, ED25519) await wallet.set_did_endpoint( @@ -161,8 +161,8 @@ async def test_set_did_endpoint_ledger_with_routing_keys( @pytest.mark.asyncio async def test_set_did_endpoint_readonly_ledger(self, wallet: IndySdkWallet): - mock_ledger = async_mock.MagicMock( - read_only=True, update_endpoint_for_did=async_mock.CoroutineMock() + mock_ledger = mock.MagicMock( + read_only=True, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did( SOV, @@ -179,8 +179,8 @@ async def test_set_did_endpoint_readonly_ledger(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_get_signing_key_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "get_key_metadata", async_mock.CoroutineMock() + with mock.patch.object( + indy.crypto, "get_key_metadata", mock.CoroutineMock() ) as mock_signing: mock_signing.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -191,8 +191,8 @@ async def test_get_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_get_local_did_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.did, "get_my_did_with_meta", async_mock.CoroutineMock() + with mock.patch.object( + indy.did, "get_my_did_with_meta", mock.CoroutineMock() ) as mock_my: mock_my.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -214,8 +214,8 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): assert info.verkey == self.test_ed25519_verkey assert info.metadata == self.test_metadata - with async_mock.patch.object( - indy.did, "set_did_metadata", async_mock.CoroutineMock() + with mock.patch.object( + indy.did, "set_did_metadata", mock.CoroutineMock() ) as mock_set_did_metadata: mock_set_did_metadata.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -226,8 +226,8 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_verify_message_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "crypto_verify", async_mock.CoroutineMock() + with mock.patch.object( + indy.crypto, "crypto_verify", mock.CoroutineMock() ) as mock_verify: mock_verify.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -250,8 +250,8 @@ async def test_verify_message_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_pack_message_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "pack_message", async_mock.CoroutineMock() + with mock.patch.object( + indy.crypto, "pack_message", mock.CoroutineMock() ) as mock_pack: mock_pack.side_effect = test_module.IndyError( # outlier test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -311,20 +311,20 @@ async def test_mock_coverage(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = IndyWalletConfig( { @@ -359,20 +359,20 @@ async def test_mock_coverage_wallet_exists_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyExistsError @@ -405,20 +405,20 @@ async def test_mock_coverage_wallet_create_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -454,20 +454,20 @@ async def test_mock_coverage_remove_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_delete.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -507,20 +507,20 @@ async def test_mock_coverage_not_found_after_creation(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -557,20 +557,20 @@ async def test_mock_coverage_open_not_found(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -605,20 +605,20 @@ async def test_mock_coverage_open_indy_already_open_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyOpenedError, {"message": "outlier"} @@ -653,20 +653,20 @@ async def test_mock_coverage_open_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -701,20 +701,20 @@ async def test_mock_coverage_open_master_secret_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -751,20 +751,20 @@ async def test_mock_coverage_open_master_secret_exists(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.CoroutineMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.CoroutineMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.CoroutineMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.AnoncredsMasterSecretDuplicateNameError diff --git a/aries_cloudagent/wallet/tests/test_key_pair.py b/aries_cloudagent/wallet/tests/test_key_pair.py index 6d0ddccb67..9126f15d6e 100644 --- a/aries_cloudagent/wallet/tests/test_key_pair.py +++ b/aries_cloudagent/wallet/tests/test_key_pair.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase import json @@ -10,11 +10,11 @@ from ..key_pair import KeyPairStorageManager, KEY_PAIR_STORAGE_TYPE -class TestKeyPairStorageManager(AsyncTestCase): +class TestKeyPairStorageManager(IsolatedAsyncioTestCase): test_public_key = b"somepublickeybytes" test_secret = b"verysecretkey" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.store = InMemoryStorage(self.profile) self.key_pair_mgr = KeyPairStorageManager(self.store) diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 71ea617792..da15998b6c 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -1,4 +1,4 @@ -import mock as async_mock +from aries_cloudagent.tests import mock from aiohttp.web import HTTPForbidden from unittest import IsolatedAsyncioTestCase @@ -23,7 +23,7 @@ class TestWalletRoutes(IsolatedAsyncioTestCase): def setUp(self): - self.wallet = async_mock.create_autospec(BaseWallet) + self.wallet = mock.create_autospec(BaseWallet) self.session_inject = {BaseWallet: self.wallet} self.profile = InMemoryProfile.test_profile() self.context = AdminRequestContext.test_context( @@ -32,9 +32,9 @@ def setUp(self): self.context.injector.bind_instance(KeyTypes, KeyTypes()) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -72,7 +72,7 @@ async def test_missing_wallet(self): await test_module.wallet_set_public_did(self.request) with self.assertRaises(HTTPForbidden): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -119,8 +119,8 @@ def test_format_did_info(self): assert result["posture"] == DIDPosture.POSTED.moniker async def test_create_did(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.create_local_did.return_value = DIDInfo( self.test_did, @@ -144,7 +144,7 @@ async def test_create_did(self): assert result is json_response.return_value async def test_create_did_unsupported_method(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "method": "madeupmethod", "options": {"key_type": "bls12381g2"}, @@ -155,7 +155,7 @@ async def test_create_did_unsupported_method(self): await test_module.wallet_create_did(self.request) async def test_create_did_unsupported_key_type(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"method": "sov", "options": {"key_type": "bls12381g2"}} ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -171,7 +171,7 @@ async def test_create_did_method_requires_user_defined_did(self): ) self.did_methods.register(did_custom) - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"method": "custom", "options": {"key_type": "ed25519"}} ) @@ -189,7 +189,7 @@ async def test_create_did_method_doesnt_support_user_defined_did(self): self.did_methods.register(did_custom) # when - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "method": "custom", "options": { @@ -209,9 +209,9 @@ async def test_create_did_x(self): await test_module.wallet_create_did(self.request) async def test_did_list(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() - ) as json_response: # , async_mock.patch.object( + with mock.patch.object( + test_module.web, "json_response", mock.Mock() + ) as json_response: # , mock.patch.object( self.wallet.get_local_dids.return_value = [ DIDInfo( self.test_did, @@ -254,8 +254,8 @@ async def test_did_list(self): async def test_did_list_filter_public(self): self.request.query = {"posture": DIDPosture.PUBLIC.moniker} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -292,8 +292,8 @@ async def test_did_list_filter_public(self): async def test_did_list_filter_posted(self): self.request.query = {"posture": DIDPosture.POSTED.moniker} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -333,8 +333,8 @@ async def test_did_list_filter_posted(self): async def test_did_list_filter_did(self): self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did.return_value = DIDInfo( self.test_did, @@ -362,8 +362,8 @@ async def test_did_list_filter_did(self): async def test_did_list_filter_did_x(self): self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did.side_effect = test_module.WalletError() result = await test_module.wallet_did_list(self.request) @@ -373,8 +373,8 @@ async def test_did_list_filter_did_x(self): async def test_did_list_filter_verkey(self): self.request.query = {"verkey": self.test_verkey} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -402,8 +402,8 @@ async def test_did_list_filter_verkey(self): async def test_did_list_filter_verkey_x(self): self.request.query = {"verkey": self.test_verkey} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did_for_verkey.side_effect = test_module.WalletError() result = await test_module.wallet_did_list(self.request) @@ -412,8 +412,8 @@ async def test_did_list_filter_verkey_x(self): assert result is json_response.return_value async def test_get_public_did(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -444,26 +444,26 @@ async def test_get_public_did_x(self): async def test_set_public_did(self): self.request.query = {"did": self.test_did} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock() + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did, @@ -472,6 +472,8 @@ async def test_set_public_did(self): SOV, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() json_response.assert_called_once_with( @@ -492,12 +494,12 @@ async def test_set_public_did_no_query_did(self): await test_module.wallet_set_public_did(self.request) async def test_set_public_did_no_ledger(self): - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) @@ -509,18 +511,18 @@ async def test_set_public_did_no_ledger(self): async def test_set_public_did_not_public(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock(return_value=None) - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock(return_value=None) + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) @@ -531,18 +533,18 @@ async def test_set_public_did_not_public(self): async def test_set_public_did_not_found(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock(return_value=None) - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock(return_value=None) + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) @@ -554,25 +556,25 @@ async def test_set_public_did_not_found(self): async def test_set_public_did_x(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did_sov, @@ -588,25 +590,25 @@ async def test_set_public_did_x(self): async def test_set_public_did_no_wallet_did(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did_sov, @@ -622,26 +624,26 @@ async def test_set_public_did_no_wallet_did(self): async def test_set_public_did_update_endpoint(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did_sov, @@ -650,6 +652,8 @@ async def test_set_public_did_update_endpoint(self): SOV, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() json_response.assert_called_once_with( @@ -670,28 +674,26 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) default_endpoint = "https://default_endpoint.com" self.context.update_settings({"default_endpoint": default_endpoint}) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock( return_value=None ) - mock_route_manager.routing_info = async_mock.AsyncMock( - return_value=(None, None) - ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.routing_info = mock.CoroutineMock(return_value=(None, None)) + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: did_info = DIDInfo( self.test_did_sov, @@ -728,19 +730,19 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) async def test_set_public_did_with_non_sov_did(self): self.request.query = {"did": self.test_did_web} - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( + mock_route_manager.__aenter__ = mock.CoroutineMock( return_value=mock_route_manager ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did_web, @@ -749,6 +751,8 @@ async def test_set_public_did_with_non_sov_did(self): WEB, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() self.wallet.set_did_endpoint.assert_not_called() @@ -767,17 +771,17 @@ async def test_set_public_did_with_non_sov_did(self): assert result is json_response.return_value async def test_set_did_endpoint(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.get_local_did.return_value = DIDInfo( @@ -795,14 +799,14 @@ async def test_set_did_endpoint(self): ED25519, ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: await test_module.wallet_set_did_endpoint(self.request) json_response.assert_called_once_with({}) async def test_set_did_endpoint_public_did_no_ledger(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -829,17 +833,17 @@ async def test_set_did_endpoint_public_did_no_ledger(self): await test_module.wallet_set_did_endpoint(self.request) async def test_set_did_endpoint_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletError() @@ -848,17 +852,17 @@ async def test_set_did_endpoint_x(self): await test_module.wallet_set_did_endpoint(self.request) async def test_set_did_endpoint_no_wallet_did(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletNotFoundError() @@ -877,8 +881,8 @@ async def test_get_did_endpoint(self): ED25519, ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: await test_module.wallet_get_did_endpoint(self.request) json_response.assert_called_once_with( @@ -913,10 +917,10 @@ async def test_get_did_endpoint_wallet_x(self): async def test_rotate_did_keypair(self): self.request.query = {"did": "did"} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -925,8 +929,8 @@ async def test_rotate_did_keypair(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = async_mock.AsyncMock() - self.wallet.rotate_did_keypair_apply = async_mock.AsyncMock() + self.wallet.rotate_did_keypair_start = mock.CoroutineMock() + self.wallet.rotate_did_keypair_apply = mock.CoroutineMock() await test_module.wallet_rotate_did_keypair(self.request) json_response.assert_called_once_with({}) @@ -945,13 +949,13 @@ async def test_rotate_did_keypair_no_query_did(self): async def test_rotate_did_keypair_did_not_local(self): self.request.query = {"did": "did"} - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( side_effect=test_module.WalletNotFoundError("Unknown DID") ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.wallet_rotate_did_keypair(self.request) - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -966,7 +970,7 @@ async def test_rotate_did_keypair_did_not_local(self): async def test_rotate_did_keypair_x(self): self.request.query = {"did": "did"} - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -975,20 +979,20 @@ async def test_rotate_did_keypair_x(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = async_mock.AsyncMock( + self.wallet.rotate_did_keypair_start = mock.CoroutineMock( side_effect=test_module.WalletError() ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_rotate_did_keypair(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/poetry.lock b/poetry.lock index 26789e52ea..3ad7d994b4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -208,17 +208,6 @@ files = [ {file = "async_timeout-4.0.3-py3-none-any.whl", hash = "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"}, ] -[[package]] -name = "asynctest" -version = "0.13.0" -description = "Enhance the standard unittest package with features for testing asyncio libraries" -optional = false -python-versions = ">=3.5" -files = [ - {file = "asynctest-0.13.0-py3-none-any.whl", hash = "sha256:5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676"}, - {file = "asynctest-0.13.0.tar.gz", hash = "sha256:c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac"}, -] - [[package]] name = "attrs" version = "23.1.0" @@ -2804,4 +2793,4 @@ indy = ["python3-indy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "25a7e7c9a8eac657166c465e0b51a2e821233801b86ac01cd6e294afdfe390b6" +content-hash = "2be14ad5c4160104421c2d4447aa5fda080347ae4206c36b278b6f93fd65fb0d" diff --git a/pyproject.toml b/pyproject.toml index b6c2019b64..bca443e084 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,6 @@ pydevd="1.5.1" pydevd-pycharm="~193.6015.39" # testing -asynctest= "0.13.0" pytest= "~7.4.0" pytest-asyncio= "^0.21.1" pytest-cov= "4.1.0"