diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index c3887ad61c..4202005c0c 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 +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.AsyncMock(return_value="abc123"), ) - handler = async_mock.AsyncMock() + handler = mock.AsyncMock() 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.AsyncMock(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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock(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.AsyncMock(), 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.AsyncMock(return_value={"a": 1}) ), ) @@ -165,17 +159,15 @@ 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() - ) as mock_start: + with mock.patch.object(web.TCPSite, "start", mock.AsyncMock()) as mock_start: mock_start.side_effect = OSError("Failure to launch") with self.assertRaises(AdminSetupError): await self.get_admin_server(settings).start() @@ -199,7 +191,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 +212,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.AsyncMock(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.AsyncMock(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.AsyncMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.AsyncMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.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.AsyncMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.AsyncMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.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.AsyncMock(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.AsyncMock(return_value="abc123"), ) - with async_mock.patch.object( + with mock.patch.object( server.multitenant_manager, "get_profile_for_token", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_get_profile: mock_get_profile.side_effect = [ test_module.MultitenantManagerError("corrupt token"), @@ -493,8 +485,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.AsyncMock() ) 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/askar/didcomm/tests/test_v2.py b/aries_cloudagent/askar/didcomm/tests/test_v2.py index 90706aad9c..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 unittest 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/commands/tests/test_help.py b/aries_cloudagent/commands/tests/test_help.py index 53a4501fbd..b94906795e 100644 --- a/aries_cloudagent/commands/tests/test_help.py +++ b/aries_cloudagent/commands/tests/test_help.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import help as command @@ -6,10 +6,10 @@ 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() @@ -18,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 c9d3cde8cc..0944977dff 100644 --- a/aries_cloudagent/commands/tests/test_init.py +++ b/aries_cloudagent/commands/tests/test_init.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ... import commands as test_module @@ -10,11 +10,11 @@ def test_available(self): 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 3664186bd8..aef197dd72 100644 --- a/aries_cloudagent/commands/tests/test_provision.py +++ b/aries_cloudagent/commands/tests/test_provision.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.base import ConfigError @@ -40,34 +40,34 @@ def test_provision_wallet(self): ) async def test_provision_ledger_configured(self): - profile = async_mock.MagicMock(close=async_mock.AsyncMock()) - with async_mock.patch.object( + profile = mock.MagicMock(close=mock.AsyncMock()) + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ) as mock_wallet_config, async_mock.patch.object( - test_module, "ledger_config", async_mock.AsyncMock(return_value=True) + ) as mock_wallet_config, mock.patch.object( + test_module, "ledger_config", mock.AsyncMock(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.AsyncMock() + with mock.patch.object( + test_module, "wallet_config", mock.AsyncMock() ) 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 @@ -76,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 1d763dd8a7..5e1464225d 100644 --- a/aries_cloudagent/commands/tests/test_start.py +++ b/aries_cloudagent/commands/tests/test_start.py @@ -1,6 +1,6 @@ import sys -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.error import ArgsParseError @@ -17,25 +17,25 @@ def test_bad_args(self): test_module.execute(["bad"]) async def test_start_shutdown_app(self): - mock_conductor = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(), - stop=async_mock.AsyncMock(), + mock_conductor = mock.MagicMock( + setup=mock.AsyncMock(), + start=mock.AsyncMock(), + stop=mock.AsyncMock(), ) await test_module.start_app(mock_conductor) await test_module.shutdown_app(mock_conductor) def test_exec_start(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "start_app", autospec=True - ) as start_app, async_mock.patch.object( + ) as start_app, mock.patch.object( test_module, "run_loop" - ) as run_loop, async_mock.patch.object( + ) as run_loop, mock.patch.object( test_module, "shutdown_app", autospec=True - ) as shutdown_app, async_mock.patch.object( - test_module, "uvloop", async_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", @@ -57,13 +57,11 @@ def test_exec_start(self): run_loop.assert_called_once() async def test_run_loop(self): - startup = async_mock.AsyncMock() + startup = mock.AsyncMock() startup_call = startup() - shutdown = async_mock.AsyncMock() + shutdown = mock.AsyncMock() 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() @@ -78,10 +76,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.AsyncMock() + mock_asyncio.gather = mock.AsyncMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = tasks @@ -94,13 +92,13 @@ async def test_run_loop(self): shutdown.assert_awaited_once() async def test_run_loop_init_x(self): - startup = async_mock.AsyncMock(side_effect=KeyError("the front fell off")) + startup = mock.AsyncMock(side_effect=KeyError("the front fell off")) startup_call = startup() - shutdown = async_mock.AsyncMock() + shutdown = mock.AsyncMock() 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) @@ -116,8 +114,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.AsyncMock() + task = mock.MagicMock() + mock_asyncio.gather = mock.AsyncMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = [task] @@ -131,10 +129,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 bde77c2c61..45b6b206fa 100644 --- a/aries_cloudagent/commands/tests/test_upgrade.py +++ b/aries_cloudagent/commands/tests/test_upgrade.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -52,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): await test_module.upgrade( settings={ @@ -76,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): await test_module.upgrade(settings={}) @@ -100,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.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -118,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.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -140,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.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -157,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.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -171,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -207,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -245,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ): @@ -266,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade( @@ -297,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -332,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -365,26 +365,26 @@ 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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() - ), async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() + ), mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: - mock_get_event_loop.return_value = async_mock.MagicMock( - run_until_complete=async_mock.MagicMock(), + mock_get_event_loop.return_value = mock.MagicMock( + run_until_complete=mock.MagicMock(), ) test_module.execute( [ @@ -397,19 +397,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -430,19 +430,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.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(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": { @@ -487,10 +487,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) @@ -505,10 +505,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 @@ -652,10 +652,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": { @@ -681,10 +681,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": { @@ -711,12 +711,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 a6f5b2c7f2..c110666606 100644 --- a/aries_cloudagent/config/tests/test_argparse.py +++ b/aries_cloudagent/config/tests/test_argparse.py @@ -1,6 +1,6 @@ from configargparse import ArgumentTypeError -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import argparse @@ -28,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() @@ -61,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() @@ -129,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() @@ -250,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() @@ -305,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() @@ -596,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_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index 637044a1e0..515f1db52c 100644 --- a/aries_cloudagent/config/tests/test_ledger.py +++ b/aries_cloudagent/config/tests/test_ledger.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import argparse @@ -16,14 +16,12 @@ class TestLedgerConfig(IsolatedAsyncioTestCase): async def test_fetch_genesis_transactions(self): - with async_mock.patch.object( - test_module, "fetch", async_mock.AsyncMock() - ) as mock_fetch: + with mock.patch.object(test_module, "fetch", mock.AsyncMock()) 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.AsyncMock(return_value=TEST_GENESIS) + with mock.patch.object( + test_module, "fetch", mock.AsyncMock(return_value=TEST_GENESIS) ) as mock_fetch: mock_fetch.side_effect = test_module.FetchError("404 Not Found") with self.assertRaises(test_module.ConfigError): @@ -35,10 +33,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.AsyncMock(return_value=TEST_GENESIS), + mock.AsyncMock(return_value=TEST_GENESIS), ) as mock_fetch: await test_module.get_genesis_transactions(settings) self.assertEqual(settings["ledger.genesis_transactions"], TEST_GENESIS) @@ -47,11 +45,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) ) ) ) @@ -63,7 +61,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) @@ -73,8 +71,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.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -82,7 +80,7 @@ async def test_ledger_config_no_taa_accept(self): }, } ), - get_latest_txn_author_acceptance=async_mock.AsyncMock( + get_latest_txn_author_acceptance=mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), read_only=False, @@ -97,8 +95,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.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = False assert not await test_module.ledger_config( @@ -109,8 +107,8 @@ async def test_accept_taa(self): settings = { "ledger.genesis_transactions": TEST_GENESIS, } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -118,13 +116,13 @@ async def test_accept_taa(self): }, } ), - get_latest_txn_author_acceptance=async_mock.AsyncMock( + get_latest_txn_author_acceptance=mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), - update_endpoint_for_did=async_mock.AsyncMock(), + update_endpoint_for_did=mock.AsyncMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock(set_did_endpoint=async_mock.AsyncMock()) + mock_wallet = mock.MagicMock(set_did_endpoint=mock.AsyncMock()) session = InMemoryProfile.test_session(settings=settings) profile = session.profile @@ -136,8 +134,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.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = True await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -147,13 +145,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.AsyncMock(), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock( + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock( side_effect=LedgerError( "Error cannot update endpoint when ledger is in read only mode" ) @@ -170,8 +168,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.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: with self.assertRaises(test_module.ConfigError) as x_context: await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -184,13 +182,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.AsyncMock(), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -203,8 +201,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.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config(profile, TEST_DID, provision=True) mock_ledger.get_txn_author_agreement.assert_not_called() @@ -217,16 +215,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.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={"taa_required": False} ), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), - update_endpoint_for_did=async_mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), + update_endpoint_for_did=mock.AsyncMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -239,8 +237,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.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config( profile, @@ -337,17 +335,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.AsyncMock(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.AsyncMock(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) ) ) ) @@ -434,17 +430,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.AsyncMock(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.AsyncMock(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) ) ) ) @@ -498,17 +492,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.AsyncMock(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.AsyncMock(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) ) ) ) @@ -565,17 +557,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.AsyncMock(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.AsyncMock(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) ) ) ) @@ -626,22 +616,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.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: + mock.AsyncMock(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 = { @@ -653,9 +641,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 = { @@ -663,34 +651,32 @@ 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.AsyncMock() + 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.AsyncMock() ) 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.AsyncMock() + 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.AsyncMock() ) 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.AsyncMock() + 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.AsyncMock() ) as mock_prompt: - mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.AsyncMock() - ) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) mock_prompt.return_value = "" assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False @@ -733,9 +719,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.AsyncMock() - ) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False ) @@ -747,7 +731,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 88bc315e31..13ceff1f8d 100644 --- a/aries_cloudagent/config/tests/test_logging.py +++ b/aries_cloudagent/config/tests/test_logging.py @@ -3,7 +3,7 @@ from io import StringIO -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from tempfile import NamedTemporaryFile @@ -21,8 +21,8 @@ class TestLoggingConfigurator(IsolatedAsyncioTestCase): 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() @@ -34,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) @@ -63,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" @@ -83,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 2b8d874f5d..944b4a7b86 100644 --- a/aries_cloudagent/config/tests/test_provider.py +++ b/aries_cloudagent/config/tests/test_provider.py @@ -1,7 +1,7 @@ from tempfile import NamedTemporaryFile from weakref import ref -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...utils.stats import Collector @@ -34,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 72f7d8d554..f7e1f848e2 100644 --- a/aries_cloudagent/config/tests/test_wallet.py +++ b/aries_cloudagent/config/tests/test_wallet.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -33,13 +33,13 @@ async def open(self, context, config): class TestWalletConfig(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.injector = Injector(enforce_typing=False) - self.session = async_mock.MagicMock(ProfileSession)() - self.session.commit = async_mock.AsyncMock() - self.profile = async_mock.MagicMock( + self.session = mock.MagicMock(ProfileSession)() + self.session.commit = mock.AsyncMock() + self.profile = mock.MagicMock( backend="indy", created=True, name="Test Wallet", - transaction=async_mock.AsyncMock(return_value=self.session), + transaction=mock.AsyncMock(return_value=self.session), ) def _inject(cls): @@ -57,32 +57,32 @@ async def test_wallet_config_existing_replace(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + 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.AsyncMock() + 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.AsyncMock() ): 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.AsyncMock(return_value=self.session), + transaction=mock.AsyncMock(return_value=self.session), ) self.context.injector.clear_binding(ProfileManager) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) @@ -94,23 +94,23 @@ async def test_wallet_config_existing_open(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + 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.AsyncMock() + 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.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -125,21 +125,21 @@ async def test_wallet_config_auto_provision(self): "auto_provision": False, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + 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.AsyncMock() - ) as mock_mgr_open, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + MockManager, "open", mock.AsyncMock() + ) as mock_mgr_open, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_mgr_open.side_effect = test_module.ProfileNotFoundError() @@ -156,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.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + 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.AsyncMock() + with mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -174,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.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + 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.AsyncMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -198,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.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + 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.AsyncMock() + 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.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -222,38 +222,38 @@ async def test_wallet_config_seed_public(self): "wallet.seed": "00000000000000000000000000000000", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_public_did=mock.AsyncMock( + 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.AsyncMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): 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.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_public_did=mock.AsyncMock( + 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.AsyncMock() + 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.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -265,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.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + 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.AsyncMock() - ) as mock_mgr_provision, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + MockManager, "provision", mock.AsyncMock() + ) as mock_mgr_provision, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_mgr_provision.return_value = self.profile diff --git a/aries_cloudagent/connections/tests/test_base_manager.py b/aries_cloudagent/connections/tests/test_base_manager.py index 256bc5f6ab..0fd7407614 100644 --- a/aries_cloudagent/connections/tests/test_base_manager.py +++ b/aries_cloudagent/connections/tests/test_base_manager.py @@ -2,7 +2,7 @@ from unittest.mock import call -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from pydid import DID, DIDDocument, DIDDocumentBuilder from pydid.doc.builder import ServiceBuilder @@ -83,8 +83,8 @@ async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) self.route_manager = CoordinateMediationV1RouteManager() self.resolver = DIDResolver() @@ -110,7 +110,7 @@ async def asyncSetUp(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 ) @@ -215,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.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(mediation_record.routing_keys, mediation_record.endpoint) ) doc = await self.manager.create_did_document( @@ -308,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) == [] @@ -330,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): @@ -354,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -378,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -425,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -448,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -491,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( @@ -512,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -531,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( method=SOV, @@ -551,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -579,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -602,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -641,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -664,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -703,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -726,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -764,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -787,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -809,11 +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.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER.rfc23, ) @@ -836,8 +836,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): ) did_doc = builder.build() - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -850,18 +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.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -876,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.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.get_key_for_did = async_mock.AsyncMock( + self.resolver.get_key_for_did = mock.AsyncMock( return_value=self.test_target_verkey ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -892,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( @@ -907,13 +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.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -936,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, @@ -956,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", @@ -985,7 +985,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): metadata=None, ) - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( self.test_endpoint, [self.test_verkey], @@ -995,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", @@ -1030,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) recip, routing = await self.manager.verification_methods_for_service( @@ -1042,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), []) ) targets = await self.manager.resolve_connection_targets(did) @@ -1064,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) targets = await self.manager.resolve_connection_targets(did) @@ -1086,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertLogs() as cm: @@ -1111,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1133,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1146,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), service_builder.services) ) await self.manager.record_did(did) @@ -1162,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.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) await self.manager.record_did(did) @@ -1189,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.AsyncMock(), + mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1204,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1219,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.AsyncMock(), + mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: self.context.injector.clear_binding(BaseCache) mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1240,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.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -1266,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.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = InjectionError() mock_mgr_find_conn.return_value = mock_conn @@ -1286,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.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = WalletNotFoundError() mock_mgr_find_conn.return_value = mock_conn @@ -1322,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1381,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(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.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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"} @@ -1425,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", @@ -1433,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1469,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", @@ -1477,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1526,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.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1549,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, @@ -1567,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.AsyncMock() + self.route_manager.route_static = mock.AsyncMock() - 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( @@ -1600,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.AsyncMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + self.route_manager.route_static = mock.AsyncMock() + 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.AsyncMock() + ) as mock_wallet_create_local_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -1629,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.AsyncMock() + default_mediator = mock.MagicMock() + self.route_manager.route_static = mock.AsyncMock() - 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( @@ -1688,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, @@ -1700,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, @@ -1712,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1730,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.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1750,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.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() ) 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1769,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.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.side_effect = StorageNotFoundError() @@ -1787,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + ) as mock_wallet_get_local_did, mock.patch.object( + self.manager, "get_connection_targets", mock.AsyncMock() ) 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..698f355df2 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 +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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock(), ): 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.AsyncMock(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.AsyncMock() + mock_outbound_mgr.return_value.start = mock.AsyncMock() + mock_outbound_mgr.return_value.stop = mock.AsyncMock() 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.AsyncMock(), + enqueue_message=mock.AsyncMock(), ) payload = "{}" @@ -707,14 +703,12 @@ 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() - ) + mock_conn_mgr.return_value.get_connection_targets = mock.AsyncMock() 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 +723,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 +739,19 @@ 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( + conductor, "queue_outbound", mock.AsyncMock() + ) 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 +774,22 @@ 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() + conn_mgr.return_value.get_connection_targets = mock.AsyncMock() mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" ) @@ -817,11 +811,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 +828,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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() admin_start.assert_awaited_once_with() @@ -861,11 +853,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 +870,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.AsyncMock(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.AsyncMock( side_effect=KeyError("double trouble") ) - conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=KeyError("triple trouble") ) await conductor.start() @@ -910,15 +900,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 +917,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.AsyncMock(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 +938,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.AsyncMock() await conductor.start() mock_mgr.return_value.create_static_connection.assert_awaited_once() @@ -959,22 +947,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.AsyncMock(), + start=mock.AsyncMock(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.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -983,18 +971,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.AsyncMock(), + start=mock.AsyncMock(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.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -1003,20 +991,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.AsyncMock(), + start=mock.AsyncMock(side_effect=KeyError("trouble")), + stop=mock.AsyncMock(), registered_transports={}, - enqueue_message=async_mock.AsyncMock(), + enqueue_message=mock.AsyncMock(), ) await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -1028,7 +1016,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 +1027,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 +1049,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 +1060,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 +1085,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.AsyncMock(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 +1115,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.AsyncMock()), + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1161,36 +1141,32 @@ 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() - ), - ) as mock_mgr, async_mock.patch.object( - MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ), async_mock.patch.object( + return_value=mock.MagicMock(set_default_mediator_by_id=mock.AsyncMock()), + ) as mock_mgr, mock.patch.object( + MediationRecord, "retrieve_by_id", mock.AsyncMock() + ), 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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1201,26 +1177,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.AsyncMock(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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1238,14 +1210,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 +1228,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 +1246,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 +1262,11 @@ async def test_shutdown_multitenant_profiles(self): multitenant_mgr._profiles.put( "test1", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.AsyncMock()), ) multitenant_mgr._profiles.put( "test2", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.AsyncMock()), ) await conductor.stop() @@ -1305,13 +1277,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.AsyncMock(return_value=unused_invite), + mark_default_invite_as_used=mock.AsyncMock(return_value=used_invite), ) @@ -1330,65 +1302,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.AsyncMock(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.AsyncMock() + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(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 +1378,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.AsyncMock(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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): assert not conductor.root_profile.settings["mediation.connections_invite"] await conductor.start() @@ -1431,8 +1397,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 +1414,33 @@ 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) - ) - mock_mediation_manager = async_mock.MagicMock( - clear_default_mediator=async_mock.AsyncMock() + connection_manager_mock = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn_record) ) + mock_mediation_manager = mock.MagicMock(clear_default_mediator=mock.AsyncMock()) # 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.AsyncMock() + ), 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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1490,8 +1452,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 +1463,23 @@ 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.AsyncMock()) 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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): # when await conductor.start() @@ -1533,7 +1491,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 +1500,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.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1574,17 +1530,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.AsyncMock(), + ) as mock_multiple_genesis_load, mock.patch.object( + test_module, "get_genesis_transactions", mock.AsyncMock() + ) 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 +1551,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.AsyncMock() + ) 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 +1566,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.AsyncMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): 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..43df17e272 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 +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.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(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.AsyncMock( + 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.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(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.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(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.AsyncMock() + ), mock.patch.object( + test_module, "validate_get_response_version", mock.AsyncMock() ): 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,10 @@ 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.AsyncMock()), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ): await responder.send_outbound(outbound_message) @@ -452,12 +448,10 @@ 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.AsyncMock()), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ): await responder.send_outbound( message=outbound_message, @@ -482,10 +476,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.AsyncMock(return_value=False), ): with self.assertRaises(RuntimeError): await responder.send_outbound( @@ -508,8 +502,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.AsyncMock() ) as mock_conn_ret_by_id: conn_rec = test_module.ConnRecord() conn_rec.state = test_module.ConnRecord.State.COMPLETED @@ -529,13 +523,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.AsyncMock()) ) 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.AsyncMock() ) as mock_conn_ret_by_id: conn_rec_a = test_module.ConnRecord() conn_rec_a.state = test_module.ConnRecord.State.REQUEST @@ -553,28 +547,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.AsyncMock() ) as mock_send_outbound: await responder.send(message) assert mock_send_outbound.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.AsyncMock() ) 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.AsyncMock() ) as mock_send_outbound: await responder.send_reply(message) assert mock_send_outbound.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.AsyncMock() ) as mock_send_outbound: await responder.send_reply(message) @@ -611,14 +605,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.AsyncMock(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.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -640,14 +634,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.AsyncMock(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.AsyncMock(return_value=("1.1", "version-with-degraded-features")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -669,14 +663,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.AsyncMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "version-not-supported")), + # mock.AsyncMock(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_event_bus.py b/aries_cloudagent/core/tests/test_event_bus.py index c201f94b24..cf36790488 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 unittest 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,8 +105,8 @@ 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) diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index eebdaa6931..7bc1175b4f 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -1,7 +1,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from unittest.mock import ANY from ...connections.models.conn_record import ConnRecord @@ -23,12 +23,12 @@ class TestOobProcessor(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = async_mock.AsyncMock() + self.inbound_message_router = mock.AsyncMock() 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 asyncSetUp(self): "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], "serviceEndpoint": "http://their-service-endpoint.com", }, - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), + save=mock.AsyncMock(), ) 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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), 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.AsyncMock(return_value=mock_oob), + mock.AsyncMock(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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), 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.AsyncMock(return_value=mock_oob), + mock.AsyncMock(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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), 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.AsyncMock(return_value=mock_oob), + mock.AsyncMock(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.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), 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.AsyncMock(return_value=mock_oob), + mock.AsyncMock(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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(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.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(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.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(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.AsyncMock(return_value=None), + mock.AsyncMock(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.AsyncMock(return_value=None), + mock.AsyncMock(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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(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,20 +435,18 @@ 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.AsyncMock(return_value=self.oob_record), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(return_value=self.oob_record), + ) as mock_retrieve, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(delete_record=async_mock.AsyncMock()) - ), + mock.AsyncMock(return_value=mock.MagicMock(delete_record=mock.AsyncMock())), ) 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( @@ -473,10 +471,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -500,10 +498,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -518,10 +516,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -538,10 +536,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -556,10 +554,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -577,10 +575,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -606,10 +604,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -631,10 +629,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -657,10 +655,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.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -678,9 +676,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.AsyncMock(), + save=mock.AsyncMock(), attach_thread_id=None, their_service=None, ) @@ -709,9 +707,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.AsyncMock(), connection_id=None - ) + oob_record = mock.MagicMock(save=mock.AsyncMock(), connection_id=None) await self.oob_processor.handle_message( self.profile, @@ -743,7 +739,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 b3d75ada63..b6373d9282 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from unittest.mock import call @@ -20,36 +20,36 @@ def setUp(self): 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.AsyncMock() + mod.setup = mock.AsyncMock() 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.AsyncMock() - definition = async_mock.MagicMock() + mod.routes.register = mock.AsyncMock() + definition = mock.MagicMock() definition.versions = [ { "major_version": 1, @@ -59,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) @@ -73,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) @@ -89,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.AsyncMock() + mod.routes.register = mock.AsyncMock() - 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) @@ -106,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) @@ -122,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, @@ -137,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) @@ -151,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) @@ -167,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.AsyncMock() + mod.routes.register = mock.AsyncMock() - 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) @@ -184,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) @@ -197,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 = [ @@ -248,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 = [ @@ -268,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 = [ @@ -288,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 = [ @@ -314,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 = [ @@ -334,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 = [ @@ -360,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 @@ -372,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 = [ @@ -385,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 = [ @@ -404,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 @@ -414,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 @@ -437,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 @@ -453,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 @@ -469,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 @@ -485,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 @@ -502,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, @@ -564,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, @@ -589,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_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py index 154e0ac322..1357b9f082 100644 --- a/aries_cloudagent/core/tests/test_protocol_registry.py +++ b/aries_cloudagent/core/tests/test_protocol_registry.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -205,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.AsyncMock() - mock.return_value.check_access.return_value = True - mock.return_value.determine_roles = async_mock.AsyncMock() - 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.AsyncMock() + mocked.return_value.check_access.return_value = True + mocked.return_value.determine_roles = mock.AsyncMock() + 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"] @@ -235,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) @@ -246,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) @@ -269,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") @@ -288,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 e4094fe8e3..6c4d1888fd 100644 --- a/aries_cloudagent/holder/tests/test_routes.py +++ b/aries_cloudagent/holder/tests/test_routes.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -38,7 +38,7 @@ def setUp(self): 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={}, @@ -49,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.AsyncMock( + mock.MagicMock( + get_credential=mock.AsyncMock( 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"}) @@ -67,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.AsyncMock( + mock.MagicMock( + get_credential=mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -80,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.AsyncMock(return_value=False) - ), + mock.MagicMock(credential_revoked=mock.AsyncMock(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}) @@ -105,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.AsyncMock( + mock.MagicMock( + credential_revoked=mock.AsyncMock( side_effect=test_module.WalletNotFoundError("no such cred") ) ), @@ -121,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.AsyncMock( + mock.MagicMock( + credential_revoked=mock.AsyncMock( side_effect=test_module.LedgerError("down for maintenance") ) ), @@ -141,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.AsyncMock( + mock.MagicMock( + get_mime_type=mock.AsyncMock( 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"}} @@ -162,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.AsyncMock(return_value=None) - ), + mock.MagicMock(delete_credential=mock.AsyncMock(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({}) @@ -178,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.AsyncMock( + mock.MagicMock( + delete_credential=mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -191,13 +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.AsyncMock(return_value=[{"hello": "world"}]) + mock.MagicMock( + get_credentials=mock.AsyncMock(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"}]}) @@ -207,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.AsyncMock( + mock.MagicMock( + get_credentials=mock.AsyncMock( side_effect=test_module.IndyHolderError() ) ), @@ -221,13 +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.AsyncMock(return_value=VC_RECORD) + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(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()) @@ -236,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.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -250,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.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageError() ) ), @@ -264,14 +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.AsyncMock(return_value=VC_RECORD), - delete_credential=async_mock.AsyncMock(return_value=None), + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), + delete_credential=mock.AsyncMock(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({}) @@ -281,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.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -295,9 +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.AsyncMock(return_value=VC_RECORD), - delete_credential=async_mock.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), + delete_credential=mock.AsyncMock( side_effect=test_module.StorageError() ), ), @@ -307,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -320,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.AsyncMock(return_value=[VC_RECORD]) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -349,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.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -364,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -377,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.AsyncMock( - side_effect=test_module.StorageError() - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(side_effect=test_module.StorageError()) ) ) ), @@ -392,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 331efbf929..3a389914fa 100644 --- a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py +++ b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py @@ -2,7 +2,7 @@ import tempfile import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager @@ -46,16 +46,16 @@ class TestIndyCredxIssuance(IsolatedAsyncioTestCase): async def asyncSetUp(self): context = InjectionContext(enforce_typing=False) - mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock(return_value={"value": {}}), - get_revoc_reg_delta=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.AsyncMock(return_value=mock_ledger) self.ledger = mock_ledger self.holder_profile = await AskarProfileManager().provision( @@ -77,8 +77,8 @@ async def asyncSetUp(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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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 7601b3fda1..307fd652b9 100644 --- a/aries_cloudagent/indy/models/tests/test_pres_preview.py +++ b/aries_cloudagent/indy/models/tests/test_pres_preview.py @@ -6,7 +6,7 @@ from unittest import TestCase from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile from ....ledger.multiple_ledger.ledger_requests_executor import ( @@ -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.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( 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 dc4b0e39f3..6784005809 100644 --- a/aries_cloudagent/indy/sdk/tests/test_holder.py +++ b/aries_cloudagent/indy/sdk/tests/test_holder.py @@ -1,7 +1,7 @@ import json import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase import indy.anoncreds @@ -16,23 +16,23 @@ @pytest.mark.indy 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.AsyncMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.MagicMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.AsyncMock(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 = ("{}", "[]") @@ -50,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" @@ -69,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.AsyncMock() - ) + mock_storage.return_value = mock.MagicMock(add_record=mock.AsyncMock()) mock_store_cred.return_value = "cred_id" @@ -100,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"} @@ -125,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"} @@ -150,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"} @@ -164,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 ): @@ -194,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 ): @@ -209,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, @@ -289,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, @@ -324,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") @@ -332,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") @@ -346,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.AsyncMock() + with mock.patch.object( # no creds revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -359,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.AsyncMock() + with mock.patch.object( # cred not revocable + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -372,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.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "value": { @@ -383,8 +381,8 @@ async def test_credential_revoked(self): 1234567890, ) ) - with async_mock.patch.object( # cred not revoked - self.holder, "get_credential", async_mock.AsyncMock() + with mock.patch.object( # cred not revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -396,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.AsyncMock() + with mock.patch.object( # cred revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -409,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, @@ -433,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, @@ -460,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 = { @@ -578,10 +576,10 @@ async def test_create_revocation_state(self): "timestamp": 1234567890, } - with async_mock.patch.object( - test_module, "create_tails_reader", async_mock.AsyncMock() - ) as mock_create_tails_reader, async_mock.patch.object( - indy.anoncreds, "create_revocation_state", async_mock.AsyncMock() + with mock.patch.object( + test_module, "create_tails_reader", mock.AsyncMock() + ) as mock_create_tails_reader, mock.patch.object( + indy.anoncreds, "create_revocation_state", mock.AsyncMock() ) 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 51932914c6..d0946a65d7 100644 --- a/aries_cloudagent/indy/sdk/tests/test_issuer.py +++ b/aries_cloudagent/indy/sdk/tests/test_issuer.py @@ -1,7 +1,7 @@ import json import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from indy.error import ( @@ -52,7 +52,7 @@ async def asyncSetUp(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) @@ -62,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) @@ -94,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 @@ -114,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 @@ -127,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, @@ -212,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, @@ -310,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, @@ -341,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, @@ -373,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 ): @@ -388,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 cf0675cd95..669656ced2 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 unittest import mock as async_mock +from unittest 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.AsyncMock()): + with mock.patch.object(opened, "close", mock.AsyncMock()): 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.AsyncMock()): + with mock.patch.object(profile.opened, "close", mock.AsyncMock()): 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 0e7a35a7d2..cd1a3a5349 100644 --- a/aries_cloudagent/indy/sdk/tests/test_util.py +++ b/aries_cloudagent/indy/sdk/tests/test_util.py @@ -4,7 +4,7 @@ import indy.blob_storage -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...util import indy_client_dir, generate_pr_nonce @@ -27,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.AsyncMock() + with mock.patch.object( + indy.blob_storage, "open_reader", mock.AsyncMock() ) 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 a5b6cfcab2..d5e9f37088 100644 --- a/aries_cloudagent/indy/sdk/tests/test_verifier.py +++ b/aries_cloudagent/indy/sdk/tests/test_verifier.py @@ -3,7 +3,7 @@ from copy import deepcopy -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from indy.error import IndyError @@ -294,8 +294,8 @@ @pytest.mark.indy class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={ "...": "...", "value": { @@ -324,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.AsyncMock() - ) 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.AsyncMock() + ) 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) @@ -359,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.AsyncMock() - ) 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.AsyncMock() + ) 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) @@ -391,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) @@ -419,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) @@ -447,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) @@ -475,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) @@ -509,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) @@ -540,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) @@ -569,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 b90c6d0a59..1ca4f752f5 100644 --- a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py +++ b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -15,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) @@ -30,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: @@ -46,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): @@ -61,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: @@ -78,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): @@ -94,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: @@ -111,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 e31ecefdf2..910f110c71 100644 --- a/aries_cloudagent/indy/tests/test_verifier.py +++ b/aries_cloudagent/indy/tests/test_verifier.py @@ -4,7 +4,7 @@ from time import time from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...ledger.multiple_ledger.ledger_requests_executor import ( @@ -309,8 +309,8 @@ async def verify_presentation( @pytest.mark.indy class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( 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/multiple_ledger/tests/test_indy_ledger_requests.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py index 4199f395d1..58c4d475e1 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile @@ -31,14 +31,14 @@ async def asyncSetUp(self): ) self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - extract_did_from_identifier=async_mock.AsyncMock( + mock.MagicMock( + extract_did_from_identifier=mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.AsyncMock( return_value=("test_prod_1", self.ledger) ), - get_ledger_inst_by_id=async_mock.AsyncMock(return_value=self.ledger), + get_ledger_inst_by_id=mock.AsyncMock(return_value=self.ledger), ), ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -68,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.AsyncMock( + mock.MagicMock( + extract_did_from_identifier=mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.AsyncMock( 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 a239c69f95..14a144959e 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py @@ -4,7 +4,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from collections import OrderedDict @@ -29,7 +29,7 @@ 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.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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 a7635b215f..6cc0d0200b 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 @@ -3,7 +3,7 @@ import pytest from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from copy import deepcopy from collections import OrderedDict @@ -61,7 +61,7 @@ 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.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) 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 e0b25fd860..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,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager @@ -69,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_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index 037c0d957f..5bbfc05dd9 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -5,7 +5,7 @@ from os import path -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -49,9 +49,7 @@ 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, @@ -75,24 +73,24 @@ async def asyncSetUp(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.AsyncMock(), + mock.AsyncMock(), 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"), @@ -115,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) @@ -139,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") @@ -153,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 @@ -175,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 @@ -198,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 @@ -230,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 @@ -251,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 @@ -269,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, @@ -287,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: @@ -299,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -323,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, @@ -341,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True), self.profile ) - ledger.get_latest_txn_author_acceptance = async_mock.AsyncMock( + ledger.get_latest_txn_author_acceptance = mock.AsyncMock( return_value={ "text": "sample", "version": "0.0", @@ -374,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, @@ -387,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 @@ -405,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, @@ -418,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 @@ -439,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, @@ -452,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 @@ -473,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 @@ -485,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, @@ -501,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 @@ -522,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, @@ -545,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 @@ -559,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.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + 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: @@ -574,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -610,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, @@ -629,25 +623,23 @@ async def test_send_schema_already_exists( mock_create_config, mock_set_proto, ): - # mock_did = async_mock.AsyncMock() + # mock_did = mock.AsyncMock() - 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.AsyncMock() + mock_add_record = mock.AsyncMock() 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 @@ -666,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, @@ -687,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.AsyncMock( + ledger._submit = mock.AsyncMock( side_effect=LedgerTransactionError("UnauthorizedClientRequest") ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + 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 @@ -717,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, @@ -732,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 @@ -756,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, @@ -773,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.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.create_schema = mock.AsyncMock( 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 @@ -798,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, @@ -817,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.AsyncMock( + ledger._submit = mock.AsyncMock( 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 @@ -841,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, @@ -862,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", "{}") @@ -874,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: - mock_wallet.get_public_did = async_mock.AsyncMock() + mock_wallet.get_public_did = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -889,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -926,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, @@ -939,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -978,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, @@ -989,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1017,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, @@ -1032,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"]}') @@ -1058,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1076,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 ), ] @@ -1088,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, @@ -1103,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"]}') @@ -1126,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() 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, @@ -1159,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 @@ -1181,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, @@ -1193,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.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + 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: @@ -1226,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, @@ -1251,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 @@ -1273,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, @@ -1283,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( @@ -1309,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, @@ -1330,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 = [] @@ -1351,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, @@ -1362,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.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + 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( @@ -1396,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() 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, @@ -1444,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() 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( @@ -1480,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" @@ -1499,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() 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( @@ -1526,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" @@ -1545,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.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock( 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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1563,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( @@ -1576,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" @@ -1595,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.AsyncMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) + issuer.create_and_store_credential_definition = mock.AsyncMock( 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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1616,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( @@ -1629,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" @@ -1648,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.AsyncMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) + issuer.create_and_store_credential_definition = mock.AsyncMock( return_value=("cred-def-id", "cred-def-json") ) ledger = IndySdkLedger( @@ -1660,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1671,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( @@ -1684,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" @@ -1703,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.AsyncMock( - return_value=False - ) + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() 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, @@ -1741,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 = [] @@ -1762,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, @@ -1771,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: @@ -1803,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, @@ -1824,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 = [] @@ -1845,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( @@ -1868,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, @@ -1881,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.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), @@ -1919,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, @@ -1932,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 @@ -1961,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, @@ -1974,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, @@ -1983,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 @@ -1992,20 +1968,20 @@ 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 @@ -2022,21 +1998,21 @@ async def test_get_key_for_did( ) 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 @@ -2056,14 +2032,14 @@ async def test_get_endpoint_for_did( ) 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 @@ -2077,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 @@ -2100,14 +2076,14 @@ async def test_get_endpoint_of_type_profile_for_did( ) 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" @@ -2116,7 +2092,7 @@ 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 @@ -2136,20 +2112,20 @@ async def test_get_all_endpoints_for_did( ) 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 @@ -2169,20 +2145,20 @@ async def test_get_all_endpoints_for_did_none( ) 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 @@ -2202,18 +2178,18 @@ async def test_get_endpoint_for_did_address_none( ) 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 @@ -2233,12 +2209,12 @@ async def test_get_endpoint_for_did_no_endpoint( ) 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, @@ -2248,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 @@ -2263,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 @@ -2281,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) @@ -2310,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 @@ -2334,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, @@ -2351,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.AsyncMock( + mock.AsyncMock( return_value=json.dumps( { "endpoint": { @@ -2373,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.AsyncMock(return_value={}), - ), async_mock.patch.object( + mock.AsyncMock(return_value={}), + ), mock.patch.object( ledger, "did_to_nym" ): mock_wallet_get_public_did.return_value = self.test_did_info @@ -2391,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, @@ -2406,18 +2382,18 @@ 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.AsyncMock() + with mock.patch.object( + ledger, "get_all_endpoints_for_did", mock.AsyncMock() ) as mock_get_all: mock_get_all.return_value = None response = await ledger.update_endpoint_for_did( @@ -2433,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, @@ -2455,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 @@ -2473,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.AsyncMock(return_value=False), + # mock.AsyncMock(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 @@ -2496,30 +2470,30 @@ 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 @@ -2539,14 +2513,14 @@ async def test_update_endpoint_for_did_duplicate( ) 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( @@ -2555,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 @@ -2566,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, @@ -2579,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( @@ -2594,7 +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.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.AsyncMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2623,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 @@ -2645,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.AsyncMock(), - replace_local_did_metadata=async_mock.AsyncMock(), + get_local_did=mock.AsyncMock(), + replace_local_did_metadata=mock.AsyncMock(), ) 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 @@ -2675,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, @@ -2688,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"}, @@ -2696,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 @@ -2709,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, @@ -2722,20 +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.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.AsyncMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2758,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( { @@ -2806,7 +2780,7 @@ 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 @@ -2818,20 +2792,20 @@ async def test_get_nym_role( ) assert mock_submit.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 @@ -2840,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( { @@ -2879,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 @@ -2887,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, @@ -2902,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})}}), @@ -2915,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 @@ -2928,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 @@ -2954,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, @@ -2969,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 @@ -2990,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, @@ -3003,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", @@ -3014,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 @@ -3022,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"}, @@ -3038,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 @@ -3047,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, @@ -3060,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", @@ -3071,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 @@ -3079,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, @@ -3092,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, @@ -3101,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 @@ -3109,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, @@ -3122,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", @@ -3133,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 @@ -3141,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 @@ -3172,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 @@ -3203,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 @@ -3231,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 @@ -3264,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 @@ -3297,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 @@ -3327,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 @@ -3345,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, @@ -3358,14 +3332,14 @@ 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 @@ -3381,11 +3355,11 @@ async def test_get_txn_author_agreement( ) 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, ), @@ -3402,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 @@ -3436,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 @@ -3452,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 @@ -3476,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" @@ -3491,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 a820d5f8c2..4d6d31860e 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=False) + ), mock.patch.object( + ledger, "is_ledger_read_only", mock.AsyncMock(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.AsyncMock( + mock.AsyncMock( 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.AsyncMock(return_value=None), + mock.AsyncMock(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.AsyncMock( + mock.AsyncMock( 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.AsyncMock(return_value=False), - ), async_mock.patch.object( + mock.AsyncMock(return_value=False), + ), mock.patch.object( ledger, "is_ledger_read_only", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(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.AsyncMock(return_value=False), + mock.AsyncMock(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.AsyncMock( + mock.AsyncMock( 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.AsyncMock(return_value={}), + mock.AsyncMock(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.AsyncMock(return_value={"id": S_ID}), + mock.AsyncMock(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.AsyncMock( + mock.AsyncMock( 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..c6ca6f2e57 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 +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.AsyncMock(), } - 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.AsyncMock(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.AsyncMock( 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.AsyncMock( 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.AsyncMock(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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock(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.AsyncMock( 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.AsyncMock( 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.AsyncMock() + ) 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.AsyncMock( + 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.AsyncMock( 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.AsyncMock() + ) 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.AsyncMock( + 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.AsyncMock( 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.AsyncMock() + ) 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.AsyncMock(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.AsyncMock( 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.AsyncMock() ) 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.AsyncMock() ) 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.AsyncMock() ) 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.AsyncMock(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.AsyncMock() ) 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock(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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock() 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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 b8cdb22a10..08ceb622a3 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -26,26 +26,26 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_credential_definition = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_credential_definition = mock.AsyncMock( return_value=( CRED_DEF_ID, {"cred": "def", "signed_txn": "..."}, True, ) ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( 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.AsyncMock( - return_value=[async_mock.MagicMock(value=CRED_DEF_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.AsyncMock( + 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.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.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.AsyncMock() + ) 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.AsyncMock( + 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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.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.AsyncMock() + ) 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), } ) ) - 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.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.ledger.__aenter__ = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.AsyncMock(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.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(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/jsonld/tests/test_credential.py b/aries_cloudagent/messaging/jsonld/tests/test_credential.py index 3a8cc08917..46ff019838 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_credential.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_credential.py @@ -3,7 +3,7 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -64,7 +64,7 @@ async def asyncSetUp(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 ed4541fc52..cfe206eec4 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -3,7 +3,7 @@ from aiohttp import web from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=did_doc) + did_resolver = DIDResolver(mock.MagicMock()) + did_resolver.resolve = mock.AsyncMock(return_value=did_doc) yield did_resolver @pytest.fixture def mock_sign_credential(): temp = test_module.sign_credential - sign_credential = async_mock.AsyncMock(return_value="fake_signage") + sign_credential = mock.AsyncMock(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.AsyncMock(return_value="fake_verify") + verify_credential = mock.AsyncMock(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.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.AsyncMock( + json=mock.AsyncMock( 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.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.AsyncMock(return_value=request_body), + json=mock.AsyncMock(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.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.AsyncMock(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.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.AsyncMock(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.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.AsyncMock(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.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.AsyncMock(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.AsyncMock(side_effect=ResolverError) + mock_resolver.dereference = mock.AsyncMock(side_effect=ResolverError) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -256,14 +256,14 @@ 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"] @@ -280,9 +280,9 @@ async def asyncSetUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.AsyncMock(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.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.AsyncMock(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.AsyncMock(return_value=posted_request_x) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + self.request.json = mock.AsyncMock(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.AsyncMock(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.AsyncMock(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 dca01ebf14..b627227a0d 100644 --- a/aries_cloudagent/messaging/models/tests/test_base.py +++ b/aries_cloudagent/messaging/models/tests/test_base.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, INCLUDE, fields, validates_schema, ValidationError @@ -82,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 ee1c038a6f..dffee831d5 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields @@ -85,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.AsyncMock() + mock_storage = mock.MagicMock() + mock_storage.add_record = mock.AsyncMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() - with async_mock.patch.object( - record, "post_save", async_mock.AsyncMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.AsyncMock()) 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.AsyncMock() + mock_storage = mock.MagicMock() + mock_storage.update_record = mock.AsyncMock() 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.AsyncMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.AsyncMock()) 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() @@ -117,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" @@ -148,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.AsyncMock(side_effect=ZeroDivisionError()) + with mock.patch.object(session, "inject", mock.MagicMock()) as mock_inject: + mock_inject.return_value = mock.MagicMock( + add_record=mock.AsyncMock(side_effect=ZeroDivisionError()) ) with self.assertRaises(ZeroDivisionError): await rec.save(session) @@ -164,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()} @@ -184,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()} @@ -194,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") @@ -260,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 3482da421f..0d2f4dc50c 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -24,22 +24,22 @@ 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.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_schema = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_schema = mock.AsyncMock( return_value=(SCHEMA_ID, {"schema": "def", "signed_txn": "..."}) ) - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( 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.AsyncMock( - return_value=[async_mock.MagicMock(value=SCHEMA_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.AsyncMock( + 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.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.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.AsyncMock() + ) 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.AsyncMock( + 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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.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.AsyncMock() + ) 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.AsyncMock(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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + self.ledger.create_and_send_schema = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.AsyncMock(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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( 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/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 4453a9286c..e894fefd75 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -17,7 +17,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) 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 b4455d9865..1776457750 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock import jwt from .. import base as test_module @@ -49,7 +49,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) 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.AsyncMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() 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.AsyncMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() - 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.AsyncMock(), + save=mock.AsyncMock(), ) 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.AsyncMock(), + save=mock.AsyncMock(), ) 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.AsyncMock(return_value=mock_wallet), - ), async_mock.patch.object( - self.manager, "get_wallet_profile", async_mock.AsyncMock() + mock.AsyncMock(return_value=mock_wallet), + ), mock.patch.object( + self.manager, "get_wallet_profile", mock.AsyncMock() ) 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 a0a78d2b66..8268a6713b 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...messaging.responder import BaseResponder @@ -12,7 +12,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) 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/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py index 4fa58a8d18..1031fffaac 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,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -10,10 +10,10 @@ 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.AsyncMock() + handler.save_connection_menu = mock.AsyncMock() 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 4d0a626af5..0d32f3c902 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,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,16 +12,16 @@ 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.AsyncMock(return_value="menu") + self.menu_service.get_active_menu = mock.AsyncMock(return_value="menu") handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) @@ -33,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.AsyncMock(return_value=None) + self.menu_service.get_active_menu = mock.AsyncMock(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 0e56a5d698..d0276ddd30 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,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,18 +12,16 @@ 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.AsyncMock( - return_value="perform" - ) + self.menu_service.perform_menu_action = mock.AsyncMock(return_value="perform") handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) @@ -35,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.Perform() - self.menu_service.perform_menu_action = async_mock.AsyncMock(return_value=None) + self.menu_service.perform_menu_action = mock.AsyncMock(return_value=None) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) 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 b8f9274222..1407df6ead 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....core.in_memory import InMemoryProfile from .....messaging.request_context import RequestContext @@ -12,12 +12,12 @@ async def asyncSetUp(self): 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.AsyncMock(return_value=self.menu_service) + self.context.inject = mock.AsyncMock(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 0e5be07b1c..54f3cacd5c 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,9 +13,9 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock() - test_module.save_connection_menu = async_mock.AsyncMock() + test_module.retrieve_connection_menu = mock.AsyncMock() + test_module.save_connection_menu = mock.AsyncMock() - 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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock() - test_module.save_connection_menu = async_mock.AsyncMock( + test_module.retrieve_connection_menu = mock.AsyncMock() + test_module.save_connection_menu = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -46,35 +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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.AsyncMock(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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.AsyncMock(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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() res = await test_module.actionmenu_perform(self.request) mock_response.assert_called_once_with({}) @@ -84,16 +84,16 @@ async def test_actionmenu_perform(self): ) async def test_actionmenu_perform_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -101,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() res = await test_module.actionmenu_request(self.request) mock_response.assert_called_once_with({}) @@ -137,16 +137,16 @@ async def test_actionmenu_request(self): ) async def test_actionmenu_request_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -154,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() - mock_menu.deserialize = async_mock.MagicMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_menu.deserialize = mock.MagicMock() res = await test_module.actionmenu_send(self.request) mock_response.assert_called_once_with({}) @@ -191,16 +191,16 @@ async def test_actionmenu_send(self): ) async def test_actionmenu_send_deserialize_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() - mock_menu.deserialize = async_mock.MagicMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_menu.deserialize = mock.MagicMock( side_effect=test_module.BaseModelError("cannot deserialize") ) @@ -208,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -227,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() 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 fe9c1e0a50..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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....core.event_bus import EventBus, MockEventBus from .....core.in_memory import InMemoryProfile @@ -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/basicmessage/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py index 652b1fdffd..c676424c86 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,9 +13,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -24,33 +24,33 @@ async def asyncSetUp(self): self.test_conn_id = "connection-id" async def test_connections_send_message(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() 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 034dd35705..19327c146d 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() 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.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() 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.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() request_context.message = ConnectionRequest() - with async_mock.patch.object( + with mock.patch.object( connection_record, "metadata_get", - async_mock.AsyncMock(return_value={"id": "test-mediation-id"}), + mock.AsyncMock(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.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = ConnectionRequest() storage: BaseStorage = session.inject(BaseStorage) - with async_mock.patch.object( + with mock.patch.object( storage, "find_record", - async_mock.AsyncMock(raises=StorageNotFoundError), + mock.AsyncMock(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.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() 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 8c0fe1ecfa..99c489f9f5 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() 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/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index 8623ac015f..cef9770402 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -58,16 +58,14 @@ async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.AsyncMock( - return_value=None - ) + self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) self.resolver = DIDResolver() self.resolver.register_resolver(LegacyPeerDIDResolver()) @@ -90,7 +88,7 @@ async def asyncSetUp(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 ) @@ -136,8 +134,8 @@ async def test_create_invitation_non_multi_use_invitation_fails_on_reuse(self): async def test_create_invitation_public(self): self.context.update_settings({"public_invites": True}) - self.route_manager.route_verkey = async_mock.AsyncMock() - with async_mock.patch.object( + self.route_manager.route_verkey = mock.AsyncMock() + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -168,7 +166,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 @@ -266,7 +264,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.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -278,7 +276,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: @@ -292,7 +290,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.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -304,10 +302,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.AsyncMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ): _, invite = await self.manager.create_invitation( routing_keys=[self.test_verkey], @@ -356,9 +354,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" ) @@ -424,14 +420,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.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -477,14 +473,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.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -528,14 +524,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.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -559,10 +555,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( @@ -576,18 +572,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.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) 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) @@ -599,10 +595,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( @@ -616,28 +612,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.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) 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( @@ -650,35 +646,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.AsyncMock() - mock_connection_record.attach_request = async_mock.AsyncMock() + mock_connection_record = mock.MagicMock() + mock_connection_record.save = mock.AsyncMock() + mock_connection_record.attach_request = mock.AsyncMock() 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.AsyncMock(return_value=mock_connection_record), + mock.AsyncMock(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( @@ -693,18 +689,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.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) 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) @@ -712,8 +708,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 @@ -728,13 +724,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): @@ -742,10 +738,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( @@ -759,23 +755,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) @@ -788,13 +784,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): @@ -802,10 +798,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( @@ -821,16 +817,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.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) 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) @@ -842,16 +838,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.AsyncMock() + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.AsyncMock() ): await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -869,24 +865,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.AsyncMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + ConnRecord, "metadata_get", mock.AsyncMock(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.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -943,23 +937,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.AsyncMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + record, "metadata_get", mock.AsyncMock(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.AsyncMock(return_value=[mediation_record]), - ), async_mock.patch.object( + mock.AsyncMock(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( @@ -990,16 +982,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.AsyncMock(return_value=True) + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.AsyncMock(return_value=True) ): await self.manager.create_response(conn_rec) @@ -1009,30 +1001,28 @@ 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.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1041,34 +1031,32 @@ 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.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=False), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(return_value=False), connection_id="test-conn-id", invitation_key="test-invitation-id", ) @@ -1080,21 +1068,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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1103,21 +1091,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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) 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 ) @@ -1125,22 +1113,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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) 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, ) @@ -1148,23 +1136,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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) 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, ) @@ -1172,28 +1160,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.AsyncMock(side_effect=ValueError) + mock_response.verify_signed_field = mock.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1201,30 +1189,28 @@ 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.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(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 e0d6c156f8..e092c0a52a 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -2,7 +2,7 @@ from unittest.mock import ANY from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -19,9 +19,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock() + mock_conn_rec.query = mock.AsyncMock() 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,29 +124,27 @@ 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), - ) - mock_conn_rec.query = async_mock.AsyncMock( - side_effect=test_module.StorageError() + get=mock.MagicMock(return_value=ConnRecord.State.COMPLETED), ) + mock_conn_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_list(self.request) 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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 +154,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.AsyncMock( + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock( return_value=("localhost:8080", "1.2.3.4:8081") ) ) @@ -180,24 +176,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.AsyncMock(side_effect=StorageNotFoundError()) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock(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.AsyncMock( - side_effect=test_module.WalletError() - ) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock(side_effect=test_module.WalletError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -205,13 +199,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) 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 @@ -223,16 +217,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_get", async_mock.AsyncMock() - ) as mock_metadata_get, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_get", mock.AsyncMock() + ) 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 @@ -244,13 +238,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) 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 @@ -265,18 +259,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.AsyncMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.AsyncMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() + ) 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 @@ -288,18 +282,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.AsyncMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.AsyncMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() + ) 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 @@ -315,8 +309,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -325,13 +319,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -347,7 +341,7 @@ async def test_connections_create_invitation(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -355,19 +349,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.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( 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"), ), ) ) @@ -396,7 +390,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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -404,10 +398,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.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -423,17 +417,17 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(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.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -441,7 +435,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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -453,23 +447,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( return_value=mock_conn_rec ) @@ -477,18 +471,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.AsyncMock() + self.request.json = mock.AsyncMock() 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() @@ -503,22 +497,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -532,18 +526,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + mock_conn_mgr.return_value.create_request = mock.AsyncMock() await test_module.connections_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -551,8 +545,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -562,12 +556,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -578,12 +572,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -596,18 +590,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() await test_module.connections_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -615,8 +609,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -626,14 +620,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_mgr.return_value.create_response = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -642,12 +636,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.AsyncMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.AsyncMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 @@ -661,12 +655,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.AsyncMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.AsyncMock() assert (await cache.get("conn_rec_state::dummy")) == "active" - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 @@ -678,10 +672,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -690,12 +684,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.AsyncMock(side_effect=test_module.StorageError()) + mock_conn_rec = mock.MagicMock( + delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - 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.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -703,7 +697,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -721,21 +715,21 @@ 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.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( return_value=(mock_my_info, mock_their_info, mock_conn_rec) ) @@ -752,7 +746,7 @@ async def test_connections_create_static(self): ) async def test_connections_create_static_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -770,19 +764,19 @@ 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.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( side_effect=test_module.WalletError() ) @@ -790,13 +784,13 @@ async def test_connections_create_static_x(self): 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_update_response_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py index 7399ce0d3c..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 @@ -4,7 +4,7 @@ from typing import AsyncGenerator import pytest from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord @@ -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_grant_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py index 62abea7057..4a3c45a20e 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=True), - ), async_mock.patch.object( + mock.AsyncMock(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.AsyncMock() - responder.send = async_mock.AsyncMock() + handler, responder = MediationGrantHandler(), mock.AsyncMock() + responder.send = mock.AsyncMock() profile = context.profile profile.context.update_settings( {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - multitenant_mgr = async_mock.AsyncMock() + multitenant_mgr = mock.AsyncMock() profile.context.injector.bind_instance(BaseMultitenantManager, multitenant_mgr) default_base_mediator = MediationRecord(routing_keys=["key1", "key2"]) - multitenant_mgr.get_default_mediator = async_mock.AsyncMock() + multitenant_mgr.get_default_mediator = mock.AsyncMock() 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.AsyncMock(return_value=False), - ), async_mock.patch.object( + mock.AsyncMock(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/tests/test_mediation_invite_store.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py index 4bf2015bc7..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 unittest import IsolatedAsyncioTestCase from unittest import TestCase -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.protocols.coordinate_mediation.mediation_invite_store import ( MediationInviteStore, @@ -49,7 +49,7 @@ def test_unused_should_create_unused_record(self): 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 e1ac4abb64..c56799eaf5 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.AsyncMock() + ) 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.AsyncMock()) + mock.MagicMock(delete_record=mock.AsyncMock()) ] * 2 await manager.store_update_results(TEST_CONN_ID, results) 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 fb9702eb54..5987124d3d 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import routes as test_module @@ -15,18 +15,18 @@ 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.AsyncMock() + self.outbound_message_router = mock.AsyncMock() 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.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: self.request_dict[k], ) serialized = { @@ -38,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.AsyncMock() + serialize=mock.MagicMock(return_value=serialized), + save=mock.AsyncMock() ) def test_mediation_sort_key(self): @@ -66,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.AsyncMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(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( @@ -88,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.AsyncMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(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( @@ -112,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.AsyncMock(side_effect=test_module.StorageError()) + mock.MagicMock( + query=mock.AsyncMock(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.AsyncMock(return_value=[])), - ) as mock_med_rec, async_mock.patch.object( + mock.MagicMock(query=mock.AsyncMock(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.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 @@ -147,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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 @@ -159,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.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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 @@ -171,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.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( - self.mock_record, "delete_record", async_mock.AsyncMock() - ) as mock_delete_record, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_mediation_record_retrieve, mock.patch.object( + self.mock_record, "delete_record", mock.AsyncMock() + ) as mock_delete_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_mediation_record_retrieve.return_value = self.mock_record @@ -187,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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 @@ -199,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.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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 @@ -213,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.AsyncMock(return_value=False), - ) as mock_mediation_record_exists, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(return_value=False), + ) as mock_mediation_record_exists, mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: - mock_med_mgr.return_value.prepare_request = async_mock.AsyncMock( + mock_med_mgr.return_value.prepare_request = mock.AsyncMock( 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"}), ), ) ) @@ -241,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.AsyncMock(return_value=async_mock.MagicMock(is_ready=False)), + mock.AsyncMock(return_value=mock.MagicMock(is_ready=False)), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -254,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ) as mock_exists_for_conn, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -269,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPNotFound ): @@ -281,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.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ): @@ -292,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.AsyncMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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) @@ -307,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.AsyncMock(return_value=self.mock_record), + mock.AsyncMock(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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(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.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(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.AsyncMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(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) @@ -347,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.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(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.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) @@ -380,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.AsyncMock(return_value=query_results), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(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) @@ -409,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.AsyncMock(return_value=[]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(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) @@ -425,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.AsyncMock(side_effect=test_module.StorageError), + mock.AsyncMock(side_effect=test_module.StorageError), ) as mock_query, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_keylist(self.request) @@ -460,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.AsyncMock( - return_value=async_mock.MagicMock( + mock.AsyncMock( + 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: @@ -502,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.AsyncMock( - return_value=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( state=MediationRecord.STATE_DENIED, connection_id="test-conn-id" ) ), @@ -527,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_update(self.request) @@ -544,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.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(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.AsyncMock(return_value=self.mock_record), - ) as mock_retrieve_by_id, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_retrieve_by_id, mock.patch.object( mock_manager.return_value, "prepare_keylist_query", - async_mock.AsyncMock(), - ) as mock_prepare_keylist_query, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_prepare_keylist_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.send_keylist_query(self.request) @@ -577,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(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.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(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.AsyncMock(return_value=self.mock_record), + mock.AsyncMock(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( @@ -609,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.AsyncMock(return_value=None), + mock.AsyncMock(return_value=None), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -624,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.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(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) @@ -639,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.AsyncMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.AsyncMock(), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) 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) @@ -661,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.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(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): @@ -677,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.AsyncMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.AsyncMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) 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) @@ -696,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.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.AsyncMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) 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): @@ -716,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.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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) @@ -738,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.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() 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.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(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) @@ -760,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.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() 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.AsyncMock(side_effect=StorageError), + mock.AsyncMock(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 4cad2ad869..c4a44e6182 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + mock_conn_mgr.return_value.accept_complete = mock.AsyncMock() request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() @@ -38,16 +38,14 @@ async def test_called(self, mock_conn_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @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.AsyncMock( + mock_conn_mgr.return_value.accept_complete = mock.AsyncMock( 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() 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 38d63d3aea..fdccf610c7 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 unittest import mock as async_mock +from unittest import mock import pytest from .. import problem_report_handler as test_module @@ -19,11 +19,11 @@ 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.AsyncMock() + manager.return_value.receive_problem_report = mock.AsyncMock() 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) @@ -31,9 +31,9 @@ async def test_called(self, manager, request_context): assert manager.return_value.receive_problem_report.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.AsyncMock() + manager.return_value.receive_problem_report = mock.AsyncMock() 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.AsyncMock( + manager.return_value.receive_problem_report = mock.AsyncMock( 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 b822cc5b11..c97fa6ad3a 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import conn_record, connection_target @@ -91,9 +91,9 @@ async def asyncSetUp(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.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock() 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.AsyncMock() - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_conn_rec.save = mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() 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.AsyncMock( + test_exist_conn.metadata_get = mock.AsyncMock( return_value={"id": "mediation-test-id"} ) test_exist_conn.accept = conn_record.ConnRecord.ACCEPT_AUTO - test_exist_conn.save = async_mock.AsyncMock() - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + test_exist_conn.save = mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=test_exist_conn ) - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() 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.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( 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 85136440be..a90adddff5 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,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import connection_target @@ -78,9 +78,9 @@ async def asyncSetUp(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.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.AsyncMock() 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.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( 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.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( 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.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( 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/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index a5098e2beb..9e89d70392 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from pydid import DIDDocument from .. import manager as test_module @@ -72,18 +72,16 @@ class TestDidExchangeManager(IsolatedAsyncioTestCase, TestConfig): async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.AsyncMock( - return_value=None - ) - self.route_manager.mediation_record_for_connection = async_mock.AsyncMock( + self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) + self.route_manager.mediation_record_for_connection = mock.AsyncMock( return_value=None ) @@ -112,28 +110,26 @@ async def asyncSetUp(self): key_type=ED25519, ) - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.get_endpoint_for_did = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.get_endpoint_for_did = mock.AsyncMock( 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.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) assert did_doc.verification_method - self.resolver.dereference_verification_method = async_mock.AsyncMock( + self.resolver.dereference_verification_method = mock.AsyncMock( 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.AsyncMock( - return_value=None - ) + self.multitenant_mgr.get_default_mediator = mock.AsyncMock(return_value=None) self.manager = DIDXManager(self.profile) assert self.manager.profile @@ -176,9 +172,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 +183,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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation(invi_msg) @@ -204,9 +200,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 +212,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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation( @@ -236,7 +232,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 +275,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.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) 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 +352,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.AsyncMock() + with self.assertRaises(DIDXManagerError) as context, mock.patch.object( + test_module.ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_retrieve_by_did: await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -371,25 +367,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.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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 +396,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.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) 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 +413,23 @@ 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) 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.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) ) @@ -471,11 +465,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.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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 +482,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 +491,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.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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 +513,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.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) request = await self.manager.create_request(mock_conn_rec, use_public_did=True) @@ -538,16 +532,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 +563,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.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) 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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) 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.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - 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 +644,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 +657,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.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError) as context: @@ -684,10 +676,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 +701,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.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( - self.manager, "record_did", async_mock.AsyncMock() - ), async_mock.patch.object( + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( + self.manager, "record_did", mock.AsyncMock() + ), 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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) 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.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) - ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - 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 +784,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 +800,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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) 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.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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 +844,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.AsyncMock(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.AsyncMock(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 +866,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 +887,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 +908,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.AsyncMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + mock.AsyncMock(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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) - mock_did_doc_from_json.return_value = async_mock.MagicMock( - did="wrong-did" - ) + 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 +952,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 +973,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.AsyncMock(side_effect=DIDXManagerError), + mock.AsyncMock(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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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 +1012,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.AsyncMock(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.AsyncMock(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 +1033,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.AsyncMock() - ) 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.AsyncMock() + ) 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 +1060,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 +1083,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.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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 +1136,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.AsyncMock(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.AsyncMock(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,24 +1166,24 @@ 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.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(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.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=None ) @@ -1213,17 +1199,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.AsyncMock(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.AsyncMock(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 +1232,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.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(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.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( 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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record @@ -1295,19 +1281,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,10 +1301,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.AsyncMock(), - attach_request=async_mock.AsyncMock(), + save=mock.AsyncMock(), + attach_request=mock.AsyncMock(), accept=ConnRecord.ACCEPT_MANUAL, - metadata_get_all=async_mock.AsyncMock(return_value={"test": "value"}), + metadata_get_all=mock.AsyncMock(return_value={"test": "value"}), ) mock_conn_rec_state_request = ConnRecord.State.REQUEST @@ -1330,42 +1316,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.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( 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.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - metadata_set=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) - 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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - 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( @@ -1383,17 +1369,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.AsyncMock(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.AsyncMock(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( @@ -1403,10 +1389,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.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError): @@ -1424,26 +1410,24 @@ 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.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) 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.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1479,20 +1463,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.AsyncMock(return_value=False) - ), async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.AsyncMock(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.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) await self.manager.create_response( @@ -1531,14 +1515,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.AsyncMock(return_value=False) + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.AsyncMock(return_value=False) ): with self.assertRaises(DIDXManagerError) as context: await self.manager.create_response( @@ -1558,15 +1542,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.AsyncMock() - ), async_mock.patch.object( + ), mock.patch.object(conn_rec, "save", mock.AsyncMock()), mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) 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( @@ -1576,13 +1558,11 @@ 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec) @@ -1595,29 +1575,27 @@ 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.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( - InMemoryWallet, "get_local_did", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( + InMemoryWallet, "get_local_did", mock.AsyncMock() ) 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1645,26 +1623,24 @@ 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.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) 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.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response( @@ -1676,26 +1652,24 @@ 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.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) 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.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) 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.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) with self.assertRaises(DIDXManagerError) as context: @@ -1705,16 +1679,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.AsyncMock(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.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1724,38 +1696,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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1763,16 +1735,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.AsyncMock(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.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1783,40 +1753,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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() ) 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.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1825,50 +1795,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.AsyncMock(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.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) 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.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=False), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(return_value=False), connection_id="test-conn-id", ) @@ -1877,28 +1845,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.AsyncMock(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.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1907,28 +1873,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.AsyncMock(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.AsyncMock(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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) 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 ) @@ -1936,8 +1900,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 @@ -1946,30 +1910,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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() ): - 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), 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.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1977,8 +1941,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 @@ -1987,30 +1951,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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() ): - 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.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), 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.AsyncMock(), + save=mock.AsyncMock(), ) with self.assertRaises(DIDXManagerError) as context: @@ -2018,88 +1982,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.AsyncMock(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.AsyncMock(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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - 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.AsyncMock(), + save=mock.AsyncMock(), ) 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() 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.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() with self.assertRaises(DIDXManagerError): @@ -2113,7 +2073,7 @@ async def test_reject_invited(self): state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() reason = "He doesn't like you!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2126,7 +2086,7 @@ async def test_reject_requested(self): state=ConnRecord.State.REQUEST.rfc23, their_role=ConnRecord.Role.REQUESTER, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() reason = "I don't like you either! You just watch yourself!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2138,20 +2098,20 @@ async def test_reject_invalid(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() 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.AsyncMock() + mock_conn.abandon = mock.AsyncMock() report = DIDXProblemReport( description={ "code": ProblemReportReason.REQUEST_NOT_ACCEPTED.value, @@ -2162,26 +2122,26 @@ async def test_receive_problem_report(self): assert mock_conn.abandon.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.AsyncMock() + mock_conn.abandon = mock.AsyncMock() 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.AsyncMock() + mock_conn.abandon = mock.AsyncMock() report = DIDXProblemReport(description={"code": "something random"}) with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2256,10 +2216,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.AsyncMock(side_effect=ResolverError()), + mock.AsyncMock(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 c851d9d805..aa0d6ad657 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -14,17 +14,15 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock()) - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock(save=mock.AsyncMock()) + 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.AsyncMock() + mock_didx_mgr.return_value.create_request = mock.AsyncMock() 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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_didx_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -83,14 +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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="mock serialization") + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="mock serialization") ) ) @@ -105,12 +103,12 @@ 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.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( side_effect=StorageNotFoundError("not found") ) @@ -125,12 +123,12 @@ 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.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( side_effect=test_module.WalletError("wallet error") ) @@ -144,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) @@ -169,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( side_effect=StorageNotFoundError("tricorder must be broken") ) @@ -192,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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") @@ -212,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() await test_module.didx_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -231,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.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -242,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.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_didx_mgr.return_value.create_response = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -258,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.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + mock_didx_mgr.return_value.reject = mock.AsyncMock() 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.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - 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.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -285,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.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_didx_mgr.return_value.reject = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -302,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 721c3c6c82..48067632e0 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=discovery_record), + mock.AsyncMock(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 ee3ca03496..238c2908fe 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 unittest import mock as async_mock +from unittest 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.AsyncMock() - ) as mock_query_match, async_mock.patch.object( - ProtocolRegistry, "prepare_disclosed", async_mock.AsyncMock() + with mock.patch.object( + ProtocolRegistry, "protocols_matching_query", mock.AsyncMock() + ) as mock_query_match, mock.patch.object( + ProtocolRegistry, "prepare_disclosed", mock.AsyncMock() ) as mock_prepare_disclosed: mock_prepare_disclosed.return_value = [ {"test": "test"}, 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 df9ea4c8a8..d543b82865 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -90,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( @@ -103,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.AsyncMock(), + mock.AsyncMock(), ) 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 7ded2bc195..5a73fceb2c 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,7 @@ import logging import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -30,9 +30,7 @@ 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=[ @@ -53,10 +51,10 @@ async def asyncSetUp(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.AsyncMock() + ) as save_ex, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -72,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = True @@ -101,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -124,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -145,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V10DiscoveryExchangeRecord(), @@ -158,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V10DiscoveryExchangeRecord() @@ -186,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -207,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.AsyncMock(), + mock.AsyncMock(), ) 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 7922044c28..bc5043e1ec 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -18,9 +18,9 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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 b6dc14c5f1..58a166b711 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=discovery_record), + mock.AsyncMock(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.AsyncMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(return_value=discovery_record), + mock.AsyncMock(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.AsyncMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(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 ee557182c6..a814506686 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 unittest import mock as async_mock +from unittest 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.AsyncMock() - ) as mock_exec_protocol_query, async_mock.patch.object( - V20DiscoveryMgr, "execute_goal_code_query", async_mock.AsyncMock() + with mock.patch.object( + V20DiscoveryMgr, "execute_protocol_query", mock.AsyncMock() + ) as mock_exec_protocol_query, mock.patch.object( + V20DiscoveryMgr, "execute_goal_code_query", mock.AsyncMock() ) as mock_goal_code_protocol_query: mock_exec_protocol_query.return_value = [ {"test": "test"}, 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 8e50df1d19..882897d57d 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -147,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( @@ -160,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.AsyncMock(), + mock.AsyncMock(), ) 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 10bad1b6d3..4e374940d0 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,7 @@ import logging import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -30,9 +30,7 @@ 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=[ { @@ -59,10 +57,10 @@ async def asyncSetUp(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.AsyncMock() + ) as save_ex, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -78,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) 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 @@ -107,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) 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 @@ -130,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -151,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.AsyncMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_receive_query.return_value = Disclosures() await self.manager.proactive_disclose_features("test123") @@ -164,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.AsyncMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: self._caplog.set_level(logging.WARNING) mock_receive_query.return_value = Disclosures() @@ -179,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V20DiscoveryExchangeRecord(), @@ -204,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V20DiscoveryExchangeRecord() @@ -232,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.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -264,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.AsyncMock(), + mock.AsyncMock(), ) 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 a4a4c83f21..a994cfafa5 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -18,9 +18,9 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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 d4e9e008d2..5c08c853c8 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,12 +13,12 @@ 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.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() @@ -33,12 +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.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = False handler = test_module.EndorsedTransactionResponseHandler() @@ -51,12 +51,12 @@ 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.AsyncMock( + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = EndorsedTransactionResponse() 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 d17d7c9fa0..401a251f75 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,12 +13,12 @@ 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.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = True handler = test_module.RefusedTransactionResponseHandler() @@ -33,12 +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.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = False handler = test_module.RefusedTransactionResponseHandler() @@ -51,12 +51,12 @@ 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.AsyncMock( + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = RefusedTransactionResponse() 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 e3203af42b..e934131a67 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord @@ -15,11 +15,11 @@ 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.AsyncMock() + mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( @@ -38,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.AsyncMock() + mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_ready = False @@ -59,11 +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.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock.AsyncMock(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 ee445b31df..12423880e7 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,12 +15,10 @@ 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.AsyncMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -38,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.AsyncMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() request_context.message = CancelTransaction() request_context.connection_ready = False handler = test_module.TransactionCancelHandler() @@ -59,11 +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.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock( + 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 53658c7f75..b488aaaca3 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,14 +13,12 @@ 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.AsyncMock() - ) + mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock() request_context.message = TransactionJobToSend() request_context.connection_ready = True handler = test_module.TransactionJobToSendHandler() @@ -35,12 +33,12 @@ 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.AsyncMock( + mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionJobToSend() 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 36fa24cb8b..33fb0e11c9 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,10 +15,10 @@ 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.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -36,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.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_ready = False handler = test_module.TransactionRequestHandler() @@ -55,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.AsyncMock( + mock_tran_mgr.return_value.receive_request = mock.AsyncMock( 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 af949ca173..bc17c2a418 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,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,12 +15,10 @@ 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.AsyncMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() request_context.message = TransactionResend() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -38,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.AsyncMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() request_context.message = TransactionResend() request_context.connection_ready = False handler = test_module.TransactionResendHandler() @@ -59,11 +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.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionResend() request_context.connection_record = ConnRecord( 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 e7c5059d39..a158437844 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 @@ -3,7 +3,7 @@ import uuid from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -102,11 +102,11 @@ async def asyncSetUp(self): self.test_endorser_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" self.test_refuser_did = "AGDEjaMunDtFtBVrn1qPKQ" - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.txn_endorse = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.txn_endorse = mock.AsyncMock( return_value=self.test_endorsed_message ) - self.ledger.register_nym = async_mock.AsyncMock(return_value=(True, {})) + self.ledger.register_nym = mock.AsyncMock(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.AsyncMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) ) self.ledger.get_indy_storage = future - self.ledger.txn_submit = async_mock.AsyncMock( + self.ledger.txn_submit = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + conn_record = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_retrieve: - mock_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) 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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) 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 791ba0aa1c..0aee212ad4 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 @@ -2,7 +2,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -32,15 +32,13 @@ async def asyncSetUp(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.AsyncMock(return_value=self.ledger) - self.ledger.txn_endorse = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.txn_submit = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.txn_endorse = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.txn_submit = mock.AsyncMock( return_value=json.dumps( { "result": { @@ -52,21 +50,19 @@ async def asyncSetUp(self): ) future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.AsyncMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) ) self.ledger.get_indy_storage = future - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( return_value={"id": SCHEMA_ID, "...": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -76,24 +72,22 @@ async def asyncSetUp(self): self.test_did = "sample-did" async def test_transactions_list(self): - with async_mock.patch.object( - TransactionRecord, "query", async_mock.AsyncMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( 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.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - 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.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock(return_value=None) - ), + mock.MagicMock(get_public_did=mock.AsyncMock(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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( 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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -718,33 +710,31 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ), ) - self.ledger.txn_endorse = async_mock.AsyncMock( - side_effect=test_module.LedgerError() - ) - - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + self.ledger.txn_endorse = mock.AsyncMock(side_effect=test_module.LedgerError()) + + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -752,8 +742,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 +754,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -777,26 +767,26 @@ async def test_endorse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - 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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -804,8 +794,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 +806,8 @@ async def test_refuse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -829,32 +819,32 @@ async def test_refuse_transaction_response(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -862,8 +852,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 +864,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -887,12 +877,12 @@ async def test_refuse_transaction_response_not_found_x(self): ), ) - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 +894,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -917,18 +907,18 @@ async def test_refuse_transaction_response_conn_base_model_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 +929,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -952,20 +942,20 @@ async def test_refuse_transaction_response_no_jobs_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(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 +966,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -989,17 +979,17 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1007,8 +997,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 +1009,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.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -1032,26 +1022,26 @@ async def test_refuse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - 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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1059,8 +1049,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 +1059,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1098,8 +1088,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 +1098,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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1119,14 +1109,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) 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 +1125,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock(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 +1143,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1167,8 +1157,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 +1167,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - 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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1200,8 +1190,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 +1200,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1239,8 +1229,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 +1239,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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1260,14 +1250,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) 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 +1266,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock(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 +1284,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_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.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1309,8 +1299,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 +1309,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - 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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1342,8 +1332,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 +1342,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.AsyncMock() - ) 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.AsyncMock() + ) 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.AsyncMock() + mock_txn_mgr.return_value = mock.MagicMock( + set_transaction_my_job=mock.AsyncMock() ) - 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.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1380,8 +1370,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1391,8 +1381,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1402,13 +1392,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1418,7 +1408,7 @@ async def test_set_endorser_info(self): ), } ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1434,13 +1424,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.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ { "transaction_my_job": ( @@ -1457,7 +1447,7 @@ async def test_set_endorser_info_no_prior_value(self): }, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1472,8 +1462,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1484,8 +1474,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1496,11 +1486,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.set_endorser_info(self.request) @@ -1509,11 +1499,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1527,11 +1517,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.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) 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.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1546,24 +1536,22 @@ 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.AsyncMock() - ) 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.AsyncMock() + ) 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.AsyncMock() + mock_txn_mgr.return_value.complete_transaction = mock.AsyncMock() mock_txn_mgr.return_value.complete_transaction.return_value = ( - async_mock.AsyncMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) - ), - async_mock.AsyncMock(), + mock.AsyncMock(serialize=mock.MagicMock(return_value={"...": "..."})), + mock.AsyncMock(), ) - 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 +1563,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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1586,8 +1574,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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1596,11 +1584,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.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) 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 +1600,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.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + complete_transaction=mock.AsyncMock( 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 +1623,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 3b3f0ceadd..45049f43e3 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -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.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.AsyncMock( 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.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.AsyncMock( 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 5ddd695a72..d66afc900b 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -35,19 +35,19 @@ async def asyncSetUp(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.AsyncMock() + mock_ctx_inject.return_value = mock.MagicMock( + return_invitation=mock.AsyncMock() ) await handler.handle(self.context, responder) 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 186c86b50b..833090611d 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -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,13 +54,13 @@ 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.AsyncMock( + mock_mgr.return_value.create_invitation = mock.AsyncMock( return_value=(mock_conn_rec, conn_invitation) ) 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 1787ffa28d..af46ee1343 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -12,9 +12,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -22,7 +22,7 @@ async def asyncSetUp(self): ) async def test_introduction_start_no_service(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -44,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -61,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.AsyncMock() + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.AsyncMock() ) await test_module.introduction_start(self.request) @@ -78,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -101,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.AsyncMock( + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.AsyncMock( side_effect=test_module.IntroductionError() ) ) @@ -117,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/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 85b0f31510..ce38c2cbbd 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -16,20 +16,20 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = True handler = test_module.CredentialAckHandler() @@ -48,12 +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.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() @@ -68,18 +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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() 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 d96a7f2688..67697fbd79 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = True handler = test_module.CredentialIssueHandler() @@ -48,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock(), - store_credential=async_mock.AsyncMock(), - send_credential_ack=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock(), + store_credential=mock.AsyncMock(), + send_credential_ack=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), ) @@ -89,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - store_credential=async_mock.AsyncMock( + store_credential=mock.AsyncMock( side_effect=test_module.IndyHolderError() ), - send_credential_ack=async_mock.AsyncMock( + send_credential_ack=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), ) @@ -123,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) 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 +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.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = False handler = test_module.CredentialIssueHandler() @@ -154,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() 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 4e0697663c..94613b174f 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = True handler = test_module.CredentialOfferHandler() @@ -48,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock( return_value=(None, "credential_request_message") ) request_context.message = CredentialOffer() @@ -88,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) 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() @@ -126,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.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() @@ -149,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() 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 bd5bcb64d3..103b975ffc 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -17,13 +17,13 @@ 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.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = CredentialProblemReport( description={ "en": "Change of plans", @@ -43,13 +43,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, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = CredentialProblemReport( @@ -71,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 51cb64533e..f723bf16e8 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,13 +14,13 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = CredentialProposal() @@ -38,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + 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.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( return_value=(None, "credential_offer_message") ) request_context.message = CredentialProposal() @@ -69,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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) 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() @@ -100,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.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() 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 0ed5e7f66d..b89fff1b98 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,21 +19,19 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = CredentialRequest() @@ -54,13 +52,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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -74,14 +70,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.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "credential_issue_message") ) request_context.message = CredentialRequest() @@ -109,13 +105,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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -129,16 +123,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.AsyncMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -147,10 +141,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) 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() @@ -158,13 +152,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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -172,14 +164,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.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "credential_issue_message") ) @@ -202,12 +194,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.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = CredentialRequest() request_context.connection_ready = False handler = test_module.CredentialRequestHandler() @@ -225,18 +217,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = CredentialRequest() handler = test_module.CredentialRequestHandler() responder = MockResponder() 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 ac20adde83..ec5dea7a8d 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -78,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.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) 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 0396176a9d..16977f34a2 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,7 @@ from copy import deepcopy from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -55,29 +55,23 @@ 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.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -134,10 +128,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 ) @@ -162,13 +156,11 @@ async def test_create_proposal(self): ) ) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( 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, @@ -200,13 +192,11 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( 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, @@ -238,9 +228,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 ) @@ -291,14 +279,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.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -369,18 +355,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.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -429,16 +413,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.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -500,18 +484,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.AsyncMock( - return_value=INDY_OFFER - ) + issuer = mock.MagicMock() + issuer.create_credential_offer = mock.AsyncMock(return_value=INDY_OFFER) self.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(CredentialManagerError): @@ -554,12 +536,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.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -590,15 +572,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.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(side_effect=StorageNotFoundError), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -640,17 +622,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.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -707,21 +687,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.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -763,7 +741,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", @@ -779,12 +757,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.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_request(request, mock_conn, None) @@ -814,17 +792,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_exchange cx_rec = await self.manager.receive_request(request, mock_conn, mock_oob) @@ -855,16 +833,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = (StorageNotFoundError(),) with self.assertRaises(CredentialManagerError): @@ -905,28 +883,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.AsyncMock( + issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( 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.AsyncMock(), + get_or_fetch_local_tails_path=mock.AsyncMock(), max_creds=10, ), ) @@ -970,7 +948,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", @@ -993,28 +971,24 @@ 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.AsyncMock( - return_value=(json.dumps(cred), None) - ) + issuer.create_credential = mock.AsyncMock(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.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF_NR - ) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF_NR) + self.ledger.__aenter__ = mock.AsyncMock(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.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1064,36 +1038,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.AsyncMock( + issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + mock.AsyncMock( 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.AsyncMock(), + set_state=mock.AsyncMock(), ), - 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.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ) ) ), - handle_full_registry=async_mock.AsyncMock(), + handle_full_registry=mock.AsyncMock(), ) (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1165,35 +1139,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.AsyncMock( + issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( 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.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ), ] @@ -1231,25 +1203,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.AsyncMock( + issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=None ) with self.assertRaises(CredentialManagerError) as context: @@ -1275,12 +1245,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.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_credential(issue, connection_id) @@ -1331,30 +1301,28 @@ 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.AsyncMock(return_value=cred_id) - holder.get_credential = async_mock.AsyncMock( - return_value=json.dumps(INDY_CRED_INFO) - ) + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock(return_value=cred_id) + holder.get_credential = mock.AsyncMock(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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) ret_exchange = await self.manager.store_credential( @@ -1410,7 +1378,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 @@ -1434,29 +1402,27 @@ 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.AsyncMock( - return_value=cred_def - ) + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.AsyncMock(return_value=cred_id) - holder.get_credential = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock(return_value=cred_id) + holder.get_credential = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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) @@ -1504,21 +1470,19 @@ 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.AsyncMock( - return_value=cred_def - ) + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1544,14 +1508,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) @@ -1579,14 +1543,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.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange ret_exchange = await self.manager.receive_credential_ack(ack, connection_id) @@ -1620,12 +1584,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.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1648,10 +1612,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.AsyncMock(), + mock.AsyncMock(), ) 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 2224c2031a..c45f34b287 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -15,9 +15,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -32,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.AsyncMock() + mock_cred_ex.query = mock.AsyncMock() 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]} @@ -56,33 +54,29 @@ 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.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_cred_ex.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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 @@ -91,12 +85,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.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -105,40 +99,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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - 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, @@ -152,26 +146,26 @@ async def test_credential_exchange_create(self): ) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - 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() @@ -183,35 +177,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.AsyncMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.AsyncMock(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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - 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, @@ -227,9 +219,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.AsyncMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.AsyncMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send(self.request) @@ -239,23 +229,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( 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): @@ -265,52 +255,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_offer = async_mock.MagicMock() + mock_cred_offer = mock.MagicMock() - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), - prepare_send=async_mock.AsyncMock( + prepare_send=mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -325,18 +313,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.AsyncMock( + self.request.json = mock.AsyncMock( 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 ) @@ -350,22 +338,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( 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): @@ -375,11 +363,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.AsyncMock( + self.request.json = mock.AsyncMock( 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() @@ -387,21 +375,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() 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): @@ -411,20 +399,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record @@ -434,7 +420,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -446,18 +432,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.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() + 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) @@ -467,7 +453,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -480,14 +466,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -498,15 +484,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.AsyncMock(return_value=None), + self.session_inject[BaseWallet] = mock.MagicMock( + get_public_did=mock.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -516,13 +502,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.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.side_effect = ( test_module.BaseModelError() ) @@ -531,7 +517,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -541,22 +527,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -564,7 +550,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -574,20 +560,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.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() - 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) @@ -597,7 +583,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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "credential_preview": "dummy", @@ -607,7 +593,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.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "cred_def_id": CRED_DEF_ID, @@ -617,7 +603,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -625,49 +611,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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -677,25 +663,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.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -704,30 +688,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() - 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) @@ -737,67 +721,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_ACKED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) @@ -805,59 +789,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -867,36 +851,36 @@ async def test_credential_exchange_send_request(self): ) async def test_credential_exchange_send_request_no_conn(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -910,107 +894,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() - mock_cred_ex.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id.return_value = mock.MagicMock( state=mock_cred_ex.STATE_OFFER_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -1020,144 +1004,138 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.issue_credential = ( - async_mock.AsyncMock() - ) + mock_credential_manager.return_value.issue_credential = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.issue_credential = ( - async_mock.AsyncMock() - ) + mock_credential_manager.return_value.issue_credential = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.AsyncMock( - side_effect=test_module.IndyIssuerError() - ) + mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) mock_credential_manager.return_value.issue_credential = mock_issue_cred with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) - mock_credential_manager.return_value = async_mock.MagicMock( - issue_credential=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + issue_credential=mock.AsyncMock( return_value=( mock_cred_ex_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -1165,31 +1143,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -1199,33 +1177,33 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -1235,42 +1213,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1279,65 +1257,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock() ) - mock_credential_manager.return_value = async_mock.MagicMock( - store_credential=async_mock.AsyncMock(return_value=mock_cred_ex_record), - send_credential_ack=async_mock.AsyncMock( - return_value=(mock_cred_ex_record, async_mock.MagicMock()) + mock_credential_manager.return_value = mock.MagicMock( + store_credential=mock.AsyncMock(return_value=mock_cred_ex_record), + send_credential_ack=mock.AsyncMock( + return_value=(mock_cred_ex_record, mock.MagicMock()) ), ) @@ -1347,29 +1323,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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.delete_record = async_mock.AsyncMock() + mock_cred_ex.delete_record = mock.AsyncMock() 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.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1377,45 +1352,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.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_rec = mock.MagicMock( + delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock(return_value=mock_rec) + mock_cred_ex.retrieve_by_id = mock.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1428,15 +1398,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1444,21 +1414,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + save_error_state=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1468,13 +1438,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 5594d6625a..e9ce6eef88 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 @@ -2,7 +2,7 @@ from time import time import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from .. import handler as test_module @@ -198,27 +198,23 @@ 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.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( 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.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -228,11 +224,11 @@ async def asyncSetUp(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) @@ -286,33 +282,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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) 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( @@ -329,7 +325,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( @@ -340,8 +336,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) @@ -387,7 +383,7 @@ async def test_create_offer(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -453,7 +449,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.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -497,7 +493,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( @@ -515,13 +511,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.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): with self.assertRaises(V20CredFormatError): await self.handler.create_offer(cred_proposal) @@ -539,7 +535,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.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -548,8 +544,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) @@ -575,12 +571,10 @@ async def test_create_request(self): ) cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=cred_def - ) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_req_meta = {} - self.holder.create_credential_request = async_mock.AsyncMock( + self.holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) @@ -610,12 +604,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.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): await self.handler.create_request( cred_ex_record, {"holder_did": holder_did} @@ -643,8 +637,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.AsyncMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -656,15 +650,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) @@ -719,21 +713,19 @@ async def test_issue_credential_revocable(self): ) cred_rev_id = "1000" - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( 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.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), max_creds=10, ), ) @@ -807,20 +799,18 @@ async def test_issue_credential_non_revocable(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), None) ) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF_NR - ) + self.ledger.get_credential_definition = mock.AsyncMock(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.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (cred_format, attachment) = await self.handler.issue_credential( cred_ex_record, retries=0 @@ -847,8 +837,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.AsyncMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -905,14 +895,12 @@ async def test_issue_credential_no_active_rr_no_retries(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=() ) with self.assertRaises(V20CredFormatError) as context: @@ -965,24 +953,22 @@ async def test_issue_credential_no_active_rr_retry(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( 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.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ), ] @@ -1038,21 +1024,19 @@ async def test_issue_credential_rr_full(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( 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.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ) ) @@ -1062,8 +1046,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) @@ -1136,18 +1120,18 @@ async def test_store_credential(self): cred_id = "cred-id" - self.holder.store_credential = async_mock.AsyncMock(return_value=cred_id) + self.holder.store_credential = mock.AsyncMock(return_value=cred_id) stored_cred = {"stored": "cred"} - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( 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.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) with self.assertRaises(V20CredFormatError) as context: @@ -1155,25 +1139,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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.AsyncMock(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.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) - 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.AsyncMock(), + save=mock.AsyncMock(), ) self.ledger.get_credential_definition.reset_mock() @@ -1257,21 +1241,21 @@ async def test_store_credential_holder_store_indy_error(self): ) cred_id = "cred-id" - self.holder.store_credential = async_mock.AsyncMock( + self.holder.store_credential = mock.AsyncMock( 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.AsyncMock(), + save=mock.AsyncMock(), ) - mock_rev_reg.return_value = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg.return_value = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) 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 f636e33375..5cc37b415d 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from unittest.mock import patch from marshmallow import ValidationError @@ -133,17 +133,15 @@ class TestV20LDProofCredFormatHandler(IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) + 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock() + self.wallet.get_local_did = mock.AsyncMock() 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.AsyncMock(), - ) as mock_can_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_can_issue, mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ), 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.AsyncMock(), + mock.AsyncMock(), ), 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.AsyncMock(), + mock.AsyncMock(), ), 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.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(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.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(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.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(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.AsyncMock() + self.holder.store_credential = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.AsyncMock( - return_value=DocumentVerificationResult(verified=True) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.AsyncMock(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.AsyncMock() + self.holder.store_credential = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.AsyncMock( - return_value=DocumentVerificationResult(verified=False) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.AsyncMock(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 5b8168bb00..9bebdb14e8 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -15,19 +15,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = True handler = test_module.V20CredAckHandler() @@ -47,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.AsyncMock() + mock_cred_mgr.return_value.receive_cred_ack = mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = False handler = test_module.V20CredAckHandler() @@ -69,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 3c48ef0c0b..a1b3b3cdff 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = True handler_inst = test_module.V20CredIssueHandler() @@ -48,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock(), - store_credential=async_mock.AsyncMock(), - send_cred_ack=async_mock.AsyncMock(return_value="cred_ack_message"), + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock(), + store_credential=mock.AsyncMock(), + send_cred_ack=mock.AsyncMock(return_value="cred_ack_message"), ) request_context.message = V20CredIssue() request_context.connection_ready = True @@ -84,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - store_credential=async_mock.AsyncMock( + store_credential=mock.AsyncMock( side_effect=[ test_module.IndyHolderError, test_module.StorageError(), ] ), - send_cred_ack=async_mock.AsyncMock(), + send_cred_ack=mock.AsyncMock(), ) request_context.message = V20CredIssue() @@ -123,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.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = False handler_inst = test_module.V20CredIssueHandler() @@ -143,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 659c63dee7..1ec77403c0 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = True handler_inst = test_module.V20CredOfferHandler() @@ -48,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock( return_value=(None, "cred_request_message") ) request_context.message = V20CredOffer() @@ -88,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -126,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.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = False handler_inst = test_module.V20CredOfferHandler() @@ -149,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 ab38598f83..fa86a31bd5 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,12 +14,12 @@ 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.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.connection_ready = True request_context.message = V20CredProblemReport( description={ @@ -40,13 +40,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, "V20CredManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = V20CredProblemReport( @@ -68,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 b28c0be8ab..4f4a069cfe 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,13 +14,13 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = V20CredProposal() @@ -38,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + 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.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( return_value=(None, "cred_offer_message") ) request_context.message = V20CredProposal() @@ -69,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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -100,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.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() 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 7a31325246..398bb2f339 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -18,21 +18,19 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = V20CredRequest() @@ -50,26 +48,24 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) 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.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "cred_issue_message") ) request_context.message = V20CredRequest() @@ -94,28 +90,26 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -124,10 +118,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.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -135,12 +129,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.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = V20CredRequest() request_context.connection_ready = False handler = test_module.V20CredRequestHandler() @@ -158,8 +152,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 422fd2ab1e..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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -22,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) @@ -34,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) 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 527585209c..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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator @@ -161,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/models/tests/test_cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py index 91a92f4c37..b39254d7dc 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -126,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.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) 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 e711de9d29..fb264a5de3 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,7 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -84,19 +84,15 @@ 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.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) @@ -129,10 +125,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" ) @@ -156,12 +152,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.AsyncMock( + mock_handler.return_value.create_proposal = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -199,12 +195,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.AsyncMock( + mock_handler.return_value.create_proposal = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -250,12 +246,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.AsyncMock() + mock_handler.return_value.receive_proposal = mock.AsyncMock() cred_proposal = V20CredProposal( credential_preview=cred_preview, @@ -323,12 +319,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.AsyncMock( + mock_handler.return_value.create_offer = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -399,12 +395,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.AsyncMock( + mock_handler.return_value.create_offer = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -509,16 +505,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.AsyncMock(return_value=stored_cx_rec), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(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.AsyncMock() + mock_handler.return_value.receive_offer = mock.AsyncMock() cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -563,17 +559,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.AsyncMock() + mock_handler.return_value.receive_offer = mock.AsyncMock() mock_retrieve.side_effect = (StorageNotFoundError(),) cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -619,12 +615,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.AsyncMock( + mock_handler.return_value.create_request = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -706,12 +702,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.AsyncMock( + mock_handler.return_value.create_request = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -758,7 +754,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, @@ -778,15 +774,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) 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.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() # mock_retrieve.return_value = stored_cx_rec cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -825,18 +821,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) 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.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() cx_rec = await self.manager.receive_request( cred_request, mock_conn, mock_oob @@ -857,7 +853,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, @@ -877,15 +873,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) 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.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -969,19 +965,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.AsyncMock( + issuer.create_credential = mock.AsyncMock( 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.AsyncMock( + mock_handler.return_value.issue_credential = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -1084,16 +1080,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.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_credential = async_mock.AsyncMock() + mock_handler.return_value.receive_credential = mock.AsyncMock() mock_retrieve.return_value = stored_cx_rec ret_cx_rec = await self.manager.receive_credential( cred_issue, @@ -1154,10 +1150,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1192,10 +1188,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1233,14 +1229,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.AsyncMock() + mock_handler.return_value.store_credential = mock.AsyncMock() ret_cx_rec = await self.manager.store_credential( stored_cx_rec, cred_id=cred_id @@ -1280,14 +1276,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) @@ -1312,13 +1308,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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) 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 @@ -1339,21 +1335,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.AsyncMock()) - stored_indy = async_mock.MagicMock(delete_record=async_mock.AsyncMock()) + stored_cx_rec = mock.MagicMock(delete_record=mock.AsyncMock()) + stored_indy = mock.MagicMock(delete_record=mock.AsyncMock()) - 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.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( - test_module, "V20CredFormat", async_mock.MagicMock() + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_id", mock.AsyncMock() + ) 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.AsyncMock( + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.AsyncMock( return_value=[ stored_indy, stored_indy, @@ -1361,9 +1357,9 @@ async def test_delete_cred_ex_record(self): ) ) ), - async_mock.MagicMock( - detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.AsyncMock(return_value=[]) + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.AsyncMock(return_value=[]) ) ), ] @@ -1384,12 +1380,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.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1418,10 +1414,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.AsyncMock(), + mock.AsyncMock(), ) 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 385898da58..8af79157eb 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,5 @@ from .....vc.ld_proofs.error import LinkedDataProofException -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -21,9 +21,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -90,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.AsyncMock(return_value=[mock_cx_rec]) - mock_cx_rec.serialize = async_mock.MagicMock( - return_value={"hello": "world"} - ) + mock_cx_rec.query = mock.AsyncMock(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( { @@ -122,44 +118,40 @@ 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.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_cx_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( 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( { @@ -172,32 +164,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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( 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( { @@ -210,12 +200,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.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -224,20 +214,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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( return_value=None ) @@ -245,26 +235,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - 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, @@ -276,22 +266,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) mock_cred_mgr.return_value.prepare_send.side_effect = ( @@ -304,7 +294,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": { @@ -318,26 +308,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - 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, @@ -349,36 +339,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + 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.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() 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) @@ -395,26 +385,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( 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): @@ -424,7 +414,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -432,46 +422,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_offer = async_mock.MagicMock() - mock_cred_mgr.return_value = async_mock.AsyncMock( - create_offer=async_mock.AsyncMock( + mock_cred_offer = mock.MagicMock() + mock_cred_mgr.return_value = mock.AsyncMock( + create_offer=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), - prepare_send=async_mock.AsyncMock( + prepare_send=mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -486,7 +474,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -494,14 +482,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) @@ -512,7 +500,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "comment", "connection_id": connection_id, @@ -524,23 +512,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( 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) @@ -549,7 +535,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -557,16 +543,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.AsyncMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec @@ -574,28 +558,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -606,18 +588,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.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + 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) @@ -625,7 +607,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -639,7 +621,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -649,22 +631,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_cred_mgr.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -672,7 +654,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -682,25 +664,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.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "comment", "credential_preview": { @@ -714,7 +696,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -724,27 +706,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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": True, "credential_preview": { @@ -754,26 +736,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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -783,24 +765,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.AsyncMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_mgr.return_value = async_mock.AsyncMock( - create_offer=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.AsyncMock( + create_offer=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -809,30 +789,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() - 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) @@ -840,26 +820,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() exception_message = "ex" mock_cred_mgr.return_value.create_offer.side_effect = ( @@ -871,67 +851,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_DONE, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) @@ -939,59 +919,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.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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) @@ -999,105 +979,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() - mock_cx_rec.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id.return_value = mock.MagicMock( state=mock_cx_rec.STATE_OFFER_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() - 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) @@ -1105,85 +1085,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.AsyncMock(return_value={"comment": "comment"}) + self.request.json = mock.AsyncMock(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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( 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) @@ -1191,30 +1171,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1222,7 +1202,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) @@ -1236,147 +1216,139 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( - return_value=mock_cx_rec - ) + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( - return_value=mock_cx_rec - ) + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.AsyncMock( - side_effect=test_module.IndyIssuerError() - ) + mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) mock_cred_mgr.return_value.issue_credential = mock_issue_cred with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( - return_value=mock_cx_rec - ) - mock_cred_mgr.return_value = async_mock.MagicMock( - issue_credential=async_mock.AsyncMock( + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) + mock_cred_mgr.return_value = mock.MagicMock( + issue_credential=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_cred_mgr.return_value.get_detail_record = async_mock.AsyncMock( + mock_cred_mgr.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1386,39 +1358,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( 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) @@ -1432,40 +1404,40 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() 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) @@ -1479,119 +1451,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock() ) - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( 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.AsyncMock(return_value=mock_cx_rec), - send_cred_ack=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + store_credential=mock.AsyncMock(return_value=mock_cx_rec), + send_cred_ack=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ), ) @@ -1602,13 +1572,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.AsyncMock() + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock() ) await test_module.credential_exchange_remove(self.request) @@ -1617,11 +1587,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.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1632,11 +1602,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.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1645,25 +1615,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1676,17 +1644,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1694,21 +1662,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + save_error_state=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1718,13 +1686,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 c92888d24d..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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,7 +14,7 @@ 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 b6b001bfd0..791bd14bec 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.AsyncMock() 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.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.AsyncMock() mock_oob_mgr.return_value.receive_problem_report.side_effect = ( OutOfBandManagerError("error") ) @@ -68,8 +68,8 @@ 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) 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 1c3567c43c..71bc022e56 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 unittest import mock as async_mock +from unittest 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.AsyncMock() - ) + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.AsyncMock() request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() @@ -52,11 +50,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_reuse_accepted_message = ( - async_mock.AsyncMock() - ) + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.AsyncMock() mock_oob_mgr.return_value.receive_reuse_accepted_message.side_effect = ( OutOfBandManagerError("error") ) 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 860743bd99..d05f7b860a 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() 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.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() reuse_accepted = HandshakeReuseAccept() mock_oob_mgr.return_value.receive_reuse_message.return_value = reuse_accepted request_context.message = HandshakeReuse() @@ -61,9 +61,9 @@ async def test_reuse_accepted(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_exception(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() mock_oob_mgr.return_value.receive_reuse_message.side_effect = ( OutOfBandManagerError("error") ) 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 90b8d70078..b3b181c6b7 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,7 @@ from typing import List from unittest.mock import ANY -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord @@ -312,7 +312,7 @@ def make_did_doc(self, did, verkey): class TestOOBManager(IsolatedAsyncioTestCase, TestConfig): def setUp(self): self.responder = MockResponder() - self.responder.send = async_mock.AsyncMock() + self.responder.send = mock.AsyncMock() self.test_mediator_routing_keys = [ "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR" @@ -320,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.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) @@ -340,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.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.AsyncMock()) ) - 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.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() 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.AsyncMock(), + save=mock.AsyncMock(), ) 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( @@ -406,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( @@ -432,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( @@ -452,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, @@ -462,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.AsyncMock() + ) as mock_get_default_mediator, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() ) as mock_metadata_set: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -503,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -517,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( @@ -537,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -551,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( @@ -571,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.AsyncMock(), - ) as mock_retrieve_cxid_v1, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_cxid_v1, mock.patch.object( test_module.V20CredExRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid_v2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -590,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( @@ -613,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_pxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -627,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( @@ -648,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.AsyncMock(), - ) as mock_retrieve_pxid_1, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_pxid_1, mock.patch.object( test_module.V20PresExRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_pxid_2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -667,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( @@ -726,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 @@ -743,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( @@ -779,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 @@ -828,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( @@ -851,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.AsyncMock( - return_value=async_mock.MagicMock( - connection_id="the-retrieved-connection-id" - ) + mock.AsyncMock( + return_value=mock.MagicMock(connection_id="the-retrieved-connection-id") ), ): conn_rec = await self.manager._wait_for_conn_rec_active("a-connection-id") @@ -866,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.AsyncMock(return_value=self.test_conn_rec), + mock.AsyncMock(return_value=self.test_conn_rec), ): oob_mgr_fetch_conn.return_value = ConnectionTarget( did=TestConfig.test_did, @@ -908,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, @@ -916,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 @@ -936,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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=False, ) @@ -993,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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=True, ) @@ -1047,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.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) await self.manager.receive_reuse_accepted_message( @@ -1084,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,) @@ -1123,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.AsyncMock(), - delete_record=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), + save=mock.AsyncMock(), ) await self.manager.receive_problem_report( @@ -1157,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(),) @@ -1169,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}) @@ -1181,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.AsyncMock() - ) as mock_didx_recv_invi, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + DIDXManager, "receive_invitation", mock.AsyncMock() + ) as mock_didx_recv_invi, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1208,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.AsyncMock(), - ) as mock_didx_recv_invi, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_didx_recv_invi, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1227,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.AsyncMock( + self.route_manager.mediation_record_if_id = mock.AsyncMock( side_effect=StorageNotFoundError ) await self.manager.receive_invitation( @@ -1245,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.AsyncMock() + ) as didx_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_conn_by_id: - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) mock_retrieve_conn_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1274,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.AsyncMock() + ) as conn_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_retrieve_by_id: - conn_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + conn_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) mock_conn_retrieve_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1365,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.AsyncMock(), - ) as oob_mgr_find_existing_conn, async_mock.patch.object( - OobRecord, "save", async_mock.AsyncMock() - ) as oob_record_save, async_mock.patch.object( - OobRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as oob_record_retrieve_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) as oob_mgr_find_existing_conn, mock.patch.object( + OobRecord, "save", mock.AsyncMock() + ) as oob_record_save, mock.patch.object( + OobRecord, "retrieve_by_id", mock.AsyncMock() + ) 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 @@ -1386,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 ) @@ -1412,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.AsyncMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.AsyncMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.AsyncMock(), - ) as perform_handshake, async_mock.patch.object( + mock.AsyncMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(return_value=test_exist_conn), + mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1433,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 ) @@ -1460,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.AsyncMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.AsyncMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.AsyncMock(), - ) as perform_handshake, async_mock.patch.object( + mock.AsyncMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(return_value=test_exist_conn), - ), async_mock.patch.object( + mock.AsyncMock(return_value=test_exist_conn), + ), mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=test_exist_conn), + mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1485,13 +1483,13 @@ async def test_receive_invitation_handshake_reuse_failed(self): requests_attach=[], ) - mock_oob = async_mock.MagicMock( - delete_record=async_mock.AsyncMock(), - emit_event=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + delete_record=mock.AsyncMock(), + emit_event=mock.AsyncMock(), ) 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 ) @@ -1522,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.AsyncMock(return_value=mock_conn), + mock.AsyncMock(return_value=mock_conn), ): - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1550,7 +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.AsyncMock()) + mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1559,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.AsyncMock(), - ) as mock_create_signing_key, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_signing_key, mock.patch.object( OutOfBandManager, "_service_decorator_from_service", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( verkey="a-verkey", metadata={}, key_type=ED25519 @@ -1611,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.AsyncMock() - ) + mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) 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.AsyncMock(), + mock.AsyncMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn oob_invitation = InvitationMessage( @@ -1654,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.AsyncMock(), + mock.AsyncMock(), ) 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 @@ -1685,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.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -1718,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.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( "", # empty endpoint [TestConfig.test_verkey], @@ -1732,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.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( None, # None endpoint [TestConfig.test_verkey], @@ -1795,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.AsyncMock() - ) as mock_connrecord_query, async_mock.patch.object( - ConnRecord, "delete_record", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "query", mock.AsyncMock() + ) as mock_connrecord_query, mock.patch.object( + ConnRecord, "delete_record", mock.AsyncMock() ) 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 03e4422e1f..385f7b977a 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord @@ -13,9 +13,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( + 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.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( + 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.AsyncMock( 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..e6b324c3b4 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 +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.AsyncMock(), ) 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.AsyncMock(), ) 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.AsyncMock(), ) 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.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_vp, mock.patch.object( test_module, "sign_presentation", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_vp, mock.patch.object( DIFPresExchHandler, "get_sign_key_credential_subject_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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 458b71b077..1e259345c5 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,20 +17,20 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() 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) @@ -44,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, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() request_context.message = PresentationAck() request_context.connection_ready = False handler = test_module.PresentationAckHandler() @@ -64,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 4855579113..176d896eab 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,21 +17,19 @@ async def test_called(self): 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() 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) @@ -47,22 +45,20 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock() - mock_pres_mgr.return_value.verify_presentation = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() + mock_pres_mgr.return_value.verify_presentation = mock.AsyncMock() 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) @@ -78,36 +74,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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value = mock.MagicMock( + receive_presentation=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - verify_presentation=async_mock.AsyncMock( + verify_presentation=mock.AsyncMock( 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 f4c3b39e25..95ad42faeb 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -17,13 +17,13 @@ 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.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = PresentationProblemReport( description={ "en": "Change of plans", @@ -43,13 +43,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, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = PresentationProblemReport( 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 254b92d647..20167b6b6d 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,17 +15,17 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + 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) @@ -38,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.AsyncMock( + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_proposal.return_value, "presentation_request_message", @@ -77,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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -100,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() @@ -109,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.AsyncMock() + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock() 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 2446afc031..03b67c8230 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -67,17 +67,17 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -98,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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -127,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -158,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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( side_effect=StorageNotFoundError ) mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -188,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", @@ -226,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.AsyncMock( + mock_holder = mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.AsyncMock( 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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -275,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", @@ -308,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -350,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", @@ -390,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -408,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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -444,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", @@ -470,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=[]) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -515,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", @@ -541,35 +539,33 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy-0"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy-0"}}]) ) ) 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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -592,10 +588,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", @@ -618,14 +614,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -636,20 +632,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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -672,10 +668,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", @@ -718,14 +714,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ { "cred_info": { @@ -767,20 +763,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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -803,10 +799,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", @@ -840,7 +836,7 @@ async def test_called_auto_present_bait_and_switch(self): auto_present=True, ) - by_reft = async_mock.AsyncMock( + by_reft = mock.AsyncMock( return_value=[ { "cred_info": { @@ -868,32 +864,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -914,12 +910,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.AsyncMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = PresentationRequest() request_context.connection_ready = False handler = test_module.PresentationRequestHandler() @@ -937,8 +933,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) 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 a55fc8e04b..c19035f3a1 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -130,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.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) 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 18c14e9c13..5a8fa5c89c 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,7 @@ from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import ( @@ -219,15 +219,13 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -243,7 +241,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -252,7 +250,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -264,15 +262,15 @@ async def asyncSetUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -287,7 +285,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -297,8 +295,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -309,11 +307,9 @@ async def asyncSetUp(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.AsyncMock( - return_value=("true", []) - ) + self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) injector.bind_instance(IndyVerifier, self.verifier) self.manager = PresentationManager(self.profile) @@ -354,9 +350,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( @@ -374,10 +370,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) @@ -393,7 +389,7 @@ async def test_create_bound_request(self): presentation_proposal_dict=proposal.serialize(), role=V10PresentationExchange.ROLE_VERIFIER, ) - exchange.save = async_mock.AsyncMock() + exchange.save = mock.AsyncMock() (ret_exchange, pres_req_msg) = await self.manager.create_bound_request( presentation_exchange_record=exchange, name=PROOF_REQ_NAME, @@ -420,7 +416,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( @@ -439,7 +435,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) @@ -458,21 +454,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -501,21 +497,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -562,21 +558,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -594,12 +590,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.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -614,9 +608,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -629,7 +623,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -639,17 +633,17 @@ async def test_create_presentation_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.AsyncMock(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 ) @@ -680,9 +674,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -696,7 +690,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -706,27 +700,27 @@ async def test_create_presentation_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( 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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -748,9 +742,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -777,7 +771,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -787,8 +781,8 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -799,21 +793,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -838,7 +832,7 @@ async def test_no_matching_creds_for_proof_req(self): nonce=PROOF_REQ_NONCE, profile=self.profile, ) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -846,7 +840,7 @@ async def test_no_matching_creds_for_proof_req(self): indy_proof_req, holder=self.holder ) - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -861,7 +855,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={ @@ -950,14 +944,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( @@ -1064,14 +1058,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) @@ -1085,7 +1079,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={ @@ -1174,9 +1168,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 @@ -1186,14 +1180,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) @@ -1232,7 +1226,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) @@ -1260,7 +1254,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) @@ -1285,12 +1279,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 @@ -1306,14 +1300,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 @@ -1327,14 +1321,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 @@ -1365,16 +1359,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.AsyncMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.AsyncMock(), + ) 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 @@ -1407,10 +1401,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.AsyncMock(), + mock.AsyncMock(), ) 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 b3b7a2e848..c4716e0df9 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,6 @@ import importlib -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import ValidationError @@ -21,9 +21,9 @@ def setUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -61,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" @@ -71,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.AsyncMock() + mock_presentation_exchange.query = mock.AsyncMock() 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]} @@ -94,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" @@ -104,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.AsyncMock( + mock_presentation_exchange.query = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -114,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" @@ -124,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.AsyncMock() + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_presentation_exchange.retrieve_by_id.side_effect = StorageNotFoundError @@ -141,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.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -174,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.AsyncMock( + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.AsyncMock( return_value=returned_credentials ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -195,9 +193,7 @@ async def test_presentation_exchange_credentials_list_single_referent(self): mock_presentation_exchange ) - 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) @@ -211,14 +207,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.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(return_value=returned_credentials) ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -232,16 +228,14 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): mock_presentation_exchange ) - 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" @@ -251,14 +245,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.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.AsyncMock() 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 @@ -267,7 +259,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" @@ -277,7 +269,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.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex.retrieve_by_id.side_effect = StorageNotFoundError @@ -288,12 +280,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -303,10 +295,8 @@ 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.AsyncMock( - return_value=mock_pres_ex_rec - ) - mock_pres_ex_rec.serialize = async_mock.MagicMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock(return_value=mock_pres_ex_rec) + mock_pres_ex_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) @@ -314,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock(return_value=mock_presentation_exchange_record) + mock.AsyncMock(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.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: @@ -355,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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -363,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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" @@ -381,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.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -419,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_generate_nonce = mock.AsyncMock() - 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.AsyncMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -516,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -524,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" @@ -551,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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( 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.AsyncMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.AsyncMock(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.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( 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: @@ -608,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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -616,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -624,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" @@ -650,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.AsyncMock() + mock_generate_nonce = mock.AsyncMock() - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( 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 ) @@ -675,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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, @@ -720,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.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.AsyncMock( 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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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" @@ -781,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.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() 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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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" @@ -825,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.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -838,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -852,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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" @@ -866,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -875,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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" @@ -909,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.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -937,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -948,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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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" @@ -982,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.AsyncMock( - return_value=(mock_presentation_exchange, async_mock.MagicMock()) + mock_mgr = mock.MagicMock( + create_presentation=mock.AsyncMock( + 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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1025,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.AsyncMock() + self.request.json = mock.AsyncMock() 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" @@ -1054,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1069,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.AsyncMock() + self.request.json = mock.AsyncMock() 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" @@ -1098,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -1114,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.AsyncMock() + self.request.json = mock.AsyncMock() 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" @@ -1127,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1136,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -1146,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" @@ -1172,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock(), + save_error_state=mock.AsyncMock(), ), ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_presentation=mock.AsyncMock( side_effect=test_module.LedgerError() ) ) @@ -1199,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" @@ -1226,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.AsyncMock( 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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1272,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.AsyncMock() + self.request.json = mock.AsyncMock() 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" @@ -1285,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1299,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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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" @@ -1327,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1363,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1397,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.AsyncMock( + self.request.json = mock.AsyncMock( 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" @@ -1415,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.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1423,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.AsyncMock() + self.request.json = mock.AsyncMock() 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.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -1453,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" @@ -1463,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) ) - 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.AsyncMock() + self.request.json = mock.AsyncMock() 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" @@ -1492,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.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1502,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" @@ -1512,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.AsyncMock( + delete_record=mock.AsyncMock( side_effect=test_module.StorageError() ), ) @@ -1526,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 3377dc39ca..63e3bc6ea7 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from pyld import jsonld @@ -365,17 +365,15 @@ class TestDIFFormatHandler(IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) + 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1163,22 +1161,18 @@ 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.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), + mock.AsyncMock(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.AsyncMock( - return_value=PresentationVerificationResult(verified=False) - ), + mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), ): output = await self.handler.verify_pres(record) assert output.verified == "false" @@ -1220,12 +1214,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.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), + mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), ) as mock_vr: output = await self.handler.verify_pres(record) assert output.verified @@ -1413,10 +1405,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.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1836,8 +1828,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 +1907,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 +1959,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 +2012,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 +2065,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 +2115,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 +2165,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 +2255,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 +2267,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 +2322,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.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), @@ -2366,8 +2356,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 438a833bb3..0f1b42277e 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,20 +17,20 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() 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) @@ -44,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.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() request_context.message = V20PresAck() request_context.connection_ready = False handler = test_module.V20PresAckHandler() @@ -64,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # 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 76b31a36d1..99371ec03e 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,21 +17,19 @@ async def test_called(self): 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() 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) @@ -47,22 +45,20 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock() - mock_pres_mgr.return_value.verify_pres = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() + mock_pres_mgr.return_value.verify_pres = mock.AsyncMock() 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) @@ -78,34 +74,30 @@ 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.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value = mock.MagicMock( + receive_pres=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - verify_pres=async_mock.AsyncMock(side_effect=test_module.LedgerError()), + verify_pres=mock.AsyncMock(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 8b3e3175d6..998cd77c37 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,12 +14,12 @@ 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.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = V20PresProblemReport( description={ "en": "Change of plans", @@ -39,12 +39,12 @@ 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.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = V20PresProblemReport( 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 6f1295d08e..87cc342853 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,19 +13,19 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + 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) @@ -38,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.AsyncMock( + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_pres_proposal.return_value, "presentation_request_message", @@ -77,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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -100,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() @@ -109,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, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock() 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 efc8a3dbde..588d747632 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -183,17 +183,17 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -214,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.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -242,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -273,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.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( side_effect=StorageNotFoundError ) mock_px_rec_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -302,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( @@ -321,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -363,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -402,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.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(mock_px_rec, "pres message") ) @@ -449,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=[ @@ -459,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -485,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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -521,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=[ @@ -531,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -555,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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -591,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=[ @@ -609,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock(return_value=[]) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( side_effect=test_indy_handler.V20PresFormatHandlerError ) request_context.connection_ready = True @@ -661,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=[ @@ -671,42 +657,40 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy-0"}}] - ) + mock.AsyncMock(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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -729,7 +713,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=[ @@ -739,22 +723,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -764,20 +748,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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -800,7 +784,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=[ @@ -810,9 +794,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=[ @@ -826,16 +808,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.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + 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.AsyncMock( + mock.AsyncMock( return_value=[ { "cred_info": { @@ -880,20 +862,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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -917,12 +899,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.AsyncMock() + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock() request_context.message = V20PresRequest() request_context.connection_ready = False handler = test_module.V20PresRequestHandler() @@ -940,8 +922,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.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) 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 4bfbbbd249..977114228b 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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -127,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.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) 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 9e2e5ade6a..810858dba5 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,7 @@ from copy import deepcopy from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -387,15 +387,13 @@ 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.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -411,7 +409,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -420,7 +418,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -432,16 +430,16 @@ async def asyncSetUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( 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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -456,7 +454,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -466,8 +464,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -478,11 +476,9 @@ async def asyncSetUp(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.AsyncMock( - return_value=("true", []) - ) + self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) injector.bind_instance(IndyVerifier, self.verifier) self.manager = V20PresManager(self.profile) @@ -527,11 +523,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, @@ -547,13 +541,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, @@ -582,7 +576,7 @@ async def test_create_bound_request_a(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.AsyncMock() + px_rec.save = mock.AsyncMock() request_data = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -616,7 +610,7 @@ async def test_create_bound_request_b(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.AsyncMock() + px_rec.save = mock.AsyncMock() (ret_px_rec, pres_req_msg) = await self.manager.create_bound_request( pres_ex_record=px_rec, comment=comment, @@ -674,7 +668,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 @@ -689,7 +683,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( @@ -721,9 +715,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 @@ -750,7 +744,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, @@ -767,7 +761,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() @@ -788,21 +782,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -842,23 +836,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -899,29 +893,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.AsyncMock(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 ) @@ -955,21 +949,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -989,12 +983,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.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -1014,9 +1006,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1029,7 +1021,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1039,17 +1031,17 @@ async def test_create_pres_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.AsyncMock(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 ) @@ -1099,9 +1091,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1115,7 +1107,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1125,31 +1117,31 @@ async def test_create_pres_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( 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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 = {} @@ -1172,9 +1164,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.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -1201,7 +1193,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.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1211,8 +1203,8 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -1223,21 +1215,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.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( 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 ) @@ -1269,7 +1261,7 @@ async def test_no_matching_creds_for_proof_req(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -1277,7 +1269,7 @@ async def test_no_matching_creds_for_proof_req(self): INDY_PROOF_REQ_NAMES, preview=None, holder=self.holder ) - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1309,15 +1301,15 @@ async def test_no_matching_creds_indy_handler(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(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 = {} @@ -1330,7 +1322,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( @@ -1381,14 +1373,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) @@ -1401,7 +1393,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( @@ -1456,14 +1448,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) @@ -1476,7 +1468,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, @@ -1538,14 +1530,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) @@ -1558,7 +1550,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, @@ -1614,14 +1606,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) @@ -1634,7 +1626,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 @@ -1683,9 +1675,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 @@ -1739,9 +1731,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 @@ -1750,7 +1742,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" @@ -1798,9 +1790,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 @@ -1854,9 +1846,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 @@ -1865,7 +1857,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( @@ -1911,9 +1903,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 @@ -1969,9 +1961,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 @@ -2027,9 +2019,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 @@ -2085,9 +2077,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 @@ -2129,13 +2121,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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.AsyncMock(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() @@ -2189,34 +2181,30 @@ 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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.AsyncMock(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.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch( + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch( "aries_cloudagent.vc.vc_ld.verify.verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=False) - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), + ), mock.patch.object( IndyVerifier, "verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), + ), mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) @@ -2259,14 +2247,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 @@ -2276,14 +2264,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 @@ -2310,16 +2298,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.AsyncMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.AsyncMock(), + ) 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 @@ -2352,10 +2340,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.AsyncMock(), + mock.AsyncMock(), ) 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 fa794969ac..b366b9c6ef 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from time import time from unittest.mock import ANY @@ -130,15 +130,13 @@ def setUp(self): 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.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -154,7 +152,7 @@ def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -163,7 +161,7 @@ def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -176,9 +174,9 @@ def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock( + mock_pres_ex_rec_cls.query = mock.AsyncMock( 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.AsyncMock( + mock_pres_ex_rec_cls.query = mock.AsyncMock( 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.AsyncMock() + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock() # 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.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) - 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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(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.AsyncMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.AsyncMock() ) 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.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(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.AsyncMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.AsyncMock() ) await test_module.present_proof_credentials_list(self.request) @@ -392,23 +388,21 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -442,10 +436,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 @@ -464,27 +458,21 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -528,10 +516,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 @@ -556,23 +544,21 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -606,10 +592,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 @@ -634,23 +620,21 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -684,10 +668,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 @@ -712,23 +696,21 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -762,10 +744,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 @@ -820,21 +802,19 @@ async def test_present_proof_credentials_single_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - 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): @@ -883,21 +863,19 @@ async def test_present_proof_credentials_double_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - 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): @@ -943,21 +921,19 @@ async def test_present_proof_credentials_list_limit_disclosure_no_bbs(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - 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): @@ -1006,21 +982,19 @@ async def test_present_proof_credentials_no_ldp_vp(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - 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): @@ -1066,32 +1040,30 @@ 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( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(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) @@ -1110,18 +1082,16 @@ async def test_present_proof_credentials_list_dif_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1157,10 +1127,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 @@ -1169,14 +1139,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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ) ) @@ -1188,10 +1158,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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1201,16 +1171,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.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - 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.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_pres_ex_rec_inst ) @@ -1218,7 +1188,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy-conn-id", "presentation_proposal": { @@ -1227,21 +1197,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.AsyncMock( - return_value=async_mock.MagicMock(is_ready=True) + mock_conn_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(is_ready=True) ) - mock_px_rec_inst = async_mock.MagicMock() - mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.AsyncMock(return_value=mock_px_rec_inst) + mock_px_rec_inst = mock.MagicMock() + mock_pres_mgr.return_value.create_exchange_for_proposal = mock.AsyncMock( + return_value=mock_px_rec_inst ) await test_module.present_proof_send_proposal(self.request) @@ -1250,12 +1220,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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1263,36 +1233,32 @@ 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( - return_value=async_mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.StorageError() - ), - save_error_state=async_mock.AsyncMock(), - ) + mock_pres_mgr.return_value.create_exchange_for_proposal = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.StorageError()), + save_error_state=mock.AsyncMock(), ) ) @@ -1303,27 +1269,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1335,28 +1299,28 @@ async def test_present_proof_create_request(self): ) async def test_present_proof_create_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - 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.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -1366,7 +1330,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1374,24 +1338,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.AsyncMock() - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock({"thread_id": "sample-thread-id"}) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock() + 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.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1403,14 +1367,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.AsyncMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.AsyncMock(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.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1418,15 +1380,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1434,7 +1396,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1442,31 +1404,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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock() + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -1476,52 +1436,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.AsyncMock( return_value=(mock_px_rec_inst, mock_pres_request) ) ) @@ -1533,39 +1493,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1573,42 +1533,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1616,13 +1576,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1630,34 +1590,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -1665,50 +1625,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.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(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.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1718,7 +1678,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1733,39 +1693,39 @@ async def test_present_proof_send_presentation(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1778,7 +1738,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "dif": proof_req, } @@ -1788,39 +1748,39 @@ async def test_present_proof_send_presentation_dif(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1831,7 +1791,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.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) + self.request.json = mock.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) self.request.match_info = { "pres_ex_id": "dummy", } @@ -1865,31 +1825,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.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=px_rec_instance ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock(side_effect=test_module.LedgerError()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock(side_effect=test_module.LedgerError()) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1897,7 +1857,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1911,10 +1871,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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -1923,7 +1883,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1938,29 +1898,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.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1968,7 +1928,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1983,37 +1943,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.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( - 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.AsyncMock( + 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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2027,17 +1987,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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2045,7 +2005,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2060,39 +2020,39 @@ async def test_present_proof_send_presentation_x(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - 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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2109,32 +2069,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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.AsyncMock(return_value=mock_px_rec_inst) + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.AsyncMock(return_value=mock_px_rec_inst) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -2144,10 +2104,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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -2158,17 +2118,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.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2178,33 +2138,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.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( 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.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2219,25 +2179,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -2247,15 +2205,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -2263,19 +2221,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -2285,16 +2243,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) ) @@ -2304,10 +2262,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.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -2317,14 +2275,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.AsyncMock( + delete_record=mock.AsyncMock( side_effect=test_module.StorageError() ), ) @@ -2334,14 +2292,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"] @@ -2425,7 +2383,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.AsyncMock(return_value={"comment": "test"}) + self.request.json = mock.AsyncMock(return_value={"comment": "test"}) self.request.match_info = { "pres_ex_id": "dummy", } 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 6cac3fcb96..a645da0bd6 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock import json from ......connections.models.connection_target import ConnectionTarget @@ -29,24 +29,22 @@ 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.AsyncMock( + mock_mgr.return_value.get_recipient = mock.AsyncMock( return_value=RouteRecord(connection_id="dummy") ) - mock_connection_mgr.return_value.get_connection_targets = ( - async_mock.AsyncMock( - return_value=[ - ConnectionTarget( - recipient_keys=["recip_key"], - ) - ] - ) + mock_connection_mgr.return_value.get_connection_targets = mock.AsyncMock( + return_value=[ + ConnectionTarget( + recipient_keys=["recip_key"], + ) + ] ) await handler.handle(self.context, responder) @@ -77,10 +75,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.AsyncMock( + mock_mgr.return_value.get_recipient = mock.AsyncMock( side_effect=test_module.RoutingManagerError() ) 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 2abf1a81e5..a3a6b4af35 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 unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError @@ -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.AsyncMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(RouteNotFoundError) as context: 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 7534548007..b69fb53b47 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -12,9 +12,9 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(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.AsyncMock() - ) 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.AsyncMock() + ) 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.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(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.AsyncMock() - ) 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.AsyncMock() + ) 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.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(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.AsyncMock() - ) 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.AsyncMock() + ) 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 e614ee832c..128684b93f 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 unittest import mock as async_mock +from unittest 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.AsyncMock( + ledger = mock.MagicMock(spec=BaseLedger) + ledger.get_all_endpoints_for_did = mock.AsyncMock( return_value={ "endpoint": "https://github.com/", "profile": "https://example.com/profile", } ) - ledger.get_key_for_did = async_mock.AsyncMock(return_value="key") + ledger.get_key_for_did = mock.AsyncMock(return_value="key") yield ledger @@ -48,8 +48,8 @@ def profile(ledger): profile = InMemoryProfile.test_profile() profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock(return_value=(None, ledger)) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, ledger)) ), ) yield profile @@ -83,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.AsyncMock(return_value=("test_ledger_id", ledger)), + mock.AsyncMock(return_value=("test_ledger_id", ledger)), ): assert await resolver.resolve(profile, TEST_DID0) @@ -99,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.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) with pytest.raises(ResolverError): @@ -130,7 +128,7 @@ async def test_supports_updated_did_sov_rules( "linked_domains": "https://example.com", } - ledger.get_all_endpoints_for_did = async_mock.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.AsyncMock(return_value=example) assert await resolver.resolve(profile, TEST_DID0) @pytest.mark.asyncio @@ -143,7 +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.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.AsyncMock(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 c447859c07..b9f577b368 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 unittest import mock as async_mock +from unittest 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.AsyncMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( 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.AsyncMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( 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.AsyncMock( - side_effect=StorageNotFoundError - ) + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock(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.AsyncMock( + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( 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.AsyncMock( - side_effect=StorageNotFoundError - ) + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock(side_effect=StorageNotFoundError) ) - resolver.supports = async_mock.AsyncMock(return_value=True) + resolver.supports = mock.AsyncMock(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 ac60dcede2..c6b5fe5073 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=props), + mock.AsyncMock(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.AsyncMock(return_value="pattern"), + mock.AsyncMock(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.AsyncMock(return_value="pattern"), + mock.AsyncMock(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.AsyncMock(return_value="pattern"), + mock.AsyncMock(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 b3e3cfa13f..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 unittest 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 50e3813af1..ca8bb55088 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 unittest import mock as async_mock +from unittest 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,37 @@ def mock_response(): @pytest.fixture def mock_resolver(resolution_result): - did_resolver = async_mock.MagicMock() - did_resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - did_resolver.resolve_with_metadata = async_mock.AsyncMock( - return_value=resolution_result - ) + did_resolver = mock.MagicMock() + did_resolver.resolve = mock.AsyncMock(return_value=did_doc) + did_resolver.resolve_with_metadata = mock.AsyncMock(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.AsyncMock() + outbound_message_router = mock.AsyncMock() 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.AsyncMock(return_value={}), + json=mock.AsyncMock(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 +96,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.AsyncMock( - side_effect=side_effect() - ) + mock_resolver.resolve_with_metadata = mock.AsyncMock(side_effect=side_effect()) profile = InMemoryProfile.test_profile() context = profile.context @@ -108,23 +104,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.AsyncMock() + outbound_message_router = mock.AsyncMock() 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.AsyncMock(return_value={}), + json=mock.AsyncMock(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 +128,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_rev_reg_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py index 9329dc7c99..d7cf28721d 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,7 @@ from os.path import join from typing import Any, Mapping, Type -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile, InMemoryProfileSession @@ -60,15 +60,15 @@ async def asyncSetUp(self): ) 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.AsyncMock() - self.ledger.send_revoc_reg_entry = async_mock.AsyncMock() + self.ledger.send_revoc_reg_def = mock.AsyncMock() + self.ledger.send_revoc_reg_entry = mock.AsyncMock() 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.AsyncMock( + self.tails_server.upload_tails_file = mock.AsyncMock( return_value=(True, "http://1.2.3.4:8088/rev-reg-id") ) self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server) @@ -172,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.AsyncMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.AsyncMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_cred_def) ) ) ) else: - return async_mock.MagicMock( - fetch=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.AsyncMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_reg_rev_def_private), ), ) @@ -214,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.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( _test_rev_reg_delta, 1234567890, ) ) - self.ledger.send_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.send_revoc_reg_entry = mock.AsyncMock( return_value={ "result": {"...": "..."}, }, @@ -230,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.AsyncMock( + mock.AsyncMock( return_value=[ test_module.IssuerCredRevRecord( record_id=test_module.UUID4_EXAMPLE, @@ -244,14 +244,14 @@ def handle(self): ) ] ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.AsyncMock(return_value=rec), - ), async_mock.patch.object( + mock.AsyncMock(return_value=rec), + ), mock.patch.object( test_module, "generate_ledger_rrrecovery_txn", - async_mock.AsyncMock(return_value=rev_reg_delta), + mock.AsyncMock(return_value=rev_reg_delta), ): assert ( _test_rev_reg_delta, @@ -274,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.AsyncMock() + with mock.patch.object( + issuer, "create_and_store_revocation_registry", mock.AsyncMock() ) as mock_create_store_rr: mock_create_store_rr.side_effect = IndyIssuerError("Not this time") @@ -291,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 @@ -313,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 4ee40798e5..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,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from copy import deepcopy from pathlib import Path @@ -84,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 @@ -102,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") ) @@ -119,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"",)]) ) ) @@ -142,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 dd3d97f255..ccdf3e2a46 100644 --- a/aries_cloudagent/revocation/tests/test_indy.py +++ b/aries_cloudagent/revocation/tests/test_indy.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -24,17 +24,17 @@ 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.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": True}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock() + self.ledger.get_revoc_reg_def = mock.AsyncMock() self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -56,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.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): result = await self.revoc.init_issuer_registry(CRED_DEF_ID) assert result.cred_def_id == CRED_DEF_ID @@ -74,7 +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.AsyncMock(return_value=None) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=None) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) with self.assertRaises(RevocationNotSupportedError) as x_revo: @@ -85,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.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": "..."}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -118,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.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -132,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.AsyncMock() + rec.generate_registry = mock.AsyncMock() - with async_mock.patch.object( - IssuerRevRegRecord, "retrieve_by_revoc_reg_id", async_mock.AsyncMock() + with mock.patch.object( + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", mock.AsyncMock() ) as mock_retrieve_by_rr_id: mock_retrieve_by_rr_id.return_value = rec await rec.generate_registry(self.profile, None) @@ -222,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 @@ -237,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.AsyncMock(return_value=(None, self.ledger)), - ), async_mock.patch.object( - RevocationRegistry, "from_definition", async_mock.MagicMock() + mock.AsyncMock(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 eb0356d8cd..d51f41e0fc 100644 --- a/aries_cloudagent/revocation/tests/test_manager.py +++ b/aries_cloudagent/revocation/tests/test_manager.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.revocation.models.issuer_cred_rev_record import ( @@ -38,15 +38,15 @@ async def asyncSetUp(self): 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), pending_pub=["2"], ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.revoke_credentials = mock.AsyncMock( 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.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) 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.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(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.AsyncMock() + mock_rev_reg = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) - revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) - revoc.return_value.get_ledger_registry = async_mock.AsyncMock( + revoc.return_value.get_ledger_registry = mock.AsyncMock( 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.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( 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.AsyncMock() - ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + mock_issuer_rev_reg_record = mock.MagicMock(mark_pending=mock.AsyncMock()) + 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.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) @@ -185,28 +181,26 @@ 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), - ), async_mock.patch.object( + mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -232,40 +226,38 @@ 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock( + mock.AsyncMock( 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.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -292,40 +284,38 @@ 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - 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.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock( + mock.AsyncMock( 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.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -337,46 +327,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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - 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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - 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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: None}) assert result == { @@ -386,23 +376,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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - 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.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(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 b0d86f7563..7c65b16e94 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -4,7 +4,7 @@ from aiohttp.web import HTTPBadRequest, HTTPNotFound from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.revocation.error import RevocationError @@ -20,9 +20,9 @@ def setUp(self): setattr(self.context, "profile", self.profile) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.AsyncMock() 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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.AsyncMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_not_found(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_mgr.return_value.revoke_credential = mock.AsyncMock( 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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + pub_pending = mock.AsyncMock() 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.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr: - pub_pending = async_mock.AsyncMock( - side_effect=test_module.RevocationError() - ) + pub_pending = mock.AsyncMock(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.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock() + clear_pending = mock.AsyncMock() mock_mgr.return_value.clear_pending_revocations = clear_pending await test_module.clear_pending_revocations(self.request) @@ -183,14 +181,14 @@ async def test_clear_pending_revocations(self): ) async def test_clear_pending_revocations_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - 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.AsyncMock(side_effect=test_module.StorageError()) + clear_pending = mock.AsyncMock(side_effect=test_module.StorageError()) mock_mgr.return_value.clear_pending_revocations = clear_pending with self.assertRaises(test_module.web.HTTPBadRequest): @@ -198,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - generate_registry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.AsyncMock( + return_value=mock.MagicMock( + generate_registry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -228,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.AsyncMock( + self.request.json = mock.AsyncMock( 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 @@ -248,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.AsyncMock( side_effect=test_module.RevocationNotSupportedError( error_code="dummy" ) @@ -283,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.AsyncMock() - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.IssuerRevRegRecord, "query", mock.AsyncMock() + ) 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"]}) @@ -300,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.AsyncMock( - 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.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -323,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -344,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.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.AsyncMock(), - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) 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) @@ -367,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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -388,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.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) 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) @@ -408,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.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) 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) @@ -429,17 +427,17 @@ async def test_get_cred_rev_record_not_found(self): ) CRED_REV_ID = "1" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") with self.assertRaises(test_module.web.HTTPNotFound): @@ -449,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.AsyncMock( - 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.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -470,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_active_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -491,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.AsyncMock( - return_value=async_mock.MagicMock(tails_local_path="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock(tails_local_path="dummy") ) ) @@ -512,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -533,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.AsyncMock() - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_upload = mock.AsyncMock() + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -559,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.AsyncMock( - return_value=async_mock.MagicMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=False, ) @@ -580,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.AsyncMock(side_effect=RevocationError("test")) - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_upload = mock.AsyncMock(side_effect=RevocationError("test")) + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -603,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.AsyncMock( - return_value=async_mock.MagicMock( - send_def=async_mock.AsyncMock(), - send_entry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_def=mock.AsyncMock(), + send_entry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -628,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -649,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.AsyncMock( - return_value=async_mock.MagicMock( - send_def=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_def=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -671,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.AsyncMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_entry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -695,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -716,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.AsyncMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_entry=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -737,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.AsyncMock(), + save=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -767,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -793,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.AsyncMock( + self.request.json = mock.AsyncMock( 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.AsyncMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -820,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -829,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.AsyncMock( - return_value=async_mock.MagicMock( - set_state=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_state=mock.AsyncMock(), + save=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -853,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.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -862,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.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -878,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": { diff --git a/aries_cloudagent/settings/tests/test_routes.py b/aries_cloudagent/settings/tests/test_routes.py index 0cd27a58eb..5e9fab046e 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value={}), + json=mock.AsyncMock(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.AsyncMock(return_value={}), + json=mock.AsyncMock(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.AsyncMock( + json=mock.AsyncMock( 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.AsyncMock( + json=mock.AsyncMock( 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/test_askar_storage.py b/aries_cloudagent/storage/tests/test_askar_storage.py index c8ae18dbf4..0400c3f433 100644 --- a/aries_cloudagent/storage/tests/test_askar_storage.py +++ b/aries_cloudagent/storage/tests/test_askar_storage.py @@ -2,7 +2,7 @@ import pytest import os -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + test_module.non_secrets, "get_wallet_record", mock.AsyncMock() ) 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.AsyncMock(), - ) as mock_update_value, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_value, mock.patch.object( test_module.non_secrets, "update_wallet_record_tags", - async_mock.AsyncMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_tags, mock.patch.object( test_module.non_secrets, "delete_wallet_record", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.AsyncMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -362,11 +362,9 @@ class TestAskarStorageSearchSession(IsolatedAsyncioTestCase): 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 8cc6ebf557..ca8136f182 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 unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...storage.error import ( @@ -182,11 +182,9 @@ 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.AsyncMock() - ) as mock_fetch: - mock_fetch.return_value = async_mock.MagicMock( - pop=async_mock.MagicMock(side_effect=IndexError()) + with mock.patch.object(search, "fetch", mock.AsyncMock()) 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") diff --git a/aries_cloudagent/storage/tests/test_indy_storage.py b/aries_cloudagent/storage/tests/test_indy_storage.py index 96606b9c87..9b41966b6b 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 unittest import mock as async_mock +from unittest 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) 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.AsyncMock() + with mock.patch.object( + indy.non_secrets, "get_wallet_record", mock.AsyncMock() ) 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.AsyncMock(), - ) as mock_update_value, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_value, mock.patch.object( indy.non_secrets, "update_wallet_record_tags", - async_mock.AsyncMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_tags, mock.patch.object( indy.non_secrets, "delete_wallet_record", - async_mock.AsyncMock(), + mock.AsyncMock(), ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.AsyncMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( # error on close + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() + ) 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.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() - ) 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.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() + ) 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/test_indy_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py index f4d08d9a28..e1afe2a2bc 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 unittest import mock as async_mock +from unittest import mock from ....config.injection_context import InjectionContext @@ -27,7 +27,7 @@ async def make_profile(): 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, { diff --git a/aries_cloudagent/tails/tests/test_indy.py b/aries_cloudagent/tails/tests/test_indy.py index eb961e0bfb..305ee21703 100644 --- a/aries_cloudagent/tails/tests/test_indy.py +++ b/aries_cloudagent/tails/tests/test_indy.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -30,9 +30,7 @@ async def test_upload(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( context, @@ -49,8 +47,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.AsyncMock( + mock.MagicMock( + get_write_ledgers=mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -58,12 +56,10 @@ 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.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -80,8 +76,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.AsyncMock( + mock.MagicMock( + get_write_ledgers=mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -89,12 +85,10 @@ 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.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -115,9 +109,7 @@ async def test_upload_x(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.side_effect = test_module.PutError("Server down for maintenance") (ok, text) = await indy_tails.upload_tails_file( diff --git a/aries_cloudagent/transport/inbound/tests/test_http_transport.py b/aries_cloudagent/transport/inbound/tests/test_http_transport.py index 2e3c793bed..0b3b582a79 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + message.wait_processing_complete = mock.AsyncMock() 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.AsyncMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.AsyncMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() @@ -113,30 +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.AsyncMock() + with mock.patch.object( + test_module.HttpTransport, "create_session", mock.AsyncMock() ) as mock_session: - mock_session.return_value = async_mock.MagicMock( - receive=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - receipt=async_mock.MagicMock(direct_response_requested=True), - wait_processing_complete=async_mock.AsyncMock(), + mock_session.return_value = mock.MagicMock( + receive=mock.AsyncMock( + return_value=mock.MagicMock( + receipt=mock.MagicMock(direct_response_requested=True), + wait_processing_complete=mock.AsyncMock(), ) ), can_respond=True, profile=InMemoryProfile.test_profile(), - clear_response=async_mock.MagicMock(), - wait_response=async_mock.AsyncMock(return_value=b"Hello world"), + clear_response=mock.MagicMock(), + wait_response=mock.AsyncMock(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.AsyncMock( - side_effect=test_module.WireFormatParseError() - ), + mock_session.return_value = mock.MagicMock( + receive=mock.AsyncMock(side_effect=test_module.WireFormatParseError()), profile=InMemoryProfile.test_profile(), ) async with self.client.post("/", data=test_message) as resp: @@ -150,12 +148,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 8a27c3fa41..e7192211e0 100644 --- a/aries_cloudagent/transport/inbound/tests/test_manager.py +++ b/aries_cloudagent/transport/inbound/tests/test_manager.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -45,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] @@ -58,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.AsyncMock() - transport.stop = async_mock.AsyncMock() + transport = mock.MagicMock() + transport.start = mock.AsyncMock() + transport.stop = mock.AsyncMock() mgr = InboundTransportManager(self.profile, None) mgr.register_transport(transport, "transport_cls") @@ -73,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.AsyncMock() + test_inbound_handler = mock.AsyncMock() mgr = InboundTransportManager(self.profile, test_inbound_handler) test_transport = "http" test_accept = True @@ -104,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 @@ -120,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) @@ -147,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.AsyncMock(return_value=("payload", "receipt")) + test_wire_format = mock.MagicMock( + parse_message=mock.AsyncMock(return_value=("payload", "receipt")) ) session = await mgr.create_session( "http", wire_format=test_wire_format, accept_undelivered=True @@ -158,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): @@ -166,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() @@ -180,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) @@ -192,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_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index 3dac5fb85f..51ce83811f 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -1,7 +1,7 @@ import asyncio import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import TestCase from ....admin.server import AdminResponder @@ -23,11 +23,11 @@ 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"} @@ -54,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( @@ -89,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.AsyncMock() + test_wire_format = mock.MagicMock() + test_wire_format.parse_message = mock.AsyncMock() 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, @@ -103,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) @@ -114,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.AsyncMock( - return_value=[async_mock.MagicMock(is_managed=True)] + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( + return_value=[mock.MagicMock(is_managed=True)] ) - self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( 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( @@ -134,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.AsyncMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.AsyncMock() + ) 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) @@ -147,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.AsyncMock( + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( side_effect=ValueError("no such wallet") ) - self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -165,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.AsyncMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.AsyncMock() + ) 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) @@ -267,9 +267,7 @@ 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.AsyncMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) assert encode.awaited_once_with(test_msg) assert result is encode.return_value @@ -292,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.AsyncMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: encode.side_effect = WireFormatError() with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(sess.wait_response(), 0.1) @@ -305,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.AsyncMock() + test_wire_format = mock.MagicMock() + test_wire_format.encode_message = mock.AsyncMock() sess = InboundSession( profile=self.profile, inbound_handler=None, @@ -318,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) @@ -347,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 dc049db5c0..765b725fdc 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 unittest import mock as async_mock +from unittest 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.AsyncMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.AsyncMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() diff --git a/aries_cloudagent/transport/outbound/tests/test_http_transport.py b/aries_cloudagent/transport/outbound/tests/test_http_transport.py index b8826afb5f..c7b203c38f 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 unittest import mock as async_mock +from unittest 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.AsyncMock(return_value=mock_response) + mock_response = mock.MagicMock(status=404) + mock_session.post = mock.MagicMock( + return_value=mock.MagicMock( + __aenter__=mock.AsyncMock(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 28095cc4e7..9f6e1c551d 100644 --- a/aries_cloudagent/transport/outbound/tests/test_manager.py +++ b/aries_cloudagent/transport/outbound/tests/test_manager.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -41,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") @@ -49,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.AsyncMock() - transport.wire_format.encode_message = async_mock.AsyncMock() - transport.start = async_mock.AsyncMock() - transport.stop = async_mock.AsyncMock() + transport = mock.MagicMock() + transport.handle_message = mock.AsyncMock() + transport.wire_format.encode_message = mock.AsyncMock() + transport.start = mock.AsyncMock() + transport.stop = mock.AsyncMock() 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") @@ -83,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() @@ -125,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() @@ -146,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.AsyncMock() + transport_cls.return_value.start = mock.AsyncMock() 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 ) @@ -167,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 @@ -215,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.AsyncMock() + with mock.patch.object( + test_module.asyncio, "sleep", mock.AsyncMock() ) as mock_sleep_x: mock_sleep_x.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -235,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.AsyncMock() - ) 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.AsyncMock() + ) 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 @@ -258,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.AsyncMock() - ) 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.AsyncMock() + ) 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 @@ -280,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", @@ -288,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) @@ -319,11 +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.AsyncMock(return_value=encoded_msg) + base_wire_format.encode_message = mock.AsyncMock(return_value=encoded_msg) profile = InMemoryProfile.test_profile(bind={BaseWireFormat: base_wire_format}) - profile.session = async_mock.AsyncMock(return_value=async_mock.MagicMock()) - outbound = async_mock.MagicMock(payload="payload", enc_payload=None) - target = async_mock.MagicMock() + profile.session = mock.AsyncMock(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) @@ -340,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 3772cfed3c..969b578c94 100644 --- a/aries_cloudagent/transport/queue/tests/test_basic_queue.py +++ b/aries_cloudagent/transport/queue/tests/test_basic_queue.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import basic as test_module @@ -37,26 +37,22 @@ 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.AsyncMock() + 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.AsyncMock() ) as mock_wait: 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()), ), ] ) @@ -69,27 +65,23 @@ 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.AsyncMock() + 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.AsyncMock() ) as mock_wait: 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 4bbaaf7ea4..a8a11fb892 100644 --- a/aries_cloudagent/transport/tests/test_pack_format.py +++ b/aries_cloudagent/transport/tests/test_pack_format.py @@ -2,7 +2,7 @@ from base64 import b64encode from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix @@ -54,9 +54,7 @@ async def test_errors(self): } serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.AsyncMock() - ) as mock_unpack: + with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: mock_unpack.return_value = "{missing-brace" with self.assertRaises(WireFormatParseError) as context: await serializer.parse_message(self.session, json.dumps(x_message)) @@ -64,9 +62,7 @@ async def test_errors(self): serializer = PackWireFormat() serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.AsyncMock() - ) as mock_unpack: + with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: mock_unpack.return_value = json.dumps([1, 2, 3]) with self.assertRaises(WireFormatParseError) as context: await serializer.parse_message(self.session, json.dumps(x_message)) @@ -92,25 +88,23 @@ async def test_pack_x(self): ["key"], ) - mock_wallet = async_mock.MagicMock( - pack_message=async_mock.AsyncMock(side_effect=WalletError()) + mock_wallet = mock.MagicMock( + pack_message=mock.AsyncMock(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.AsyncMock( + mock_wallet = mock.MagicMock( + pack_message=mock.AsyncMock( 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 3b0784e779..acddd20d2d 100644 --- a/aries_cloudagent/transport/tests/test_stats.py +++ b/aries_cloudagent/transport/tests/test_stats.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -7,9 +7,9 @@ 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/utils/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py index 2b8f20c624..e8e5e676ff 100644 --- a/aries_cloudagent/utils/tests/test_task_queue.py +++ b/aries_cloudagent/utils/tests/test_task_queue.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ..task_queue import CompletedTask, PendingTask, TaskQueue, task_exc_info @@ -84,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() @@ -106,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.AsyncMock() + with mock.patch.object( + queue, "drain", mock.MagicMock() + ) as mock_drain, mock.patch.object( + queue, "wait_for", mock.AsyncMock() ) as mock_wait_for: mock_drain.side_effect = [queue.loop.create_task(noop()), None] await queue.complete(cleanup=True) @@ -138,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/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py index d2e9353d96..a59e738916 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,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from aries_cloudagent.wallet.key_type import ED25519 @@ -27,12 +27,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.AsyncMock(return_value=signed), + mock.AsyncMock(return_value=signed), ) as sign_message: singed_ret = await key_pair.sign(b"Message") @@ -56,10 +56,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.AsyncMock(return_value=True), + mock.AsyncMock(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 f8858b8a92..884006a36a 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,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ...validation_result import PurposeResult from ..controller_proof_purpose import ControllerProofPurpose @@ -33,18 +33,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 +65,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 +73,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 +86,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 +94,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 b11641e071..052acd1603 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,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ....tests.data import TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519 from ....tests.document_loader import custom_document_loader @@ -31,7 +31,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 +54,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 +78,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 +100,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 97c061b6bf..dfa4749fcc 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,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ...validation_result import PurposeResult from ..assertion_proof_purpose import AssertionProofPurpose @@ -25,15 +25,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 +53,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 +76,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 +100,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 13e3d76c7c..4865f9c9c4 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,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from .....messaging.util import datetime_to_str from ..proof_purpose import ProofPurpose @@ -24,11 +24,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 +40,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 +55,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 ca4ccc453a..24ffe32e96 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,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -138,9 +138,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 6f408e1729..4900ba7c25 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,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -202,8 +202,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/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index 6866237672..7ed91bc6d1 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,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from datetime import datetime import pytest @@ -112,8 +112,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 +124,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 +163,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 +305,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/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index a2953d2f48..e1d049af6e 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 unittest import mock as async_mock +from unittest 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.AsyncMock() + with mock.patch.object( + indy.did, "replace_keys_start", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.did, "replace_keys_apply", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.crypto, "create_key", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.did, "create_and_store_my_did", mock.AsyncMock() ) 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.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.AsyncMock() ) 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.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.AsyncMock() ) 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.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=True, update_endpoint_for_did=mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.crypto, "get_key_metadata", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.did, "get_my_did_with_meta", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.did, "set_did_metadata", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.crypto, "crypto_verify", mock.AsyncMock() ) 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.AsyncMock() + with mock.patch.object( + indy.crypto, "pack_message", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) 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.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.AnoncredsMasterSecretDuplicateNameError diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 71ea617792..ee0cdc7072 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 +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.AsyncMock(), } - 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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.AsyncMock( 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,24 @@ 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.AsyncMock() + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(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, @@ -492,14 +490,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.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) self.request.query = {"did": self.test_did_sov} @@ -509,20 +505,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.AsyncMock(return_value=None) + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with self.assertRaises(test_module.web.HTTPNotFound): @@ -531,20 +525,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.AsyncMock(return_value=None) + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) self.wallet.get_local_did.side_effect = test_module.WalletNotFoundError() @@ -554,25 +546,23 @@ 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.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(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 +578,23 @@ 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.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(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 +610,24 @@ 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.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(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.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(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, @@ -670,28 +656,22 @@ 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.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(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( - return_value=None - ) - mock_route_manager.routing_info = async_mock.AsyncMock( - return_value=(None, None) - ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) + mock_route_manager.routing_info = mock.AsyncMock(return_value=(None, None)) + mock_route_manager.__aenter__ = mock.AsyncMock(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 +708,17 @@ 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.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(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, @@ -767,17 +745,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.AsyncMock( 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.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.get_local_did.return_value = DIDInfo( @@ -795,14 +773,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.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -829,17 +807,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.AsyncMock( 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.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletError() @@ -848,17 +826,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.AsyncMock( 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.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletNotFoundError() @@ -877,8 +855,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 +891,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.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -925,8 +903,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.AsyncMock() + self.wallet.rotate_did_keypair_apply = mock.AsyncMock() await test_module.wallet_rotate_did_keypair(self.request) json_response.assert_called_once_with({}) @@ -945,13 +923,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.AsyncMock( 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.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -966,7 +944,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.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -975,20 +953,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.AsyncMock( 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"]