From cfc2b8c301f8c20ed81ec0119dd30139880420e7 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 21:30:07 -0400 Subject: [PATCH] fix: provide CoroutineMock adapter Signed-off-by: Daniel Bluhm --- .../admin/tests/test_admin_server.py | 44 +- .../commands/tests/test_provision.py | 12 +- aries_cloudagent/commands/tests/test_start.py | 20 +- .../commands/tests/test_upgrade.py | 78 ++-- aries_cloudagent/config/tests/test_ledger.py | 74 ++-- aries_cloudagent/config/tests/test_wallet.py | 76 ++-- .../connections/tests/test_base_manager.py | 166 ++++---- aries_cloudagent/core/tests/test_conductor.py | 144 +++---- .../core/tests/test_dispatcher.py | 60 +-- .../core/tests/test_oob_processor.py | 86 ++-- .../core/tests/test_plugin_registry.py | 10 +- .../core/tests/test_protocol_registry.py | 6 +- aries_cloudagent/holder/tests/test_routes.py | 50 +-- .../indy/credx/tests/test_cred_issuance.py | 10 +- .../indy/models/tests/test_pres_preview.py | 6 +- .../indy/sdk/tests/test_holder.py | 22 +- .../indy/sdk/tests/test_profile.py | 6 +- aries_cloudagent/indy/sdk/tests/test_util.py | 4 +- .../indy/sdk/tests/test_verifier.py | 8 +- aries_cloudagent/indy/tests/test_verifier.py | 6 +- .../tests/test_indy_ledger_requests.py | 12 +- .../tests/test_indy_manager.py | 34 +- .../tests/test_indy_vdr_manager.py | 34 +- aries_cloudagent/ledger/tests/test_indy.py | 88 ++-- .../ledger/tests/test_indy_vdr.py | 24 +- aries_cloudagent/ledger/tests/test_routes.py | 82 ++-- .../tests/test_routes.py | 62 +-- .../messaging/jsonld/tests/test_routes.py | 36 +- .../models/tests/test_base_record.py | 12 +- .../messaging/schemas/tests/test_routes.py | 70 ++-- .../multitenant/admin/tests/test_routes.py | 106 ++--- .../tests/test_askar_profile_manager.py | 4 +- .../multitenant/tests/test_base.py | 16 +- .../multitenant/tests/test_manager.py | 4 +- .../multitenant/tests/test_route_manager.py | 28 +- .../v1_0/handlers/tests/test_menu_handler.py | 4 +- .../tests/test_menu_request_handler.py | 6 +- .../handlers/tests/test_perform_handler.py | 8 +- .../actionmenu/v1_0/tests/test_controller.py | 4 +- .../actionmenu/v1_0/tests/test_routes.py | 64 +-- .../basicmessage/v1_0/tests/test_routes.py | 16 +- .../handlers/tests/test_request_handler.py | 24 +- .../handlers/tests/test_response_handler.py | 12 +- .../connections/v1_0/tests/test_manager.py | 108 ++--- .../connections/v1_0/tests/test_routes.py | 122 +++--- .../tests/test_mediation_grant_handler.py | 14 +- .../v1_0/tests/test_mediation_manager.py | 10 +- .../v1_0/tests/test_route_manager.py | 98 ++--- .../v1_0/tests/test_routes.py | 124 +++--- .../handlers/tests/test_complete_handler.py | 6 +- .../tests/test_problem_report_handler.py | 8 +- .../handlers/tests/test_request_handler.py | 24 +- .../handlers/tests/test_response_handler.py | 12 +- .../didexchange/v1_0/tests/test_manager.py | 388 +++++++++--------- .../didexchange/v1_0/tests/test_routes.py | 56 +-- .../handlers/tests/test_disclose_handler.py | 4 +- .../v1_0/handlers/tests/test_query_handler.py | 6 +- .../v1_0/models/tests/test_record.py | 6 +- .../discovery/v1_0/tests/test_manager.py | 38 +- .../discovery/v1_0/tests/test_routes.py | 16 +- .../tests/test_disclosures_handler.py | 12 +- .../handlers/tests/test_queries_handler.py | 6 +- .../v2_0/models/tests/test_record.py | 6 +- .../discovery/v2_0/tests/test_manager.py | 42 +- .../discovery/v2_0/tests/test_routes.py | 16 +- ...t_endorsed_transaction_response_handler.py | 8 +- ...st_refused_transaction_response_handler.py | 8 +- ...est_transaction_acknowledgement_handler.py | 8 +- .../tests/test_transaction_cancel_handler.py | 8 +- .../test_transaction_job_to_send_handler.py | 6 +- .../tests/test_transaction_request_handler.py | 8 +- .../tests/test_transaction_resend_handler.py | 8 +- .../v1_0/tests/test_manager.py | 24 +- .../v1_0/tests/test_routes.py | 338 +++++++-------- .../tests/test_forward_invitation_handler.py | 6 +- .../handlers/tests/test_invitation_handler.py | 4 +- .../tests/test_invitation_request_handler.py | 4 +- .../introduction/v0_1/tests/test_routes.py | 14 +- .../tests/test_credential_ack_handler.py | 12 +- .../tests/test_credential_issue_handler.py | 40 +- .../tests/test_credential_offer_handler.py | 28 +- .../test_credential_problem_report_handler.py | 6 +- .../tests/test_credential_proposal_handler.py | 18 +- .../tests/test_credential_request_handler.py | 42 +- .../models/tests/test_credential_exchange.py | 4 +- .../v1_0/tests/test_manager.py | 128 +++--- .../v1_0/tests/test_routes.py | 300 +++++++------- .../v2_0/formats/indy/tests/test_handler.py | 94 +++-- .../formats/ld_proof/tests/test_handler.py | 42 +- .../handlers/tests/test_cred_ack_handler.py | 10 +- .../handlers/tests/test_cred_issue_handler.py | 28 +- .../handlers/tests/test_cred_offer_handler.py | 28 +- .../tests/test_cred_problem_report_handler.py | 6 +- .../tests/test_cred_proposal_handler.py | 20 +- .../tests/test_cred_request_handler.py | 34 +- .../v2_0/models/tests/test_cred_ex_record.py | 4 +- .../v2_0/tests/test_manager.py | 78 ++-- .../v2_0/tests/test_routes.py | 336 +++++++-------- .../tests/test_problem_report_handler.py | 6 +- .../tests/test_reuse_accept_handler.py | 6 +- .../v1_0/handlers/tests/test_reuse_handler.py | 8 +- .../out_of_band/v1_0/tests/test_manager.py | 118 +++--- .../out_of_band/v1_0/tests/test_routes.py | 24 +- .../dif/tests/test_pres_exch_handler.py | 42 +- .../tests/test_presentation_ack_handler.py | 10 +- .../tests/test_presentation_handler.py | 26 +- ...est_presentation_problem_report_handler.py | 6 +- .../test_presentation_proposal_handler.py | 16 +- .../test_presentation_request_handler.py | 102 ++--- .../v1_0/models/tests/test_record.py | 4 +- .../present_proof/v1_0/tests/test_manager.py | 72 ++-- .../present_proof/v1_0/tests/test_routes.py | 222 +++++----- .../v2_0/formats/dif/tests/test_handler.py | 44 +- .../handlers/tests/test_pres_ack_handler.py | 10 +- .../v2_0/handlers/tests/test_pres_handler.py | 26 +- .../tests/test_pres_problem_report_handler.py | 6 +- .../tests/test_pres_proposal_handler.py | 16 +- .../tests/test_pres_request_handler.py | 102 ++--- .../v2_0/models/tests/test_record.py | 4 +- .../present_proof/v2_0/tests/test_manager.py | 94 +++-- .../present_proof/v2_0/tests/test_routes.py | 348 ++++++++-------- .../v1_0/tests/test_routes.py | 14 +- .../v2_0/tests/test_routes.py | 18 +- .../handlers/tests/test_forward_handler.py | 20 +- .../v1_0/tests/test_routing_manager.py | 6 +- .../trustping/v1_0/tests/test_routes.py | 16 +- .../resolver/default/tests/test_indy.py | 16 +- .../default/tests/test_legacy_peer.py | 14 +- .../resolver/default/tests/test_universal.py | 10 +- .../resolver/tests/test_routes.py | 18 +- .../tests/test_issuer_rev_reg_record.py | 24 +- .../revocation/tests/test_indy.py | 22 +- .../revocation/tests/test_manager.py | 96 +++-- .../revocation/tests/test_routes.py | 137 +++---- .../settings/tests/test_routes.py | 10 +- .../storage/tests/test_askar_storage.py | 44 +- .../storage/tests/test_in_memory_storage.py | 4 +- .../storage/tests/test_indy_storage.py | 70 ++-- aries_cloudagent/tails/tests/test_indy.py | 22 +- aries_cloudagent/tests/mock.py | 20 + .../inbound/tests/test_http_transport.py | 18 +- .../transport/inbound/tests/test_manager.py | 10 +- .../transport/inbound/tests/test_session.py | 22 +- .../inbound/tests/test_ws_transport.py | 4 +- .../outbound/tests/test_http_transport.py | 6 +- .../transport/outbound/tests/test_manager.py | 22 +- .../outbound/tests/test_ws_transport.py | 2 +- .../transport/queue/tests/test_basic_queue.py | 6 +- .../transport/tests/test_pack_format.py | 14 +- aries_cloudagent/utils/tests/test_http.py | 2 +- .../utils/tests/test_task_queue.py | 4 +- .../crypto/tests/test_wallet_key_pair.py | 6 +- .../wallet/tests/test_indy_wallet.py | 126 +++--- aries_cloudagent/wallet/tests/test_routes.py | 168 ++++---- 154 files changed, 3495 insertions(+), 3270 deletions(-) create mode 100644 aries_cloudagent/tests/mock.py diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index 4202005c0c..5a209981f6 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from aiohttp import ClientSession, DummyCookieJar, TCPConnector, web from aiohttp.test_utils import unused_port @@ -44,9 +44,9 @@ async def test_debug_middleware(self): method="GET", path_qs="/hello/world?a=1&b=2", match_info={"match": "info"}, - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - handler = mock.AsyncMock() + handler = mock.CoroutineMock() await test_module.debug_middleware(request, handler) mock_logger.isEnabledFor.assert_called_once() @@ -62,7 +62,7 @@ async def test_ready_middleware(self): request = mock.MagicMock( rel_url="/", app=mock.MagicMock(_state={"ready": False}) ) - handler = mock.AsyncMock(return_value="OK") + handler = mock.CoroutineMock(return_value="OK") with self.assertRaises(test_module.web.HTTPServiceUnavailable): await test_module.ready_middleware(request, handler) @@ -70,28 +70,28 @@ async def test_ready_middleware(self): assert await test_module.ready_middleware(request, handler) == "OK" request.app._state["ready"] = True - handler = mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.LedgerConfigError("Bad config") ) with self.assertRaises(test_module.LedgerConfigError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.web.HTTPFound(location="/api/doc") ) with self.assertRaises(test_module.web.HTTPFound): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = mock.AsyncMock( + handler = mock.CoroutineMock( side_effect=test_module.asyncio.CancelledError("Cancelled") ) with self.assertRaises(test_module.asyncio.CancelledError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = mock.AsyncMock(side_effect=KeyError("No such thing")) + handler = mock.CoroutineMock(side_effect=KeyError("No such thing")) with self.assertRaises(KeyError): await test_module.ready_middleware(request, handler) @@ -123,10 +123,10 @@ def get_admin_server( profile, self.outbound_message_router, self.webhook_router, - conductor_stop=mock.AsyncMock(), + conductor_stop=mock.CoroutineMock(), task_queue=TaskQueue(max_active=4) if task_queue else None, conductor_stats=( - None if task_queue else mock.AsyncMock(return_value={"a": 1}) + None if task_queue else mock.CoroutineMock(return_value={"a": 1}) ), ) @@ -167,7 +167,9 @@ async def test_start_stop(self): ) await server.stop() - with mock.patch.object(web.TCPSite, "start", mock.AsyncMock()) as mock_start: + with mock.patch.object( + web.TCPSite, "start", mock.CoroutineMock() + ) as mock_start: mock_start.side_effect = OSError("Failure to launch") with self.assertRaises(AdminSetupError): await self.get_admin_server(settings).start() @@ -216,7 +218,7 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={"Authorization": "Bearer ..."}, path="/multitenancy/etc", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) @@ -225,7 +227,7 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={}, path="/protected/non-multitenancy/non-server", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) @@ -234,9 +236,9 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - mock_handler = mock.AsyncMock() + mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.called_once_with(mock_request) @@ -244,9 +246,9 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={"Authorization": "Non-bearer ..."}, path="/test", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) - mock_handler = mock.AsyncMock() + mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.called_once_with(mock_request) @@ -257,7 +259,7 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={"Authorization": "Non-bearer ..."}, path="/protected/non-multitenancy/non-server", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await setup_ctx_middle(mock_request, None) @@ -266,12 +268,12 @@ async def test_import_routes_multitenant_middleware(self): method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=mock.AsyncMock(return_value="abc123"), + text=mock.CoroutineMock(return_value="abc123"), ) with mock.patch.object( server.multitenant_manager, "get_profile_for_token", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_profile: mock_get_profile.side_effect = [ test_module.MultitenantManagerError("corrupt token"), @@ -486,7 +488,7 @@ async def server(): async def test_on_record_event(server, event_topic, webhook_topic): profile = InMemoryProfile.test_profile() with mock.patch.object( - server, "send_webhook", mock.AsyncMock() + server, "send_webhook", mock.CoroutineMock() ) as mock_send_webhook: await server._on_record_event(profile, Event(event_topic, None)) mock_send_webhook.assert_called_once_with(profile, webhook_topic, None) diff --git a/aries_cloudagent/commands/tests/test_provision.py b/aries_cloudagent/commands/tests/test_provision.py index aef197dd72..15b7438791 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...config.base import ConfigError @@ -40,24 +40,24 @@ def test_provision_wallet(self): ) async def test_provision_ledger_configured(self): - profile = mock.MagicMock(close=mock.AsyncMock()) + profile = mock.MagicMock(close=mock.CoroutineMock()) with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ) as mock_wallet_config, mock.patch.object( - test_module, "ledger_config", mock.AsyncMock(return_value=True) + test_module, "ledger_config", mock.CoroutineMock(return_value=True) ) as mock_ledger_config: await test_module.provision({}) async def test_provision_config_x(self): with mock.patch.object( - test_module, "wallet_config", mock.AsyncMock() + test_module, "wallet_config", mock.CoroutineMock() ) as mock_wallet_config: mock_wallet_config.side_effect = ConfigError("oops") with self.assertRaises(test_module.ProvisionError): diff --git a/aries_cloudagent/commands/tests/test_start.py b/aries_cloudagent/commands/tests/test_start.py index 5e1464225d..8e55eb1939 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...config.error import ArgsParseError @@ -18,9 +18,9 @@ def test_bad_args(self): async def test_start_shutdown_app(self): mock_conductor = mock.MagicMock( - setup=mock.AsyncMock(), - start=mock.AsyncMock(), - stop=mock.AsyncMock(), + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(), + stop=mock.CoroutineMock(), ) await test_module.start_app(mock_conductor) await test_module.shutdown_app(mock_conductor) @@ -57,9 +57,9 @@ def test_exec_start(self): run_loop.assert_called_once() async def test_run_loop(self): - startup = mock.AsyncMock() + startup = mock.CoroutineMock() startup_call = startup() - shutdown = mock.AsyncMock() + shutdown = mock.CoroutineMock() shutdown_call = shutdown() with mock.patch.object(test_module, "asyncio", autospec=True) as mock_asyncio: test_module.run_loop(startup_call, shutdown_call) @@ -79,7 +79,7 @@ async def test_run_loop(self): mock.MagicMock(), mock.MagicMock(cancel=mock.MagicMock()), ] - mock_asyncio.gather = mock.AsyncMock() + mock_asyncio.gather = mock.CoroutineMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = tasks @@ -92,9 +92,9 @@ async def test_run_loop(self): shutdown.assert_awaited_once() async def test_run_loop_init_x(self): - startup = mock.AsyncMock(side_effect=KeyError("the front fell off")) + startup = mock.CoroutineMock(side_effect=KeyError("the front fell off")) startup_call = startup() - shutdown = mock.AsyncMock() + shutdown = mock.CoroutineMock() shutdown_call = shutdown() with mock.patch.object( test_module, "asyncio", autospec=True @@ -115,7 +115,7 @@ 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 = mock.MagicMock() - mock_asyncio.gather = mock.AsyncMock() + mock_asyncio.gather = mock.CoroutineMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = [task] diff --git a/aries_cloudagent/commands/tests/test_upgrade.py b/aries_cloudagent/commands/tests/test_upgrade.py index 45b6b206fa..6814dc77d3 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -55,18 +55,18 @@ async def test_upgrade_storage_from_version_included(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), + mock.CoroutineMock(return_value=[ConnRecord()]), ), mock.patch.object( - ConnRecord, "save", mock.AsyncMock() + ConnRecord, "save", mock.CoroutineMock() ): await test_module.upgrade( settings={ @@ -79,18 +79,18 @@ async def test_upgrade_storage_missing_from_version(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), + mock.CoroutineMock(return_value=[ConnRecord()]), ), mock.patch.object( - ConnRecord, "save", mock.AsyncMock() + ConnRecord, "save", mock.CoroutineMock() ): await test_module.upgrade(settings={}) @@ -103,8 +103,8 @@ async def test_upgrade_from_version(self): with mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), - ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -121,8 +121,8 @@ async def test_upgrade_all_subwallets(self): with mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), - ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -143,8 +143,8 @@ async def test_upgrade_specified_subwallets(self): with mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), - ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -160,8 +160,8 @@ async def test_upgrade_specified_subwallets(self): with mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), - ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): + mock.CoroutineMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.CoroutineMock()): await test_module.upgrade( profile=self.profile, ) @@ -174,10 +174,10 @@ async def test_upgrade_callable(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( @@ -210,10 +210,10 @@ async def test_upgrade_callable_named_tag(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( @@ -248,10 +248,10 @@ async def test_upgrade_x_same_version(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ): @@ -269,18 +269,18 @@ async def test_upgrade_missing_from_version(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), + mock.CoroutineMock(return_value=[ConnRecord()]), ), mock.patch.object( - ConnRecord, "save", mock.AsyncMock() + ConnRecord, "save", mock.CoroutineMock() ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade( @@ -300,10 +300,10 @@ async def test_upgrade_x_callable_not_set(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( @@ -335,10 +335,10 @@ async def test_upgrade_x_class_not_found(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( @@ -368,18 +368,18 @@ async def test_execute(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( ConnRecord, "query", - mock.AsyncMock(return_value=[ConnRecord()]), + mock.CoroutineMock(return_value=[ConnRecord()]), ), mock.patch.object( - ConnRecord, "save", mock.AsyncMock() + ConnRecord, "save", mock.CoroutineMock() ), mock.patch.object( asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: @@ -400,10 +400,10 @@ async def test_upgrade_x_invalid_record_type(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( @@ -433,10 +433,10 @@ async def test_upgrade_force(self): with mock.patch.object( test_module, "wallet_config", - mock.AsyncMock( + mock.CoroutineMock( return_value=( self.profile, - mock.AsyncMock(did="public DID", verkey="verkey"), + mock.CoroutineMock(did="public DID", verkey="verkey"), ) ), ), mock.patch.object( diff --git a/aries_cloudagent/config/tests/test_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index 515f1db52c..c48865d921 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .. import argparse @@ -16,12 +16,14 @@ class TestLedgerConfig(IsolatedAsyncioTestCase): async def test_fetch_genesis_transactions(self): - with mock.patch.object(test_module, "fetch", mock.AsyncMock()) as mock_fetch: + with mock.patch.object( + test_module, "fetch", mock.CoroutineMock() + ) as mock_fetch: await test_module.fetch_genesis_transactions("http://1.2.3.4:9000/genesis") async def test_fetch_genesis_transactions_x(self): with mock.patch.object( - test_module, "fetch", mock.AsyncMock(return_value=TEST_GENESIS) + test_module, "fetch", mock.CoroutineMock(return_value=TEST_GENESIS) ) as mock_fetch: mock_fetch.side_effect = test_module.FetchError("404 Not Found") with self.assertRaises(test_module.ConfigError): @@ -36,7 +38,7 @@ async def test_get_genesis_url(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS), + mock.CoroutineMock(return_value=TEST_GENESIS), ) as mock_fetch: await test_module.get_genesis_transactions(settings) self.assertEqual(settings["ledger.genesis_transactions"], TEST_GENESIS) @@ -72,7 +74,7 @@ async def test_ledger_config_no_taa_accept(self): "default_endpoint": "http://1.2.3.4:8051", } mock_ledger = mock.MagicMock( - get_txn_author_agreement=mock.AsyncMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={ "taa_required": True, "taa_record": { @@ -80,7 +82,7 @@ async def test_ledger_config_no_taa_accept(self): }, } ), - get_latest_txn_author_acceptance=mock.AsyncMock( + get_latest_txn_author_acceptance=mock.CoroutineMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), read_only=False, @@ -96,7 +98,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) with mock.patch.object( - test_module, "accept_taa", mock.AsyncMock() + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: mock_accept_taa.return_value = False assert not await test_module.ledger_config( @@ -108,7 +110,7 @@ async def test_accept_taa(self): "ledger.genesis_transactions": TEST_GENESIS, } mock_ledger = mock.MagicMock( - get_txn_author_agreement=mock.AsyncMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={ "taa_required": True, "taa_record": { @@ -116,13 +118,13 @@ async def test_accept_taa(self): }, } ), - get_latest_txn_author_acceptance=mock.AsyncMock( + get_latest_txn_author_acceptance=mock.CoroutineMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), - update_endpoint_for_did=mock.AsyncMock(), + update_endpoint_for_did=mock.CoroutineMock(), read_only=False, ) - mock_wallet = mock.MagicMock(set_did_endpoint=mock.AsyncMock()) + mock_wallet = mock.MagicMock(set_did_endpoint=mock.CoroutineMock()) session = InMemoryProfile.test_session(settings=settings) profile = session.profile @@ -135,7 +137,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - test_module, "accept_taa", mock.AsyncMock() + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: mock_accept_taa.return_value = True await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -146,12 +148,12 @@ async def test_ledger_config_read_only_skip_taa_accept(self): "ledger.genesis_transactions": TEST_GENESIS, } mock_ledger = mock.MagicMock( - get_txn_author_agreement=mock.AsyncMock(), - get_latest_txn_author_acceptance=mock.AsyncMock(), + get_txn_author_agreement=mock.CoroutineMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), read_only=True, ) mock_wallet = mock.MagicMock( - set_did_endpoint=mock.AsyncMock( + set_did_endpoint=mock.CoroutineMock( side_effect=LedgerError( "Error cannot update endpoint when ledger is in read only mode" ) @@ -169,7 +171,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - test_module, "accept_taa", mock.AsyncMock() + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: with self.assertRaises(test_module.ConfigError) as x_context: await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -183,12 +185,12 @@ async def test_ledger_config_read_only_skip_profile_endpoint_publish(self): "profile_endpoint": "http://agent.ca", } mock_ledger = mock.MagicMock( - get_txn_author_agreement=mock.AsyncMock(), - get_latest_txn_author_acceptance=mock.AsyncMock(), + get_txn_author_agreement=mock.CoroutineMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), read_only=True, ) mock_wallet = mock.MagicMock( - set_did_endpoint=mock.AsyncMock(), + set_did_endpoint=mock.CoroutineMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -202,7 +204,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - test_module, "accept_taa", mock.AsyncMock() + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: await test_module.ledger_config(profile, TEST_DID, provision=True) mock_ledger.get_txn_author_agreement.assert_not_called() @@ -216,15 +218,15 @@ async def test_ledger_config_read_write_skip_taa_endpoint_publish(self): "profile_endpoint": "http://agent-profile.ca", } mock_ledger = mock.MagicMock( - get_txn_author_agreement=mock.AsyncMock( + get_txn_author_agreement=mock.CoroutineMock( return_value={"taa_required": False} ), - get_latest_txn_author_acceptance=mock.AsyncMock(), - update_endpoint_for_did=mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.CoroutineMock(), + update_endpoint_for_did=mock.CoroutineMock(), read_only=False, ) mock_wallet = mock.MagicMock( - set_did_endpoint=mock.AsyncMock(), + set_did_endpoint=mock.CoroutineMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -238,7 +240,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - test_module, "accept_taa", mock.AsyncMock() + test_module, "accept_taa", mock.CoroutineMock() ) as mock_accept_taa: await test_module.ledger_config( profile, @@ -338,7 +340,7 @@ async def test_load_multiple_genesis_transactions_from_config_a(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.return_value = mock.MagicMock( __enter__=mock.MagicMock( @@ -433,7 +435,7 @@ async def test_load_multiple_genesis_transactions_from_config_b(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.return_value = mock.MagicMock( __enter__=mock.MagicMock( @@ -495,7 +497,7 @@ async def test_load_multiple_genesis_transactions_config_error_a(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.return_value = mock.MagicMock( __enter__=mock.MagicMock( @@ -560,7 +562,7 @@ async def test_load_multiple_genesis_transactions_multiple_write(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.return_value = mock.MagicMock( __enter__=mock.MagicMock( @@ -619,7 +621,7 @@ async def test_load_multiple_genesis_transactions_from_config_io_x(self): with mock.patch.object( test_module, "fetch_genesis_transactions", - mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.side_effect = IOError("no read permission") with self.assertRaises(test_module.ConfigError): @@ -654,7 +656,7 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): 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() + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: mock_prompt.side_effect = EOFError() assert not await test_module.accept_taa( @@ -664,7 +666,7 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): 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() + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: mock_prompt.return_value = "x" assert not await test_module.accept_taa( @@ -674,9 +676,11 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): 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() + test_module.prompt_toolkit, "prompt", mock.CoroutineMock() ) as mock_prompt: - mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) + mock_ledger = mock.MagicMock( + accept_txn_author_agreement=mock.CoroutineMock() + ) mock_prompt.return_value = "" assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False @@ -719,7 +723,7 @@ async def test_ledger_accept_taa(self): "ledger.taa_acceptance_version": "1.0", } ) - mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.CoroutineMock()) assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False ) diff --git a/aries_cloudagent/config/tests/test_wallet.py b/aries_cloudagent/config/tests/test_wallet.py index f7e1f848e2..45b96b5f9a 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -34,12 +34,12 @@ class TestWalletConfig(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.injector = Injector(enforce_typing=False) self.session = mock.MagicMock(ProfileSession)() - self.session.commit = mock.AsyncMock() + self.session.commit = mock.CoroutineMock() self.profile = mock.MagicMock( backend="indy", created=True, name="Test Wallet", - transaction=mock.AsyncMock(return_value=self.session), + transaction=mock.CoroutineMock(return_value=self.session), ) def _inject(cls): @@ -58,11 +58,11 @@ async def test_wallet_config_existing_replace(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=mock.AsyncMock(), - create_local_did=mock.AsyncMock( + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -71,7 +71,7 @@ async def test_wallet_config_existing_replace(self): 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() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -82,7 +82,7 @@ async def test_wallet_config_existing_open(self): backend="indy", created=False, name="Test Wallet", - transaction=mock.AsyncMock(return_value=self.session), + transaction=mock.CoroutineMock(return_value=self.session), ) self.context.injector.clear_binding(ProfileManager) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) @@ -95,11 +95,11 @@ async def test_wallet_config_existing_open(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=mock.AsyncMock(), - create_local_did=mock.AsyncMock( + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -110,7 +110,7 @@ async def test_wallet_config_existing_open(self): 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() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -126,20 +126,20 @@ async def test_wallet_config_auto_provision(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=mock.AsyncMock(), - create_local_did=mock.AsyncMock( + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - MockManager, "open", mock.AsyncMock() + MockManager, "open", mock.CoroutineMock() ) as mock_mgr_open, mock.patch.object( - test_module, "add_or_update_version_to_storage", mock.AsyncMock() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_mgr_open.side_effect = test_module.ProfileNotFoundError() @@ -157,13 +157,13 @@ async def test_wallet_config_non_indy_x(self): ) self.profile.backend = "not-indy" mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - test_module, "add_or_update_version_to_storage", mock.AsyncMock() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -175,7 +175,7 @@ async def test_wallet_config_bad_seed_x(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -186,7 +186,7 @@ async def test_wallet_config_bad_seed_x(self): "seed_to_did", mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), ) as mock_seed_to_did, mock.patch.object( - test_module, "add_or_update_version_to_storage", mock.AsyncMock() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -199,9 +199,9 @@ async def test_wallet_config_seed_local(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock(return_value=None), - set_public_did=mock.AsyncMock(), - create_local_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -210,7 +210,7 @@ async def test_wallet_config_seed_local(self): 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() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -223,9 +223,9 @@ async def test_wallet_config_seed_public(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock(return_value=None), - set_public_did=mock.AsyncMock(), - create_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -236,15 +236,15 @@ async def test_wallet_config_seed_public(self): "seed_to_did", mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), ) as mock_seed_to_did, mock.patch.object( - test_module, "add_or_update_version_to_storage", mock.AsyncMock() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_seed_no_public_did(self): mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock(return_value=None), - set_public_did=mock.AsyncMock(), - create_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock(return_value=None), + set_public_did=mock.CoroutineMock(), + create_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -253,7 +253,7 @@ async def test_wallet_config_seed_no_public_did(self): 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() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -266,20 +266,20 @@ async def test_wallet_config_for_key_derivation_method(self): } ) mock_wallet = mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=mock.AsyncMock(), - create_local_did=mock.AsyncMock( + set_public_did=mock.CoroutineMock(), + create_local_did=mock.CoroutineMock( return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with mock.patch.object( - MockManager, "provision", mock.AsyncMock() + MockManager, "provision", mock.CoroutineMock() ) as mock_mgr_provision, mock.patch.object( - test_module, "add_or_update_version_to_storage", mock.AsyncMock() + test_module, "add_or_update_version_to_storage", mock.CoroutineMock() ): 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 0fd7407614..341d27b2e6 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from pydid import DID, DIDDocument, DIDDocumentBuilder from pydid.doc.builder import ServiceBuilder @@ -84,7 +84,7 @@ async def asyncSetUp(self): self.responder = MockResponder() self.oob_mock = mock.MagicMock( - clean_finished_oob_record=mock.AsyncMock(return_value=None) + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) self.route_manager = CoordinateMediationV1RouteManager() self.resolver = DIDResolver() @@ -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 = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(mediation_record.routing_keys, mediation_record.endpoint) ) doc = await self.manager.create_did_document( @@ -336,7 +336,7 @@ async def test_fetch_connection_targets_conn_invitation_did_no_resolver(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -384,7 +384,7 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -454,7 +454,7 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( @@ -518,7 +518,7 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( method=SOV, @@ -557,7 +557,7 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -608,7 +608,7 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -670,7 +670,7 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -732,7 +732,7 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -793,7 +793,7 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -813,7 +813,7 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_no_resolver(self) mock_conn = mock.MagicMock( my_did=self.test_did, - retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.CoroutineMock(return_value=mock_oob_invite), state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER.rfc23, ) @@ -836,8 +836,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): ) did_doc = builder.build() - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = mock.AsyncMock( + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) + self.resolver.dereference = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -861,7 +861,7 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.CoroutineMock(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 = mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.CoroutineMock( return_value=self.test_endpoint ) - self.resolver.get_key_for_did = mock.AsyncMock( + self.resolver.get_key_for_did = mock.CoroutineMock( return_value=self.test_target_verkey ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -913,7 +913,7 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.CoroutineMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -985,7 +985,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): metadata=None, ) - self.manager.resolve_invitation = mock.AsyncMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( self.test_endpoint, [self.test_verkey], @@ -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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( 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 = mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.CoroutineMock( return_value=(doc, doc.service) ) await self.manager.record_did(did) @@ -1196,7 +1196,7 @@ async def test_find_inbound_connection(self): with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_conn_mgr_resolve_conn: mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1205,7 +1205,7 @@ async def test_find_inbound_connection(self): # Second pass: in cache with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1225,7 +1225,7 @@ async def test_find_inbound_connection_no_cache(self): with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_conn_mgr_resolve_conn: self.context.injector.clear_binding(BaseCache) mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1244,9 +1244,9 @@ async def test_resolve_inbound_connection(self): mock_conn.connection_id = "dummy" with mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( - self.manager, "find_connection", mock.AsyncMock() + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -1270,9 +1270,9 @@ async def test_resolve_inbound_connection_injector_error(self): mock_conn.connection_id = "dummy" with mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( - self.manager, "find_connection", mock.AsyncMock() + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = InjectionError() mock_mgr_find_conn.return_value = mock_conn @@ -1290,9 +1290,9 @@ async def test_resolve_inbound_connection_wallet_not_found_error(self): mock_conn.connection_id = "dummy" with mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + InMemoryWallet, "get_local_did_for_verkey", mock.CoroutineMock() ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( - self.manager, "find_connection", mock.AsyncMock() + self.manager, "find_connection", mock.CoroutineMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = WalletNotFoundError() mock_mgr_find_conn.return_value = mock_conn @@ -1328,7 +1328,7 @@ async def test_get_connection_targets_conn_invitation_no_did(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1387,13 +1387,13 @@ async def test_get_connection_targets_retrieve_connection(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) with mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn mock_conn_target_ser.return_value = {"serialized": "value"} @@ -1436,9 +1436,9 @@ async def test_get_connection_targets_from_cache(self): with mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - self.manager, "fetch_connection_targets", mock.AsyncMock() + self.manager, "fetch_connection_targets", mock.CoroutineMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1480,9 +1480,9 @@ async def test_get_connection_targets_no_cache(self): with mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - self.manager, "fetch_connection_targets", mock.AsyncMock() + self.manager, "fetch_connection_targets", mock.CoroutineMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1532,7 +1532,7 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.CoroutineMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1565,7 +1565,7 @@ async def test_create_static_connection_multitenant(self): ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = mock.AsyncMock() + self.route_manager.route_static = mock.CoroutineMock() with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True @@ -1596,11 +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 = mock.AsyncMock() + self.route_manager.route_static = mock.CoroutineMock() with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did, mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -1624,7 +1624,7 @@ async def test_create_static_connection_multitenant_mediator(self): ) default_mediator = mock.MagicMock() - self.route_manager.route_static = mock.AsyncMock() + self.route_manager.route_static = mock.CoroutineMock() with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True @@ -1701,11 +1701,11 @@ async def test_create_static_connection_their_seed_only(self): async def test_find_connection_retrieve_by_did(self): with mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1719,13 +1719,13 @@ 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 mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1739,14 +1739,14 @@ async def test_find_connection_retrieve_by_did_auto_disclose_features(self): async def test_find_connection_retrieve_by_invitation_key(self): with mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_key", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.find_connection( @@ -1758,9 +1758,9 @@ async def test_find_connection_retrieve_by_invitation_key(self): async def test_find_connection_retrieve_none_by_invitation_key(self): with mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_key", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.side_effect = StorageNotFoundError() @@ -1776,11 +1776,11 @@ async def test_get_endpoints(self): conn_id = "dummy" with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( InMemoryWallet, "get_local_did", autospec=True ) as mock_wallet_get_local_did, mock.patch.object( - self.manager, "get_connection_targets", mock.AsyncMock() + self.manager, "get_connection_targets", mock.CoroutineMock() ) as mock_get_conn_targets: mock_retrieve.return_value = mock.MagicMock() mock_wallet_get_local_did.return_value = mock.MagicMock( diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index 698f355df2..88cc2ab072 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...admin.base_server import BaseAdminServer @@ -114,7 +114,7 @@ async def test_startup_version_record_exists(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value="v0.7.3")), + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.7.3")), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -124,7 +124,7 @@ async def test_startup_version_record_exists(self): ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) @@ -168,7 +168,7 @@ async def test_startup_version_no_upgrade_add_record(self): ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value="v0.8.1")), + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.8.1")), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -176,7 +176,7 @@ async def test_startup_version_no_upgrade_add_record(self): ), mock.patch.object( test_module, "add_version_record", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) @@ -200,7 +200,7 @@ async def test_startup_version_no_upgrade_add_record(self): ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -238,7 +238,7 @@ async def test_startup_version_force_upgrade(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value="v0.8.0")), + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.8.0")), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -246,7 +246,7 @@ async def test_startup_version_force_upgrade(self): ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) @@ -272,7 +272,7 @@ async def test_startup_version_force_upgrade(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value="v0.7.0")), + mock.CoroutineMock(return_value=mock.MagicMock(value="v0.7.0")), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -280,7 +280,7 @@ async def test_startup_version_force_upgrade(self): ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) @@ -306,7 +306,7 @@ async def test_startup_version_force_upgrade(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(side_effect=StorageNotFoundError()), + mock.CoroutineMock(side_effect=StorageNotFoundError()), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -314,7 +314,7 @@ async def test_startup_version_force_upgrade(self): ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): await conductor.setup() session = await conductor.root_profile.session() @@ -342,7 +342,7 @@ async def test_startup_version_record_not_exists(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(side_effect=StorageNotFoundError()), + mock.CoroutineMock(side_effect=StorageNotFoundError()), ), mock.patch.object( test_module, "get_upgrade_version_list", @@ -350,7 +350,7 @@ async def test_startup_version_record_not_exists(self): ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) @@ -416,12 +416,12 @@ async def test_startup_no_public_did(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): mock_outbound_mgr.return_value.registered_transports = {} - mock_outbound_mgr.return_value.enqueue_message = mock.AsyncMock() - mock_outbound_mgr.return_value.start = mock.AsyncMock() - mock_outbound_mgr.return_value.stop = mock.AsyncMock() + mock_outbound_mgr.return_value.enqueue_message = mock.CoroutineMock() + mock_outbound_mgr.return_value.start = mock.CoroutineMock() + mock_outbound_mgr.return_value.stop = mock.CoroutineMock() await conductor.setup() mock_inbound_mgr.return_value.setup.assert_awaited_once() @@ -688,8 +688,8 @@ async def test_handle_nots(self): test_module, "OutboundTransportManager", mock.MagicMock() ) as mock_outbound_mgr: mock_outbound_mgr.return_value = mock.MagicMock( - setup=mock.AsyncMock(), - enqueue_message=mock.AsyncMock(), + setup=mock.CoroutineMock(), + enqueue_message=mock.CoroutineMock(), ) payload = "{}" @@ -708,7 +708,7 @@ async def test_handle_nots(self): ) 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 = mock.AsyncMock() + mock_conn_mgr.return_value.get_connection_targets = mock.CoroutineMock() 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() @@ -749,7 +749,7 @@ async def test_handle_not_returned_ledger_x(self): with mock.patch.object( conductor.dispatcher, "run_task", mock.MagicMock() ) as mock_dispatch_run, mock.patch.object( - conductor, "queue_outbound", mock.AsyncMock() + conductor, "queue_outbound", mock.CoroutineMock() ) as mock_queue, mock.patch.object( conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: @@ -789,7 +789,7 @@ async def test_queue_outbound_ledger_x(self): ) 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 = mock.AsyncMock() + conn_mgr.return_value.get_connection_targets = mock.CoroutineMock() mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" ) @@ -835,7 +835,7 @@ async def test_admin(self): ) as admin_stop, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() admin_start.assert_awaited_once_with() @@ -881,13 +881,13 @@ async def test_admin_startx(self): ) as conn_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): admin_start.side_effect = KeyError("trouble") - oob_mgr.return_value.create_invitation = mock.AsyncMock( + oob_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=KeyError("double trouble") ) - conn_mgr.return_value.create_invitation = mock.AsyncMock( + conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=KeyError("triple trouble") ) await conductor.start() @@ -922,7 +922,7 @@ async def test_start_static(self): ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: @@ -938,7 +938,7 @@ async def test_start_static(self): ED25519, ) - mock_mgr.return_value.create_static_connection = mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() await conductor.start() mock_mgr.return_value.create_static_connection.assert_awaited_once() @@ -955,14 +955,14 @@ async def test_start_x_in(self): test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_intx_mgr.return_value = mock.MagicMock( - setup=mock.AsyncMock(), - start=mock.AsyncMock(side_effect=KeyError("trouble")), + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), ) mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_mgr.return_value.create_static_connection = mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -977,12 +977,12 @@ async def test_start_x_out_a(self): test_module, "OutboundTransportManager" ) as mock_outx_mgr: mock_outx_mgr.return_value = mock.MagicMock( - setup=mock.AsyncMock(), - start=mock.AsyncMock(side_effect=KeyError("trouble")), + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), registered_transports={"test": mock.MagicMock(schemes=["http"])}, ) await conductor.setup() - mock_mgr.return_value.create_static_connection = mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -997,14 +997,14 @@ async def test_start_x_out_b(self): test_module, "OutboundTransportManager" ) as mock_outx_mgr: mock_outx_mgr.return_value = mock.MagicMock( - setup=mock.AsyncMock(), - start=mock.AsyncMock(side_effect=KeyError("trouble")), - stop=mock.AsyncMock(), + setup=mock.CoroutineMock(), + start=mock.CoroutineMock(side_effect=KeyError("trouble")), + stop=mock.CoroutineMock(), registered_transports={}, - enqueue_message=mock.AsyncMock(), + enqueue_message=mock.CoroutineMock(), ) await conductor.setup() - mock_mgr.return_value.create_static_connection = mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.CoroutineMock() with self.assertRaises(KeyError): await conductor.start() @@ -1088,7 +1088,7 @@ async def test_print_invite_connection(self): with mock.patch("sys.stdout", new=StringIO()) as captured, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: @@ -1126,11 +1126,11 @@ async def test_clear_default_mediator(self): with mock.patch.object( test_module, "MediationManager", - return_value=mock.MagicMock(clear_default_mediator=mock.AsyncMock()), + return_value=mock.MagicMock(clear_default_mediator=mock.CoroutineMock()), ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1152,9 +1152,11 @@ async def test_set_default_mediator(self): with mock.patch.object( test_module, "MediationManager", - return_value=mock.MagicMock(set_default_mediator_by_id=mock.AsyncMock()), + return_value=mock.MagicMock( + set_default_mediator_by_id=mock.CoroutineMock() + ), ) as mock_mgr, mock.patch.object( - MediationRecord, "retrieve_by_id", mock.AsyncMock() + MediationRecord, "retrieve_by_id", mock.CoroutineMock() ), mock.patch.object( test_module, "LOGGER", @@ -1166,7 +1168,7 @@ async def test_set_default_mediator(self): ), mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1188,11 +1190,11 @@ async def test_set_default_mediator_x(self): with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=Exception()), + mock.CoroutineMock(side_effect=Exception()), ), mock.patch.object(test_module, "LOGGER") as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1262,11 +1264,11 @@ async def test_shutdown_multitenant_profiles(self): multitenant_mgr._profiles.put( "test1", - mock.MagicMock(close=mock.AsyncMock()), + mock.MagicMock(close=mock.CoroutineMock()), ) multitenant_mgr._profiles.put( "test2", - mock.MagicMock(close=mock.AsyncMock()), + mock.MagicMock(close=mock.CoroutineMock()), ) await conductor.stop() @@ -1282,8 +1284,8 @@ def get_invite_store_mock( used_invite = MediationInviteRecord(invite_string, used=True) return mock.MagicMock( - get_mediation_invite_record=mock.AsyncMock(return_value=unused_invite), - mark_default_invite_as_used=mock.AsyncMock(return_value=used_invite), + get_mediation_invite_record=mock.CoroutineMock(return_value=unused_invite), + mark_default_invite_as_used=mock.CoroutineMock(return_value=used_invite), ) @@ -1327,15 +1329,15 @@ async def test_mediator_invitation_0160(self, mock_from_url, _): "ConnectionManager", mock.MagicMock( return_value=mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=mock_conn_record) + receive_invitation=mock.CoroutineMock(return_value=mock_conn_record) ) ), ) as mock_mgr, mock.patch.object( - mock_conn_record, "metadata_set", mock.AsyncMock() + mock_conn_record, "metadata_set", mock.CoroutineMock() ), mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1383,13 +1385,13 @@ async def test_mediator_invitation_0434(self, mock_from_url, _): "OutOfBandManager", mock.MagicMock( return_value=mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=oob_record) + receive_invitation=mock.CoroutineMock(return_value=oob_record) ) ), ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): assert not conductor.root_profile.settings["mediation.connections_invite"] await conductor.start() @@ -1426,21 +1428,23 @@ async def test_mediation_invitation_should_use_stored_invitation( patched_invite_store.return_value = mocked_store connection_manager_mock = mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=mock_conn_record) + receive_invitation=mock.CoroutineMock(return_value=mock_conn_record) + ) + mock_mediation_manager = mock.MagicMock( + clear_default_mediator=mock.CoroutineMock() ) - mock_mediation_manager = mock.MagicMock(clear_default_mediator=mock.AsyncMock()) # when with mock.patch.object( test_module, "ConnectionManager", return_value=connection_manager_mock ), mock.patch.object( - mock_conn_record, "metadata_set", mock.AsyncMock() + mock_conn_record, "metadata_set", mock.CoroutineMock() ), mock.patch.object( test_module, "MediationManager", return_value=mock_mediation_manager ), mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1474,12 +1478,14 @@ async def test_mediation_invitation_should_not_create_connection_for_old_invitat invite_store_mock = get_invite_store_mock(invite_string, True) patched_invite_store.return_value = invite_store_mock - connection_manager_mock = mock.MagicMock(receive_invitation=mock.AsyncMock()) + connection_manager_mock = mock.MagicMock( + receive_invitation=mock.CoroutineMock() + ) patched_connection_manager.return_value = connection_manager_mock with mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): # when await conductor.start() @@ -1517,7 +1523,7 @@ async def test_mediator_invitation_x(self, _): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + mock.CoroutineMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1533,9 +1539,9 @@ async def test_setup_ledger_both_multiple_and_base(self): with mock.patch.object( test_module, "load_multiple_genesis_transactions_from_config", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_multiple_genesis_load, mock.patch.object( - test_module, "get_genesis_transactions", mock.AsyncMock() + test_module, "get_genesis_transactions", mock.CoroutineMock() ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: @@ -1552,7 +1558,7 @@ async def test_setup_ledger_only_base(self): conductor = test_module.Conductor(builder) with mock.patch.object( - test_module, "get_genesis_transactions", mock.AsyncMock() + test_module, "get_genesis_transactions", mock.CoroutineMock() ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: @@ -1575,11 +1581,11 @@ async def test_startup_x_no_storage_version(self): ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - mock.AsyncMock(side_effect=StorageNotFoundError()), + mock.CoroutineMock(side_effect=StorageNotFoundError()), ), mock.patch.object( test_module, "upgrade", - mock.AsyncMock(), + mock.CoroutineMock(), ): mock_outbound_mgr.return_value.registered_transports = { "test": mock.MagicMock(schemes=["http"]) diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index 43df17e272..12f4ae5c4d 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 +from aries_cloudagent.tests import mock import pytest from marshmallow import EXCLUDE @@ -116,14 +116,14 @@ async def test_dispatch(self): ) as conn_mgr_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.AsyncMock(return_value="1.1"), + mock.CoroutineMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", - mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): conn_mgr_mock.return_value = mock.MagicMock( - find_inbound_connection=mock.AsyncMock( + find_inbound_connection=mock.CoroutineMock( return_value=mock.MagicMock(connection_id="dummy") ) ) @@ -165,11 +165,11 @@ async def test_dispatch_versioned_message(self): ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.AsyncMock(return_value="1.1"), + mock.CoroutineMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", - mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -284,11 +284,11 @@ async def test_dispatch_versioned_message_handle_greater_succeeds(self): ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.AsyncMock(return_value="1.1"), + mock.CoroutineMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", - mock.AsyncMock(return_value=("1.1", None)), + mock.CoroutineMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -342,9 +342,9 @@ async def test_bad_message_dispatch_parse_x(self): rcv = Receiver() bad_messages = ["not even a dict", {"bad": "message"}] with mock.patch.object( - test_module, "get_version_from_message_type", mock.AsyncMock() + test_module, "get_version_from_message_type", mock.CoroutineMock() ), mock.patch.object( - test_module, "validate_get_response_version", mock.AsyncMock() + test_module, "validate_get_response_version", mock.CoroutineMock() ): for bad in bad_messages: await dispatcher.queue_message( @@ -425,10 +425,12 @@ async def test_create_send_outbound(self): outbound_message = await responder.create_outbound( json.dumps(message.serialize()) ) - with mock.patch.object(responder, "_send", mock.AsyncMock()), mock.patch.object( + with mock.patch.object( + responder, "_send", mock.CoroutineMock() + ), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ): await responder.send_outbound(outbound_message) @@ -448,10 +450,12 @@ async def test_create_send_outbound_with_msg_attrs(self): message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) outbound_message = await responder.create_outbound(message) - with mock.patch.object(responder, "_send", mock.AsyncMock()), mock.patch.object( + with mock.patch.object( + responder, "_send", mock.CoroutineMock() + ), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ): await responder.send_outbound( message=outbound_message, @@ -479,7 +483,7 @@ async def test_create_send_outbound_with_msg_attrs_x(self): with mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ): with self.assertRaises(RuntimeError): await responder.send_outbound( @@ -503,7 +507,7 @@ async def test_conn_rec_active_state_check_a(self): message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_ret_by_id: conn_rec = test_module.ConnRecord() conn_rec.state = test_module.ConnRecord.State.COMPLETED @@ -523,13 +527,13 @@ async def test_conn_rec_active_state_check_b(self): profile = make_profile() profile.context.injector.bind_instance(BaseCache, InMemoryCache()) profile.context.injector.bind_instance( - EventBus, mock.MagicMock(notify=mock.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.CoroutineMock()) ) context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_ret_by_id: conn_rec_a = test_module.ConnRecord() conn_rec_a.state = test_module.ConnRecord.State.REQUEST @@ -548,27 +552,27 @@ async def test_create_enc_outbound(self): message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) with mock.patch.object( - responder, "send_outbound", mock.AsyncMock() + responder, "send_outbound", mock.CoroutineMock() ) 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 mock.patch.object( - responder, "send_outbound", mock.AsyncMock() + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send(message) message = StubAgentMessage() with mock.patch.object( - responder, "send_outbound", mock.AsyncMock() + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send_reply(message) assert mock_send_outbound.called_once() message = json.dumps(StubAgentMessage().serialize()) with mock.patch.object( - responder, "send_outbound", mock.AsyncMock() + responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send_reply(message) @@ -608,11 +612,11 @@ def _smaller_scope(): # with mock.patch.object( # test_module, # "get_version_from_message_type", - # mock.AsyncMock(return_value="1.1"), + # mock.CoroutineMock(return_value="1.1"), # ), mock.patch.object( # test_module, # "validate_get_response_version", - # mock.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), + # mock.CoroutineMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -637,11 +641,11 @@ def _smaller_scope(): # with mock.patch.object( # test_module, # "get_version_from_message_type", - # mock.AsyncMock(return_value="1.1"), + # mock.CoroutineMock(return_value="1.1"), # ), mock.patch.object( # test_module, # "validate_get_response_version", - # mock.AsyncMock(return_value=("1.1", "version-with-degraded-features")), + # mock.CoroutineMock(return_value=("1.1", "version-with-degraded-features")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -666,11 +670,11 @@ def _smaller_scope(): # with mock.patch.object( # test_module, # "get_version_from_message_type", - # mock.AsyncMock(return_value="1.1"), + # mock.CoroutineMock(return_value="1.1"), # ), mock.patch.object( # test_module, # "validate_get_response_version", - # mock.AsyncMock(return_value=("1.1", "version-not-supported")), + # mock.CoroutineMock(return_value=("1.1", "version-not-supported")), # ): # with self.assertRaises(test_module.MessageParseError): # await dispatcher.queue_message( diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index 7bc1175b4f..af0f1ba2ee 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 +from aries_cloudagent.tests import mock from unittest.mock import ANY from ...connections.models.conn_record import ConnRecord @@ -23,7 +23,7 @@ class TestOobProcessor(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = mock.AsyncMock() + self.inbound_message_router = mock.CoroutineMock() self.oob_processor = OobMessageProcessor( inbound_message_router=self.inbound_message_router ) @@ -36,9 +36,9 @@ async def asyncSetUp(self): "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], "serviceEndpoint": "http://their-service-endpoint.com", }, - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), - save=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), + save=mock.CoroutineMock(), ) self.context = RequestContext.test_context() self.context.message = ConnectionInvitation() @@ -48,8 +48,8 @@ async def test_clean_finished_oob_record_no_multi_use_no_request_attach(self): test_message.assign_thread_id("the-thid", "the-pthid") mock_oob = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=False, invitation=mock.MagicMock(requests_attach=[]), ) @@ -57,7 +57,7 @@ async def test_clean_finished_oob_record_no_multi_use_no_request_attach(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -76,8 +76,8 @@ async def test_clean_finished_oob_record_multi_use(self): test_message.assign_thread_id("the-thid", "the-pthid") mock_oob = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, invitation=mock.MagicMock(requests_attach=[]), ) @@ -85,7 +85,7 @@ async def test_clean_finished_oob_record_multi_use(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -105,7 +105,7 @@ async def test_clean_finished_oob_record_x(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError(),) @@ -115,8 +115,8 @@ async def test_clean_finished_oob_record_x(self): async def test_find_oob_target_for_outbound_message(self): mock_oob = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", @@ -139,7 +139,7 @@ async def test_find_oob_target_for_outbound_message(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -177,7 +177,7 @@ async def test_find_oob_target_for_outbound_message_oob_not_found(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -190,8 +190,8 @@ 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 = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", @@ -211,7 +211,7 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=mock_oob), + mock.CoroutineMock(return_value=mock_oob), ): message = json.dumps({}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) @@ -250,7 +250,7 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -266,7 +266,7 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -282,7 +282,7 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -298,7 +298,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -322,7 +322,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" @@ -344,7 +344,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" @@ -360,7 +360,7 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -375,7 +375,7 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE @@ -396,7 +396,7 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED @@ -417,7 +417,7 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED @@ -438,11 +438,13 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve, mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock.MagicMock(delete_record=mock.AsyncMock())), + mock.CoroutineMock( + return_value=mock.MagicMock(delete_record=mock.CoroutineMock()) + ), ) as mock_retrieve_conn: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE @@ -474,7 +476,7 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_set(self): with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -501,7 +503,7 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -519,7 +521,7 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_matching with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -539,7 +541,7 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -557,7 +559,7 @@ async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -578,7 +580,7 @@ async def test_find_oob_record_for_inbound_message_their_service_matching_with_m with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -607,7 +609,7 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -632,7 +634,7 @@ async def test_find_oob_record_for_inbound_message_session_emit_delete( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -658,7 +660,7 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=self.oob_record), + mock.CoroutineMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -678,7 +680,7 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( async def test_handle_message_connection(self): oob_record = mock.MagicMock( connection_id="the-conn-id", - save=mock.AsyncMock(), + save=mock.CoroutineMock(), attach_thread_id=None, their_service=None, ) @@ -707,7 +709,7 @@ async def test_handle_message_connection(self): self.inbound_message_router.assert_called_once_with(self.profile, ANY, False) async def test_handle_message_connectionless(self): - oob_record = mock.MagicMock(save=mock.AsyncMock(), connection_id=None) + oob_record = mock.MagicMock(save=mock.CoroutineMock(), connection_id=None) await self.oob_processor.handle_message( self.profile, diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index b6373d9282..07c3bd0f69 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from unittest.mock import call @@ -38,7 +38,7 @@ async def test_setup(self): self.registry._plugins[mod_name] = mod assert list(self.registry.plugin_names) == [mod_name] assert list(self.registry.plugins) == [mod] - mod.setup = mock.AsyncMock() + mod.setup = mock.CoroutineMock() await self.registry.init_context(ctx) mod.setup.assert_awaited_once_with(ctx) @@ -48,7 +48,7 @@ async def test_register_routes(self): mod.__name__ = mod_name app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = mock.AsyncMock() + mod.routes.register = mock.CoroutineMock() definition = mock.MagicMock() definition.versions = [ { @@ -93,7 +93,7 @@ async def test_register_routes_mod_no_version(self): mod.__name__ = mod_name app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = mock.AsyncMock() + mod.routes.register = mock.CoroutineMock() with mock.patch.object( ClassLoader, @@ -171,7 +171,7 @@ async def test_post_process_routes_mod_no_version(self): mod.__name__ = mod_name app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = mock.AsyncMock() + mod.routes.register = mock.CoroutineMock() with mock.patch.object( ClassLoader, diff --git a/aries_cloudagent/core/tests/test_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py index 1357b9f082..d5383bba1d 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -206,9 +206,9 @@ async def test_disclosed(self): {self.test_message_type: self.test_message_handler} ) mocked = mock.MagicMock() - mocked.return_value.check_access = mock.AsyncMock() + mocked.return_value.check_access = mock.CoroutineMock() mocked.return_value.check_access.return_value = True - mocked.return_value.determine_roles = mock.AsyncMock() + mocked.return_value.determine_roles = mock.CoroutineMock() mocked.return_value.determine_roles.return_value = ["ROLE"] self.registry.register_controllers({self.test_protocol: mocked}) protocols = [self.test_protocol] diff --git a/aries_cloudagent/holder/tests/test_routes.py b/aries_cloudagent/holder/tests/test_routes.py index 6c4d1888fd..88323ce8e0 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -50,7 +50,7 @@ async def test_credentials_get(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credential=mock.AsyncMock( + get_credential=mock.CoroutineMock( return_value=json.dumps({"hello": "world"}) ) ), @@ -68,7 +68,7 @@ async def test_credentials_get_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credential=mock.AsyncMock( + get_credential=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -84,7 +84,7 @@ async def test_credentials_revoked(self): ) self.profile.context.injector.bind_instance( IndyHolder, - mock.MagicMock(credential_revoked=mock.AsyncMock(return_value=False)), + mock.MagicMock(credential_revoked=mock.CoroutineMock(return_value=False)), ) with mock.patch.object( @@ -108,7 +108,7 @@ async def test_credentials_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - credential_revoked=mock.AsyncMock( + credential_revoked=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError("no such cred") ) ), @@ -126,7 +126,7 @@ async def test_credentials_x_ledger(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - credential_revoked=mock.AsyncMock( + credential_revoked=mock.CoroutineMock( side_effect=test_module.LedgerError("down for maintenance") ) ), @@ -140,7 +140,7 @@ async def test_attribute_mime_types_get(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_mime_type=mock.AsyncMock( + get_mime_type=mock.CoroutineMock( side_effect=[None, {"a": "application/jpeg"}] ) ), @@ -160,7 +160,7 @@ async def test_credentials_remove(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - mock.MagicMock(delete_credential=mock.AsyncMock(return_value=None)), + mock.MagicMock(delete_credential=mock.CoroutineMock(return_value=None)), ) with mock.patch.object( @@ -175,7 +175,7 @@ async def test_credentials_remove_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - delete_credential=mock.AsyncMock( + delete_credential=mock.CoroutineMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -188,7 +188,7 @@ async def test_credentials_list(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials=mock.AsyncMock(return_value=[{"hello": "world"}]) + get_credentials=mock.CoroutineMock(return_value=[{"hello": "world"}]) ), ) @@ -204,7 +204,7 @@ async def test_credentials_list_x_holder(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials=mock.AsyncMock( + get_credentials=mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) ), @@ -218,7 +218,7 @@ async def test_w3c_cred_get(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD) + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD) ), ) @@ -233,7 +233,7 @@ async def test_w3c_cred_get_not_found_x(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -247,7 +247,7 @@ async def test_w3c_cred_get_storage_x(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageError() ) ), @@ -261,8 +261,8 @@ async def test_w3c_cred_remove(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), - delete_credential=mock.AsyncMock(return_value=None), + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD), + delete_credential=mock.CoroutineMock(return_value=None), ), ) @@ -278,7 +278,7 @@ async def test_w3c_cred_remove_not_found_x(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock( + retrieve_credential_by_id=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -292,8 +292,8 @@ async def test_w3c_cred_remove_storage_x(self): self.profile.context.injector.bind_instance( VCHolder, mock.MagicMock( - retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), - delete_credential=mock.AsyncMock( + retrieve_credential_by_id=mock.CoroutineMock(return_value=VC_RECORD), + delete_credential=mock.CoroutineMock( side_effect=test_module.StorageError() ), ), @@ -303,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -319,7 +319,7 @@ async def test_w3c_creds_list(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=[VC_RECORD]) + fetch=mock.CoroutineMock(return_value=[VC_RECORD]) ) ) ), @@ -332,7 +332,7 @@ async def test_w3c_creds_list(self): json_response.assert_called_once_with({"results": [VC_RECORD.serialize()]}) async def test_w3c_creds_list_not_found_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -348,7 +348,7 @@ async def test_w3c_creds_list_not_found_x(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -360,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "types": [ "VerifiableCredential", @@ -376,7 +376,7 @@ async def test_w3c_creds_list_storage_x(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(side_effect=test_module.StorageError()) + fetch=mock.CoroutineMock(side_effect=test_module.StorageError()) ) ) ), diff --git a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py index 3a389914fa..4ef865101f 100644 --- a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py +++ b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py @@ -2,7 +2,7 @@ import tempfile import pytest -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager @@ -47,15 +47,15 @@ class TestIndyCredxIssuance(IsolatedAsyncioTestCase): async def asyncSetUp(self): context = InjectionContext(enforce_typing=False) mock_ledger = mock.MagicMock( - get_credential_definition=mock.AsyncMock(return_value={"value": {}}), - get_revoc_reg_delta=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.CoroutineMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.CoroutineMock(return_value=mock_ledger) self.ledger = mock_ledger self.holder_profile = await AskarProfileManager().provision( @@ -78,7 +78,7 @@ async def asyncSetUp(self): self.issuer_profile._context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, mock_ledger) ) ), diff --git a/aries_cloudagent/indy/models/tests/test_pres_preview.py b/aries_cloudagent/indy/models/tests/test_pres_preview.py index 307fd652b9..85efec79f9 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 +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....ledger.multiple_ledger.ledger_requests_executor import ( @@ -408,7 +408,7 @@ async def test_to_indy_proof_request_revo_default_interval(self): mock_get_ledger.return_value = ( None, mock.MagicMock( - get_credential_definition=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), @@ -455,7 +455,7 @@ async def test_to_indy_proof_request_revo(self): mock_get_ledger.return_value = ( None, mock.MagicMock( - get_credential_definition=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), diff --git a/aries_cloudagent/indy/sdk/tests/test_holder.py b/aries_cloudagent/indy/sdk/tests/test_holder.py index 6784005809..f9a3084958 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase import indy.anoncreds @@ -18,14 +18,14 @@ class TestIndySdkHolder(IsolatedAsyncioTestCase): def setUp(self): mock_ledger = mock.MagicMock( get_credential_definition=mock.MagicMock(return_value={"value": {}}), - get_revoc_reg_delta=mock.AsyncMock( + get_revoc_reg_delta=mock.CoroutineMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.CoroutineMock(return_value=mock_ledger) self.ledger = mock_ledger self.wallet = mock.MagicMock() @@ -74,7 +74,7 @@ async def test_store_credential_with_mime_types(self, mock_store_cred): with mock.patch.object( test_module, "IndySdkStorage", mock.MagicMock() ) as mock_storage: - mock_storage.return_value = mock.MagicMock(add_record=mock.AsyncMock()) + mock_storage.return_value = mock.MagicMock(add_record=mock.CoroutineMock()) mock_store_cred.return_value = "cred_id" @@ -345,7 +345,7 @@ async def test_get_credential_x(self, mock_get_cred): async def test_credential_revoked(self): with mock.patch.object( # no creds revoked - self.holder, "get_credential", mock.AsyncMock() + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -358,7 +358,7 @@ async def test_credential_revoked(self): assert not result with mock.patch.object( # cred not revocable - self.holder, "get_credential", mock.AsyncMock() + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -370,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 = mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "value": { @@ -382,7 +382,7 @@ async def test_credential_revoked(self): ) ) with mock.patch.object( # cred not revoked - self.holder, "get_credential", mock.AsyncMock() + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -395,7 +395,7 @@ async def test_credential_revoked(self): assert not result with mock.patch.object( # cred revoked - self.holder, "get_credential", mock.AsyncMock() + self.holder, "get_credential", mock.CoroutineMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -577,9 +577,9 @@ async def test_create_revocation_state(self): } with mock.patch.object( - test_module, "create_tails_reader", mock.AsyncMock() + test_module, "create_tails_reader", mock.CoroutineMock() ) as mock_create_tails_reader, mock.patch.object( - indy.anoncreds, "create_revocation_state", mock.AsyncMock() + indy.anoncreds, "create_revocation_state", mock.CoroutineMock() ) as mock_create_rr_state: mock_create_rr_state.return_value = json.dumps(rr_state) diff --git a/aries_cloudagent/indy/sdk/tests/test_profile.py b/aries_cloudagent/indy/sdk/tests/test_profile.py index 669656ced2..11f7edc6bf 100644 --- a/aries_cloudagent/indy/sdk/tests/test_profile.py +++ b/aries_cloudagent/indy/sdk/tests/test_profile.py @@ -1,6 +1,6 @@ import logging -from unittest import mock +from aries_cloudagent.tests import mock import pytest from ....config.injection_context import InjectionContext @@ -20,7 +20,7 @@ async def open_wallet(): handle=1, master_secret_id="master-secret", ) - with mock.patch.object(opened, "close", mock.AsyncMock()): + with mock.patch.object(opened, "close", mock.CoroutineMock()): yield opened @@ -86,7 +86,7 @@ async def test_properties(profile: IndySdkProfile): with pytest.raises(ProfileError): await profile.remove() - with mock.patch.object(profile.opened, "close", mock.AsyncMock()): + with mock.patch.object(profile.opened, "close", mock.CoroutineMock()): await profile.remove() assert profile.opened is None diff --git a/aries_cloudagent/indy/sdk/tests/test_util.py b/aries_cloudagent/indy/sdk/tests/test_util.py index cd1a3a5349..fb587d8f40 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...util import indy_client_dir, generate_pr_nonce @@ -28,7 +28,7 @@ async def test_tails_reader(self): print("1234123412431234", file=f) with mock.patch.object( - indy.blob_storage, "open_reader", mock.AsyncMock() + indy.blob_storage, "open_reader", mock.CoroutineMock() ) as mock_blob_open_reader: result = await create_tails_reader(tails_local) assert result == mock_blob_open_reader.return_value diff --git a/aries_cloudagent/indy/sdk/tests/test_verifier.py b/aries_cloudagent/indy/sdk/tests/test_verifier.py index d5e9f37088..964514c0c9 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from indy.error import IndyError @@ -295,7 +295,7 @@ class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): self.ledger = mock.MagicMock( - get_credential_definition=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": { @@ -329,7 +329,7 @@ async def test_verify_presentation(self, mock_verify): mock_verify.return_value = "val" with mock.patch.object( - self.verifier, "pre_verify", mock.AsyncMock() + self.verifier, "pre_verify", mock.CoroutineMock() ) as mock_pre_verify, mock.patch.object( self.verifier, "non_revoc_intervals", mock.MagicMock() ) as mock_non_revox, mock.patch.object( @@ -364,7 +364,7 @@ async def test_verify_presentation_x_indy(self, mock_verify): mock_verify.side_effect = IndyError(error_code=1) with mock.patch.object( - self.verifier, "pre_verify", mock.AsyncMock() + self.verifier, "pre_verify", mock.CoroutineMock() ) as mock_pre_verify, mock.patch.object( self.verifier, "non_revoc_intervals", mock.MagicMock() ) as mock_non_revox, mock.patch.object( diff --git a/aries_cloudagent/indy/tests/test_verifier.py b/aries_cloudagent/indy/tests/test_verifier.py index 910f110c71..54c836d42a 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 +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...ledger.multiple_ledger.ledger_requests_executor import ( @@ -310,7 +310,7 @@ async def verify_presentation( class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): self.ledger = mock.MagicMock( - get_credential_definition=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": { @@ -380,7 +380,7 @@ async def test_check_timestamps(self): mock_get_ledger.return_value = ( None, mock.MagicMock( - get_credential_definition=mock.AsyncMock( + get_credential_definition=mock.CoroutineMock( return_value={ "...": "...", "value": {"no": "revocation"}, 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 58c4d475e1..7c66af6316 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 +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile @@ -32,13 +32,13 @@ async def asyncSetUp(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - extract_did_from_identifier=mock.AsyncMock( + extract_did_from_identifier=mock.CoroutineMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.CoroutineMock( return_value=("test_prod_1", self.ledger) ), - get_ledger_inst_by_id=mock.AsyncMock(return_value=self.ledger), + get_ledger_inst_by_id=mock.CoroutineMock(return_value=self.ledger), ), ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -69,10 +69,10 @@ async def test_get_ledger_for_identifier_x(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - extract_did_from_identifier=mock.AsyncMock( + extract_did_from_identifier=mock.CoroutineMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.CoroutineMock( side_effect=MultipleLedgerManagerError ), ), diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py index 14a144959e..f280c8b06c 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 +from aries_cloudagent.tests 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 = mock.AsyncMock(send=mock.AsyncMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -144,7 +144,7 @@ async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) @@ -179,7 +179,7 @@ async def test_get_ledger_by_did_self_cert_b( non_production_ledgers=self.non_production_ledger, ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) @@ -214,9 +214,9 @@ async def test_get_ledger_by_did_not_self_cert( } ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -243,7 +243,7 @@ async def test_get_ledger_by_did_state_proof_not_valid( get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -262,7 +262,7 @@ async def test_get_ledger_by_did_no_data( get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply.get("result").pop("data") with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -305,7 +305,7 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) @@ -329,9 +329,9 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -365,7 +365,7 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( non_production_ledgers=self.non_production_ledger, ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) @@ -400,9 +400,9 @@ 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 mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -425,9 +425,9 @@ async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) @@ -447,7 +447,7 @@ async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) 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 6cc0d0200b..196bd87390 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py @@ -3,7 +3,7 @@ import pytest from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests 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 = mock.AsyncMock(send=mock.AsyncMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -173,7 +173,7 @@ async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -208,7 +208,7 @@ async def test_get_ledger_by_did_self_cert_b( non_production_ledgers=self.non_production_ledger, ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -243,9 +243,9 @@ async def test_get_ledger_by_did_not_self_cert( } ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -272,7 +272,7 @@ async def test_get_ledger_by_did_state_proof_not_valid( get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -291,7 +291,7 @@ async def test_get_ledger_by_did_no_data( get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply.pop("data") with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -334,7 +334,7 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -358,9 +358,9 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -394,7 +394,7 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( non_production_ledgers=self.non_production_ledger, ) with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY @@ -429,9 +429,9 @@ 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 mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -454,9 +454,9 @@ async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( - test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() + test_module.SubTrie, "verify_spv_proof", mock.CoroutineMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY @@ -476,7 +476,7 @@ async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with mock.patch.object( - test_module.asyncio, "wait", mock.AsyncMock() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index 5bbfc05dd9..fe96748b04 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -75,7 +75,7 @@ async def asyncSetUp(self): context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) with mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile( - mock.AsyncMock(), + mock.CoroutineMock(), context, ) self.session = await self.profile.session() @@ -297,7 +297,7 @@ async def test_submit_signed( with self.assertRaises(BadLedgerRequestError): await ledger._submit("{}", True) - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -344,11 +344,11 @@ async def test_submit_signed_taa_accept( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True), self.profile ) - ledger.get_latest_txn_author_acceptance = mock.AsyncMock( + ledger.get_latest_txn_author_acceptance = mock.CoroutineMock( return_value={ "text": "sample", "version": "0.0", @@ -555,7 +555,7 @@ async def test_send_schema( r'{"op":"REPLY","result":{"txnMetadata":{"seqNo": 1}}}' ) future = asyncio.Future() - future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, mock.patch.object( @@ -570,7 +570,7 @@ async def test_send_schema( issuer, "schema_name", "schema_version", [1, 2, 3] ) - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -623,7 +623,7 @@ async def test_send_schema_already_exists( mock_create_config, mock_set_proto, ): - # mock_did = mock.AsyncMock() + # mock_did = mock.CoroutineMock() mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) @@ -631,7 +631,7 @@ async def test_send_schema_already_exists( issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - mock_add_record = mock.AsyncMock() + mock_add_record = mock.CoroutineMock() future = asyncio.Future() future.set_result( mock.MagicMock(return_value=mock.MagicMock(add_record=mock_add_record)) @@ -684,11 +684,11 @@ async def test_send_schema_ledger_transaction_error_already_exists( issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = mock.AsyncMock( + ledger._submit = mock.CoroutineMock( side_effect=LedgerTransactionError("UnauthorizedClientRequest") ) future = asyncio.Future() - future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, mock.patch.object( @@ -764,7 +764,7 @@ async def test_send_schema_issuer_error( mock_is_ledger_read_only.return_value = False issuer = mock.MagicMock(IndyIssuer) - issuer.create_schema = mock.AsyncMock( + issuer.create_schema = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -807,7 +807,7 @@ async def test_send_schema_ledger_transaction_error( issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = mock.AsyncMock( + ledger._submit = mock.CoroutineMock( side_effect=LedgerTransactionError("Some other error message") ) with mock.patch.object( @@ -859,9 +859,9 @@ async def test_send_schema_no_seq_no( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: - mock_wallet.get_public_did = mock.AsyncMock() + mock_wallet.get_public_did = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -888,7 +888,7 @@ async def test_check_existing_schema( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -931,7 +931,7 @@ async def test_get_schema( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -979,7 +979,7 @@ async def test_get_schema_not_found( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1043,7 +1043,7 @@ async def test_get_schema_by_seq_no( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1111,7 +1111,7 @@ async def test_get_schema_by_wrong_seq_no( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -1175,7 +1175,7 @@ async def test_send_credential_definition( tag = "default" ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) future = asyncio.Future() - future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, mock.patch.object( @@ -1344,7 +1344,7 @@ 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(mock.MagicMock(add_record=mock.AsyncMock())) + future.set_result(mock.MagicMock(add_record=mock.CoroutineMock())) with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, mock.patch.object( @@ -1398,7 +1398,7 @@ async def test_send_credential_definition_no_such_schema( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1442,7 +1442,7 @@ async def test_send_credential_definition_offer_exception( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1488,7 +1488,7 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1528,7 +1528,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_fetch_cred_def.return_value = {} issuer = mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = mock.AsyncMock( + issuer.credential_definition_in_wallet = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -1537,7 +1537,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1578,8 +1578,8 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_fetch_cred_def.return_value = {} issuer = mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) - issuer.create_and_store_credential_definition = mock.AsyncMock( + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) + issuer.create_and_store_credential_definition = mock.CoroutineMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -1588,7 +1588,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1629,8 +1629,8 @@ async def test_send_credential_definition_read_only( mock_fetch_cred_def.return_value = {} issuer = mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) - issuer.create_and_store_credential_definition = mock.AsyncMock( + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) + issuer.create_and_store_credential_definition = mock.CoroutineMock( return_value=("cred-def-id", "cred-def-json") ) ledger = IndySdkLedger( @@ -1641,7 +1641,7 @@ async def test_send_credential_definition_read_only( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1682,14 +1682,14 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_fetch_cred_def.return_value = cred_def issuer = mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) + issuer.credential_definition_in_wallet = mock.CoroutineMock(return_value=False) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1866,7 +1866,7 @@ async def test_get_credential_definition( with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.CoroutineMock() mock_did = mock_wallet_get_public_did.return_value ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), @@ -2337,7 +2337,7 @@ async def test_update_endpoint_for_did_calls_attr_json( ) as mock_wallet_get_public_did, mock.patch.object( ledger, "_construct_attr_json", - mock.AsyncMock( + mock.CoroutineMock( return_value=json.dumps( { "endpoint": { @@ -2352,7 +2352,7 @@ async def test_update_endpoint_for_did_calls_attr_json( ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - mock.AsyncMock(return_value={}), + mock.CoroutineMock(return_value={}), ), mock.patch.object( ledger, "did_to_nym" ): @@ -2393,7 +2393,7 @@ async def test_update_endpoint_for_did_no_prior_endpoints( mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: with mock.patch.object( - ledger, "get_all_endpoints_for_did", mock.AsyncMock() + ledger, "get_all_endpoints_for_did", mock.CoroutineMock() ) as mock_get_all: mock_get_all.return_value = None response = await ledger.update_endpoint_for_did( @@ -2450,7 +2450,7 @@ async def test_update_endpoint_of_type_profile_for_did( # ledger = mock.patch.object( # ledger, # "is_ledger_read_only", - # mock.AsyncMock(return_value=False), + # mock.CoroutineMock(return_value=False), # ) with mock.patch.object( IndySdkWallet, "get_public_did" @@ -2568,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 = mock.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.CoroutineMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2630,8 +2630,8 @@ async def test_register_nym_no_public_did( ): mock_wallet = mock.MagicMock( type="indy", - get_local_did=mock.AsyncMock(), - replace_local_did_metadata=mock.AsyncMock(), + get_local_did=mock.CoroutineMock(), + replace_local_did_metadata=mock.CoroutineMock(), ) mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) @@ -2709,7 +2709,7 @@ async def test_register_nym_steward_register_others_did( ) 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 = mock.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.CoroutineMock() async with ledger: await ledger.register_nym( self.test_did, diff --git a/aries_cloudagent/ledger/tests/test_indy_vdr.py b/aries_cloudagent/ledger/tests/test_indy_vdr.py index 4d6d31860e..6ad326c8cd 100644 --- a/aries_cloudagent/ledger/tests/test_indy_vdr.py +++ b/aries_cloudagent/ledger/tests/test_indy_vdr.py @@ -2,7 +2,7 @@ import indy_vdr import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile @@ -48,7 +48,7 @@ async def close(): with mock.patch.object(ledger.pool, "open", open), mock.patch.object( ledger.pool, "close", close ), mock.patch.object( - ledger, "is_ledger_read_only", mock.AsyncMock(return_value=False) + ledger, "is_ledger_read_only", mock.CoroutineMock(return_value=False) ): yield ledger @@ -104,7 +104,7 @@ async def test_fetch_txn_author_agreement( with mock.patch.object( ledger.pool_handle, "submit_request", - mock.AsyncMock( + mock.CoroutineMock( side_effect=[ {"data": {"aml": ".."}}, {"data": {"text": "text", "version": "1.0"}}, @@ -227,7 +227,7 @@ async def test_send_schema( with mock.patch.object( ledger, "check_existing_schema", - mock.AsyncMock(return_value=None), + mock.CoroutineMock(return_value=None), ): schema_id, schema_def = await ledger.create_and_send_schema( issuer, "schema_name", "9.1", ["a", "b"] @@ -287,7 +287,7 @@ async def test_send_schema_already_exists( with mock.patch.object( ledger, "check_existing_schema", - mock.AsyncMock( + mock.CoroutineMock( return_value=( issuer.create_schema.return_value[0], {"schema": "result"}, @@ -321,11 +321,11 @@ async def test_send_schema_ledger_read_only( with mock.patch.object( ledger, "check_existing_schema", - mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ), mock.patch.object( ledger, "is_ledger_read_only", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ): with pytest.raises(LedgerError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -354,7 +354,7 @@ async def test_send_schema_ledger_transaction_error( with mock.patch.object( ledger, "check_existing_schema", - mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ): with pytest.raises(LedgerTransactionError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -743,7 +743,7 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg with mock.patch.object( ledger, "_construct_attr_json", - mock.AsyncMock( + mock.CoroutineMock( return_value=json.dumps( { "endpoint": { @@ -758,7 +758,7 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - mock.AsyncMock(return_value={}), + mock.CoroutineMock(return_value={}), ): await ledger.update_endpoint_for_did( test_did.did, @@ -1011,7 +1011,7 @@ async def test_credential_definition_id2schema_id(self, ledger: IndyVdrLedger): with mock.patch.object( ledger, "get_schema", - mock.AsyncMock(return_value={"id": S_ID}), + mock.CoroutineMock(return_value={"id": S_ID}), ) as mock_get_schema: s_id_short = await ledger.credential_definition_id2schema_id( f"55GkHamhTU1ZbTbV2ab9DE:3:CL:{SEQ_NO}:tag" @@ -1034,7 +1034,7 @@ async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): with mock.patch.object( ledger.pool_handle, "submit_request", - mock.AsyncMock( + mock.CoroutineMock( side_effect=[ {"data": json.dumps({"seqNo": 1234})}, {"data": {"txn": {"data": {"role": "101", "alias": "Billy"}}}}, diff --git a/aries_cloudagent/ledger/tests/test_routes.py b/aries_cloudagent/ledger/tests/test_routes.py index c6ca6f2e57..4347823376 100644 --- a/aries_cloudagent/ledger/tests/test_routes.py +++ b/aries_cloudagent/ledger/tests/test_routes.py @@ -1,7 +1,7 @@ from typing import Tuple from unittest import IsolatedAsyncioTestCase -import mock +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -30,7 +30,7 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -49,7 +49,7 @@ async def test_missing_ledger(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.profile.context.injector.clear_binding(BaseLedger) @@ -82,7 +82,7 @@ async def test_get_verkey_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -102,7 +102,7 @@ async def test_get_verkey_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -130,7 +130,7 @@ async def test_get_verkey_multitenant(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: @@ -153,7 +153,7 @@ async def test_get_verkey_did_not_public(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -167,7 +167,7 @@ async def test_get_verkey_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -181,7 +181,7 @@ async def test_get_endpoint(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -206,7 +206,7 @@ async def test_get_endpoint_multitenant(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: @@ -224,7 +224,7 @@ async def test_get_endpoint_of_type_profile(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -257,7 +257,7 @@ async def test_get_endpoint_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -325,21 +325,21 @@ async def test_register_nym_create_transaction_for_endorser(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock( + create_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -369,21 +369,21 @@ async def test_register_nym_create_transaction_for_endorser_no_public_did(self): self.profile.context.settings["endorser.author"] = True with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock( + create_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -412,15 +412,15 @@ async def test_register_nym_create_transaction_for_endorser_storage_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock(side_effect=test_module.StorageError()) + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -446,7 +446,7 @@ async def test_register_nym_create_transaction_for_endorser_not_found_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -468,7 +468,7 @@ async def test_register_nym_create_transaction_for_endorser_base_model_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -492,10 +492,10 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_info_x( } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) self.ledger.register_nym.return_value: Tuple[bool, dict] = ( True, @@ -516,10 +516,10 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_did_x(se } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -537,7 +537,7 @@ async def test_get_nym_role_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -556,7 +556,7 @@ async def test_get_nym_role_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -583,7 +583,7 @@ async def test_get_nym_role_multitenant(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: @@ -603,7 +603,7 @@ async def test_get_nym_role_ledger_txn_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -619,7 +619,7 @@ async def test_get_nym_role_bad_ledger_req(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -635,7 +635,7 @@ async def test_get_nym_role_ledger_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -649,7 +649,7 @@ async def test_rotate_public_did_keypair(self): with mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = mock.AsyncMock() + self.ledger.rotate_public_did_keypair = mock.CoroutineMock() await test_module.rotate_public_did_keypair(self.request) json_response.assert_called_once_with({}) @@ -658,7 +658,7 @@ async def test_rotate_public_did_keypair_public_wallet_x(self): with mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = mock.AsyncMock( + self.ledger.rotate_public_did_keypair = mock.CoroutineMock( side_effect=test_module.WalletError("Exception") ) @@ -701,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -714,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -742,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "version": "version", "text": "text", @@ -773,7 +773,7 @@ async def test_get_write_ledger(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - get_ledger_id_by_ledger_pool_name=mock.AsyncMock( + get_ledger_id_by_ledger_pool_name=mock.CoroutineMock( return_value="test_ledger_id" ) ), @@ -805,14 +805,14 @@ async def test_get_ledger_config(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - get_prod_ledgers=mock.AsyncMock( + get_prod_ledgers=mock.CoroutineMock( return_value={ "test_1": mock.MagicMock(), "test_2": mock.MagicMock(), "test_5": mock.MagicMock(), } ), - get_nonprod_ledgers=mock.AsyncMock( + get_nonprod_ledgers=mock.CoroutineMock( return_value={ "test_3": mock.MagicMock(), "test_4": mock.MagicMock(), diff --git a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py index 08ceb622a3..4b941f3795 100644 --- a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py +++ b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -27,15 +27,15 @@ def setUp(self): self.profile_injector = self.profile.context.injector self.ledger = mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_credential_definition = mock.AsyncMock( + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.create_and_send_credential_definition = mock.CoroutineMock( return_value=( CRED_DEF_ID, {"cred": "def", "signed_txn": "..."}, True, ) ) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"cred": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) @@ -44,7 +44,7 @@ def setUp(self): self.profile_injector.bind_instance(IndyIssuer, self.issuer) self.storage = mock.create_autospec(BaseStorage) - self.storage.find_all_records = mock.AsyncMock( + self.storage.find_all_records = mock.CoroutineMock( return_value=[mock.MagicMock(value=CRED_DEF_ID)] ) self.session_inject[BaseStorage] = self.storage @@ -54,7 +54,7 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -64,7 +64,7 @@ def setUp(self): ) async def test_send_credential_definition(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -103,21 +103,21 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock( + create_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -140,7 +140,7 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): async def test_send_credential_definition_create_transaction_for_endorser_storage_x( self, ): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -154,12 +154,12 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -167,7 +167,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag ) ) mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock(side_effect=test_module.StorageError()) + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -178,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -192,7 +192,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -204,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -218,7 +218,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -230,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -244,10 +244,10 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_definitions_send_credential_definition( @@ -257,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -271,10 +271,10 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -286,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -302,7 +302,7 @@ async def test_send_credential_definition_no_ledger(self): ) async def test_send_credential_definition_ledger_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -312,7 +312,7 @@ async def test_send_credential_definition_ledger_x(self): self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.__aenter__ = mock.AsyncMock( + self.ledger.__aenter__ = mock.CoroutineMock( side_effect=test_module.LedgerError("oops") ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -334,7 +334,7 @@ async def test_get_credential_definition(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -361,7 +361,7 @@ async def test_get_credential_definition_multitenant(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request @@ -378,7 +378,7 @@ async def test_get_credential_definition_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index cfe206eec4..b36a21b162 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 +from aries_cloudagent.tests import mock from pyld import jsonld import pytest @@ -60,14 +60,14 @@ def did_doc(): @pytest.fixture def mock_resolver(did_doc): did_resolver = DIDResolver(mock.MagicMock()) - did_resolver.resolve = mock.AsyncMock(return_value=did_doc) + did_resolver.resolve = mock.CoroutineMock(return_value=did_doc) yield did_resolver @pytest.fixture def mock_sign_credential(): temp = test_module.sign_credential - sign_credential = mock.AsyncMock(return_value="fake_signage") + sign_credential = mock.CoroutineMock(return_value="fake_signage") test_module.sign_credential = sign_credential yield test_module.sign_credential test_module.sign_credential = temp @@ -76,7 +76,7 @@ def mock_sign_credential(): @pytest.fixture def mock_verify_credential(): temp = test_module.verify_credential - verify_credential = mock.AsyncMock(return_value="fake_verify") + verify_credential = mock.CoroutineMock(return_value="fake_verify") test_module.verify_credential = verify_credential yield test_module.verify_credential test_module.verify_credential = temp @@ -85,7 +85,7 @@ def mock_verify_credential(): @pytest.fixture def mock_sign_request(mock_sign_credential): context = AdminRequestContext.test_context() - outbound_message_router = mock.AsyncMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -93,7 +93,7 @@ def mock_sign_request(mock_sign_credential): request = mock.MagicMock( match_info={}, query={}, - json=mock.AsyncMock( + json=mock.CoroutineMock( return_value={ "verkey": "fake_verkey", "doc": {}, @@ -138,7 +138,7 @@ 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 = mock.AsyncMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -146,7 +146,7 @@ def _mock_verify_request(request_body=request_body): request = mock.MagicMock( match_info={}, query={}, - json=mock.AsyncMock(return_value=request_body), + json=mock.CoroutineMock(return_value=request_body), __getitem__=lambda _, k: request_dict[k], ) return request @@ -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 = mock.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.CoroutineMock(side_effect=error()) await test_module.sign(mock_sign_request) assert "error" in mock_response.call_args[0][0] @@ -183,7 +183,7 @@ async def test_sign_bad_req_error(mock_sign_request, mock_response, error): @pytest.mark.parametrize("error", [WalletError]) @pytest.mark.asyncio async def test_sign_bad_req_http_error(mock_sign_request, mock_response, error): - test_module.sign_credential = mock.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.CoroutineMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.sign(mock_sign_request) @@ -206,7 +206,7 @@ async def test_verify(mock_verify_request, mock_response): ) @pytest.mark.asyncio async def test_verify_bad_req_error(mock_verify_request, mock_response, error): - test_module.verify_credential = mock.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.CoroutineMock(side_effect=error()) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -220,7 +220,7 @@ async def test_verify_bad_req_error(mock_verify_request, mock_response, error): ) @pytest.mark.asyncio async def test_verify_bad_req_http_error(mock_verify_request, mock_response, error): - test_module.verify_credential = mock.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.CoroutineMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.verify(mock_verify_request()) @@ -229,7 +229,7 @@ async def test_verify_bad_req_http_error(mock_verify_request, mock_response, err async def test_verify_bad_ver_meth_deref_req_error( mock_resolver, mock_verify_request, mock_response ): - mock_resolver.dereference = mock.AsyncMock(side_effect=ResolverError) + mock_resolver.dereference = mock.CoroutineMock(side_effect=ResolverError) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -280,7 +280,7 @@ async def asyncSetUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -333,7 +333,7 @@ async def test_verify_credential(self): }, } - self.request.json = mock.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.CoroutineMock(return_value=POSTED_REQUEST) with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.verify(self.request) @@ -468,7 +468,7 @@ async def test_sign_credential(self): }, }, } - self.request.json = mock.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.CoroutineMock(return_value=POSTED_REQUEST) with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.sign(self.request) @@ -481,7 +481,7 @@ 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 = mock.AsyncMock(return_value=posted_request_x) + self.request.json = mock.CoroutineMock(return_value=posted_request_x) with mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: @@ -491,7 +491,7 @@ 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 = mock.AsyncMock(return_value=posted_request) + self.request.json = mock.CoroutineMock(return_value=posted_request) with mock.patch.object( jsonld, "compact", mock.MagicMock() ) as mock_compact, mock.patch.object( diff --git a/aries_cloudagent/messaging/models/tests/test_base_record.py b/aries_cloudagent/messaging/models/tests/test_base_record.py index dffee831d5..23148bf2ca 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -1,6 +1,6 @@ import json -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields @@ -86,10 +86,10 @@ def test_from_storage_values(self): async def test_post_save_new(self): session = InMemoryProfile.test_session() mock_storage = mock.MagicMock() - mock_storage.add_record = mock.AsyncMock() + mock_storage.add_record = mock.CoroutineMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() - with mock.patch.object(record, "post_save", mock.AsyncMock()) as post_save: + with mock.patch.object(record, "post_save", mock.CoroutineMock()) as post_save: await record.save(session, reason="reason", event=True) post_save.assert_called_once_with(session, True, None, True) mock_storage.add_record.assert_called_once() @@ -97,13 +97,13 @@ async def test_post_save_new(self): async def test_post_save_exist(self): session = InMemoryProfile.test_session() mock_storage = mock.MagicMock() - mock_storage.update_record = mock.AsyncMock() + mock_storage.update_record = mock.CoroutineMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() last_state = "last_state" record._last_state = last_state record._id = "id" - with mock.patch.object(record, "post_save", mock.AsyncMock()) as post_save: + with mock.patch.object(record, "post_save", mock.CoroutineMock()) as post_save: await record.save(session, reason="reason", event=False) post_save.assert_called_once_with(session, False, last_state, False) mock_storage.update_record.assert_called_once() @@ -146,7 +146,7 @@ async def test_save_x(self): rec = ARecordImpl(a="1", b="0", code="one") with mock.patch.object(session, "inject", mock.MagicMock()) as mock_inject: mock_inject.return_value = mock.MagicMock( - add_record=mock.AsyncMock(side_effect=ZeroDivisionError()) + add_record=mock.CoroutineMock(side_effect=ZeroDivisionError()) ) with self.assertRaises(ZeroDivisionError): await rec.save(session) diff --git a/aries_cloudagent/messaging/schemas/tests/test_routes.py b/aries_cloudagent/messaging/schemas/tests/test_routes.py index 0d2f4dc50c..baf6ae26e0 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -25,11 +25,11 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector self.ledger = mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_schema = mock.AsyncMock( + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.create_and_send_schema = mock.CoroutineMock( return_value=(SCHEMA_ID, {"schema": "def", "signed_txn": "..."}) ) - self.ledger.get_schema = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock( return_value={"schema": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) @@ -38,7 +38,7 @@ def setUp(self): self.profile_injector.bind_instance(IndyIssuer, self.issuer) self.storage = mock.create_autospec(BaseStorage) - self.storage.find_all_records = mock.AsyncMock( + self.storage.find_all_records = mock.CoroutineMock( return_value=[mock.MagicMock(value=SCHEMA_ID)] ) self.session_inject[BaseStorage] = self.storage @@ -47,7 +47,7 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -57,7 +57,7 @@ def setUp(self): ) async def test_send_schema(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -88,7 +88,7 @@ async def test_send_schema(self): ) async def test_send_schema_create_transaction_for_endorser(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -102,21 +102,21 @@ async def test_send_schema_create_transaction_for_endorser(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock( + create_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -139,7 +139,7 @@ async def test_send_schema_create_transaction_for_endorser(self): ) async def test_send_schema_create_transaction_for_endorser_storage_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -153,15 +153,15 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_record=mock.AsyncMock(side_effect=test_module.StorageError()) + create_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -173,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -187,7 +187,7 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -195,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -209,7 +209,7 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -217,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -231,16 +231,16 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(se } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -254,10 +254,10 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel } with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "endorser_name": ("name"), } @@ -267,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -280,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -288,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 = mock.AsyncMock( + self.ledger.create_and_send_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -307,7 +307,7 @@ async def test_get_schema(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -332,7 +332,7 @@ async def test_get_schema_multitenant(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value @@ -347,7 +347,7 @@ async def test_get_schema_on_seq_no(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -364,11 +364,11 @@ async def test_get_schema_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -380,13 +380,13 @@ async def test_get_schema_x_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) diff --git a/aries_cloudagent/multitenant/admin/tests/test_routes.py b/aries_cloudagent/multitenant/admin/tests/test_routes.py index 7a5dc7ceeb..2d24d902ee 100644 --- a/aries_cloudagent/multitenant/admin/tests/test_routes.py +++ b/aries_cloudagent/multitenant/admin/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from marshmallow.exceptions import ValidationError from ...base import BaseMultitenantManager, MultitenantManagerError @@ -14,9 +14,9 @@ class TestMultitenantRoutes(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.mock_multitenant_mgr = mock.MagicMock( - __aexit__=mock.AsyncMock(), autospec=True + __aexit__=mock.CoroutineMock(), autospec=True ) - self.mock_multitenant_mgr.__aenter__ = mock.AsyncMock( + self.mock_multitenant_mgr.__aenter__ = mock.CoroutineMock( return_value=self.mock_multitenant_mgr ) @@ -27,7 +27,7 @@ async def asyncSetUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -82,7 +82,7 @@ async def test_wallets_list(self): ) ), ] - mock_wallet_record.query = mock.AsyncMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.return_value = [wallets[2], wallets[0], wallets[1]] await test_module.wallets_list(self.request) @@ -94,7 +94,7 @@ async def test_wallets_list_x(self): with mock.patch.object( test_module, "WalletRecord", autospec=True ) as mock_wallet_record: - mock_wallet_record.query = mock.AsyncMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.side_effect = StorageError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -123,7 +123,7 @@ async def test_wallets_list_query(self): ) ), ] - mock_wallet_record.query = mock.AsyncMock() + mock_wallet_record.query = mock.CoroutineMock() mock_wallet_record.query.return_value = wallets await test_module.wallets_list(self.request) @@ -154,7 +154,7 @@ async def test_wallet_create_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: wallet_mock = mock.MagicMock( @@ -166,11 +166,11 @@ async def test_wallet_create_tenant_settings(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) print(self.request["context"]) @@ -206,7 +206,7 @@ async def test_wallet_create(self): "wallet_webhook_urls": [], "wallet_dispatch_type": "base", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: wallet_mock = mock.MagicMock( @@ -218,11 +218,11 @@ async def test_wallet_create(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) print(self.request["context"]) @@ -247,7 +247,7 @@ async def test_wallet_create(self): async def test_wallet_create_x(self): body = {} - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.mock_multitenant_mgr.create_wallet.side_effect = MultitenantManagerError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -270,13 +270,13 @@ async def test_wallet_create_optional_default_fields(self): "label": "my_test_label", "image_url": "https://image.com", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=mock.MagicMock() ) - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock() + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -299,13 +299,13 @@ async def test_wallet_create_raw_key_derivation(self): "wallet_key": "test", "wallet_key_derivation": "RAW", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.CoroutineMock( return_value=mock.MagicMock() ) - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock() + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -333,7 +333,7 @@ async def test_wallet_update_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -353,7 +353,7 @@ async def test_wallet_update_tenant_settings(self): } ) ) - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -375,7 +375,7 @@ async def test_wallet_update(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -392,7 +392,7 @@ async def test_wallet_update(self): } ) ) - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -412,7 +412,7 @@ async def test_wallet_update_no_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -427,7 +427,7 @@ async def test_wallet_update_no_wallet_webhook_urls(self): } ) ) - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -448,7 +448,7 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -465,7 +465,7 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): } ) ) - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( return_value=wallet_mock ) @@ -486,10 +486,10 @@ async def test_wallet_update_wallet_settings_x(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( side_effect=test_module.WalletSettingsError("bad settings") ) @@ -500,7 +500,7 @@ async def test_wallet_update_wallet_settings_x(self): async def test_wallet_update_no_params(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {} - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_update(self.request) @@ -508,8 +508,8 @@ async def test_wallet_update_no_params(self): async def test_wallet_update_not_found(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {"label": "test-label"} - self.request.json = mock.AsyncMock(return_value=body) - self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( + self.request.json = mock.CoroutineMock(return_value=body) + self.mock_multitenant_mgr.update_wallet = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -524,7 +524,7 @@ async def test_wallet_get(self): ) with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -539,7 +539,7 @@ async def test_wallet_get_not_found(self): self.request.match_info = {"wallet_id": "dummy"} with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.side_effect = StorageNotFoundError() @@ -554,7 +554,7 @@ async def test_wallet_get_x(self): ) with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -570,13 +570,13 @@ async def test_wallet_create_token_managed(self): ) with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) @@ -589,20 +589,20 @@ async def test_wallet_create_token_managed(self): async def test_wallet_create_token_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) mock_wallet_record = mock.MagicMock() mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.CoroutineMock( return_value="test_token" ) @@ -615,7 +615,7 @@ async def test_wallet_create_token_unmanaged(self): async def test_wallet_create_token_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) mock_wallet_record = mock.MagicMock() mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} @@ -623,7 +623,7 @@ async def test_wallet_create_token_managed_wallet_key_provided_throws(self): mock_wallet_record.requires_external_key = False with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -635,7 +635,7 @@ async def test_wallet_create_token_x(self): self.request.match_info = {"wallet_id": "dummy"} with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock.MagicMock() @@ -658,9 +658,9 @@ async def test_wallet_remove_managed(self): with mock.patch.object( test_module.web, "json_response" ) as mock_response, mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): - self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() await test_module.wallet_remove(self.request) @@ -671,14 +671,14 @@ async def test_wallet_remove_managed(self): async def test_wallet_remove_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) with mock.patch.object( test_module.web, "json_response" ) as mock_response, mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): - self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() await test_module.wallet_remove(self.request) @@ -689,13 +689,13 @@ async def test_wallet_remove_unmanaged(self): async def test_wallet_remove_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + self.request.json = mock.CoroutineMock(return_value={"wallet_key": "dummy_key"}) mock_wallet_record = mock.MagicMock() mock_wallet_record.requires_external_key = False with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -706,10 +706,10 @@ async def test_wallet_remove_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.CoroutineMock() with mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + test_module.WalletRecord, "retrieve_by_id", mock.CoroutineMock() ): with self.assertRaises(test_module.web.HTTPUnauthorized): self.mock_multitenant_mgr.remove_wallet.side_effect = ( diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index e894fefd75..2070f835ab 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -1,7 +1,7 @@ import asyncio from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests 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 = mock.AsyncMock(send=mock.AsyncMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = AskarProfileMultitenantManager(self.profile) diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index 1776457750..4d572c9a83 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -1,7 +1,7 @@ from datetime import datetime from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests 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 = mock.AsyncMock(send=mock.AsyncMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MockMultitenantManager(self.profile) @@ -209,7 +209,7 @@ 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 = mock.MagicMock() - mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.route_verkey = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -247,7 +247,7 @@ async def test_create_wallet_adds_wallet_route(self): ) mock_route_manager = mock.MagicMock() - mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.route_verkey = mock.CoroutineMock() with mock.patch.object( WalletRecord, "save" @@ -371,7 +371,7 @@ async def test_create_auth_token_managed(self): key_management_mode=WalletRecord.MODE_MANAGED, requires_external_key=False, settings={}, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -395,7 +395,7 @@ async def test_create_auth_token_unmanaged(self): key_management_mode=WalletRecord.MODE_UNMANAGED, requires_external_key=True, settings={"wallet.type": "indy"}, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -681,9 +681,9 @@ async def test_get_profile_for_key(self): with mock.patch.object( self.manager, "_get_wallet_by_key", - mock.AsyncMock(return_value=mock_wallet), + mock.CoroutineMock(return_value=mock_wallet), ), mock.patch.object( - self.manager, "get_wallet_profile", mock.AsyncMock() + self.manager, "get_wallet_profile", mock.CoroutineMock() ) as mock_get_wallet_profile: profile = await self.manager.get_profile_for_key( self.context, "test-verkey" diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index 8268a6713b..17bd7f0331 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 +from aries_cloudagent.tests 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 = mock.AsyncMock(send=mock.AsyncMock()) + self.responder = mock.CoroutineMock(send=mock.CoroutineMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MultitenantManager(self.profile) diff --git a/aries_cloudagent/multitenant/tests/test_route_manager.py b/aries_cloudagent/multitenant/tests/test_route_manager.py index b6b62e0ad2..771b4a81fd 100644 --- a/aries_cloudagent/multitenant/tests/test_route_manager.py +++ b/aries_cloudagent/multitenant/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock import pytest from ...core.in_memory import InMemoryProfile @@ -75,9 +75,9 @@ async def test_route_for_key_sub_mediator_no_base_mediator( ) with mock.patch.object( - route_manager, "get_base_wallet_mediator", mock.AsyncMock(return_value=None) + route_manager, "get_base_wallet_mediator", mock.CoroutineMock(return_value=None) ), mock.patch.object( - RoutingManager, "create_route_record", mock.AsyncMock() + RoutingManager, "create_route_record", mock.CoroutineMock() ) as mock_create_route_record: keylist_update = await route_manager._route_for_key( sub_profile, @@ -119,9 +119,9 @@ async def test_route_for_key_sub_mediator_and_base_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.AsyncMock(return_value=base_mediation_record), + mock.CoroutineMock(return_value=base_mediation_record), ), mock.patch.object( - RoutingManager, "create_route_record", mock.AsyncMock() + RoutingManager, "create_route_record", mock.CoroutineMock() ) as mock_create_route_record: keylist_update = await route_manager._route_for_key( sub_profile, @@ -160,9 +160,9 @@ async def test_route_for_key_base_mediator_no_sub_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.AsyncMock(return_value=base_mediation_record), + mock.CoroutineMock(return_value=base_mediation_record), ), mock.patch.object( - RoutingManager, "create_route_record", mock.AsyncMock() + RoutingManager, "create_route_record", mock.CoroutineMock() ) as mock_create_route_record: keylist_update = await route_manager._route_for_key( sub_profile, @@ -195,7 +195,9 @@ async def test_route_for_key_skip_if_exists_and_exists( mediation_record = MediationRecord( mediation_id="test-mediation-id", connection_id="test-mediator-conn-id" ) - with mock.patch.object(RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock()): + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() + ): keylist_update = await route_manager._route_for_key( sub_profile, TEST_VERKEY, @@ -219,7 +221,7 @@ async def test_route_for_key_skip_if_exists_and_absent( with mock.patch.object( RouteRecord, "retrieve_by_recipient_key", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ): keylist_update = await route_manager._route_for_key( sub_profile, @@ -325,7 +327,7 @@ async def test_routing_info_with_base_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.AsyncMock(return_value=base_mediation_record), + mock.CoroutineMock(return_value=base_mediation_record), ): keys, endpoint = await route_manager.routing_info(sub_profile, None) assert keys == base_mediation_record.routing_keys @@ -353,7 +355,7 @@ async def test_routing_info_with_base_mediator_and_sub_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.AsyncMock(return_value=base_mediation_record), + mock.CoroutineMock(return_value=base_mediation_record), ): keys, endpoint = await route_manager.routing_info(sub_profile, mediation_record) assert keys == [*base_mediation_record.routing_keys, *mediation_record.routing_keys] @@ -365,10 +367,10 @@ async def test_connection_from_recipient_key( sub_profile: Profile, base_route_manager: BaseWalletRouteManager ): manager = mock.MagicMock() - manager.get_profile_for_key = mock.AsyncMock(return_value=sub_profile) + manager.get_profile_for_key = mock.CoroutineMock(return_value=sub_profile) sub_profile.context.injector.bind_instance(BaseMultitenantManager, manager) with mock.patch.object( - RouteManager, "connection_from_recipient_key", mock.AsyncMock() + RouteManager, "connection_from_recipient_key", mock.CoroutineMock() ) as mock_conn_for_recip: result = await base_route_manager.connection_from_recipient_key( sub_profile, TEST_VERKEY 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 1031fffaac..4034bf5ea0 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -13,7 +13,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" - handler.save_connection_menu = mock.AsyncMock() + handler.save_connection_menu = mock.CoroutineMock() responder = MockResponder() request_context.message = handler.Menu() diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py index 0d32f3c902..30d97e65f4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -21,7 +21,7 @@ async def test_called(self): responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = mock.AsyncMock(return_value="menu") + self.menu_service.get_active_menu = mock.CoroutineMock(return_value="menu") handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) @@ -42,7 +42,7 @@ async def test_called_no_active_menu(self): responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = mock.AsyncMock(return_value=None) + self.menu_service.get_active_menu = mock.CoroutineMock(return_value=None) handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py index d0276ddd30..a8decf96ab 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -21,7 +21,9 @@ async def test_called(self): responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = mock.AsyncMock(return_value="perform") + self.menu_service.perform_menu_action = mock.CoroutineMock( + return_value="perform" + ) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) @@ -42,7 +44,7 @@ async def test_called_no_active_menu(self): responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = mock.AsyncMock(return_value=None) + self.menu_service.perform_menu_action = mock.CoroutineMock(return_value=None) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index 1407df6ead..46072e2f3e 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....core.in_memory import InMemoryProfile from .....messaging.request_context import RequestContext @@ -17,7 +17,7 @@ async def test_controller(self): self.context.injector.bind_instance( test_module.BaseMenuService, self.menu_service ) - self.context.inject = mock.AsyncMock(return_value=self.menu_service) + self.context.inject = mock.CoroutineMock(return_value=self.menu_service) controller = test_module.Controller("protocol") diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index 54f3cacd5c..0d157842e8 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,7 +13,7 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -23,22 +23,22 @@ def setUp(self): ) async def test_actionmenu_close(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = mock.AsyncMock() - test_module.save_connection_menu = mock.AsyncMock() + test_module.retrieve_connection_menu = mock.CoroutineMock() + test_module.save_connection_menu = mock.CoroutineMock() 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = mock.AsyncMock() - test_module.save_connection_menu = mock.AsyncMock( + test_module.retrieve_connection_menu = mock.CoroutineMock() + test_module.save_connection_menu = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -46,25 +46,25 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.CoroutineMock(return_value=None) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.actionmenu_close(self.request) async def test_actionmenu_fetch(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.CoroutineMock(return_value=None) 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -74,7 +74,7 @@ async def test_actionmenu_perform(self): ) as mock_perform, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.actionmenu_perform(self.request) mock_response.assert_called_once_with({}) @@ -84,7 +84,7 @@ async def test_actionmenu_perform(self): ) async def test_actionmenu_perform_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -93,7 +93,7 @@ async def test_actionmenu_perform_no_conn_record(self): test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -101,7 +101,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -110,14 +110,14 @@ async def test_actionmenu_perform_conn_not_ready(self): test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_perform(self.request) async def test_actionmenu_request(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -127,7 +127,7 @@ async def test_actionmenu_request(self): ) as menu_request, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.actionmenu_request(self.request) mock_response.assert_called_once_with({}) @@ -137,7 +137,7 @@ async def test_actionmenu_request(self): ) async def test_actionmenu_request_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -146,7 +146,7 @@ async def test_actionmenu_request_no_conn_record(self): test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -154,7 +154,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -163,14 +163,14 @@ async def test_actionmenu_request_conn_not_ready(self): test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_request(self.request) async def test_actionmenu_send(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -180,7 +180,7 @@ async def test_actionmenu_send(self): ) as mock_menu, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_menu.deserialize = mock.MagicMock() res = await test_module.actionmenu_send(self.request) @@ -191,7 +191,7 @@ async def test_actionmenu_send(self): ) async def test_actionmenu_send_deserialize_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -199,7 +199,7 @@ async def test_actionmenu_send_deserialize_x(self): ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_menu.deserialize = mock.MagicMock( side_effect=test_module.BaseModelError("cannot deserialize") ) @@ -208,7 +208,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -219,7 +219,7 @@ async def test_actionmenu_send_no_conn_record(self): mock_menu.deserialize = mock.MagicMock() # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -227,7 +227,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( @@ -238,7 +238,7 @@ async def test_actionmenu_send_conn_not_ready(self): mock_menu.deserialize = mock.MagicMock() # Emulate connection not ready - mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.CoroutineMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): 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 c676424c86..de3373f053 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,7 +13,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -24,7 +24,7 @@ async def asyncSetUp(self): self.test_conn_id = "connection-id" async def test_connections_send_message(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} with mock.patch.object( @@ -34,14 +34,14 @@ async def test_connections_send_message(self): ) as mock_basic_message, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_connection_record.retrieve_by_id = mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() res = await test_module.connections_send_message(self.request) mock_response.assert_called_once_with({}) mock_basic_message.assert_called_once() async def test_connections_send_message_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} with mock.patch.object( @@ -50,7 +50,7 @@ async def test_connections_send_message_no_conn_record(self): test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -58,7 +58,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"conn_id": self.test_conn_id} with mock.patch.object( @@ -67,7 +67,7 @@ async def test_connections_send_message_not_ready(self): test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate connection not ready - mock_connection_record.retrieve_by_id = mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False await test_module.connections_send_message(self.request) 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 19327c146d..1820a71820 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ......core.profile import ProfileSession from ......connections.models import connection_target @@ -77,7 +77,7 @@ class TestRequestHandler: @pytest.mark.asyncio @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -92,10 +92,10 @@ async def test_called(self, mock_conn_mgr, request_context): async def test_called_with_auto_response(self, mock_conn_mgr, request_context): mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = mock.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -115,15 +115,15 @@ async def test_connection_record_with_mediation_metadata_auto_response( ): mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = mock.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() request_context.message = ConnectionRequest() with mock.patch.object( connection_record, "metadata_get", - mock.AsyncMock(return_value={"id": "test-mediation-id"}), + mock.CoroutineMock(return_value={"id": "test-mediation-id"}), ): handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -139,13 +139,13 @@ async def test_connection_record_with_mediation_metadata_auto_response( async def test_connection_record_without_mediation_metadata( self, mock_conn_mgr, request_context, session, connection_record ): - mock_conn_mgr.return_value.receive_request = mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = ConnectionRequest() storage: BaseStorage = session.inject(BaseStorage) with mock.patch.object( storage, "find_record", - mock.AsyncMock(raises=StorageNotFoundError), + mock.CoroutineMock(raises=StorageNotFoundError), ) as mock_storage_find_record: handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -159,7 +159,7 @@ async def test_connection_record_without_mediation_metadata( @pytest.mark.asyncio @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) @@ -182,7 +182,7 @@ async def test_problem_report(self, mock_conn_mgr, request_context): 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 = mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) @@ -212,7 +212,7 @@ async def test_problem_report_did_doc( 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 = mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.CoroutineMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) 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 99c489f9f5..f5a08522ae 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -69,7 +69,7 @@ class TestResponseHandler: @pytest.mark.asyncio @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -83,7 +83,7 @@ async def test_called(self, mock_conn_mgr, request_context): @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 = mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -99,7 +99,7 @@ async def test_called_auto_ping(self, mock_conn_mgr, request_context): @pytest.mark.asyncio @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED ) @@ -122,7 +122,7 @@ async def test_problem_report(self, mock_conn_mgr, request_context): 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 = mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) @@ -150,7 +150,7 @@ async def test_problem_report_did_doc( 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 = mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.CoroutineMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) 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 cef9770402..fe09ae8d8f 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -59,13 +59,15 @@ async def asyncSetUp(self): self.responder = MockResponder() self.oob_mock = mock.MagicMock( - clean_finished_oob_record=mock.AsyncMock(return_value=None) + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) self.route_manager = mock.MagicMock(RouteManager) - self.route_manager.routing_info = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) + self.route_manager.mediation_record_if_id = mock.CoroutineMock( + return_value=None + ) self.resolver = DIDResolver() self.resolver.register_resolver(LegacyPeerDIDResolver()) @@ -134,7 +136,7 @@ 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 = mock.AsyncMock() + self.route_manager.route_verkey = mock.CoroutineMock() with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: @@ -264,7 +266,7 @@ async def test_create_invitation_multi_use_metadata_transfers_to_connection(self assert await new_conn_rec.metadata_get_all(session) == {"test": "value"} async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): - self.route_manager.routing_info = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -290,7 +292,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) mock_get_default_mediator.assert_not_called() async def test_create_invitation_mediation_using_default(self): - self.route_manager.routing_info = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -305,7 +307,7 @@ async def test_create_invitation_mediation_using_default(self): with mock.patch.object( self.route_manager, "mediation_record_if_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ): _, invite = await self.manager.create_invitation( routing_keys=[self.test_verkey], @@ -427,7 +429,7 @@ async def test_create_request_multitenant(self): ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - mock.AsyncMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -480,7 +482,7 @@ async def test_create_request_mediation_id(self): ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - mock.AsyncMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -531,7 +533,7 @@ async def test_create_request_default_mediator(self): ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - mock.AsyncMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -583,7 +585,7 @@ async def test_receive_request_public_did_oob_invite(self): ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -623,7 +625,7 @@ async def test_receive_request_public_did_unsolicited_fails(self): ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -647,8 +649,8 @@ async def test_receive_request_public_did_conn_invite(self): ) mock_connection_record = mock.MagicMock() - mock_connection_record.save = mock.AsyncMock() - mock_connection_record.attach_request = mock.AsyncMock() + mock_connection_record.save = mock.CoroutineMock() + mock_connection_record.attach_request = mock.CoroutineMock() self.context.update_settings({"public_invites": True}) with mock.patch.object( @@ -664,7 +666,7 @@ async def test_receive_request_public_did_conn_invite(self): ), mock.patch.object( ConnRecord, "retrieve_by_invitation_msg_id", - mock.AsyncMock(return_value=mock_connection_record), + mock.CoroutineMock(return_value=mock_connection_record), ) as mock_conn_retrieve_by_invitation_msg_id: conn_rec = await self.manager.receive_request(mock_request, receipt) assert conn_rec @@ -700,7 +702,7 @@ async def test_receive_request_public_did_unsolicited(self): ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -826,7 +828,7 @@ async def test_receive_request_public_did_no_auto_accept(self): ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() + ConnRecord, "retrieve_by_invitation_msg_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -847,7 +849,7 @@ async def test_create_response(self): ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True ) as mock_sign, mock.patch.object( - conn_rec, "metadata_get", mock.AsyncMock() + conn_rec, "metadata_get", mock.CoroutineMock() ): await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -868,7 +870,7 @@ async def test_create_response_multitenant(self): with mock.patch.object( ConnRecord, "log_state", autospec=True ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( - ConnRecord, "metadata_get", mock.AsyncMock(return_value=False) + ConnRecord, "metadata_get", mock.CoroutineMock(return_value=False) ), mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), mock.patch.object( @@ -880,7 +882,7 @@ async def test_create_response_multitenant(self): ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - mock.AsyncMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -940,7 +942,7 @@ async def test_create_response_mediation(self): with mock.patch.object( ConnRecord, "log_state", autospec=True ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( - record, "metadata_get", mock.AsyncMock(return_value=False) + record, "metadata_get", mock.CoroutineMock(return_value=False) ), mock.patch.object( ConnectionManager, "create_did_document", autospec=True ) as create_did_document, mock.patch.object( @@ -948,7 +950,7 @@ async def test_create_response_mediation(self): ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - mock.AsyncMock(return_value=[mediation_record]), + mock.CoroutineMock(return_value=[mediation_record]), ), mock.patch.object( record, "retrieve_request", autospec=True ), mock.patch.object( @@ -991,7 +993,7 @@ async def test_create_response_auto_send_mediation_request(self): ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True ) as mock_sign, mock.patch.object( - conn_rec, "metadata_get", mock.AsyncMock(return_value=True) + conn_rec, "metadata_get", mock.CoroutineMock(return_value=True) ): await self.manager.create_response(conn_rec) @@ -1007,22 +1009,24 @@ async def test_accept_response_find_by_thread_id(self): mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") + mock_response.verify_signed_field = mock.CoroutineMock( + return_value="sig_verkey" + ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock() + MediationManager, "get_default_mediator", mock.CoroutineMock() ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1037,26 +1041,28 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") + mock_response.verify_signed_field = mock.CoroutineMock( + return_value="sig_verkey" + ) receipt = MessageReceipt(sender_did=self.test_target_did) with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock() + MediationManager, "get_default_mediator", mock.CoroutineMock() ): mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=self.test_target_did, did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(return_value=False), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=False), connection_id="test-conn-id", invitation_key="test-invitation-id", ) @@ -1080,9 +1086,9 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1103,7 +1109,7 @@ async def test_accept_response_find_by_thread_id_bad_state(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 @@ -1124,7 +1130,7 @@ async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, @@ -1148,7 +1154,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, @@ -1166,22 +1172,22 @@ async def test_accept_response_verify_invitation_key_sign_failure(self): mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = mock.AsyncMock(side_effect=ValueError) + mock_response.verify_signed_field = mock.CoroutineMock(side_effect=ValueError) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock() + MediationManager, "get_default_mediator", mock.CoroutineMock() ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1195,22 +1201,24 @@ async def test_accept_response_auto_send_mediation_request(self): mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") + mock_response.verify_signed_field = mock.CoroutineMock( + return_value="sig_verkey" + ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock() + MediationManager, "get_default_mediator", mock.CoroutineMock() ): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(return_value=True), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=True), connection_id="test-conn-id", invitation_key="test-invitation-key", ) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index e092c0a52a..3328c9adbe 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 +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -19,7 +19,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -45,7 +45,7 @@ async def test_connections_list(self): with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.query = mock.AsyncMock() + mock_conn_rec.query = mock.CoroutineMock() mock_conn_rec.Role = ConnRecord.Role mock_conn_rec.State = mock.MagicMock( COMPLETED=STATE_COMPLETED, @@ -132,7 +132,9 @@ async def test_connections_list_x(self): COMPLETED=STATE_COMPLETED, get=mock.MagicMock(return_value=ConnRecord.State.COMPLETED), ) - mock_conn_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) + mock_conn_rec.query = mock.CoroutineMock( + side_effect=test_module.StorageError() + ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_list(self.request) @@ -143,7 +145,7 @@ async def test_connections_retrieve(self): mock_conn_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -162,7 +164,7 @@ async def test_connections_endpoints(self): test_module.web, "json_response" ) as mock_response: mock_conn_mgr_cls.return_value = mock.MagicMock( - get_endpoints=mock.AsyncMock( + get_endpoints=mock.CoroutineMock( return_value=("localhost:8080", "1.2.3.4:8081") ) ) @@ -184,14 +186,14 @@ async def test_connections_endpoints_x(self): test_module.web, "json_response" ) as mock_response: mock_conn_mgr_cls.return_value = mock.MagicMock( - get_endpoints=mock.AsyncMock(side_effect=StorageNotFoundError()) + get_endpoints=mock.CoroutineMock(side_effect=StorageNotFoundError()) ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_endpoints(self.request) mock_conn_mgr_cls.return_value = mock.MagicMock( - get_endpoints=mock.AsyncMock(side_effect=test_module.WalletError()) + get_endpoints=mock.CoroutineMock(side_effect=test_module.WalletError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -202,9 +204,9 @@ async def test_connections_metadata(self): mock_conn_rec = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - mock_conn_rec, "metadata_get_all", mock.AsyncMock() + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -221,11 +223,11 @@ async def test_connections_metadata_get_single(self): self.request.query = {"key": "test"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - mock_conn_rec, "metadata_get_all", mock.AsyncMock() + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() ) as mock_metadata_get_all, mock.patch.object( - mock_conn_rec, "metadata_get", mock.AsyncMock() + mock_conn_rec, "metadata_get", mock.CoroutineMock() ) as mock_metadata_get, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -241,9 +243,9 @@ async def test_connections_metadata_x(self): mock_conn_rec = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - mock_conn_rec, "metadata_get_all", mock.AsyncMock() + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -260,16 +262,16 @@ async def test_connections_metadata_x(self): async def test_connections_metadata_set(self): self.request.match_info = {"conn_id": "dummy"} mock_conn_rec = mock.MagicMock() - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"metadata": {"hello": "world"}} ) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - mock_conn_rec, "metadata_get_all", mock.AsyncMock() + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() ) as mock_metadata_get_all, mock.patch.object( - mock_conn_rec, "metadata_set", mock.AsyncMock() + mock_conn_rec, "metadata_set", mock.CoroutineMock() ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -283,16 +285,16 @@ 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 = mock.MagicMock() - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"metadata": {"hello": "world"}} ) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( - mock_conn_rec, "metadata_get_all", mock.AsyncMock() + mock_conn_rec, "metadata_get_all", mock.CoroutineMock() ) as mock_metadata_get_all, mock.patch.object( - mock_conn_rec, "metadata_set", mock.AsyncMock() + mock_conn_rec, "metadata_set", mock.CoroutineMock() ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -310,7 +312,7 @@ async def test_connections_retrieve_not_found(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -325,7 +327,7 @@ async def test_connections_retrieve_x(self): ) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -341,7 +343,7 @@ async def test_connections_create_invitation(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -354,7 +356,7 @@ async def test_connections_create_invitation(self): ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( return_value=( mock.MagicMock( # connection record connection_id="dummy", alias="conn-alias" @@ -390,7 +392,7 @@ async def test_connections_create_invitation(self): async def test_connections_create_invitation_x(self): self.context.update_settings({"public_invites": True}) - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -401,7 +403,7 @@ async def test_connections_create_invitation_x(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -417,7 +419,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -427,7 +429,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -435,7 +437,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): async def test_connections_create_invitation_public_forbidden(self): self.context.update_settings({"public_invites": False}) - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -447,7 +449,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -463,7 +465,7 @@ async def test_connections_receive_invitation(self): ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=mock_conn_rec ) @@ -471,7 +473,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -497,7 +499,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -512,7 +514,7 @@ async def test_connections_receive_invitation_x_bad_mediation_id(self): ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -530,14 +532,14 @@ async def test_connections_accept_invitation(self): mock_conn_rec.serialize = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, mock.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 = mock.AsyncMock() + mock_conn_mgr.return_value.create_request = mock.CoroutineMock() await test_module.connections_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -546,7 +548,7 @@ async def test_connections_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -557,11 +559,11 @@ async def test_connections_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = mock.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -573,11 +575,11 @@ async def test_connections_accept_invitation_x_bad_mediation_id(self): self.request.query["mediation_id"] = "some-id" with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = mock.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -594,14 +596,14 @@ async def test_connections_accept_request(self): mock_conn_rec.serialize = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, mock.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 = mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.CoroutineMock() await test_module.connections_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -610,7 +612,7 @@ async def test_connections_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -621,13 +623,13 @@ async def test_connections_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_response = mock.AsyncMock( + mock_conn_mgr.return_value.create_response = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError() ) @@ -637,10 +639,10 @@ async def test_connections_accept_request_x(self): async def test_connections_remove(self): self.request.match_info = {"conn_id": "dummy"} mock_conn_rec = mock.MagicMock() - mock_conn_rec.delete_record = mock.AsyncMock() + mock_conn_rec.delete_record = mock.CoroutineMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -656,10 +658,10 @@ async def test_connections_remove_cache_key(self): profile.context.injector.bind_instance(BaseCache, cache) self.request.match_info = {"conn_id": "dummy"} mock_conn_rec = mock.MagicMock() - mock_conn_rec.delete_record = mock.AsyncMock() + mock_conn_rec.delete_record = mock.CoroutineMock() assert (await cache.get("conn_rec_state::dummy")) == "active" with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -675,7 +677,7 @@ async def test_connections_remove_not_found(self): mock_conn_rec = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -685,11 +687,11 @@ 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 = mock.MagicMock( - delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) + delete_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -697,7 +699,7 @@ async def test_connections_remove_x(self): await test_module.connections_remove(self.request) async def test_connections_create_static(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -729,7 +731,7 @@ async def test_connections_create_static(self): ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.CoroutineMock( return_value=(mock_my_info, mock_their_info, mock_conn_rec) ) @@ -746,7 +748,7 @@ async def test_connections_create_static(self): ) async def test_connections_create_static_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -776,7 +778,7 @@ async def test_connections_create_static_x(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.CoroutineMock( side_effect=test_module.WalletError() ) 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 4a3c45a20e..5234713869 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py @@ -1,7 +1,7 @@ """Test mediate grant message handler.""" import pytest -from unittest import mock +from aries_cloudagent.tests import mock from aries_cloudagent.core.profile import ProfileSession @@ -84,7 +84,7 @@ async def test_handler_connection_has_set_to_default_meta( with mock.patch.object( context.connection_record, "metadata_get", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: @@ -96,19 +96,19 @@ 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(), mock.AsyncMock() - responder.send = mock.AsyncMock() + handler, responder = MediationGrantHandler(), mock.CoroutineMock() + responder.send = mock.CoroutineMock() profile = context.profile profile.context.update_settings( {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - multitenant_mgr = mock.AsyncMock() + multitenant_mgr = mock.CoroutineMock() profile.context.injector.bind_instance(BaseMultitenantManager, multitenant_mgr) default_base_mediator = MediationRecord(routing_keys=["key1", "key2"]) - multitenant_mgr.get_default_mediator = mock.AsyncMock() + multitenant_mgr.get_default_mediator = mock.CoroutineMock() multitenant_mgr.get_default_mediator.return_value = default_base_mediator record = MediationRecord(connection_id=TEST_CONN_ID) @@ -133,7 +133,7 @@ async def test_handler_connection_no_set_to_default( with mock.patch.object( context.connection_record, "metadata_get", - mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: 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 c56799eaf5..8f013fe177 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py @@ -2,7 +2,7 @@ import logging from typing import AsyncIterable, Iterable -from unittest import mock +from aries_cloudagent.tests import mock import pytest from .. import manager as test_module @@ -252,7 +252,7 @@ async def test_set_set_get_default_mediator_id( async def test_set_default_mediator_by_id(self, manager: MediationManager): with mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: await manager.set_default_mediator_by_id("test") @@ -405,7 +405,7 @@ async def test_store_update_results( ] with mock.patch.object( - RouteRecord, "query", mock.AsyncMock() + RouteRecord, "query", mock.CoroutineMock() ) as mock_route_rec_query, mock.patch.object( test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: @@ -415,12 +415,12 @@ async def test_store_update_results( mock_logger_error.assert_called_once() with mock.patch.object( - RouteRecord, "query", mock.AsyncMock() + RouteRecord, "query", mock.CoroutineMock() ) as mock_route_rec_query, mock.patch.object( test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.return_value = [ - mock.MagicMock(delete_record=mock.AsyncMock()) + mock.MagicMock(delete_record=mock.CoroutineMock()) ] * 2 await manager.store_update_results(TEST_CONN_ID, results) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py index 04d9f1db7f..ac23e8c4ef 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock import pytest from .....connections.models.conn_record import ConnRecord @@ -34,8 +34,8 @@ class MockRouteManager(RouteManager): """Concretion of RouteManager for testing.""" - _route_for_key = mock.AsyncMock() - routing_info = mock.AsyncMock() + _route_for_key = mock.CoroutineMock() + routing_info = mock.CoroutineMock() @pytest.fixture @@ -51,8 +51,10 @@ def profile(mock_responder: MockResponder): @pytest.fixture def route_manager(): manager = MockRouteManager() - manager._route_for_key = mock.AsyncMock(return_value=mock.MagicMock(KeylistUpdate)) - manager.routing_info = mock.AsyncMock(return_value=([], None)) + manager._route_for_key = mock.CoroutineMock( + return_value=mock.MagicMock(KeylistUpdate) + ) + manager.routing_info = mock.CoroutineMock(return_value=([], None)) yield manager @@ -64,8 +66,8 @@ def mediation_route_manager(): @pytest.fixture def conn_record(): record = ConnRecord(connection_id="12345") - record.metadata_get = mock.AsyncMock(return_value={}) - record.metadata_set = mock.AsyncMock() + record.metadata_get = mock.CoroutineMock(return_value={}) + record.metadata_set = mock.CoroutineMock() yield record @@ -78,9 +80,9 @@ async def test_get_or_create_my_did_no_did( with mock.patch.object( InMemoryWallet, "create_local_did", - mock.AsyncMock(return_value=mock_did_info), + mock.CoroutineMock(return_value=mock_did_info), ) as mock_create_local_did, mock.patch.object( - conn_record, "save", mock.AsyncMock() + conn_record, "save", mock.CoroutineMock() ) as mock_save: info = await route_manager.get_or_create_my_did(profile, conn_record) assert mock_did_info == info @@ -95,7 +97,7 @@ async def test_get_or_create_my_did_existing_did( conn_record.my_did = "test-did" mock_did_info = mock.MagicMock(DIDInfo) with mock.patch.object( - InMemoryWallet, "get_local_did", mock.AsyncMock(return_value=mock_did_info) + InMemoryWallet, "get_local_did", mock.CoroutineMock(return_value=mock_did_info) ) as mock_get_local_did: info = await route_manager.get_or_create_my_did(profile, conn_record) assert mock_did_info == info @@ -110,9 +112,9 @@ async def test_mediation_record_for_connection_mediation_id( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.AsyncMock() + route_manager, "save_mediator_for_connection", mock.CoroutineMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, mediation_record.mediation_id @@ -133,9 +135,9 @@ async def test_mediation_record_for_connection_mediation_metadata( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.AsyncMock() + route_manager, "save_mediator_for_connection", mock.CoroutineMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, "another-mediation-id" @@ -153,9 +155,9 @@ async def test_mediation_record_for_connection_default( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.AsyncMock() + route_manager, "save_mediator_for_connection", mock.CoroutineMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, None, or_default=True @@ -173,7 +175,7 @@ async def test_mediation_record_if_id_with_id( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_retrieve_by_id: actual = await route_manager.mediation_record_if_id( profile, mediation_id=mediation_record.mediation_id @@ -192,7 +194,7 @@ async def test_mediation_record_if_id_with_id_bad_state( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ): with pytest.raises(RouteManagerError): await route_manager.mediation_record_if_id( @@ -210,9 +212,9 @@ async def test_mediation_record_if_id_with_id_and_default( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_retrieve_by_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock() + MediationManager, "get_default_mediator", mock.CoroutineMock() ) as mock_get_default_mediator: actual = await route_manager.mediation_record_if_id( profile, mediation_id=mediation_record.mediation_id, or_default=True @@ -231,11 +233,11 @@ async def test_mediation_record_if_id_without_id_and_default( mediation_id="test-mediation-id", state=MediationRecord.STATE_GRANTED ) with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.AsyncMock() + MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id, mock.patch.object( MediationManager, "get_default_mediator", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_get_default_mediator: actual = await route_manager.mediation_record_if_id( profile, mediation_id=None, or_default=True @@ -251,9 +253,9 @@ async def test_mediation_record_if_id_without_id_and_no_default( route_manager: RouteManager, ): with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.AsyncMock(return_value=None) + MediationRecord, "retrieve_by_id", mock.CoroutineMock(return_value=None) ) as mock_retrieve_by_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.AsyncMock(return_value=None) + MediationManager, "get_default_mediator", mock.CoroutineMock(return_value=None) ) as mock_get_default_mediator: assert ( await route_manager.mediation_record_if_id( @@ -274,7 +276,7 @@ async def test_route_connection_as_invitee( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.AsyncMock(return_value=mock_did_info), + mock.CoroutineMock(return_value=mock_did_info), ): await route_manager.route_connection_as_invitee( profile, conn_record, [mediation_record] @@ -294,7 +296,7 @@ async def test_route_connection_as_inviter( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.AsyncMock(return_value=mock_did_info), + mock.CoroutineMock(return_value=mock_did_info), ): await route_manager.route_connection_as_inviter( profile, conn_record, [mediation_record] @@ -319,11 +321,11 @@ async def test_route_connection_state_inviter_replace_key_none( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.AsyncMock(return_value=mock_did_info), + mock.CoroutineMock(return_value=mock_did_info), ), mock.patch.object( InMemoryWallet, "get_public_did", - mock.AsyncMock( + mock.CoroutineMock( return_value=DIDInfo( TEST_RECORD_DID, TEST_RECORD_VERKEY, @@ -353,9 +355,9 @@ async def test_route_connection_state_invitee( conn_record.state = "invitation" conn_record.their_role = "responder" with mock.patch.object( - route_manager, "route_connection_as_invitee", mock.AsyncMock() + route_manager, "route_connection_as_invitee", mock.CoroutineMock() ) as mock_route_connection_as_invitee, mock.patch.object( - route_manager, "route_connection_as_inviter", mock.AsyncMock() + route_manager, "route_connection_as_inviter", mock.CoroutineMock() ) as mock_route_connection_as_inviter: await route_manager.route_connection(profile, conn_record, [mediation_record]) mock_route_connection_as_invitee.assert_called_once() @@ -370,9 +372,9 @@ async def test_route_connection_state_inviter( conn_record.state = "request" conn_record.their_role = "requester" with mock.patch.object( - route_manager, "route_connection_as_invitee", mock.AsyncMock() + route_manager, "route_connection_as_invitee", mock.CoroutineMock() ) as mock_route_connection_as_invitee, mock.patch.object( - route_manager, "route_connection_as_inviter", mock.AsyncMock() + route_manager, "route_connection_as_inviter", mock.CoroutineMock() ) as mock_route_connection_as_inviter: await route_manager.route_connection(profile, conn_record, [mediation_record]) mock_route_connection_as_inviter.assert_called_once() @@ -399,7 +401,7 @@ async def test_route_invitation_with_key( mediation_record = MediationRecord(mediation_id="test-mediation-id") conn_record.invitation_key = "test-invitation-key" with mock.patch.object( - route_manager, "save_mediator_for_connection", mock.AsyncMock() + route_manager, "save_mediator_for_connection", mock.CoroutineMock() ): await route_manager.route_invitation(profile, conn_record, mediation_record) route_manager._route_for_key.assert_called_once() @@ -411,7 +413,7 @@ async def test_route_invitation_without_key( ): mediation_record = MediationRecord(mediation_id="test-mediation-id") with mock.patch.object( - route_manager, "save_mediator_for_connection", mock.AsyncMock() + route_manager, "save_mediator_for_connection", mock.CoroutineMock() ): with pytest.raises(ValueError): await route_manager.route_invitation(profile, conn_record, mediation_record) @@ -444,7 +446,7 @@ async def test_route_static( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.AsyncMock(return_value=mock_did_info), + mock.CoroutineMock(return_value=mock_did_info), ): await route_manager.route_static(profile, conn_record, mediation_record) route_manager._route_for_key.assert_called_once_with( @@ -464,10 +466,10 @@ async def test_save_mediator_for_connection_record( mediation_record = MediationRecord(mediation_id="test-mediation-id") session = mock.MagicMock() profile.session = mock.MagicMock(return_value=session) - session.__aenter__ = mock.AsyncMock(return_value=session) - session.__aexit__ = mock.AsyncMock() + session.__aenter__ = mock.CoroutineMock(return_value=session) + session.__aexit__ = mock.CoroutineMock() with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.AsyncMock() + MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: await route_manager.save_mediator_for_connection( profile, conn_record, mediation_record @@ -489,12 +491,12 @@ async def test_save_mediator_for_connection_id( mediation_record = MediationRecord(mediation_id="test-mediation-id") session = mock.MagicMock() profile.session = mock.MagicMock(return_value=session) - session.__aenter__ = mock.AsyncMock(return_value=session) - session.__aexit__ = mock.AsyncMock() + session.__aenter__ = mock.CoroutineMock(return_value=session) + session.__aexit__ = mock.CoroutineMock() with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mediation_record), + mock.CoroutineMock(return_value=mediation_record), ) as mock_retrieve_by_id: await route_manager.save_mediator_for_connection( profile, conn_record, mediation_id=mediation_record.mediation_id @@ -514,7 +516,7 @@ async def test_save_mediator_for_connection_no_mediator( conn_record: ConnRecord, ): with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.AsyncMock() + MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: await route_manager.save_mediator_for_connection(profile, conn_record) mock_retrieve_by_id.assert_not_called() @@ -528,7 +530,7 @@ async def test_connection_from_recipient_key_invite( with mock.patch.object( ConnRecord, "retrieve_by_tag_filter", - mock.AsyncMock(return_value=conn_record), + mock.CoroutineMock(return_value=conn_record), ): result = await route_manager.connection_from_recipient_key(profile, TEST_VERKEY) assert conn_record == result @@ -540,14 +542,14 @@ async def test_connection_from_recipient_key_local_did( ): mock_provider = mock.MagicMock() mock_wallet = mock.MagicMock() - mock_wallet.get_local_did_for_verkey = mock.AsyncMock() + mock_wallet.get_local_did_for_verkey = mock.CoroutineMock() mock_provider.provide = mock.MagicMock(return_value=mock_wallet) session = await profile.session() session.context.injector.bind_provider(BaseWallet, mock_provider) with mock.patch.object( profile, "session", mock.MagicMock(return_value=session) ), mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock(return_value=conn_record) + ConnRecord, "retrieve_by_did", mock.CoroutineMock(return_value=conn_record) ): result = await route_manager.connection_from_recipient_key(profile, TEST_VERKEY) assert conn_record == result @@ -589,7 +591,9 @@ async def test_mediation_route_for_key_skip_if_exists_and_exists( mediation_record = MediationRecord( mediation_id="test-mediation-id", connection_id="test-mediator-conn-id" ) - with mock.patch.object(RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock()): + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() + ): keylist_update = await mediation_route_manager._route_for_key( profile, TEST_VERKEY, @@ -613,7 +617,7 @@ async def test_mediation_route_for_key_skip_if_exists_and_absent( with mock.patch.object( RouteRecord, "retrieve_by_recipient_key", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ): keylist_update = await mediation_route_manager._route_for_key( profile, 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 5987124d3d..bdf9911c32 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .. import routes as test_module @@ -15,7 +15,7 @@ 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 = mock.AsyncMock() + self.outbound_message_router = mock.CoroutineMock() self.request_dict = { "context": self.context, "outbound_message_router": self.outbound_message_router, @@ -26,7 +26,7 @@ def setUp(self): "conn_id": "test-conn-id", }, query={}, - json=mock.AsyncMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: self.request_dict[k], ) serialized = { @@ -41,7 +41,7 @@ def setUp(self): self.mock_record = mock.MagicMock( **serialized, serialize=mock.MagicMock(return_value=serialized), - save=mock.AsyncMock() + save=mock.CoroutineMock() ) def test_mediation_sort_key(self): @@ -69,7 +69,7 @@ async def test_list_mediation_requests(self): with mock.patch.object( test_module.MediationRecord, "query", - mock.AsyncMock(return_value=[self.mock_record]), + mock.CoroutineMock(return_value=[self.mock_record]), ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as json_response, mock.patch.object( @@ -91,7 +91,7 @@ async def test_list_mediation_requests_filters(self): with mock.patch.object( test_module.MediationRecord, "query", - mock.AsyncMock(return_value=[self.mock_record]), + mock.CoroutineMock(return_value=[self.mock_record]), ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as json_response, mock.patch.object( @@ -116,7 +116,7 @@ async def test_list_mediation_requests_x(self): test_module, "MediationRecord", mock.MagicMock( - query=mock.AsyncMock(side_effect=test_module.StorageError()) + query=mock.CoroutineMock(side_effect=test_module.StorageError()) ), ) as mock_med_rec: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -126,7 +126,7 @@ async def test_list_mediation_requests_no_records(self): with mock.patch.object( test_module, "MediationRecord", - mock.MagicMock(query=mock.AsyncMock(return_value=[])), + mock.MagicMock(query=mock.CoroutineMock(return_value=[])), ) as mock_med_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -135,7 +135,7 @@ async def test_list_mediation_requests_no_records(self): async def test_retrieve_mediation_request(self): with mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -150,7 +150,7 @@ async def test_retrieve_mediation_request_x_not_found(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -162,7 +162,7 @@ async def test_retrieve_mediation_request_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -172,9 +172,9 @@ async def test_retrieve_mediation_request_x_storage_error(self): async def test_delete_mediation_request(self): with mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_mediation_record_retrieve, mock.patch.object( - self.mock_record, "delete_record", mock.AsyncMock() + self.mock_record, "delete_record", mock.CoroutineMock() ) as mock_delete_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -190,7 +190,7 @@ async def test_delete_mediation_request_x_not_found(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -202,7 +202,7 @@ async def test_delete_mediation_request_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -220,11 +220,11 @@ async def test_request_mediation(self): ) as mock_response, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - mock.AsyncMock(return_value=False), + mock.CoroutineMock(return_value=False), ) as mock_mediation_record_exists, mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: - mock_med_mgr.return_value.prepare_request = mock.AsyncMock( + mock_med_mgr.return_value.prepare_request = mock.CoroutineMock( return_value=( self.mock_record, mock.MagicMock( # mediation request @@ -244,7 +244,7 @@ async def test_request_mediation_x_conn_not_ready(self): with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock.MagicMock(is_ready=False)), + mock.CoroutineMock(return_value=mock.MagicMock(is_ready=False)), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -255,11 +255,11 @@ async def test_request_mediation_x_already_exists(self): body = {} self.request.json.return_value = body with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ) as mock_exists_for_conn, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -272,7 +272,7 @@ async def test_request_mediation_x_conn_not_found(self): with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPNotFound ): @@ -284,7 +284,7 @@ async def test_request_mediation_x_storage_error(self): with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ): @@ -295,7 +295,7 @@ async def test_mediation_request_grant_role_server(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -310,7 +310,7 @@ async def test_mediation_request_grant_role_client_x(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) @@ -318,7 +318,7 @@ async def test_mediation_request_grant_x_rec_not_found(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_grant(self.request) @@ -326,7 +326,7 @@ async def test_mediation_request_grant_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) @@ -335,7 +335,7 @@ async def test_mediation_request_deny_role_server(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -348,7 +348,7 @@ 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 mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + test_module.MediationRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ): @@ -362,7 +362,7 @@ async def test_mediation_request_deny_x_rec_not_found(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_deny(self.request) @@ -370,7 +370,7 @@ async def test_mediation_request_deny_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) @@ -388,7 +388,7 @@ async def test_get_keylist(self): with mock.patch.object( test_module.RouteRecord, "query", - mock.AsyncMock(return_value=query_results), + mock.CoroutineMock(return_value=query_results), ) as mock_query, mock.patch.object( self.profile, "session", @@ -410,7 +410,7 @@ async def test_get_keylist_no_matching_records(self): with mock.patch.object( test_module.RouteRecord, "query", - mock.AsyncMock(return_value=[]), + mock.CoroutineMock(return_value=[]), ) as mock_query, mock.patch.object( self.profile, "session", @@ -426,7 +426,7 @@ async def test_get_keylist_storage_error(self): with mock.patch.object( test_module.RouteRecord, "query", - mock.AsyncMock(side_effect=test_module.StorageError), + mock.CoroutineMock(side_effect=test_module.StorageError), ) as mock_query, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_keylist(self.request) @@ -461,7 +461,7 @@ async def test_send_keylist_update(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock( state=MediationRecord.STATE_GRANTED, connection_id="test-conn-id" ) @@ -503,7 +503,7 @@ async def test_send_keylist_update_bad_mediation_state(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock( state=MediationRecord.STATE_DENIED, connection_id="test-conn-id" ) @@ -528,7 +528,7 @@ async def test_send_keylist_update_x_no_mediation_rec(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_update(self.request) @@ -545,7 +545,7 @@ async def test_send_keylist_update_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_update(self.request) @@ -556,11 +556,11 @@ async def test_send_keylist_query(self, mock_manager): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_retrieve_by_id, mock.patch.object( mock_manager.return_value, "prepare_keylist_query", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_prepare_keylist_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -578,7 +578,7 @@ async def test_send_keylist_query_x_no_mediation_record(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_query(self.request) @@ -586,7 +586,7 @@ async def test_send_keylist_query_x_storage_error(self): with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_query(self.request) @@ -597,7 +597,7 @@ async def test_get_default_mediator(self): ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -612,7 +612,7 @@ async def test_get_empty_default_mediator(self): ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(return_value=None), + mock.CoroutineMock(return_value=None), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -627,7 +627,7 @@ async def test_get_default_mediator_storage_error(self): ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mgr_get_default_record: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_default_mediator(self.request) @@ -640,11 +640,11 @@ async def test_set_default_mediator(self): with mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -662,11 +662,11 @@ async def test_set_default_mediator_storage_error(self): with mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -678,11 +678,11 @@ async def test_clear_default_mediator(self): with mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(return_value=self.mock_record), + mock.CoroutineMock(return_value=self.mock_record), ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -697,11 +697,11 @@ async def test_clear_default_mediator_storage_error(self): with mock.patch.object( test_module.MediationManager, "get_default_mediator", - mock.AsyncMock(side_effect=test_module.StorageError()), + mock.CoroutineMock(side_effect=test_module.StorageError()), ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -717,13 +717,13 @@ async def test_update_keylist_for_connection(self): mock_route_manager = mock.MagicMock(RouteManager) mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = mock.AsyncMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -739,15 +739,15 @@ async def test_update_keylist_for_connection_not_found(self): mock_route_manager = mock.MagicMock(RouteManager) mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = mock.AsyncMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPNotFound): await test_module.update_keylist_for_connection(self.request) @@ -761,15 +761,15 @@ async def test_update_keylist_for_connection_storage_error(self): mock_route_manager = mock.MagicMock(RouteManager) mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = mock.AsyncMock( + mock_route_manager.route_connection = mock.CoroutineMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.CoroutineMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=StorageError), + mock.CoroutineMock(side_effect=StorageError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.update_keylist_for_connection(self.request) 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 c4a44e6182..301746565e 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 +from aries_cloudagent.tests import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -27,7 +27,7 @@ class TestDIDXCompleteHandler: @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = mock.AsyncMock() + mock_conn_mgr.return_value.accept_complete = mock.CoroutineMock() request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() @@ -40,7 +40,7 @@ async def test_called(self, mock_conn_mgr, request_context): @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_x(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = mock.AsyncMock( + mock_conn_mgr.return_value.accept_complete = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value ) 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 fdccf610c7..53a61131a0 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 +from aries_cloudagent.tests import mock import pytest from .. import problem_report_handler as test_module @@ -21,7 +21,7 @@ class TestDIDXProblemReportHandler: @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_called(self, manager, request_context): - manager.return_value.receive_problem_report = mock.AsyncMock() + manager.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = DIDXProblemReport() request_context.connection_record = mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() @@ -33,7 +33,7 @@ async def test_called(self, manager, request_context): @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_called_no_conn(self, manager, request_context): - manager.return_value.receive_problem_report = mock.AsyncMock() + manager.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = DIDXProblemReport() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() @@ -45,7 +45,7 @@ async def test_called_no_conn(self, manager, request_context): async def test_called_unrecognized_report_exception( self, manager, request_context, caplog ): - manager.return_value.receive_problem_report = mock.AsyncMock( + manager.return_value.receive_problem_report = mock.CoroutineMock( side_effect=DIDXManagerError() ) request_context.message = DIDXProblemReport() 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 c97fa6ad3a..c956b5f8c8 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import conn_record, connection_target @@ -93,7 +93,7 @@ async def asyncSetUp(self): @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -110,11 +110,11 @@ async def test_called(self, mock_didx_mgr): async def test_called_with_auto_response(self, mock_didx_mgr): mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = conn_record.ConnRecord.ACCEPT_AUTO - mock_conn_rec.save = mock.AsyncMock() - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + mock_conn_rec.save = mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) - mock_didx_mgr.return_value.create_response = mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -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 = mock.AsyncMock( + test_exist_conn.metadata_get = mock.CoroutineMock( return_value={"id": "mediation-test-id"} ) test_exist_conn.accept = conn_record.ConnRecord.ACCEPT_AUTO - test_exist_conn.save = mock.AsyncMock() - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + test_exist_conn.save = mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=test_exist_conn ) - mock_didx_mgr.return_value.create_response = mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() test_ctx = RequestContext.test_context() test_ctx.message = DIDXRequest() test_ctx.message_receipt = MessageReceipt() @@ -164,7 +164,7 @@ async def test_connection_record_with_mediation_metadata_auto_response( @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) @@ -189,7 +189,7 @@ async def test_problem_report(self, mock_didx_mgr): @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 = mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) @@ -225,7 +225,7 @@ async def test_problem_report_did_doc_no_conn_target( mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) 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 a90adddff5..af9fd617ee 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import connection_target @@ -80,7 +80,7 @@ async def asyncSetUp(self): @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = mock.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -95,7 +95,7 @@ async def test_called(self, mock_didx_mgr): @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 = mock.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -112,7 +112,7 @@ async def test_called_auto_ping(self, mock_didx_mgr): @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) @@ -142,7 +142,7 @@ async def test_problem_report_did_doc( mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) @@ -178,7 +178,7 @@ async def test_problem_report_did_doc_no_conn_target( mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) 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 9e89d70392..a44e87dd27 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 +from aries_cloudagent.tests import mock from pydid import DIDDocument from .. import manager as test_module @@ -73,15 +73,17 @@ async def asyncSetUp(self): self.responder = MockResponder() self.oob_mock = mock.MagicMock( - clean_finished_oob_record=mock.AsyncMock(return_value=None) + clean_finished_oob_record=mock.CoroutineMock(return_value=None) ) self.route_manager = mock.MagicMock(RouteManager) - self.route_manager.routing_info = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) - self.route_manager.mediation_record_for_connection = mock.AsyncMock( + self.route_manager.mediation_record_if_id = mock.CoroutineMock( + return_value=None + ) + self.route_manager.mediation_record_for_connection = mock.CoroutineMock( return_value=None ) @@ -111,16 +113,16 @@ async def asyncSetUp(self): ) self.ledger = mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) - self.ledger.get_endpoint_for_did = mock.AsyncMock( + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.get_endpoint_for_did = mock.CoroutineMock( return_value=TestConfig.test_endpoint ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.resolver = mock.MagicMock() did_doc = DIDDocument.deserialize(DOC) - self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.CoroutineMock(return_value=did_doc) assert did_doc.verification_method - self.resolver.dereference_verification_method = mock.AsyncMock( + self.resolver.dereference_verification_method = mock.CoroutineMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -129,7 +131,9 @@ async def asyncSetUp(self): self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) - self.multitenant_mgr.get_default_mediator = mock.AsyncMock(return_value=None) + self.multitenant_mgr.get_default_mediator = mock.CoroutineMock( + return_value=None + ) self.manager = DIDXManager(self.profile) assert self.manager.profile @@ -185,7 +189,7 @@ async def test_receive_invitation(self): invi_msg = invi_rec.invitation mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) invitee_record = await self.manager.receive_invitation(invi_msg) @@ -214,7 +218,7 @@ async def test_receive_invitation_oob_public_did(self): invi_msg.services = [public_did_info.did] mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) invitee_record = await self.manager.receive_invitation( @@ -276,7 +280,7 @@ async def test_create_request_implicit(self): await mediation_record.save(session) with mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: @@ -353,7 +357,7 @@ async def test_create_request_implicit_x_public_already_connected(self): ED25519, ) with self.assertRaises(DIDXManagerError) as context, mock.patch.object( - test_module.ConnRecord, "retrieve_by_did", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve_by_did: await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -373,16 +377,16 @@ async def test_create_request(self): their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=mock.AsyncMock( + retrieve_invitation=mock.CoroutineMock( return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) with mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={}) @@ -399,7 +403,7 @@ async def test_create_request_multitenant(self): with mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: @@ -414,7 +418,9 @@ async def test_create_request_multitenant(self): key_type=ED25519, ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) await self.manager.create_request( @@ -424,12 +430,12 @@ async def test_create_request_multitenant(self): their_role=ConnRecord.Role.RESPONDER.rfc160, alias="Bob", my_did=None, - retrieve_invitation=mock.AsyncMock( + retrieve_invitation=mock.CoroutineMock( return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) ) @@ -466,7 +472,7 @@ async def test_create_request_mediation_id(self): await record.attach_invitation(session, invi) with mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={}) @@ -491,16 +497,16 @@ async def test_create_request_my_endpoint(self): invitation_key=TestConfig.test_verkey, state=ConnRecord.State.REQUEST.rfc23, alias="Bob", - retrieve_invitation=mock.AsyncMock( + retrieve_invitation=mock.CoroutineMock( return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) with mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={}) @@ -519,12 +525,12 @@ async def test_create_request_public_did(self): their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=mock.AsyncMock( + retrieve_invitation=mock.CoroutineMock( return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) request = await self.manager.create_request(mock_conn_rec, use_public_did=True) @@ -576,9 +582,9 @@ async def test_receive_request_explicit_public_did(self): ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ), mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: @@ -594,20 +600,20 @@ async def test_receive_request_explicit_public_did(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - 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(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST mock_conn_rec_cls.State.get = 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 = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -621,7 +627,7 @@ async def test_receive_request_explicit_public_did(self): ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) mock_response.return_value = mock.MagicMock( @@ -660,7 +666,7 @@ async def test_receive_request_invi_not_found(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError) as context: @@ -714,11 +720,11 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ), mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( - self.manager, "record_did", mock.AsyncMock() + self.manager, "record_did", mock.CoroutineMock() ), mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: @@ -734,20 +740,20 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - 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(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST mock_conn_rec_cls.State.get = 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 = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -761,7 +767,7 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) mock_response.return_value = mock.MagicMock( @@ -809,20 +815,20 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - 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(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST mock_conn_rec_cls.State.get = 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 = mock.CoroutineMock( + return_value=mock.MagicMock(save=mock.CoroutineMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -848,7 +854,7 @@ async def test_receive_request_public_did_x_not_public(self): did=TestConfig.test_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value="dummy-did-doc") ), @@ -917,19 +923,19 @@ async def test_receive_request_public_did_x_wrong_did(self): ) as mock_did_doc_from_json, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + mock.CoroutineMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), ): mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=mock.AsyncMock(), - retrieve_request=mock.AsyncMock(), - metadata_get_all=mock.AsyncMock(return_value={}), - save=mock.AsyncMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) mock_did_doc_from_json.return_value = mock.MagicMock(did="wrong-did") @@ -980,19 +986,19 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(side_effect=DIDXManagerError), + mock.CoroutineMock(side_effect=DIDXManagerError), ): mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=mock.AsyncMock(), - retrieve_request=mock.AsyncMock(), - metadata_get_all=mock.AsyncMock(return_value={}), - save=mock.AsyncMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) @@ -1016,7 +1022,7 @@ async def test_receive_request_public_did_no_public_invites(self): did=TestConfig.test_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value="dummy-did-doc") ), @@ -1040,7 +1046,7 @@ async def test_receive_request_public_did_no_public_invites(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( test_module.DIDDoc, "from_json", mock.MagicMock() ) as mock_did_doc_from_json: @@ -1094,23 +1100,23 @@ async def test_receive_request_public_did_no_auto_accept(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=mock.AsyncMock(), - retrieve_request=mock.AsyncMock(), - metadata_get_all=mock.AsyncMock(return_value={}), - save=mock.AsyncMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=mock_conn_record ) @@ -1140,7 +1146,7 @@ async def test_receive_request_implicit_public_did_not_enabled(self): did=TestConfig.test_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value="dummy-did-doc") ), @@ -1175,15 +1181,15 @@ async def test_receive_request_implicit_public_did_not_enabled(self): ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=None ) @@ -1203,7 +1209,7 @@ async def test_receive_request_implicit_public_did(self): did=TestConfig.test_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value="dummy-did-doc") ), @@ -1241,15 +1247,15 @@ async def test_receive_request_implicit_public_did(self): ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.CoroutineMock( return_value=None ) @@ -1257,11 +1263,11 @@ async def test_receive_request_implicit_public_did(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - 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(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + metadata_get_all=mock.CoroutineMock(return_value={}), + metadata_get=mock.CoroutineMock(return_value=True), + save=mock.CoroutineMock(), ) mock_conn_rec_cls.return_value = mock_conn_record @@ -1301,10 +1307,10 @@ async def test_receive_request_peer_did(self): is_multiuse_invitation=True, state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.REQUESTER.rfc23, - save=mock.AsyncMock(), - attach_request=mock.AsyncMock(), + save=mock.CoroutineMock(), + attach_request=mock.CoroutineMock(), accept=ConnRecord.ACCEPT_MANUAL, - metadata_get_all=mock.AsyncMock(return_value={"test": "value"}), + metadata_get_all=mock.CoroutineMock(return_value={"test": "value"}), ) mock_conn_rec_state_request = ConnRecord.State.REQUEST @@ -1327,26 +1333,26 @@ async def test_receive_request_peer_did(self): ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( return_value=mock_conn ) mock_conn_rec_cls.return_value = mock.MagicMock( accept=ConnRecord.ACCEPT_AUTO, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=mock.AsyncMock(), - retrieve_request=mock.AsyncMock(), - save=mock.AsyncMock(), - metadata_set=mock.AsyncMock(), + attach_request=mock.CoroutineMock(), + retrieve_request=mock.CoroutineMock(), + save=mock.CoroutineMock(), + metadata_set=mock.CoroutineMock(), ) mock_did_doc.from_json = mock.MagicMock( return_value=mock.MagicMock(did=TestConfig.test_did) ) mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) mock_response.return_value = mock.MagicMock( @@ -1373,7 +1379,7 @@ async def test_receive_request_peer_did_not_found_x(self): did=TestConfig.test_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value="dummy-did-doc") ), @@ -1392,7 +1398,7 @@ async def test_receive_request_peer_did_not_found_x(self): with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.CoroutineMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError): @@ -1411,9 +1417,9 @@ async def test_create_response(self): ) with mock.patch.object( - test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() ) as mock_retrieve_req, mock.patch.object( - conn_rec, "save", mock.AsyncMock() + conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, mock.patch.object( @@ -1421,13 +1427,15 @@ async def test_create_response(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock() ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1470,13 +1478,13 @@ async def test_create_response_mediation_id(self): ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_save, mock.patch.object( - record, "metadata_get", mock.AsyncMock(return_value=False) + record, "metadata_get", mock.CoroutineMock(return_value=False) ), mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: mock_attach_deco.data_base64 = mock.MagicMock( return_value=mock.MagicMock( - data=mock.MagicMock(sign=mock.AsyncMock()) + data=mock.MagicMock(sign=mock.CoroutineMock()) ) ) await self.manager.create_response( @@ -1522,7 +1530,7 @@ async def test_create_response_mediation_id_invalid_conn_state(self): ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_save, mock.patch.object( - record, "metadata_get", mock.AsyncMock(return_value=False) + record, "metadata_get", mock.CoroutineMock(return_value=False) ): with self.assertRaises(DIDXManagerError) as context: await self.manager.create_response( @@ -1544,10 +1552,10 @@ async def test_create_response_multitenant(self): with mock.patch.object( test_module.ConnRecord, "retrieve_request" - ), mock.patch.object(conn_rec, "save", mock.AsyncMock()), mock.patch.object( + ), mock.patch.object(conn_rec, "save", mock.CoroutineMock()), mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: @@ -1562,7 +1570,9 @@ async def test_create_response_multitenant(self): serialize=mock.MagicMock() ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) await self.manager.create_response(conn_rec) @@ -1576,9 +1586,9 @@ async def test_create_response_conn_rec_my_did(self): ) with mock.patch.object( - test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() ) as mock_retrieve_req, mock.patch.object( - conn_rec, "save", mock.AsyncMock() + conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, mock.patch.object( @@ -1586,16 +1596,18 @@ async def test_create_response_conn_rec_my_did(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc, mock.patch.object( - InMemoryWallet, "get_local_did", mock.AsyncMock() + InMemoryWallet, "get_local_did", mock.CoroutineMock() ) as mock_get_loc_did: mock_get_loc_did.return_value = self.did_info mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock() ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1624,9 +1636,9 @@ async def test_create_response_use_public_did(self): ) with mock.patch.object( - test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() ) as mock_retrieve_req, mock.patch.object( - conn_rec, "save", mock.AsyncMock() + conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, mock.patch.object( @@ -1634,13 +1646,15 @@ async def test_create_response_use_public_did(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock() ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) await self.manager.create_response( @@ -1653,9 +1667,9 @@ async def test_create_response_use_public_did_x_no_public_did(self): ) with mock.patch.object( - test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + test_module.ConnRecord, "retrieve_request", mock.CoroutineMock() ) as mock_retrieve_req, mock.patch.object( - conn_rec, "save", mock.AsyncMock() + conn_rec, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, mock.patch.object( @@ -1663,13 +1677,15 @@ async def test_create_response_use_public_did_x_no_public_did(self): ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, mock.patch.object( - self.manager, "create_did_document", mock.AsyncMock() + self.manager, "create_did_document", mock.CoroutineMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = mock.MagicMock( serialize=mock.MagicMock() ) mock_attach_deco.data_base64 = mock.MagicMock( - return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.CoroutineMock()) + ) ) with self.assertRaises(DIDXManagerError) as context: @@ -1684,7 +1700,7 @@ async def test_accept_response_find_by_thread_id(self): mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1699,9 +1715,9 @@ async def test_accept_response_find_by_thread_id(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: @@ -1712,7 +1728,7 @@ async def test_accept_response_find_by_thread_id(self): did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1721,13 +1737,13 @@ async def test_accept_response_find_by_thread_id(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1740,7 +1756,7 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1756,13 +1772,13 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser, mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did @@ -1771,7 +1787,7 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1780,13 +1796,13 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1800,7 +1816,7 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1812,9 +1828,9 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: @@ -1826,7 +1842,7 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1835,8 +1851,8 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel ) ), state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(return_value=False), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(return_value=False), connection_id="test-conn-id", ) @@ -1850,7 +1866,7 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1862,9 +1878,9 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1878,7 +1894,7 @@ async def test_accept_response_find_by_thread_id_bad_state(self): mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1890,7 +1906,7 @@ async def test_accept_response_find_by_thread_id_bad_state(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 @@ -1913,13 +1929,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser, mock.patch.object( - self.manager, "record_did", mock.AsyncMock() + self.manager, "record_did", mock.CoroutineMock() ): mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did @@ -1927,13 +1943,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1954,13 +1970,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser, mock.patch.object( - self.manager, "record_did", mock.AsyncMock() + self.manager, "record_did", mock.CoroutineMock() ): mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did @@ -1968,13 +1984,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), - metadata_get=mock.AsyncMock(), + save=mock.CoroutineMock(), + metadata_get=mock.CoroutineMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) with self.assertRaises(DIDXManagerError) as context: @@ -1987,7 +2003,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), @@ -1999,9 +2015,9 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): with mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id, mock.patch.object( DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: @@ -2010,7 +2026,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): did=TestConfig.test_target_did, did_doc_attach=mock.MagicMock( data=mock.MagicMock( - verify=mock.AsyncMock(return_value=True), + verify=mock.CoroutineMock(return_value=True), signed=mock.MagicMock( decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -2019,11 +2035,11 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) with self.assertRaises(DIDXManagerError): @@ -2034,9 +2050,9 @@ async def test_accept_complete(self): receipt = MessageReceipt(sender_did=TestConfig.test_target_did) with mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.CoroutineMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED @@ -2045,11 +2061,11 @@ async def test_accept_complete_with_disclose(self): receipt = MessageReceipt(sender_did=TestConfig.test_target_did) self.context.update_settings({"auto_disclose_features": True}) with mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id, mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() + V20DiscoveryMgr, "proactive_disclose_features", mock.CoroutineMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.CoroutineMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED mock_proactive_disclose_features.assert_called_once() @@ -2059,7 +2075,7 @@ async def test_accept_complete_x_not_found(self): receipt = MessageReceipt(sender_did=TestConfig.test_target_did) with mock.patch.object( - ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ConnRecord, "retrieve_by_request_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() with self.assertRaises(DIDXManagerError): @@ -2073,7 +2089,7 @@ async def test_reject_invited(self): state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() reason = "He doesn't like you!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2086,7 +2102,7 @@ async def test_reject_requested(self): state=ConnRecord.State.REQUEST.rfc23, their_role=ConnRecord.Role.REQUESTER, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() reason = "I don't like you either! You just watch yourself!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2098,7 +2114,7 @@ async def test_reject_invalid(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() reason = "I'll be careful." with self.assertRaises(DIDXManagerError) as context: await self.manager.reject(mock_conn, reason=reason) @@ -2111,7 +2127,7 @@ async def test_receive_problem_report(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport( description={ "code": ProblemReportReason.REQUEST_NOT_ACCEPTED.value, @@ -2128,7 +2144,7 @@ async def test_receive_problem_report_x_missing_description(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport() with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2141,7 +2157,7 @@ async def test_receive_problem_report_x_unrecognized_code(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = mock.AsyncMock() + mock_conn.abandon = mock.CoroutineMock() report = DIDXProblemReport(description={"code": "something random"}) with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2219,7 +2235,7 @@ async def test_resolve_did_document_error(self): with mock.patch.object( self.resolver, "resolve", - mock.AsyncMock(side_effect=ResolverError()), + mock.CoroutineMock(side_effect=ResolverError()), ): with self.assertRaises(DIDXManagerError) as ctx: await self.manager.get_resolved_did_document(public_did_info.did) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py index aa0d6ad657..6a3926b5b3 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -14,7 +14,7 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -31,7 +31,7 @@ async def test_didx_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = mock.MagicMock(save=mock.AsyncMock()) + mock_conn_rec = mock.MagicMock(save=mock.CoroutineMock()) mock_conn_rec.serialize = mock.MagicMock() with mock.patch.object( @@ -42,7 +42,7 @@ async def test_didx_accept_invitation(self): 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 = mock.AsyncMock() + mock_didx_mgr.return_value.create_request = mock.CoroutineMock() await test_module.didx_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -51,7 +51,7 @@ async def test_didx_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -62,11 +62,11 @@ async def test_didx_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr: - mock_didx_mgr.return_value.create_request = mock.AsyncMock( + mock_didx_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) @@ -86,7 +86,7 @@ async def test_didx_create_request_implicit(self): ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value="mock serialization") ) @@ -108,7 +108,7 @@ async def test_didx_create_request_implicit_not_found_x(self): ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( side_effect=StorageNotFoundError("not found") ) @@ -128,7 +128,7 @@ async def test_didx_create_request_implicit_wallet_x(self): ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.CoroutineMock( side_effect=test_module.WalletError("wallet error") ) @@ -142,7 +142,7 @@ async def test_didx_receive_request_implicit(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() mock_conn_rec = mock.MagicMock() mock_conn_rec.serialize = mock.MagicMock() @@ -154,7 +154,7 @@ async def test_didx_receive_request_implicit(self): ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_conn_rec ) @@ -167,7 +167,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module.DIDXRequest, "deserialize", mock.MagicMock() @@ -176,7 +176,7 @@ async def test_didx_receive_request_implicit_not_found_x(self): ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=StorageNotFoundError("tricorder must be broken") ) @@ -190,7 +190,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module.DIDXRequest, "deserialize", mock.MagicMock() @@ -214,14 +214,14 @@ async def test_didx_accept_request(self): mock_conn_rec.serialize = mock.MagicMock() with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, mock.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 = mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.CoroutineMock() await test_module.didx_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -230,7 +230,7 @@ async def test_didx_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -241,13 +241,13 @@ async def test_didx_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_response = mock.AsyncMock( + mock_didx_mgr.return_value.create_response = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) @@ -256,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 = mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = mock.AsyncMock() + mock_didx_mgr.return_value.reject = mock.CoroutineMock() await test_module.didx_reject(self.request) async def test_didx_reject_x_not_found(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -283,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 = mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.CoroutineMock(return_value={"reason": "asdf"}) with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = mock.AsyncMock( + mock_didx_mgr.return_value.reject = mock.CoroutineMock( side_effect=test_module.DIDXManagerError() ) 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 48067632e0..10cc70d019 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.base_handler import HandlerException @@ -56,7 +56,7 @@ async def test_disclose(self, request_context): with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py index 238c2908fe..3e1ec32d1f 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 +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.request_context import RequestContext @@ -68,9 +68,9 @@ async def test_receive_query_process_disclosed(self, request_context): handler = QueryHandler() responder = MockResponder() with mock.patch.object( - ProtocolRegistry, "protocols_matching_query", mock.AsyncMock() + ProtocolRegistry, "protocols_matching_query", mock.CoroutineMock() ) as mock_query_match, mock.patch.object( - ProtocolRegistry, "prepare_disclosed", mock.AsyncMock() + ProtocolRegistry, "prepare_disclosed", mock.CoroutineMock() ) as mock_prepare_disclosed: mock_prepare_disclosed.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py index d543b82865..6580b2b1e9 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -93,7 +93,7 @@ async def test_exists_for_connection_id_not_found(self): with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( @@ -106,7 +106,7 @@ async def test_exists_for_connection_id_duplicate(self): with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py index 5a73fceb2c..f11d271356 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py @@ -2,7 +2,7 @@ import logging import pytest -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -54,7 +54,7 @@ async def test_receive_disclosure(self): with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True ) as save_ex, mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -75,13 +75,13 @@ async def test_receive_disclosure_retreive_by_conn(self): ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_connection_id, mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = True @@ -104,9 +104,9 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -127,9 +127,9 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -146,7 +146,7 @@ async def test_check_if_disclosure_received(self): with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V10DiscoveryExchangeRecord(), @@ -159,19 +159,19 @@ async def test_create_and_send_query_with_connection(self): with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - mock.AsyncMock(), + mock.CoroutineMock(), ) as save_ex, mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + V10DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received, mock.patch.object( - self.responder, "send", mock.AsyncMock() + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V10DiscoveryExchangeRecord() @@ -187,13 +187,13 @@ async def test_create_and_send_query_with_connection_no_responder(self): with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - mock.AsyncMock(), + mock.CoroutineMock(), ) as save_ex, mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + V10DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -208,7 +208,7 @@ async def test_create_and_send_query_with_no_connection(self): with mock.patch.object( V10DiscoveryMgr, "receive_query", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclose() received_ex_rec = await self.manager.create_and_send_query(query="*") diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py index bc5043e1ec..ce4a4a34e6 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext @@ -18,7 +18,7 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query": "*"} @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query": "*", "connection_id": "test", "comment": "test"} @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -84,7 +84,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() test_recs = [ V10DiscoveryExchangeRecord( @@ -123,7 +123,7 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module.web, "json_response" 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 58a166b711..6e190148b8 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from aries_cloudagent.storage.error import StorageNotFoundError @@ -64,7 +64,7 @@ async def test_disclosures(self, request_context): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -104,11 +104,11 @@ async def test_disclosures_connection_id_no_thid(self, request_context): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(return_value=discovery_record), + mock.CoroutineMock(return_value=discovery_record), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -142,11 +142,11 @@ async def test_disclosures_no_conn_id_no_thid(self, request_context): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py index a814506686..1998a973e0 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ......core.protocol_registry import ProtocolRegistry from ......core.goal_code_registry import GoalCodeRegistry @@ -132,9 +132,9 @@ async def test_receive_query_process_disclosed(self, request_context): handler = QueriesHandler() responder = MockResponder() with mock.patch.object( - V20DiscoveryMgr, "execute_protocol_query", mock.AsyncMock() + V20DiscoveryMgr, "execute_protocol_query", mock.CoroutineMock() ) as mock_exec_protocol_query, mock.patch.object( - V20DiscoveryMgr, "execute_goal_code_query", mock.AsyncMock() + V20DiscoveryMgr, "execute_goal_code_query", mock.CoroutineMock() ) as mock_goal_code_protocol_query: mock_exec_protocol_query.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py index 882897d57d..64e0e82689 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -150,7 +150,7 @@ async def test_exists_for_connection_id_not_found(self): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( @@ -163,7 +163,7 @@ async def test_exists_for_connection_id_duplicate(self): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py index 4e374940d0..badaa637b4 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py @@ -2,7 +2,7 @@ import logging import pytest -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -60,7 +60,7 @@ async def test_receive_disclosure(self): with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True ) as save_ex, mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -81,11 +81,11 @@ async def test_receive_disclosure_retreive_by_conn(self): ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: @@ -110,7 +110,7 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: @@ -133,9 +133,9 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -152,9 +152,9 @@ async def test_proactive_disclosure(self): with mock.patch.object( V20DiscoveryMgr, "receive_query", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_receive_query, mock.patch.object( - self.responder, "send", mock.AsyncMock() + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_receive_query.return_value = Disclosures() await self.manager.proactive_disclose_features("test123") @@ -165,9 +165,9 @@ async def test_proactive_disclosure_no_responder(self): with mock.patch.object( V20DiscoveryMgr, "receive_query", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_receive_query, mock.patch.object( - self.responder, "send", mock.AsyncMock() + self.responder, "send", mock.CoroutineMock() ) as mock_send: self._caplog.set_level(logging.WARNING) mock_receive_query.return_value = Disclosures() @@ -180,7 +180,7 @@ async def test_check_if_disclosure_received(self): with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V20DiscoveryExchangeRecord(), @@ -205,19 +205,19 @@ async def test_create_and_send_query_with_connection(self): with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - mock.AsyncMock(), + mock.CoroutineMock(), ) as save_ex, mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + V20DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received, mock.patch.object( - self.responder, "send", mock.AsyncMock() + self.responder, "send", mock.CoroutineMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V20DiscoveryExchangeRecord() @@ -233,13 +233,13 @@ async def test_create_and_send_query_with_connection_no_responder(self): with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - mock.AsyncMock(), + mock.CoroutineMock(), ) as save_ex, mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + V20DiscoveryMgr, "check_if_disclosure_received", mock.CoroutineMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -265,7 +265,7 @@ async def test_create_and_send_query_with_no_connection(self): with mock.patch.object( V20DiscoveryMgr, "receive_query", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclosures() received_ex_rec = await self.manager.create_and_send_query( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py index a994cfafa5..d6c5ecd2f6 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext @@ -18,7 +18,7 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"query_protocol": "*"} @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = { "query_protocol": "*", @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -104,7 +104,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.query = {"connection_id": "test"} @@ -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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() test_recs = [ V20DiscoveryExchangeRecord( @@ -153,7 +153,7 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module.web, "json_response" 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 5c08c853c8..5a33ffdb02 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() @@ -38,7 +38,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = False handler = test_module.EndorsedTransactionResponseHandler() @@ -56,7 +56,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock( + mock_tran_mgr.return_value.receive_endorse_response = mock.CoroutineMock( 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 401a251f75..b2d8558cac 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = True handler = test_module.RefusedTransactionResponseHandler() @@ -38,7 +38,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = False handler = test_module.RefusedTransactionResponseHandler() @@ -56,7 +56,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock( + mock_tran_mgr.return_value.receive_refuse_response = mock.CoroutineMock( 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 e934131a67..dc92327ef9 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord @@ -19,7 +19,7 @@ async def test_called(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - mock.AsyncMock() + mock.CoroutineMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( @@ -44,7 +44,7 @@ async def test_called_not_ready(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - mock.AsyncMock() + mock.CoroutineMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_ready = False @@ -63,7 +63,7 @@ async def test_called_x(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - mock.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock.CoroutineMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py index 12423880e7..1fd36bed57 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock() request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -41,7 +41,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock() request_context.message = CancelTransaction() request_context.connection_ready = False handler = test_module.TransactionCancelHandler() @@ -58,7 +58,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock( + mock_tran_mgr.return_value.receive_cancel_transaction = mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) request_context.message = CancelTransaction() 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 b488aaaca3..8bb0867548 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock() + mock_tran_mgr.return_value.set_transaction_their_job = mock.CoroutineMock() request_context.message = TransactionJobToSend() request_context.connection_ready = True handler = test_module.TransactionJobToSendHandler() @@ -38,7 +38,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock( + mock_tran_mgr.return_value.set_transaction_their_job = mock.CoroutineMock( 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 33fb0e11c9..10d5c7975e 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = mock.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = TransactionRequest() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -41,7 +41,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = mock.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = TransactionRequest() request_context.connection_ready = False handler = test_module.TransactionRequestHandler() @@ -58,7 +58,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = mock.AsyncMock( + mock_tran_mgr.return_value.receive_request = mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionRequest() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py index bc17c2a418..1cb00b198b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -18,7 +18,7 @@ async def test_called(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock() request_context.message = TransactionResend() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -41,7 +41,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock() request_context.message = TransactionResend() request_context.connection_ready = False handler = test_module.TransactionResendHandler() @@ -58,7 +58,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock( + mock_tran_mgr.return_value.receive_transaction_resend = mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionResend() 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 a158437844..82902dfe93 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -3,7 +3,7 @@ import uuid from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -103,10 +103,10 @@ async def asyncSetUp(self): self.test_refuser_did = "AGDEjaMunDtFtBVrn1qPKQ" self.ledger = mock.create_autospec(BaseLedger) - self.ledger.txn_endorse = mock.AsyncMock( + self.ledger.txn_endorse = mock.CoroutineMock( return_value=self.test_endorsed_message ) - self.ledger.register_nym = mock.AsyncMock(return_value=(True, {})) + self.ledger.register_nym = mock.CoroutineMock(return_value=(True, {})) self.context = AdminRequestContext.test_context() self.profile = self.context.profile @@ -459,10 +459,10 @@ async def test_complete_transaction(self): ) future = asyncio.Future() future.set_result( - mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.CoroutineMock())) ) self.ledger.get_indy_storage = future - self.ledger.txn_submit = mock.AsyncMock( + self.ledger.txn_submit = mock.CoroutineMock( return_value=json.dumps( { "result": { @@ -479,7 +479,7 @@ async def test_complete_transaction(self): ConnRecord, "retrieve_by_id" ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( TransactionJob.TRANSACTION_ENDORSER.name @@ -732,13 +732,13 @@ async def test_receive_transaction_resend(self): async def test_set_transaction_my_job(self): conn_record = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=mock.AsyncMock(), + metadata_set=mock.CoroutineMock(), ) for i in range(2): @@ -749,16 +749,16 @@ async def test_set_transaction_their_job(self): mock_receipt = mock.MagicMock() with mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=mock.AsyncMock(), + metadata_set=mock.CoroutineMock(), ) for i in range(2): @@ -769,7 +769,7 @@ async def test_set_transaction_their_job_conn_not_found(self): mock_receipt = mock.MagicMock() with mock.patch.object( - ConnRecord, "retrieve_by_did", mock.AsyncMock() + ConnRecord, "retrieve_by_did", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index 0aee212ad4..ad79131aa4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -2,7 +2,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -36,9 +36,9 @@ async def asyncSetUp(self): ) 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( + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.txn_endorse = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.txn_submit = mock.CoroutineMock( return_value=json.dumps( { "result": { @@ -50,17 +50,17 @@ async def asyncSetUp(self): ) future = asyncio.Future() future.set_result( - mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.CoroutineMock())) ) self.ledger.get_indy_storage = future - self.ledger.get_schema = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock( return_value={"id": SCHEMA_ID, "...": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -73,7 +73,7 @@ async def asyncSetUp(self): async def test_transactions_list(self): with mock.patch.object( - TransactionRecord, "query", mock.AsyncMock() + TransactionRecord, "query", mock.CoroutineMock() ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -86,7 +86,7 @@ async def test_transactions_list(self): async def test_transactions_list_x(self): with mock.patch.object( - TransactionRecord, "query", mock.AsyncMock() + TransactionRecord, "query", mock.CoroutineMock() ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -99,7 +99,7 @@ async def test_transactions_retrieve(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -114,7 +114,7 @@ async def test_transactions_retrieve_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError() @@ -125,7 +125,7 @@ async def test_transactions_retrieve_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.BaseModelError() @@ -136,22 +136,22 @@ async def test_transaction_create_request(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - create_request=mock.AsyncMock( + create_request=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -161,7 +161,7 @@ async def test_transaction_create_request(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -183,13 +183,13 @@ async def test_transaction_create_request_not_found_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -200,18 +200,18 @@ async def test_transaction_create_request_base_model_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -231,20 +231,20 @@ async def test_transaction_create_request_no_jobs_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_request=mock.AsyncMock( + create_request=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -254,7 +254,7 @@ async def test_transaction_create_request_no_jobs_x(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -267,20 +267,20 @@ async def test_transaction_create_request_no_my_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_request=mock.AsyncMock( + create_request=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -290,7 +290,7 @@ async def test_transaction_create_request_no_my_job_x(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -309,20 +309,20 @@ async def test_transaction_create_request_no_their_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_request=mock.AsyncMock( + create_request=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -332,7 +332,7 @@ async def test_transaction_create_request_no_their_job_x(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -351,18 +351,18 @@ async def test_transaction_create_request_my_wrong_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -382,25 +382,25 @@ async def test_transaction_create_request_mgr_create_request_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - create_request=mock.AsyncMock( + create_request=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -423,7 +423,7 @@ async def test_endorse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -436,9 +436,9 @@ async def test_endorse_transaction_response(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -449,7 +449,7 @@ async def test_endorse_transaction_response(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_endorse_response=mock.AsyncMock( + create_endorse_response=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -459,7 +459,7 @@ async def test_endorse_transaction_response(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -484,7 +484,7 @@ 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, - mock.MagicMock(get_public_did=mock.AsyncMock(return_value=None)), + mock.MagicMock(get_public_did=mock.CoroutineMock(return_value=None)), ) with mock.patch.object( self.context.profile, @@ -500,7 +500,7 @@ async def test_endorse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -513,7 +513,7 @@ async def test_endorse_transaction_response_not_found_x(self): ) with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", @@ -529,7 +529,7 @@ async def test_endorse_transaction_response_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -542,9 +542,9 @@ async def test_endorse_transaction_response_base_model_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", @@ -564,7 +564,7 @@ async def test_endorse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -577,16 +577,16 @@ async def test_endorse_transaction_response_no_jobs_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -601,7 +601,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -614,9 +614,9 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -625,7 +625,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_endorse_response=mock.AsyncMock( + create_endorse_response=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -635,7 +635,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -656,7 +656,7 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -669,16 +669,16 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -699,7 +699,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -710,12 +710,14 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ), ) - self.ledger.txn_endorse = mock.AsyncMock(side_effect=test_module.LedgerError()) + self.ledger.txn_endorse = mock.CoroutineMock( + side_effect=test_module.LedgerError() + ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -724,7 +726,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_endorse_response=mock.AsyncMock( + create_endorse_response=mock.CoroutineMock( return_value=( mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -734,7 +736,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -755,7 +757,7 @@ async def test_endorse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -768,9 +770,9 @@ async def test_endorse_transaction_response_txn_mgr_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -781,12 +783,12 @@ async def test_endorse_transaction_response_txn_mgr_x(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_endorse_response=mock.AsyncMock( + create_endorse_response=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -807,7 +809,7 @@ async def test_refuse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -820,9 +822,9 @@ async def test_refuse_transaction_response(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -833,7 +835,7 @@ async def test_refuse_transaction_response(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_refuse_response=mock.AsyncMock( + create_refuse_response=mock.CoroutineMock( return_value=( mock.MagicMock( # transaction connection_id="dummy", @@ -844,7 +846,7 @@ async def test_refuse_transaction_response(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -865,7 +867,7 @@ async def test_refuse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -878,7 +880,7 @@ async def test_refuse_transaction_response_not_found_x(self): ) with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", @@ -895,7 +897,7 @@ async def test_refuse_transaction_response_conn_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -908,9 +910,9 @@ async def test_refuse_transaction_response_conn_base_model_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", @@ -930,7 +932,7 @@ async def test_refuse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -943,16 +945,16 @@ async def test_refuse_transaction_response_no_jobs_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -967,7 +969,7 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -980,16 +982,16 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1010,7 +1012,7 @@ async def test_refuse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, mock.MagicMock( - get_public_did=mock.AsyncMock( + get_public_did=mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -1023,9 +1025,9 @@ async def test_refuse_transaction_response_txn_mgr_x(self): ) with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( @@ -1036,12 +1038,12 @@ async def test_refuse_transaction_response_txn_mgr_x(self): mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = mock.MagicMock( - create_refuse_response=mock.AsyncMock( + create_refuse_response=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1060,16 +1062,16 @@ async def test_cancel_transaction(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - cancel_transaction=mock.AsyncMock( + cancel_transaction=mock.CoroutineMock( return_value=( mock.MagicMock( # transaction connection_id="dummy", @@ -1080,7 +1082,7 @@ async def test_cancel_transaction(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1099,7 +1101,7 @@ async def test_cancel_transaction_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1110,9 +1112,9 @@ async def test_cancel_transaction_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() mock_txn_rec_retrieve.return_value = mock.MagicMock( @@ -1126,12 +1128,12 @@ async def test_cancel_transaction_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1144,12 +1146,12 @@ async def test_cancel_transaction_wrong_my_job_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1168,21 +1170,21 @@ async def test_cancel_transaction_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - cancel_transaction=mock.AsyncMock( + cancel_transaction=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1201,16 +1203,16 @@ async def test_transaction_resend(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - transaction_resend=mock.AsyncMock( + transaction_resend=mock.CoroutineMock( return_value=( mock.MagicMock( # transaction connection_id="dummy", @@ -1221,7 +1223,7 @@ async def test_transaction_resend(self): ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1240,7 +1242,7 @@ async def test_transaction_resend_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1251,9 +1253,9 @@ async def test_transaction_resend_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() mock_txn_rec_retrieve.return_value = mock.MagicMock( @@ -1267,12 +1269,12 @@ async def test_transaction_resend_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1285,12 +1287,12 @@ async def test_transaction_resend_my_wrong_job_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1310,21 +1312,21 @@ async def test_transaction_resend_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - transaction_resend=mock.AsyncMock( + transaction_resend=mock.CoroutineMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1343,17 +1345,17 @@ async def test_set_endorser_role(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = mock.MagicMock( - set_transaction_my_job=mock.AsyncMock() + set_transaction_my_job=mock.CoroutineMock() ) mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1371,7 +1373,7 @@ async def test_set_endorser_role_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1382,7 +1384,7 @@ async def test_set_endorser_role_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1393,12 +1395,12 @@ async def test_set_endorser_info(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1408,7 +1410,7 @@ async def test_set_endorser_info(self): ), } ), - metadata_set=mock.AsyncMock(), + metadata_set=mock.CoroutineMock(), ) await test_module.set_endorser_info(self.request) @@ -1425,12 +1427,12 @@ 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 mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( side_effect=[ { "transaction_my_job": ( @@ -1447,7 +1449,7 @@ async def test_set_endorser_info_no_prior_value(self): }, ] ), - metadata_set=mock.AsyncMock(), + metadata_set=mock.CoroutineMock(), ) await test_module.set_endorser_info(self.request) @@ -1463,7 +1465,7 @@ async def test_set_endorser_info_not_found_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1475,7 +1477,7 @@ async def test_set_endorser_info_base_model_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1487,10 +1489,10 @@ async def test_set_endorser_info_no_transaction_jobs_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock(return_value=None) + metadata_get=mock.CoroutineMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.set_endorser_info(self.request) @@ -1500,10 +1502,10 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1518,10 +1520,10 @@ 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 mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = mock.MagicMock( - metadata_get=mock.AsyncMock( + metadata_get=mock.CoroutineMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1537,17 +1539,19 @@ 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 mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value.complete_transaction = mock.AsyncMock() + mock_txn_mgr.return_value.complete_transaction = mock.CoroutineMock() mock_txn_mgr.return_value.complete_transaction.return_value = ( - mock.AsyncMock(serialize=mock.MagicMock(return_value={"...": "..."})), - mock.AsyncMock(), + mock.CoroutineMock( + serialize=mock.MagicMock(return_value={"...": "..."}) + ), + mock.CoroutineMock(), ) mock_txn_rec_retrieve.return_value = mock.MagicMock( @@ -1564,7 +1568,7 @@ async def test_transaction_write_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1575,7 +1579,7 @@ async def test_transaction_write_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1585,7 +1589,7 @@ 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 mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.return_value = mock.MagicMock( serialize=mock.MagicMock(return_value={"...": "..."}), @@ -1601,12 +1605,12 @@ 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 mock.patch.object( - TransactionRecord, "retrieve_by_id", mock.AsyncMock() + TransactionRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_txn_rec_retrieve, mock.patch.object( test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = mock.MagicMock( - complete_transaction=mock.AsyncMock( + complete_transaction=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) 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 45049f43e3..3049526ed3 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -45,7 +45,7 @@ async def test_handle(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = mock.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=ConnRecord(connection_id="dummy") ) @@ -59,7 +59,7 @@ async def test_handle_x(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = mock.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=test_module.ConnectionManagerError("oops") ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py index d66afc900b..7acb9b4425 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 +from aries_cloudagent.tests import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -47,7 +47,7 @@ async def test_handle(self): self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: mock_ctx_inject.return_value = mock.MagicMock( - return_invitation=mock.AsyncMock() + return_invitation=mock.CoroutineMock() ) 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 833090611d..96e710841a 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 +from aries_cloudagent.tests import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -60,7 +60,7 @@ async def test_handle_auto_accept(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.create_invitation = mock.AsyncMock( + mock_mgr.return_value.create_invitation = mock.CoroutineMock( 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 af46ee1343..9ace9b497a 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -12,7 +12,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -22,7 +22,7 @@ async def asyncSetUp(self): ) async def test_introduction_start_no_service(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -70,7 +70,7 @@ async def test_introduction_start(self): test_module.web, "json_response" ) as mock_response: mock_ctx_inject.return_value = mock.MagicMock( - start_introduction=mock.AsyncMock() + start_introduction=mock.CoroutineMock() ) await test_module.introduction_start(self.request) @@ -84,7 +84,7 @@ async def test_introduction_start(self): mock_response.assert_called_once_with({}) async def test_introduction_start_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -108,7 +108,7 @@ async def test_introduction_start_x(self): self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: mock_ctx_inject.return_value = mock.MagicMock( - start_introduction=mock.AsyncMock( + start_introduction=mock.CoroutineMock( side_effect=test_module.IntroductionError() ) ) 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 ce38c2cbbd..aed4264e6b 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase @@ -17,7 +17,7 @@ async def test_called(self): request_context = RequestContext.test_context() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -29,7 +29,7 @@ async def test_called(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = True handler = test_module.CredentialAckHandler() @@ -53,7 +53,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() @@ -69,7 +69,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) @@ -79,7 +79,7 @@ async def test_called_no_connection_no_oob(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py index 67697fbd79..c0c6e46ce5 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,7 +19,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -28,7 +28,7 @@ async def test_called(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() request_context.connection_ready = True handler = test_module.CredentialIssueHandler() @@ -51,7 +51,7 @@ async def test_called_auto_store(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -61,12 +61,12 @@ async def test_called_auto_store(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = mock.MagicMock( - receive_credential=mock.AsyncMock(), - store_credential=mock.AsyncMock(), - send_credential_ack=mock.AsyncMock( + receive_credential=mock.CoroutineMock(), + store_credential=mock.CoroutineMock(), + send_credential_ack=mock.CoroutineMock( return_value=( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), ) @@ -92,7 +92,7 @@ async def test_called_auto_store_x(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -102,16 +102,16 @@ async def test_called_auto_store_x(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = mock.MagicMock( - receive_credential=mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + receive_credential=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - store_credential=mock.AsyncMock( + store_credential=mock.CoroutineMock( side_effect=test_module.IndyHolderError() ), - send_credential_ack=mock.AsyncMock( + send_credential_ack=mock.CoroutineMock( return_value=( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), ) @@ -122,7 +122,7 @@ async def test_called_auto_store_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: @@ -137,7 +137,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() request_context.connection_ready = False handler = test_module.CredentialIssueHandler() @@ -153,7 +153,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) @@ -163,7 +163,7 @@ async def test_called_no_connection_no_oob(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = CredentialIssue() handler = test_module.CredentialIssueHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py index 94613b174f..65f7ca1541 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,7 +19,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -28,7 +28,7 @@ async def test_called(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = True handler = test_module.CredentialOfferHandler() @@ -52,7 +52,7 @@ async def test_called_auto_request(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -61,8 +61,8 @@ async def test_called_auto_request(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() - mock_cred_mgr.return_value.create_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( return_value=(None, "credential_request_message") ) request_context.message = CredentialOffer() @@ -92,7 +92,7 @@ async def test_called_auto_request_x(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -101,10 +101,10 @@ async def test_called_auto_request_x(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_cred_mgr.return_value.create_request = mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -114,7 +114,7 @@ async def test_called_auto_request_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: @@ -129,7 +129,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() @@ -148,7 +148,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) @@ -158,7 +158,7 @@ async def test_no_conn_no_oob(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py index 103b975ffc..ef9253a439 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -23,7 +23,7 @@ async def test_called(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = CredentialProblemReport( description={ "en": "Change of plans", @@ -49,7 +49,7 @@ async def test_called_x(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock( side_effect=test_module.StorageError("Disk full") ) 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 f723bf16e8..47637ccfce 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -19,7 +19,7 @@ async def test_called(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False @@ -43,11 +43,11 @@ async def test_called_auto_offer(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( return_value=(None, "credential_offer_message") ) request_context.message = CredentialProposal() @@ -74,11 +74,11 @@ async def test_called_auto_offer_x(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - 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 = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -88,7 +88,7 @@ async def test_called_auto_offer_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: @@ -103,7 +103,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = CredentialProposal() request_context.connection_ready = False handler = test_module.CredentialProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py index b89fff1b98..bc4b5ea21d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -23,14 +23,16 @@ async def test_called(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False @@ -56,7 +58,9 @@ async def test_called_auto_issue(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -73,11 +77,11 @@ async def test_called_auto_issue(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "credential_issue_message") ) request_context.message = CredentialRequest() @@ -109,7 +113,9 @@ async def test_called_auto_issue_x(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -126,13 +132,13 @@ async def test_called_auto_issue_x(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr, mock.patch.object( - cred_ex_rec, "save_error_state", mock.AsyncMock() + cred_ex_rec, "save_error_state", mock.CoroutineMock() ): - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -142,7 +148,7 @@ async def test_called_auto_issue_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: @@ -156,7 +162,9 @@ async def test_called_auto_issue_no_preview(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -167,11 +175,11 @@ async def test_called_auto_issue_no_preview(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "credential_issue_message") ) @@ -199,7 +207,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = CredentialRequest() request_context.connection_ready = False handler = test_module.CredentialRequestHandler() @@ -218,7 +226,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) @@ -228,7 +236,7 @@ async def test_called_no_connection_no_oob(self): with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = CredentialRequest() handler = test_module.CredentialRequestHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py index ec5dea7a8d..042f9e3d19 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -79,7 +79,7 @@ async def test_save_error_state(self): await record.save(session) with mock.patch.object( - record, "save", mock.AsyncMock() + record, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: 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 16977f34a2..5beb1b48ff 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -3,7 +3,7 @@ from copy import deepcopy from time import time -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -60,18 +60,20 @@ async def asyncSetUp(self): Ledger = mock.MagicMock() self.ledger = Ledger() - 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( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=CRED_DEF + ) + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -156,7 +158,7 @@ async def test_create_proposal(self): ) ) - self.ledger.credential_definition_id2schema_id = mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) @@ -192,7 +194,7 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - self.ledger.credential_definition_id2schema_id = mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) @@ -284,7 +286,7 @@ async def test_create_free_offer(self): self.context.injector.bind_instance(BaseCache, self.cache) issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = mock.AsyncMock( + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -364,7 +366,7 @@ async def test_create_free_offer_attr_mismatch(self): self.context.injector.bind_instance(BaseCache, self.cache) issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = mock.AsyncMock( + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -422,7 +424,7 @@ async def test_create_bound_offer(self): ) as set_cached_key: get_cached_key.return_value = None issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = mock.AsyncMock( + issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -493,7 +495,7 @@ async def test_create_bound_offer_no_cred_def(self): ) as set_cached_key: get_cached_key.return_value = None issuer = mock.MagicMock() - issuer.create_credential_offer = mock.AsyncMock(return_value=INDY_OFFER) + issuer.create_credential_offer = mock.CoroutineMock(return_value=INDY_OFFER) self.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(CredentialManagerError): @@ -541,7 +543,7 @@ async def test_receive_offer_proposed(self): ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -580,7 +582,7 @@ async def test_receive_free_offer(self): ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(side_effect=StorageNotFoundError), + mock.CoroutineMock(side_effect=StorageNotFoundError), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -624,13 +626,13 @@ async def test_create_request(self): with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_req_meta = {} holder = mock.MagicMock() - holder.create_credential_request = mock.AsyncMock( + holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -693,13 +695,13 @@ async def test_create_request_no_cache(self): with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value=cred_def ) cred_req_meta = {} holder = mock.MagicMock() - holder.create_credential_request = mock.AsyncMock( + holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -762,7 +764,7 @@ async def test_receive_request(self): ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_request(request, mock_conn, None) @@ -802,7 +804,7 @@ async def test_receive_request_no_connection_cred_request(self): ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_exchange cx_rec = await self.manager.receive_request(request, mock_conn, mock_oob) @@ -842,7 +844,7 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = (StorageNotFoundError(),) with self.assertRaises(CredentialManagerError): @@ -886,7 +888,7 @@ async def test_issue_credential_revocable(self): issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1000" - issuer.create_credential = mock.AsyncMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -896,7 +898,7 @@ async def test_issue_credential_revocable(self): ) as revoc, mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, @@ -904,7 +906,7 @@ async def test_issue_credential_revocable(self): mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", - get_or_fetch_local_tails_path=mock.AsyncMock(), + get_or_fetch_local_tails_path=mock.CoroutineMock(), max_creds=10, ), ) @@ -973,14 +975,18 @@ async def test_issue_credential_non_revocable(self): issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = mock.AsyncMock(return_value=(json.dumps(cred), None)) + issuer.create_credential = mock.CoroutineMock( + return_value=(json.dumps(cred), None) + ) self.context.injector.bind_instance(IndyIssuer, issuer) Ledger = mock.MagicMock() self.ledger = 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.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=CRED_DEF_NR + ) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) self.context.injector.clear_binding(BaseLedger) self.context.injector.bind_instance(BaseLedger, self.ledger) with mock.patch.object( @@ -988,7 +994,7 @@ async def test_issue_credential_non_revocable(self): ) as save_ex, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ): (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1040,7 +1046,7 @@ async def test_issue_credential_fills_rr(self): issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = mock.AsyncMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), stored_exchange.revocation_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -1052,22 +1058,22 @@ async def test_issue_credential_fills_rr(self): ) as save_ex: revoc.return_value = mock.MagicMock( get_or_create_active_registry=( - mock.AsyncMock( + mock.CoroutineMock( return_value=( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=mock.AsyncMock(), + set_state=mock.CoroutineMock(), ), mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", max_creds=1000, - get_or_fetch_local_tails_path=(mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ) ) ), - handle_full_registry=mock.AsyncMock(), + handle_full_registry=mock.CoroutineMock(), ) (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1142,30 +1148,30 @@ async def test_issue_credential_no_active_rr_no_retries(self): issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = mock.AsyncMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( side_effect=[ None, ( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=mock.AsyncMock(), + set_state=mock.CoroutineMock(), ), mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ), ] @@ -1206,20 +1212,20 @@ async def test_issue_credential_no_active_rr_retry(self): issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = mock.AsyncMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=None ) with self.assertRaises(CredentialManagerError) as context: @@ -1250,7 +1256,7 @@ async def test_receive_credential(self): ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(return_value=stored_exchange), + mock.CoroutineMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_credential(issue, connection_id) @@ -1302,13 +1308,15 @@ async def test_store_credential(self): cred_id = "cred-id" holder = mock.MagicMock() - holder.store_credential = mock.AsyncMock(return_value=cred_id) - holder.get_credential = mock.AsyncMock(return_value=json.dumps(INDY_CRED_INFO)) + holder.store_credential = mock.CoroutineMock(return_value=cred_id) + holder.get_credential = mock.CoroutineMock( + return_value=json.dumps(INDY_CRED_INFO) + ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1322,7 +1330,7 @@ async def test_store_credential(self): ) as delete_ex: mock_rev_reg.from_definition = mock.MagicMock( return_value=mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock() + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) ret_exchange = await self.manager.store_credential( @@ -1403,19 +1411,21 @@ async def test_store_credential_no_preview(self): await stored_exchange.save(self.session) cred_def = mock.MagicMock() - self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=cred_def + ) cred_id = "cred-id" holder = mock.MagicMock() - holder.store_credential = mock.AsyncMock(return_value=cred_id) - holder.get_credential = mock.AsyncMock( + holder.store_credential = mock.CoroutineMock(return_value=cred_id) + holder.get_credential = mock.CoroutineMock( return_value=json.dumps(cred_info_no_rev) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1471,18 +1481,20 @@ async def test_store_credential_holder_store_indy_error(self): await stored_exchange.save(self.session) cred_def = mock.MagicMock() - self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=cred_def + ) cred_id = "cred-id" holder = mock.MagicMock() - holder.store_credential = mock.AsyncMock( + holder.store_credential = mock.CoroutineMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1550,7 +1562,7 @@ async def test_receive_credential_ack(self): ) as delete_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange ret_exchange = await self.manager.receive_credential_ack(ack, connection_id) @@ -1589,7 +1601,7 @@ async def test_receive_problem_report(self): ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1615,7 +1627,7 @@ async def test_receive_problem_report_x(self): with mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py index c45f34b287..e100a50a58 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -15,7 +15,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -35,7 +35,7 @@ async def test_credential_exchange_list(self): with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.query = mock.AsyncMock() + mock_cred_ex.query = mock.CoroutineMock() mock_cred_ex.query.return_value = [mock_cred_ex] mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} @@ -59,7 +59,9 @@ async def test_credential_exchange_list_x(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.query = mock.AsyncMock(side_effect=test_module.StorageError()) + mock_cred_ex.query = mock.CoroutineMock( + side_effect=test_module.StorageError() + ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) @@ -71,7 +73,7 @@ async def test_credential_exchange_retrieve(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} @@ -90,7 +92,7 @@ async def test_credential_exchange_retrieve_not_found(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -104,7 +106,7 @@ async def test_credential_exchange_retrieve_x(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex mock_cred_ex.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() @@ -113,7 +115,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -124,11 +126,11 @@ async def test_credential_exchange_create(self): ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cred_ex_record = mock.MagicMock() @@ -146,7 +148,7 @@ async def test_credential_exchange_create(self): ) async def test_credential_exchange_create_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -157,11 +159,11 @@ async def test_credential_exchange_create_x(self): ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cred_ex_record = mock.MagicMock() @@ -177,14 +179,14 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_proposal(self): conn_id = "connection-id" - self.request.json = mock.AsyncMock(return_value={"connection_id": conn_id}) + self.request.json = mock.CoroutineMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_create(self.request) assert "credential_proposal" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -195,11 +197,11 @@ async def test_credential_exchange_send(self): ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cred_ex_record = mock.MagicMock() @@ -219,7 +221,7 @@ async def test_credential_exchange_send(self): async def test_credential_exchange_send_no_proposal(self): conn_id = "connection-id" - self.request.json = mock.AsyncMock(return_value={"connection_id": conn_id}) + self.request.json = mock.CoroutineMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send(self.request) @@ -229,7 +231,7 @@ async def test_credential_exchange_send_no_conn_record(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -239,7 +241,7 @@ async def test_credential_exchange_send_no_conn_record(self): test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -255,7 +257,7 @@ async def test_credential_exchange_send_not_ready(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -276,7 +278,7 @@ async def test_credential_exchange_send_not_ready(self): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -287,18 +289,18 @@ async def test_credential_exchange_send_x(self): ): mock_cred_ex_record = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value = mock.MagicMock( - create_offer=mock.AsyncMock( + create_offer=mock.CoroutineMock( return_value=( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), - prepare_send=mock.AsyncMock( + prepare_send=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -313,7 +315,7 @@ async def test_credential_exchange_send_proposal(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -338,7 +340,7 @@ async def test_credential_exchange_send_proposal(self): ) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -348,7 +350,7 @@ async def test_credential_exchange_send_proposal_no_conn_record(self): test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -363,7 +365,7 @@ async def test_credential_exchange_send_proposal_deser_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -375,7 +377,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -385,7 +387,7 @@ async def test_credential_exchange_send_proposal_not_ready(self): test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_proposal.return_value = ( @@ -399,7 +401,7 @@ async def test_credential_exchange_send_proposal_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -410,7 +412,7 @@ async def test_credential_exchange_send_proposal_x(self): ) as mock_credential_manager: mock_cred_ex_record = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record @@ -420,7 +422,7 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -439,7 +441,7 @@ async def test_credential_exchange_create_free_offer(self): ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, @@ -453,7 +455,7 @@ async def test_credential_exchange_create_free_offer(self): ) async def test_credential_exchange_create_free_offer_no_cred_def_id(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -466,14 +468,14 @@ async def test_credential_exchange_create_free_offer_no_cred_def_id(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_preview(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = {"comment": "comment", "cred_def_id": "dummy"} with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -485,14 +487,14 @@ 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] = mock.MagicMock( - get_public_did=mock.AsyncMock(return_value=None), + get_public_did=mock.CoroutineMock(return_value=None), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_deser_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -507,7 +509,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.side_effect = ( test_module.BaseModelError() @@ -517,7 +519,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -536,10 +538,10 @@ async def test_credential_exchange_create_free_offer_x(self): serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_credential_manager.return_value = mock.MagicMock( - create_offer=mock.AsyncMock( + create_offer=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock.MagicMock(), @@ -550,7 +552,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -567,7 +569,7 @@ async def test_credential_exchange_send_free_offer(self): ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_cred_ex_record = mock.MagicMock() @@ -583,7 +585,7 @@ async def test_credential_exchange_send_free_offer(self): ) async def test_credential_exchange_send_free_offer_no_cred_def_id(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = { "comment": "comment", "credential_preview": "dummy", @@ -593,7 +595,7 @@ async def test_credential_exchange_send_free_offer_no_cred_def_id(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_preview(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value = { "comment": "comment", "cred_def_id": CRED_DEF_ID, @@ -603,7 +605,7 @@ async def test_credential_exchange_send_free_offer_no_preview(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -617,11 +619,11 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -631,7 +633,7 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.json.return_value["auto_issue"] = True with mock.patch.object( @@ -640,10 +642,10 @@ async def test_credential_exchange_send_free_offer_not_ready(self): test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -653,7 +655,7 @@ async def test_credential_exchange_send_free_offer_not_ready(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -672,11 +674,11 @@ async def test_credential_exchange_send_free_offer_x(self): ) as mock_response: mock_cred_ex_record = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_credential_manager.return_value = mock.MagicMock( - create_offer=mock.AsyncMock( + create_offer=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock.MagicMock(), @@ -688,7 +690,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -700,12 +702,12 @@ async def test_credential_exchange_send_bound_offer(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_cred_ex_record = mock.MagicMock() @@ -721,7 +723,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -729,14 +731,14 @@ async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -748,19 +750,19 @@ async def test_credential_exchange_send_bound_offer_no_conn_record(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cred_ex.STATE_PROPOSAL_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -770,7 +772,7 @@ async def test_credential_exchange_send_bound_offer_no_conn_record(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -778,10 +780,10 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cred_ex.STATE_ACKED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) @@ -789,7 +791,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -801,16 +803,16 @@ async def test_credential_exchange_send_bound_offer_not_ready(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -820,7 +822,7 @@ async def test_credential_exchange_send_bound_offer_not_ready(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -832,7 +834,7 @@ async def test_credential_exchange_send_request(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -851,7 +853,7 @@ async def test_credential_exchange_send_request(self): ) async def test_credential_exchange_send_request_no_conn(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -865,12 +867,12 @@ async def test_credential_exchange_send_request_no_conn(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + mock_oob_rec.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -894,7 +896,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -902,14 +904,14 @@ async def test_credential_exchange_send_request_bad_cred_ex_id(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -921,18 +923,18 @@ async def test_credential_exchange_send_request_no_conn_record(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock.MagicMock( state=mock_cred_ex.STATE_OFFER_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -942,7 +944,7 @@ async def test_credential_exchange_send_request_no_conn_record(self): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -954,16 +956,16 @@ async def test_credential_exchange_send_request_not_ready(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.CoroutineMock() mock_credential_manager.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -973,7 +975,7 @@ async def test_credential_exchange_send_request_not_ready(self): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_issue(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -985,7 +987,7 @@ async def test_credential_exchange_issue(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) @@ -1004,7 +1006,7 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1012,20 +1014,20 @@ async def test_credential_exchange_issue_bad_cred_ex_id(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", serialize=mock.MagicMock(), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1035,16 +1037,16 @@ async def test_credential_exchange_issue_no_conn_record(self): 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 = mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.issue_credential = mock.AsyncMock() + mock_credential_manager.return_value.issue_credential = mock.CoroutineMock() mock_credential_manager.return_value.issue_credential.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1054,7 +1056,7 @@ async def test_credential_exchange_issue_no_conn_record(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1064,16 +1066,16 @@ async def test_credential_exchange_issue_not_ready(self): ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.issue_credential = mock.AsyncMock() + mock_credential_manager.return_value.issue_credential = mock.CoroutineMock() mock_credential_manager.return_value.issue_credential.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1083,13 +1085,13 @@ async def test_credential_exchange_issue_not_ready(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", serialize=mock.MagicMock(), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1099,27 +1101,29 @@ async def test_credential_exchange_issue_rev_reg_full(self): 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 = mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) + mock_issue_cred = mock.CoroutineMock( + 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1128,11 +1132,11 @@ async def test_credential_exchange_issue_deser_x(self): ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: - mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_cred_ex_rec ) mock_credential_manager.return_value = mock.MagicMock( - issue_credential=mock.AsyncMock( + issue_credential=mock.CoroutineMock( return_value=( mock_cred_ex_rec, mock.MagicMock(), @@ -1143,7 +1147,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1155,7 +1159,7 @@ async def test_credential_exchange_store(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) @@ -1177,7 +1181,7 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1191,7 +1195,7 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) @@ -1213,7 +1217,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1221,14 +1225,14 @@ async def test_credential_exchange_store_bad_cred_ex_id(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1240,15 +1244,15 @@ async def test_credential_exchange_store_no_conn_record(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cred_ex.STATE_CREDENTIAL_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1264,7 +1268,7 @@ async def test_credential_exchange_store_no_conn_record(self): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1276,20 +1280,20 @@ async def test_credential_exchange_store_not_ready(self): ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1304,15 +1308,15 @@ async def test_credential_exchange_store_x(self): mock_cred_ex_record = mock.MagicMock( state=mock_cred_ex_cls.STATE_CREDENTIAL_RECEIVED, serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_credential_manager.return_value = mock.MagicMock( - store_credential=mock.AsyncMock(return_value=mock_cred_ex_record), - send_credential_ack=mock.AsyncMock( + store_credential=mock.CoroutineMock(return_value=mock_cred_ex_record), + send_credential_ack=mock.CoroutineMock( return_value=(mock_cred_ex_record, mock.MagicMock()) ), ) @@ -1328,10 +1332,10 @@ async def test_credential_exchange_remove(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.delete_record = mock.AsyncMock() + mock_cred_ex.delete_record = mock.CoroutineMock() await test_module.credential_exchange_remove(self.request) @@ -1344,7 +1348,7 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1359,15 +1363,15 @@ async def test_credential_exchange_remove_x(self): ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) mock_rec = mock.MagicMock( - delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) + delete_record=mock.CoroutineMock(side_effect=test_module.StorageError()) ) - mock_cred_ex.retrieve_by_id = mock.AsyncMock(return_value=mock_rec) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock(return_value=mock_rec) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1384,8 +1388,8 @@ async def test_credential_exchange_problem_report(self): ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1398,7 +1402,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1406,7 +1410,7 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1414,7 +1418,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1426,9 +1430,9 @@ async def test_credential_exchange_problem_report_x(self): ) as mock_problem_report, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( - save_error_state=mock.AsyncMock( + save_error_state=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) 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 e9ce6eef88..77abf110c3 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py @@ -2,7 +2,7 @@ from time import time import json from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from marshmallow import ValidationError from .. import handler as test_module @@ -203,18 +203,20 @@ async def asyncSetUp(self): # Ledger Ledger = mock.MagicMock() self.ledger = Ledger() - 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( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=CRED_DEF + ) + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -292,7 +294,7 @@ async def test_check_uniqueness(self): with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_indy_query: mock_indy_query.return_value = [] await self.handler._check_uniqueness("dummy-cx-id") @@ -300,7 +302,7 @@ async def test_check_uniqueness(self): with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_indy_query: mock_indy_query.return_value = [mock.MagicMock()] with self.assertRaises(V20CredFormatError) as context: @@ -383,7 +385,7 @@ async def test_create_offer(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = mock.AsyncMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -449,7 +451,7 @@ async def test_create_offer_no_cache(self): await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = mock.AsyncMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -511,13 +513,13 @@ async def test_create_offer_attr_mismatch(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = mock.AsyncMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): with self.assertRaises(V20CredFormatError): await self.handler.create_offer(cred_proposal) @@ -535,7 +537,7 @@ async def test_create_offer_no_matching_sent_cred_def(self): filters_attach=[AttachDecorator.data_base64({}, ident="0")], ) - self.issuer.create_credential_offer = mock.AsyncMock( + self.issuer.create_credential_offer = mock.CoroutineMock( return_value=json.dumps(INDY_OFFER) ) @@ -571,10 +573,12 @@ async def test_create_request(self): ) cred_def = {"cred": "def"} - self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=cred_def + ) cred_req_meta = {} - self.holder.create_credential_request = mock.AsyncMock( + self.holder.create_credential_request = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) @@ -609,7 +613,7 @@ async def test_create_request(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): await self.handler.create_request( cred_ex_record, {"holder_did": holder_did} @@ -638,7 +642,7 @@ async def test_create_request_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_OFFER_RECEIVED) with mock.patch.object( - self.handler, "_check_uniqueness", mock.AsyncMock() + self.handler, "_check_uniqueness", mock.CoroutineMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -713,19 +717,19 @@ async def test_issue_credential_revocable(self): ) cred_rev_id = "1000" - self.issuer.create_credential = mock.AsyncMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), max_creds=10, ), ) @@ -799,10 +803,12 @@ async def test_issue_credential_non_revocable(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = mock.AsyncMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), None) ) - self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF_NR) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=CRED_DEF_NR + ) self.context.injector.bind_instance( BaseMultitenantManager, mock.MagicMock(MultitenantManager, autospec=True), @@ -810,7 +816,7 @@ async def test_issue_credential_non_revocable(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ): (cred_format, attachment) = await self.handler.issue_credential( cred_ex_record, retries=0 @@ -838,7 +844,7 @@ async def test_issue_credential_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_REQUEST_RECEIVED) with mock.patch.object( - self.handler, "_check_uniqueness", mock.AsyncMock() + self.handler, "_check_uniqueness", mock.CoroutineMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -895,12 +901,12 @@ async def test_issue_credential_no_active_rr_no_retries(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = mock.AsyncMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=() ) with self.assertRaises(V20CredFormatError) as context: @@ -953,22 +959,22 @@ async def test_issue_credential_no_active_rr_retry(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = mock.AsyncMock( + self.issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( side_effect=[ None, ( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=mock.AsyncMock(), + set_state=mock.CoroutineMock(), ), mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ), ] @@ -1024,19 +1030,19 @@ async def test_issue_credential_rr_full(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = mock.AsyncMock( + self.issuer.create_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerRevocationRegistryFullError("Nope") ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_or_create_active_registry = mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.CoroutineMock( return_value=( mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=mock.AsyncMock(), + set_state=mock.CoroutineMock(), ), mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.CoroutineMock()), ), ) ) @@ -1120,9 +1126,9 @@ async def test_store_credential(self): cred_id = "cred-id" - self.holder.store_credential = mock.AsyncMock(return_value=cred_id) + self.holder.store_credential = mock.CoroutineMock(return_value=cred_id) stored_cred = {"stored": "cred"} - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps(stored_cred) ) @@ -1131,7 +1137,7 @@ async def test_store_credential(self): ) as mock_rev_reg: mock_rev_reg.from_definition = mock.MagicMock( return_value=mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock() + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) with self.assertRaises(V20CredFormatError) as context: @@ -1144,7 +1150,7 @@ async def test_store_credential(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object( test_module, "RevocationRegistry", autospec=True ) as mock_rev_reg, mock.patch.object( @@ -1152,12 +1158,12 @@ async def test_store_credential(self): ) as mock_get_detail_record: mock_rev_reg.from_definition = mock.MagicMock( return_value=mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock() + get_or_fetch_local_tails_path=mock.CoroutineMock() ) ) mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) self.ledger.get_credential_definition.reset_mock() @@ -1241,7 +1247,7 @@ async def test_store_credential_holder_store_indy_error(self): ) cred_id = "cred-id" - self.holder.store_credential = mock.AsyncMock( + self.holder.store_credential = mock.CoroutineMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) @@ -1252,10 +1258,10 @@ async def test_store_credential_holder_store_indy_error(self): ) as mock_rev_reg: mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) mock_rev_reg.return_value = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock() + get_or_fetch_local_tails_path=mock.CoroutineMock() ) with self.assertRaises(test_module.IndyHolderError) as context: await self.handler.store_credential(stored_cx_rec, cred_id) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index 5cc37b415d..bc868d08ca 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,7 +1,7 @@ from copy import deepcopy from .......vc.ld_proofs.error import LinkedDataProofException from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from unittest.mock import patch from marshmallow import ValidationError @@ -238,7 +238,7 @@ async def test_assert_can_issue_with_id_and_proof_type(self): with mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did=TEST_DID_SOV, @@ -277,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 = mock.AsyncMock() + self.wallet.get_local_did = mock.CoroutineMock() did_info = await self.handler._did_info_for_did(TEST_DID_SOV) self.wallet.get_local_did.assert_called_once_with( @@ -298,11 +298,11 @@ async def test_get_suite_for_detail(self): with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_can_issue, mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: suite = await self.handler._get_suite_for_detail(detail) @@ -454,7 +454,7 @@ async def test_create_offer(self): with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_can_issue, patch.object( test_module, "get_properties_without_context", return_value=[] ): @@ -494,7 +494,7 @@ async def test_create_offer_adds_bbs_context(self): with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - mock.AsyncMock(), + mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -519,7 +519,7 @@ async def test_create_offer_adds_ed25519_2020_context(self): with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - mock.AsyncMock(), + mock.CoroutineMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -541,7 +541,7 @@ async def test_create_offer_x_wrong_attributes(self): with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - mock.AsyncMock(), + mock.CoroutineMock(), ), patch.object( test_module, "get_properties_without_context", @@ -790,9 +790,9 @@ async def test_issue_credential(self): with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_suite, mock.patch.object( - test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -843,9 +843,9 @@ async def test_issue_credential_adds_bbs_context(self): with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_suite, mock.patch.object( - test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -887,9 +887,9 @@ async def test_issue_credential_adds_ed25519_2020_context(self): with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_suite, mock.patch.object( - test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + test_module, "issue", mock.CoroutineMock(return_value=LD_PROOF_VC) ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -1141,16 +1141,16 @@ async def test_store_credential(self): ) cred_id = "cred_id" - self.holder.store_credential = mock.AsyncMock() + self.holder.store_credential = mock.CoroutineMock() with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - mock.AsyncMock(return_value=DocumentVerificationResult(verified=True)), + mock.CoroutineMock(return_value=DocumentVerificationResult(verified=True)), ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -1202,16 +1202,16 @@ async def test_store_credential_x_not_verified(self): ) cred_id = "cred_id" - self.holder.store_credential = mock.AsyncMock() + self.holder.store_credential = mock.CoroutineMock() with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - mock.AsyncMock(return_value=DocumentVerificationResult(verified=False)), + mock.CoroutineMock(return_value=DocumentVerificationResult(verified=False)), ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", 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 9bebdb14e8..146588ad08 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -18,7 +18,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -27,7 +27,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.CoroutineMock() request_context.message = V20CredAck() request_context.connection_ready = True handler = test_module.V20CredAckHandler() @@ -52,7 +52,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_cred_ack = mock.AsyncMock() + mock_cred_mgr.return_value.receive_cred_ack = mock.CoroutineMock() request_context.message = V20CredAck() request_context.connection_ready = False handler = test_module.V20CredAckHandler() @@ -70,7 +70,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py index a1b3b3cdff..6bf6d4db8b 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,7 +19,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -28,7 +28,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = V20CredIssue() request_context.connection_ready = True handler_inst = test_module.V20CredIssueHandler() @@ -51,7 +51,7 @@ async def test_called_auto_store(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -61,9 +61,9 @@ async def test_called_auto_store(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: 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"), + receive_credential=mock.CoroutineMock(), + store_credential=mock.CoroutineMock(), + send_cred_ack=mock.CoroutineMock(return_value="cred_ack_message"), ) request_context.message = V20CredIssue() request_context.connection_ready = True @@ -87,7 +87,7 @@ async def test_called_auto_store_x(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -97,16 +97,16 @@ async def test_called_auto_store_x(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = mock.MagicMock( - receive_credential=mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + receive_credential=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - store_credential=mock.AsyncMock( + store_credential=mock.CoroutineMock( side_effect=[ test_module.IndyHolderError, test_module.StorageError(), ] ), - send_cred_ack=mock.AsyncMock(), + send_cred_ack=mock.CoroutineMock(), ) request_context.message = V20CredIssue() @@ -126,7 +126,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.CoroutineMock() request_context.message = V20CredIssue() request_context.connection_ready = False handler_inst = test_module.V20CredIssueHandler() @@ -142,7 +142,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py index 1ec77403c0..83f5b01a6f 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,7 +19,7 @@ async def test_called(self): request_context.connection_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -28,7 +28,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = V20CredOffer() request_context.connection_ready = True handler_inst = test_module.V20CredOfferHandler() @@ -52,7 +52,7 @@ async def test_called_auto_request(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -61,8 +61,8 @@ async def test_called_auto_request(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() - mock_cred_mgr.return_value.create_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( return_value=(None, "cred_request_message") ) request_context.message = V20CredOffer() @@ -92,7 +92,7 @@ async def test_called_auto_request_x(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -101,10 +101,10 @@ async def test_called_auto_request_x(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_cred_mgr.return_value.create_request = mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -114,9 +114,9 @@ async def test_called_auto_request_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.AsyncMock() + handler._logger, "exception", mock.CoroutineMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -129,7 +129,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.CoroutineMock() request_context.message = V20CredOffer() request_context.connection_ready = False handler_inst = test_module.V20CredOfferHandler() @@ -148,7 +148,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py index fa86a31bd5..df1df7cf58 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -19,7 +19,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.connection_ready = True request_context.message = V20CredProblemReport( description={ @@ -46,7 +46,7 @@ async def test_called_x(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.CoroutineMock( side_effect=test_module.StorageError("Disk full") ) 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 4f4a069cfe..b6694a9506 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -19,7 +19,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False @@ -43,11 +43,11 @@ async def test_called_auto_offer(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( return_value=(None, "cred_offer_message") ) request_context.message = V20CredProposal() @@ -74,11 +74,11 @@ async def test_called_auto_offer_x(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - 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 = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -88,9 +88,9 @@ async def test_called_auto_offer_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.AsyncMock() + handler._logger, "exception", mock.CoroutineMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -103,7 +103,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = V20CredProposal() request_context.connection_ready = False handler_inst = test_module.V20CredProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py index 398bb2f339..8d6877749a 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -22,14 +22,16 @@ async def test_called(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False @@ -52,7 +54,9 @@ async def test_called_auto_issue(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -61,11 +65,11 @@ async def test_called_auto_issue(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( return_value=(None, "cred_issue_message") ) request_context.message = V20CredRequest() @@ -96,20 +100,22 @@ async def test_called_auto_issue_x(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr, mock.patch.object( - cred_ex_rec, "save_error_state", mock.AsyncMock() + cred_ex_rec, "save_error_state", mock.CoroutineMock() ): - mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock( side_effect=test_module.IndyIssuerError() ) @@ -119,9 +125,9 @@ async def test_called_auto_issue_x(self): responder = MockResponder() with mock.patch.object( - responder, "send_reply", mock.AsyncMock() + responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.AsyncMock() + handler._logger, "exception", mock.CoroutineMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -134,7 +140,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = V20CredRequest() request_context.connection_ready = False handler = test_module.V20CredRequestHandler() @@ -153,7 +159,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py index b39254d7dc..ad4c449601 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -127,7 +127,7 @@ async def test_save_error_state(self): await record.save(session) with mock.patch.object( - record, "save", mock.AsyncMock() + record, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: 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 fb264a5de3..ba3c0c38fb 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -88,11 +88,13 @@ async def asyncSetUp(self): Ledger = mock.MagicMock() self.ledger = Ledger() - 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( + self.ledger.get_schema = mock.CoroutineMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.CoroutineMock( + return_value=CRED_DEF + ) + self.ledger.get_revoc_reg_def = mock.CoroutineMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.CoroutineMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.CoroutineMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) @@ -157,7 +159,7 @@ async def test_create_proposal(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = mock.AsyncMock( + mock_handler.return_value.create_proposal = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -200,7 +202,7 @@ async def test_create_proposal_no_preview(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = mock.AsyncMock( + mock_handler.return_value.create_proposal = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -251,7 +253,7 @@ async def test_receive_proposal(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_proposal = mock.AsyncMock() + mock_handler.return_value.receive_proposal = mock.CoroutineMock() cred_proposal = V20CredProposal( credential_preview=cred_preview, @@ -324,7 +326,7 @@ async def test_create_free_offer(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = mock.AsyncMock( + mock_handler.return_value.create_offer = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -400,7 +402,7 @@ async def test_create_bound_offer(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = mock.AsyncMock( + mock_handler.return_value.create_offer = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -510,11 +512,11 @@ async def test_receive_offer_proposed(self): ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(return_value=stored_cx_rec), + mock.CoroutineMock(return_value=stored_cx_rec), ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = mock.AsyncMock() + mock_handler.return_value.receive_offer = mock.CoroutineMock() cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -565,11 +567,11 @@ async def test_receive_free_offer(self): with mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = mock.AsyncMock() + mock_handler.return_value.receive_offer = mock.CoroutineMock() mock_retrieve.side_effect = (StorageNotFoundError(),) cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -620,7 +622,7 @@ async def test_create_bound_request(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = mock.AsyncMock( + mock_handler.return_value.create_request = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -707,7 +709,7 @@ async def test_create_free_request(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = mock.AsyncMock( + mock_handler.return_value.create_request = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -777,12 +779,12 @@ async def test_receive_request(self): with mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = mock.AsyncMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() # mock_retrieve.return_value = stored_cx_rec cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -827,12 +829,12 @@ async def test_receive_request_no_connection_cred_request(self): with mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.return_value = stored_cx_rec - mock_handler.return_value.receive_request = mock.AsyncMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() cx_rec = await self.manager.receive_request( cred_request, mock_conn, mock_oob @@ -876,12 +878,12 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): with mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = mock.AsyncMock() + mock_handler.return_value.receive_request = mock.CoroutineMock() cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -967,7 +969,7 @@ async def test_issue_credential(self): issuer = mock.MagicMock() cred_rev_id = "1000" - issuer.create_credential = mock.AsyncMock( + issuer.create_credential = mock.CoroutineMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -977,7 +979,7 @@ async def test_issue_credential(self): ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.issue_credential = mock.AsyncMock( + mock_handler.return_value.issue_credential = mock.CoroutineMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -1085,11 +1087,11 @@ async def test_receive_cred(self): ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_credential = mock.AsyncMock() + mock_handler.return_value.receive_credential = mock.CoroutineMock() mock_retrieve.return_value = stored_cx_rec ret_cx_rec = await self.manager.receive_credential( cred_issue, @@ -1153,7 +1155,7 @@ async def test_receive_cred_x_extra_formats(self): with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1191,7 +1193,7 @@ async def test_receive_cred_x_no_formats(self): with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1236,7 +1238,7 @@ async def test_store_credential(self): ) as mock_delete, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.store_credential = mock.AsyncMock() + mock_handler.return_value.store_credential = mock.CoroutineMock() ret_cx_rec = await self.manager.store_credential( stored_cx_rec, cred_id=cred_id @@ -1313,7 +1315,7 @@ async def test_receive_cred_ack(self): ) as mock_save, mock.patch.object( V20CredExRecord, "delete_record", autospec=True ) as mock_delete, mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + V20CredExRecord, "retrieve_by_conn_and_thread", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True ) as mock_delete: @@ -1335,13 +1337,13 @@ async def test_receive_cred_ack(self): mock_delete.assert_called_once() async def test_delete_cred_ex_record(self): - stored_cx_rec = mock.MagicMock(delete_record=mock.AsyncMock()) - stored_indy = mock.MagicMock(delete_record=mock.AsyncMock()) + stored_cx_rec = mock.MagicMock(delete_record=mock.CoroutineMock()) + stored_indy = mock.MagicMock(delete_record=mock.CoroutineMock()) with mock.patch.object( V20CredExRecord, "delete_record", autospec=True ) as mock_delete, mock.patch.object( - V20CredExRecord, "retrieve_by_id", mock.AsyncMock() + V20CredExRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module, "V20CredFormat", mock.MagicMock() ) as mock_cred_format: @@ -1349,7 +1351,7 @@ async def test_delete_cred_ex_record(self): mock_cred_format.Format = [ mock.MagicMock( detail=mock.MagicMock( - query_by_cred_ex_id=mock.AsyncMock( + query_by_cred_ex_id=mock.CoroutineMock( return_value=[ stored_indy, stored_indy, @@ -1359,7 +1361,7 @@ async def test_delete_cred_ex_record(self): ), mock.MagicMock( detail=mock.MagicMock( - query_by_cred_ex_id=mock.AsyncMock(return_value=[]) + query_by_cred_ex_id=mock.CoroutineMock(return_value=[]) ) ), ] @@ -1385,7 +1387,7 @@ async def test_receive_problem_report(self): ) as save_ex, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1417,7 +1419,7 @@ async def test_receive_problem_report_x(self): with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py index 8af79157eb..9d7d8dab9c 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ from .....vc.ld_proofs.error import LinkedDataProofException -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -21,7 +21,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -93,7 +93,7 @@ async def test_credential_exchange_list(self): with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.query = mock.AsyncMock(return_value=[mock_cx_rec]) + mock_cx_rec.query = mock.CoroutineMock(return_value=[mock_cx_rec]) mock_cx_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) with mock.patch.object(test_module.web, "json_response") as mock_response: @@ -123,7 +123,9 @@ async def test_credential_exchange_list_x(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) + mock_cx_rec.query = mock.CoroutineMock( + side_effect=test_module.StorageError() + ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) @@ -137,12 +139,12 @@ async def test_credential_exchange_retrieve(self): ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"...": "..."}) @@ -171,12 +173,12 @@ async def test_credential_exchange_retrieve_indy_ld_proof(self): ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"in": "dy"}) @@ -205,7 +207,7 @@ async def test_credential_exchange_retrieve_not_found(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -221,13 +223,13 @@ async def test_credential_exchange_retrieve_x(self): ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( return_value=None ) @@ -235,7 +237,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -246,11 +248,11 @@ async def test_credential_exchange_create(self): ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cx_rec = mock.MagicMock() @@ -266,7 +268,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -277,11 +279,11 @@ async def test_credential_exchange_create_x(self): ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cred_mgr.return_value.prepare_send.side_effect = ( @@ -294,7 +296,7 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_filter(self): connection_id = "connection-id" - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": { @@ -308,7 +310,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -319,11 +321,11 @@ async def test_credential_exchange_send(self): ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) mock_cx_rec = mock.MagicMock() @@ -339,7 +341,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -353,12 +355,12 @@ async def test_credential_exchange_send_request_no_conn_no_holder_did(self): ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + mock_oob_rec.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.CoroutineMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -385,7 +387,7 @@ async def test_credential_exchange_send_no_conn_record(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -398,7 +400,7 @@ async def test_credential_exchange_send_no_conn_record(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -414,7 +416,7 @@ async def test_credential_exchange_send_not_ready(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -438,7 +440,7 @@ async def test_credential_exchange_send_not_ready(self): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -449,17 +451,17 @@ async def test_credential_exchange_send_x(self): ) as mock_cred_preview_deser: mock_cred_ex_record = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_cred_offer = mock.MagicMock() - mock_cred_mgr.return_value = mock.AsyncMock( - create_offer=mock.AsyncMock( + mock_cred_mgr.return_value = mock.CoroutineMock( + create_offer=mock.CoroutineMock( return_value=( - mock.AsyncMock(), - mock.AsyncMock(), + mock.CoroutineMock(), + mock.CoroutineMock(), ) ), - prepare_send=mock.AsyncMock( + prepare_send=mock.CoroutineMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -474,7 +476,7 @@ async def test_credential_exchange_send_proposal(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -500,7 +502,7 @@ async def test_credential_exchange_send_proposal(self): async def test_credential_exchange_send_proposal_no_filter(self): connection_id = "connection-id" - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "comment", "connection_id": connection_id, @@ -512,7 +514,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -522,7 +524,7 @@ async def test_credential_exchange_send_proposal_no_conn_record(self): test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -535,7 +537,7 @@ async def test_credential_exchange_send_proposal_x(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -550,7 +552,7 @@ async def test_credential_exchange_send_proposal_x(self): ) as mock_cred_mgr: mock_cx_rec = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec @@ -558,7 +560,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -568,7 +570,7 @@ async def test_credential_exchange_send_proposal_not_ready(self): test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_cred_mgr.return_value.create_proposal.return_value = mock.MagicMock() @@ -577,7 +579,7 @@ async def test_credential_exchange_send_proposal_not_ready(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -595,7 +597,7 @@ async def test_credential_exchange_create_free_offer(self): ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, @@ -607,7 +609,7 @@ async def test_credential_exchange_create_free_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_free_offer_no_filter(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -621,7 +623,7 @@ async def test_credential_exchange_create_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -640,10 +642,10 @@ async def test_credential_exchange_create_free_offer_x(self): serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_cred_mgr.return_value = mock.MagicMock( - create_offer=mock.AsyncMock( + create_offer=mock.CoroutineMock( return_value=( mock_cx_rec, mock.MagicMock(), @@ -654,7 +656,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -671,7 +673,7 @@ async def test_credential_exchange_send_free_offer(self): ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, @@ -682,7 +684,7 @@ async def test_credential_exchange_send_free_offer(self): 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "comment", "credential_preview": { @@ -696,7 +698,7 @@ async def test_credential_exchange_send_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -712,11 +714,11 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -726,7 +728,7 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": True, "credential_preview": { @@ -742,10 +744,10 @@ async def test_credential_exchange_send_free_offer_not_ready(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -755,7 +757,7 @@ async def test_credential_exchange_send_free_offer_not_ready(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "auto_issue": False, "credential_preview": { @@ -774,10 +776,10 @@ async def test_credential_exchange_send_free_offer_x(self): ) as mock_response: mock_cx_rec = mock.MagicMock( serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_cred_mgr.return_value = mock.AsyncMock( - create_offer=mock.AsyncMock( + mock_cred_mgr.return_value = mock.CoroutineMock( + create_offer=mock.CoroutineMock( return_value=( mock_cx_rec, mock.MagicMock(), @@ -789,7 +791,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -801,12 +803,12 @@ async def test_credential_exchange_send_bound_offer(self): ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cx_rec = mock.MagicMock() @@ -820,7 +822,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -832,12 +834,12 @@ async def test_credential_exchange_send_bound_offer_linked_data_error(self): ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cx_rec = mock.MagicMock() @@ -851,7 +853,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -859,14 +861,14 @@ async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -878,19 +880,19 @@ async def test_credential_exchange_send_bound_offer_no_conn_record(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cx_rec.STATE_PROPOSAL_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -900,7 +902,7 @@ async def test_credential_exchange_send_bound_offer_no_conn_record(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -908,10 +910,10 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cx_rec.STATE_DONE, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) @@ -919,7 +921,7 @@ 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 = mock.AsyncMock(return_value={}) + self.request.json = mock.CoroutineMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -931,16 +933,16 @@ async def test_credential_exchange_send_bound_offer_not_ready(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -950,7 +952,7 @@ async def test_credential_exchange_send_bound_offer_not_ready(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -962,7 +964,7 @@ async def test_credential_exchange_send_request(self): ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) @@ -979,7 +981,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -987,14 +989,14 @@ async def test_credential_exchange_send_request_bad_cred_ex_id(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1006,18 +1008,18 @@ async def test_credential_exchange_send_request_no_conn_record(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value = mock.MagicMock( state=mock_cx_rec.STATE_OFFER_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1027,7 +1029,7 @@ async def test_credential_exchange_send_request_no_conn_record(self): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1039,16 +1041,16 @@ async def test_credential_exchange_send_request_not_ready(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.CoroutineMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1058,7 +1060,7 @@ async def test_credential_exchange_send_request_not_ready(self): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_free_request(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1071,7 +1073,7 @@ async def test_credential_exchange_send_free_request(self): ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() mock_cx_rec = mock.MagicMock() @@ -1085,14 +1087,14 @@ 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 = mock.AsyncMock(return_value={"comment": "comment"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "comment"}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send_free_request(self.request) assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_request_no_conn_record(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1104,11 +1106,11 @@ async def test_credential_exchange_send_free_request_no_conn_record(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_request = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() mock_cred_mgr.return_value.create_request.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1118,7 +1120,7 @@ async def test_credential_exchange_send_free_request_no_conn_record(self): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_not_ready(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1130,10 +1132,10 @@ async def test_credential_exchange_send_free_request_not_ready(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_request = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.CoroutineMock() mock_cred_mgr.return_value.create_request.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1143,7 +1145,7 @@ async def test_credential_exchange_send_free_request_not_ready(self): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1156,7 +1158,7 @@ async def test_credential_exchange_send_free_request_x(self): ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1171,7 +1173,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1185,13 +1187,13 @@ async def test_credential_exchange_issue(self): ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) mock_cx_rec = mock.MagicMock() - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1216,7 +1218,7 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1224,20 +1226,20 @@ async def test_credential_exchange_issue_bad_cred_ex_id(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = mock.MagicMock( conn_id="dummy", serialize=mock.MagicMock(), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1247,14 +1249,16 @@ async def test_credential_exchange_issue_no_conn_record(self): 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 = mock.AsyncMock(return_value=mock_cx_rec) + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock_cx_rec + ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock() mock_cred_mgr.return_value.issue_credential.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1264,7 +1268,7 @@ async def test_credential_exchange_issue_no_conn_record(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1274,16 +1278,16 @@ async def test_credential_exchange_issue_not_ready(self): ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.CoroutineMock() mock_cred_mgr.return_value.issue_credential.return_value = ( mock.MagicMock(), mock.MagicMock(), @@ -1293,13 +1297,13 @@ async def test_credential_exchange_issue_not_ready(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = mock.MagicMock( conn_id="dummy", serialize=mock.MagicMock(), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1309,25 +1313,29 @@ async def test_credential_exchange_issue_rev_reg_full(self): 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 = mock.AsyncMock(return_value=mock_cx_rec) + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock_cx_rec + ) - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) + mock_issue_cred = mock.CoroutineMock( + 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = mock.MagicMock( connection_id="dummy", serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1336,16 +1344,18 @@ async def test_credential_exchange_issue_deser_x(self): ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( + return_value=mock_cx_rec + ) mock_cred_mgr.return_value = mock.MagicMock( - issue_credential=mock.AsyncMock( + issue_credential=mock.CoroutineMock( return_value=( mock_cx_rec, mock.MagicMock(), ) ) ) - mock_cred_mgr.return_value.get_detail_record = mock.AsyncMock( + mock_cred_mgr.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1358,7 +1368,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1372,11 +1382,11 @@ async def test_credential_exchange_store(self): ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1404,7 +1414,7 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1422,7 +1432,7 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) 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 = mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) @@ -1451,7 +1461,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1459,14 +1469,14 @@ async def test_credential_exchange_store_bad_cred_ex_id(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1478,15 +1488,15 @@ async def test_credential_exchange_store_no_conn_record(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_cx_rec.STATE_CREDENTIAL_RECEIVED, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1500,7 +1510,7 @@ async def test_credential_exchange_store_no_conn_record(self): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1512,20 +1522,20 @@ async def test_credential_exchange_store_not_ready(self): ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.CoroutineMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.CoroutineMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"cred_ex_id": "dummy"} with mock.patch.object( @@ -1542,12 +1552,12 @@ async def test_credential_exchange_store_x(self): mock_cx_rec = mock.MagicMock( state=mock_cx_rec_cls.STATE_CREDENTIAL_RECEIVED, serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_cx_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock() ) - mock_handler.return_value.get_detail_record = mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.CoroutineMock( side_effect=[ mock.MagicMock( # indy serialize=mock.MagicMock(return_value={"...": "..."}) @@ -1557,8 +1567,8 @@ async def test_credential_exchange_store_x(self): ) mock_cred_mgr.return_value = mock.MagicMock( - store_credential=mock.AsyncMock(return_value=mock_cx_rec), - send_cred_ack=mock.AsyncMock( + store_credential=mock.CoroutineMock(return_value=mock_cx_rec), + send_cred_ack=mock.CoroutineMock( return_value=( mock_cx_rec, mock.MagicMock(), @@ -1578,7 +1588,7 @@ async def test_credential_exchange_remove(self): test_module.web, "json_response" ) as mock_response: mock_cred_mgr.return_value = mock.MagicMock( - delete_cred_ex_record=mock.AsyncMock() + delete_cred_ex_record=mock.CoroutineMock() ) await test_module.credential_exchange_remove(self.request) @@ -1591,7 +1601,7 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = mock.MagicMock( - delete_cred_ex_record=mock.AsyncMock( + delete_cred_ex_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1606,7 +1616,7 @@ async def test_credential_exchange_remove_x(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = mock.MagicMock( - delete_cred_ex_record=mock.AsyncMock( + delete_cred_ex_record=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1615,7 +1625,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1630,8 +1640,8 @@ async def test_credential_exchange_problem_report(self): ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1644,7 +1654,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1654,7 +1664,7 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): ) as mock_cred_mgr_cls, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1662,7 +1672,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1674,9 +1684,9 @@ async def test_credential_exchange_problem_report_x(self): ) as mock_problem_report, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( - save_error_state=mock.AsyncMock( + save_error_state=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) 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 791bd14bec..2b5fe61d91 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 +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -38,7 +38,7 @@ class TestOOBProblemReportHandler: @pytest.mark.asyncio @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 = mock.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = OOBProblemReport( description={ "en": "No such connection", @@ -57,7 +57,7 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): @pytest.mark.asyncio @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 = mock.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.CoroutineMock() mock_oob_mgr.return_value.receive_problem_report.side_effect = ( OutOfBandManagerError("error") ) 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 71bc022e56..660f9a11c2 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 +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -38,7 +38,7 @@ class TestHandshakeReuseAcceptHandler: @pytest.mark.asyncio @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 = mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.CoroutineMock() request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() @@ -52,7 +52,7 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): @pytest.mark.asyncio @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 = mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.CoroutineMock() 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 d05f7b860a..9fd96174e4 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 +from aries_cloudagent.tests import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -31,7 +31,7 @@ class TestHandshakeReuseHandler: @pytest.mark.asyncio @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() request_context.connection_record = ConnRecord() @@ -46,7 +46,7 @@ async def test_called(self, mock_oob_mgr, request_context): @pytest.mark.asyncio @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 = mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() reuse_accepted = HandshakeReuseAccept() mock_oob_mgr.return_value.receive_reuse_message.return_value = reuse_accepted request_context.message = HandshakeReuse() @@ -63,7 +63,7 @@ async def test_reuse_accepted(self, mock_oob_mgr, request_context): @pytest.mark.asyncio @mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() 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 b3b181c6b7..62f7db787c 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -6,7 +6,7 @@ from typing import List from unittest.mock import ANY -from unittest import mock +from aries_cloudagent.tests 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 = mock.AsyncMock() + self.responder.send = mock.CoroutineMock() self.test_mediator_routing_keys = [ "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR" @@ -321,7 +321,7 @@ def setUp(self): self.test_mediator_endpoint = "http://mediator.example.com" self.route_manager = mock.MagicMock(RouteManager) - self.route_manager.routing_info = mock.AsyncMock( + self.route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) @@ -340,7 +340,7 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseResponder, self.responder) self.profile.context.injector.bind_instance( - EventBus, mock.MagicMock(notify=mock.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.CoroutineMock()) ) self.mt_mgr = mock.MagicMock() self.mt_mgr = mock.create_autospec(MultitenantManager) @@ -352,7 +352,7 @@ def setUp(self): ) self.manager = OutOfBandManager(self.profile) assert self.manager.profile - self.manager.resolve_invitation = mock.AsyncMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -366,7 +366,7 @@ def setUp(self): their_role=ConnRecord.Role.REQUESTER, state=ConnRecord.State.COMPLETED, their_public_did=self.their_public_did, - save=mock.AsyncMock(), + save=mock.CoroutineMock(), ) async def test_create_invitation_handshake_succeeds(self): @@ -466,7 +466,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) MediationManager, "get_default_mediator_id", ) as mock_get_default_mediator, mock.patch.object( - mock_conn_rec, "metadata_set", mock.AsyncMock() + mock_conn_rec, "metadata_set", mock.CoroutineMock() ) as mock_metadata_set: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -508,7 +508,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -542,7 +542,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -576,11 +576,11 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10CredentialExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid_v1, mock.patch.object( test_module.V20CredExRecord, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_cxid_v2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -618,7 +618,7 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_pxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -653,11 +653,11 @@ async def test_create_invitation_attachment_present_proof_v2_0(self): ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_pxid_1, mock.patch.object( test_module.V20PresExRecord, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_pxid_2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -854,7 +854,7 @@ async def test_wait_for_conn_rec_active_retrieve_by_id(self): with mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock(connection_id="the-retrieved-connection-id") ), ): @@ -871,7 +871,7 @@ async def test_create_handshake_reuse_msg(self): ) as oob_mgr_fetch_conn, mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock(return_value=self.test_conn_rec), + mock.CoroutineMock(return_value=self.test_conn_rec), ): oob_mgr_fetch_conn.return_value = ConnectionTarget( did=TestConfig.test_did, @@ -946,8 +946,8 @@ async def test_receive_reuse_message_existing_found(self): self.profile, "notify", autospec=True ) as mock_notify: mock_retrieve_oob.return_value = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=False, ) @@ -1003,8 +1003,8 @@ async def test_receive_reuse_message_existing_found_multi_use(self): self.profile, "notify", autospec=True ) as mock_notify: mock_retrieve_oob.return_value = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), multi_use=True, ) @@ -1051,8 +1051,8 @@ async def test_receive_reuse_accepted(self): OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.return_value = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), ) await self.manager.receive_reuse_accepted_message( @@ -1125,9 +1125,9 @@ async def test_receive_problem_report(self): OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.return_value = mock.MagicMock( - emit_event=mock.AsyncMock(), - delete_record=mock.AsyncMock(), - save=mock.AsyncMock(), + emit_event=mock.CoroutineMock(), + delete_record=mock.CoroutineMock(), + save=mock.CoroutineMock(), ) await self.manager.receive_problem_report( @@ -1180,9 +1180,9 @@ async def test_receive_invitation_with_valid_mediation(self): ) await mediation_record.save(session) with mock.patch.object( - DIDXManager, "receive_invitation", mock.AsyncMock() + DIDXManager, "receive_invitation", mock.CoroutineMock() ) as mock_didx_recv_invi, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1211,11 +1211,11 @@ async def test_receive_invitation_with_invalid_mediation(self): with mock.patch.object( DIDXManager, "receive_invitation", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_didx_recv_invi, mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1225,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 = mock.AsyncMock( + self.route_manager.mediation_record_if_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) await self.manager.receive_invitation( @@ -1248,10 +1248,10 @@ async def test_receive_invitation_didx_services_with_service_block(self): with mock.patch.object( test_module, "DIDXManager", autospec=True ) as didx_mgr_cls, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve_conn_by_id: didx_mgr_cls.return_value = mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=mock_conn) + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) mock_retrieve_conn_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1277,10 +1277,10 @@ async def test_receive_invitation_connection_protocol(self): with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as conn_mgr_cls, mock.patch.object( - ConnRecord, "retrieve_by_id", mock.AsyncMock() + ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_conn_retrieve_by_id: conn_mgr_cls.return_value = mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=mock_conn) + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) mock_conn_retrieve_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1366,11 +1366,11 @@ async def test_existing_conn_record_public_did(self): with mock.patch.object( ConnRecord, "find_existing_connection", - mock.AsyncMock(), + mock.CoroutineMock(), ) as oob_mgr_find_existing_conn, mock.patch.object( - OobRecord, "save", mock.AsyncMock() + OobRecord, "save", mock.CoroutineMock() ) as oob_record_save, mock.patch.object( - OobRecord, "retrieve_by_id", mock.AsyncMock() + OobRecord, "retrieve_by_id", mock.CoroutineMock() ) as oob_record_retrieve_by_id, mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True ) as oob_mgr_fetch_conn: @@ -1413,15 +1413,15 @@ async def test_receive_invitation_handshake_reuse(self): with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - mock.AsyncMock(), + mock.CoroutineMock(), ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - mock.AsyncMock(), + mock.CoroutineMock(), ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - mock.AsyncMock(return_value=test_exist_conn), + mock.CoroutineMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1461,19 +1461,19 @@ async def test_receive_invitation_handshake_reuse_failed(self): with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - mock.AsyncMock(), + mock.CoroutineMock(), ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - mock.AsyncMock(), + mock.CoroutineMock(), ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - mock.AsyncMock(return_value=test_exist_conn), + mock.CoroutineMock(return_value=test_exist_conn), ), mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock(return_value=test_exist_conn), + mock.CoroutineMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1484,8 +1484,8 @@ async def test_receive_invitation_handshake_reuse_failed(self): ) mock_oob = mock.MagicMock( - delete_record=mock.AsyncMock(), - emit_event=mock.AsyncMock(), + delete_record=mock.CoroutineMock(), + emit_event=mock.CoroutineMock(), ) perform_handshake.return_value = mock_oob @@ -1527,10 +1527,10 @@ async def test_receive_invitation_services_with_service_did(self): ) as didx_mgr_cls, mock.patch.object( ConnRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock_conn), + mock.CoroutineMock(return_value=mock_conn), ): didx_mgr_cls.return_value = mock.MagicMock( - receive_invitation=mock.AsyncMock(return_value=mock_conn) + receive_invitation=mock.CoroutineMock(return_value=mock_conn) ) oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1548,7 +1548,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) + mock_oob_processor = mock.MagicMock(handle_message=mock.CoroutineMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1560,11 +1560,11 @@ async def test_request_attach_oob_message_processor_connectionless(self): with mock.patch.object( InMemoryWallet, "create_signing_key", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_signing_key, mock.patch.object( OutOfBandManager, "_service_decorator_from_service", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( verkey="a-verkey", metadata={}, key_type=ED25519 @@ -1609,7 +1609,7 @@ async def test_request_attach_oob_message_processor_connection(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) + mock_oob_processor = mock.MagicMock(handle_message=mock.CoroutineMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1617,7 +1617,7 @@ async def test_request_attach_oob_message_processor_connection(self): with mock.patch.object( ConnRecord, "find_existing_connection", - mock.AsyncMock(), + mock.CoroutineMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn oob_invitation = InvitationMessage( @@ -1655,7 +1655,7 @@ async def test_request_attach_wait_for_conn_rec_active(self): ) as mock_wait_for_conn_rec_active, mock.patch.object( ConnRecord, "find_existing_connection", - mock.AsyncMock(), + mock.CoroutineMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn mock_wait_for_conn_rec_active.return_value = None @@ -1681,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 = mock.AsyncMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -1714,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 = mock.AsyncMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( "", # empty endpoint [TestConfig.test_verkey], @@ -1728,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 = mock.AsyncMock() + self.manager.resolve_invitation = mock.CoroutineMock() self.manager.resolve_invitation.return_value = ( None, # None endpoint [TestConfig.test_verkey], @@ -1792,9 +1792,9 @@ async def test_delete_stale_connection_by_invitation(self): ) ] with mock.patch.object( - ConnRecord, "query", mock.AsyncMock() + ConnRecord, "query", mock.CoroutineMock() ) as mock_connrecord_query, mock.patch.object( - ConnRecord, "delete_record", mock.AsyncMock() + ConnRecord, "delete_record", mock.CoroutineMock() ) as mock_connrecord_delete: mock_connrecord_query.return_value = records await self.manager.delete_stale_connection_by_invitation("test123") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py index 385f7b977a..22bcd06226 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord @@ -13,7 +13,7 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -33,14 +33,14 @@ async def test_invitation_create(self): "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object( test_module, "OutOfBandManager", autospec=True ) 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 = mock.AsyncMock( + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"abc": "123"}) ) @@ -76,14 +76,14 @@ async def test_invitation_create_with_accept(self): "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = mock.AsyncMock(return_value=body) + self.request.json = mock.CoroutineMock(return_value=body) with mock.patch.object( test_module, "OutOfBandManager", autospec=True ) 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 = mock.AsyncMock( + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value={"abc": "123"}) ) @@ -109,7 +109,7 @@ async def test_invitation_create_with_accept(self): async def test_invitation_create_x(self): self.request.query = {"multi_use": "true"} - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "attachments": mock.MagicMock(), "handshake_protocols": [23], @@ -122,7 +122,7 @@ async def test_invitation_create_x(self): ) 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 = mock.AsyncMock( + mock_oob_mgr.return_value.create_invitation = mock.CoroutineMock( side_effect=test_module.OutOfBandManagerError() ) @@ -131,7 +131,7 @@ async def test_invitation_create_x(self): mock_json_response.assert_not_called() async def test_invitation_receive(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() expected_connection_record = ConnRecord(connection_id="some-id") with mock.patch.object( @@ -141,7 +141,7 @@ async def test_invitation_receive(self): ), mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = mock.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.CoroutineMock( return_value=expected_connection_record ) @@ -156,7 +156,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "OutOfBandManager", autospec=True @@ -165,7 +165,7 @@ async def test_invitation_receive_x(self): ) 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 = mock.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.CoroutineMock( side_effect=test_module.StorageError("cannot write") ) 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 e6b324c3b4..06d844df64 100644 --- a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py @@ -4,7 +4,7 @@ from typing import Sequence from uuid import uuid4 -import mock +from aries_cloudagent.tests import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2, ED25519 @@ -2040,7 +2040,7 @@ async def test_get_sign_key_credential_subject_id(self, profile): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2105,7 +2105,7 @@ async def test_get_sign_key_credential_subject_id_error(self, profile): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2173,7 +2173,7 @@ async def test_get_sign_key_credential_subject_id_bbsbls(self, profile): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info: did_info = DIDInfo( did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", @@ -2243,23 +2243,23 @@ async def test_create_vp_no_issuer(self, profile, setup_tuple): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_merge, mock.patch.object( test_module, "create_presentation", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_make_req.return_value = mock.MagicMock() mock_apply_req.return_value = mock.MagicMock() @@ -2296,27 +2296,27 @@ async def test_create_vp_with_bbs_suite(self, profile, setup_tuple): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_merge, mock.patch.object( test_module, "create_presentation", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp, mock.patch.object( test_module, "sign_presentation", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_sign_vp: mock_make_req.return_value = mock.MagicMock() mock_apply_req.return_value = mock.MagicMock() @@ -2354,27 +2354,27 @@ async def test_create_vp_no_issuer_with_bbs_suite(self, profile, setup_tuple): with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_merge, mock.patch.object( test_module, "create_presentation", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp, mock.patch.object( DIFPresExchHandler, "get_sign_key_credential_subject_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_sign_key_cred_subject: mock_make_req.return_value = mock.MagicMock() mock_apply_req.return_value = mock.MagicMock() 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 1e259345c5..ae963a3ef1 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -18,7 +18,7 @@ async def test_called(self): session = request_context.session() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -27,7 +27,7 @@ async def test_called(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.CoroutineMock() request_context.message = PresentationAck() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -49,7 +49,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.CoroutineMock() request_context.message = PresentationAck() request_context.connection_ready = False handler = test_module.PresentationAckHandler() @@ -65,7 +65,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py index 176d896eab..0ce2d5ab5d 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,14 +19,16 @@ async def test_called(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.CoroutineMock() request_context.message = Presentation() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -47,15 +49,17 @@ async def test_called_auto_verify(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() - mock_pres_mgr.return_value.verify_presentation = mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.CoroutineMock() + mock_pres_mgr.return_value.verify_presentation = mock.CoroutineMock() request_context.message = Presentation() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -76,7 +80,9 @@ async def test_called_auto_verify_x(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -84,10 +90,10 @@ async def test_called_auto_verify_x(self): test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value = mock.MagicMock( - receive_presentation=mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + receive_presentation=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - verify_presentation=mock.AsyncMock( + verify_presentation=mock.CoroutineMock( side_effect=test_module.LedgerError() ), ) 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 95ad42faeb..99a756785b 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -23,7 +23,7 @@ async def test_called(self): test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = PresentationProblemReport( description={ "en": "Change of plans", @@ -49,7 +49,7 @@ async def test_called_x(self): test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock( 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 20167b6b6d..c3df16088a 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -20,7 +20,7 @@ async def test_called(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) request_context.message = PresentationProposal() @@ -47,10 +47,10 @@ async def test_called_auto_request(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( return_value=( mock_pres_mgr.return_value.receive_proposal.return_value, "presentation_request_message", @@ -86,10 +86,10 @@ async def test_called_auto_request_x(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( side_effect=test_module.LedgerError() ) @@ -112,7 +112,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock() + mock_pres_mgr.return_value.receive_proposal = mock.CoroutineMock() request_context.message = PresentationProposal() request_context.connection_ready = False handler = test_module.PresentationProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py index 03b67c8230..68875205b3 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase @@ -76,7 +76,7 @@ async def test_called(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -103,11 +103,11 @@ async def test_called(self): ) 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -136,7 +136,7 @@ async def test_called_not_found(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -163,12 +163,12 @@ async def test_called_not_found(self): ) 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( side_effect=StorageNotFoundError ) mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -227,12 +227,12 @@ async def test_called_auto_present(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( - get_credentials_for_presentation_request_by_referent=mock.AsyncMock( + get_credentials_for_presentation_request_by_referent=mock.CoroutineMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) @@ -245,14 +245,14 @@ async def test_called_auto_present(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -311,17 +311,17 @@ async def test_called_auto_present_x(self): mock_px_rec = mock.MagicMock( presentation_proposal_dict=presentation_proposal, auto_present=True, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -333,14 +333,14 @@ async def test_called_auto_present_x(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -389,13 +389,13 @@ async def test_called_auto_present_no_preview(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -412,14 +412,14 @@ async def test_called_auto_present_no_preview(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -469,13 +469,13 @@ async def test_called_auto_present_pred_no_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[]) + mock.CoroutineMock(return_value=[]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -487,14 +487,14 @@ async def test_called_auto_present_pred_no_match(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -540,13 +540,15 @@ async def test_called_auto_present_pred_single_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy-0"}}]) + mock.CoroutineMock( + return_value=[{"cred_info": {"referent": "dummy-0"}}] + ) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -558,14 +560,14 @@ async def test_called_auto_present_pred_single_match(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -615,13 +617,13 @@ async def test_called_auto_present_pred_multi_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -638,14 +640,14 @@ async def test_called_auto_present_pred_multi_match(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -715,13 +717,13 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ { "cred_info": { @@ -769,14 +771,14 @@ async def test_called_auto_present_multi_cred_match_reft(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -836,7 +838,7 @@ async def test_called_auto_present_bait_and_switch(self): auto_present=True, ) - by_reft = mock.AsyncMock( + by_reft = mock.CoroutineMock( return_value=[ { "cred_info": { @@ -870,7 +872,7 @@ async def test_called_auto_present_bait_and_switch(self): request_context.injector.bind_instance(IndyHolder, mock_holder) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -882,14 +884,14 @@ async def test_called_auto_present_bait_and_switch(self): 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 = mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.CoroutineMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -915,7 +917,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_request = mock.AsyncMock() + mock_pres_mgr.return_value.receive_request = mock.CoroutineMock() request_context.message = PresentationRequest() request_context.connection_ready = False handler = test_module.PresentationRequestHandler() @@ -934,7 +936,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py index c19035f3a1..55577fb6bb 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -131,7 +131,7 @@ async def test_save_error_state(self): await record.save(session) with mock.patch.object( - record, "save", mock.AsyncMock() + record, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: 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 5a8fa5c89c..5ff7ee0eeb 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py @@ -2,7 +2,7 @@ from time import time -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import ( @@ -221,11 +221,11 @@ async def asyncSetUp(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -241,7 +241,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -250,7 +250,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -263,14 +263,14 @@ async def asyncSetUp(self): injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), ) Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -285,7 +285,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -295,8 +295,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -309,7 +309,9 @@ async def asyncSetUp(self): Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) + self.verifier.verify_presentation = mock.CoroutineMock( + return_value=("true", []) + ) injector.bind_instance(IndyVerifier, self.verifier) self.manager = PresentationManager(self.profile) @@ -389,7 +391,7 @@ async def test_create_bound_request(self): presentation_proposal_dict=proposal.serialize(), role=V10PresentationExchange.ROLE_VERIFIER, ) - exchange.save = mock.AsyncMock() + exchange.save = mock.CoroutineMock() (ret_exchange, pres_req_msg) = await self.manager.create_bound_request( presentation_exchange_record=exchange, name=PROOF_REQ_NAME, @@ -455,7 +457,7 @@ async def test_create_presentation(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -498,7 +500,7 @@ async def test_create_presentation_proof_req_non_revoc_interval_none(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -559,7 +561,7 @@ async def test_create_presentation_self_asserted(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -592,8 +594,8 @@ async def test_create_presentation_self_asserted(self): async def test_create_presentation_no_revocation(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -610,7 +612,7 @@ async def test_create_presentation_no_revocation(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -623,7 +625,7 @@ async def test_create_presentation_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -633,7 +635,7 @@ async def test_create_presentation_no_revocation(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) with mock.patch.object( @@ -676,7 +678,7 @@ async def test_create_presentation_bad_revoc_state(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -690,7 +692,7 @@ async def test_create_presentation_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -700,14 +702,14 @@ async def test_create_presentation_bad_revoc_state(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( side_effect=IndyHolderError("Problem", {"message": "Nope"}) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -744,7 +746,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -771,7 +773,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -781,8 +783,8 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -794,7 +796,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -832,7 +834,7 @@ async def test_no_matching_creds_for_proof_req(self): nonce=PROOF_REQ_NONCE, profile=self.profile, ) - get_creds = mock.AsyncMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -840,7 +842,7 @@ async def test_no_matching_creds_for_proof_req(self): indy_proof_req, holder=self.holder ) - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1364,7 +1366,7 @@ async def test_receive_problem_report(self): ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex, mock.patch.object( self.profile, "session", @@ -1404,7 +1406,7 @@ async def test_receive_problem_report_x(self): with mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py index c4716e0df9..97781cc39e 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from marshmallow import ValidationError @@ -21,7 +21,7 @@ def setUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -71,7 +71,7 @@ async def test_presentation_exchange_list(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = mock.AsyncMock() + mock_presentation_exchange.query = mock.CoroutineMock() mock_presentation_exchange.query.return_value = [mock_presentation_exchange] mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { @@ -102,7 +102,7 @@ async def test_presentation_exchange_list_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = mock.AsyncMock( + mock_presentation_exchange.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -122,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 = mock.AsyncMock() + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_presentation_exchange.retrieve_by_id.side_effect = StorageNotFoundError @@ -141,11 +141,11 @@ async def test_presentation_exchange_credentials_x(self): IndyHolder, mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.CoroutineMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.CoroutineMock()) with mock.patch( ( @@ -173,7 +173,7 @@ async def test_presentation_exchange_credentials_list_single_referent(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=mock.AsyncMock( + get_credentials_for_presentation_request_by_referent=mock.CoroutineMock( return_value=returned_credentials ) ), @@ -209,7 +209,7 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): IndyHolder, mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) @@ -245,7 +245,7 @@ async def test_presentation_exchange_retrieve(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = mock.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.CoroutineMock() mock_pres_ex.retrieve_by_id.return_value = mock_pres_ex mock_pres_ex.serialize = mock.MagicMock() mock_pres_ex.serialize.return_value = {"thread_id": "sample-thread-id"} @@ -269,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 = mock.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex.retrieve_by_id.side_effect = StorageNotFoundError @@ -283,7 +283,7 @@ async def test_presentation_exchange_retrieve_x(self): mock_pres_ex_rec = mock.MagicMock( connection_id="abc123", thread_id="thid123", - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch( ( @@ -295,7 +295,9 @@ async def test_presentation_exchange_retrieve_x(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = mock.AsyncMock(return_value=mock_pres_ex_rec) + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock_pres_ex_rec + ) mock_pres_ex_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) @@ -304,7 +306,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -321,7 +323,7 @@ async def test_presentation_exchange_send_proposal(self): mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - mock.AsyncMock(return_value=mock_presentation_exchange_record) + mock.CoroutineMock(return_value=mock_presentation_exchange_record) ) mock_preview.return_value.deserialize.return_value = mock.MagicMock() @@ -333,7 +335,7 @@ async def test_presentation_exchange_send_proposal(self): ) async def test_presentation_exchange_send_proposal_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -343,7 +345,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 = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -351,7 +353,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -369,14 +371,14 @@ 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 = mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -393,12 +395,12 @@ async def test_presentation_exchange_send_proposal_x(self): mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -407,7 +409,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"comment": "dummy", "proof_request": {}} ) @@ -435,7 +437,7 @@ async def test_presentation_exchange_create_request(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = mock.AsyncMock() + mock_generate_nonce = mock.CoroutineMock() mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator @@ -445,7 +447,7 @@ async def test_presentation_exchange_create_request(self): "thread_id": "sample-thread-id" } mock_mgr = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_presentation_exchange ) ) @@ -458,7 +460,7 @@ async def test_presentation_exchange_create_request(self): ) async def test_presentation_exchange_create_request_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"comment": "dummy", "proof_request": {}} ) @@ -488,12 +490,12 @@ async def test_presentation_exchange_create_request_x(self): mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -502,7 +504,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -537,7 +539,7 @@ async def test_presentation_exchange_send_free_request(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_attach_decorator.data_base64 = mock.MagicMock( @@ -549,7 +551,7 @@ async def test_presentation_exchange_send_free_request(self): } mock_mgr = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_presentation_exchange ) ) @@ -562,7 +564,7 @@ async def test_presentation_exchange_send_free_request(self): ) async def test_presentation_exchange_send_free_request_not_found(self): - self.request.json = mock.AsyncMock(return_value={"connection_id": "dummy"}) + self.request.json = mock.CoroutineMock(return_value={"connection_id": "dummy"}) with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -571,14 +573,14 @@ async def test_presentation_exchange_send_free_request_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_not_ready(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": "dummy", "proof_request": {}} ) @@ -590,7 +592,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 = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -598,7 +600,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -632,21 +634,21 @@ async def test_presentation_exchange_send_free_request_x(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = mock.AsyncMock() + mock_generate_nonce = mock.CoroutineMock() mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - mock.AsyncMock( + mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) ) - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_attach_decorator.data_base64 = mock.MagicMock( @@ -657,20 +659,20 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -702,7 +704,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) mock_presentation_exchange.serialize = mock.MagicMock() @@ -710,12 +712,12 @@ async def test_presentation_exchange_send_bound_request(self): "thread_id": "sample-thread-id" } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - create_bound_request=mock.AsyncMock( + create_bound_request=mock.CoroutineMock( return_value=(mock_presentation_exchange, mock_presentation_request) ) ) @@ -728,7 +730,7 @@ async def test_presentation_exchange_send_bound_request(self): ) async def test_presentation_exchange_send_bound_request_not_found(self): - self.request.json = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -761,18 +763,18 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) - mock_connection_record.retrieve_by_id = mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.CoroutineMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_not_ready(self): - self.request.json = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -805,12 +807,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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -818,13 +820,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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -832,7 +834,7 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -846,7 +848,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -855,7 +857,7 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -889,7 +891,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock_presentation_exchange ) mock_presentation_exchange.serialize = mock.MagicMock() @@ -897,12 +899,12 @@ async def test_presentation_exchange_send_bound_request_x(self): "thread_id": "sample-thread-id", } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - create_bound_request=mock.AsyncMock( + create_bound_request=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -917,7 +919,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -929,14 +931,14 @@ async def test_presentation_exchange_send_presentation(self): self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -962,7 +964,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", @@ -972,11 +974,11 @@ async def test_presentation_exchange_send_presentation(self): ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - create_presentation=mock.AsyncMock( + create_presentation=mock.CoroutineMock( return_value=(mock_presentation_exchange, mock.MagicMock()) ) ) @@ -989,13 +991,13 @@ async def test_presentation_exchange_send_presentation(self): ) async def test_presentation_exchange_send_presentation_px_rec_not_found(self): - self.request.json = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1003,7 +1005,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -1032,14 +1034,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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -1047,7 +1049,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -1076,7 +1078,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", @@ -1084,7 +1086,7 @@ async def test_presentation_exchange_send_presentation_not_ready(self): ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) @@ -1092,7 +1094,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -1105,7 +1107,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -1114,7 +1116,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -1150,22 +1152,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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ), ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - create_presentation=mock.AsyncMock( + create_presentation=mock.CoroutineMock( side_effect=test_module.LedgerError() ) ) @@ -1204,7 +1206,7 @@ async def test_presentation_exchange_verify_presentation(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", @@ -1215,11 +1217,11 @@ async def test_presentation_exchange_verify_presentation(self): ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - verify_presentation=mock.AsyncMock( + verify_presentation=mock.CoroutineMock( return_value=mock_presentation_exchange.retrieve_by_id.return_value ) ) @@ -1232,13 +1234,13 @@ async def test_presentation_exchange_verify_presentation(self): 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1248,7 +1250,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -1261,7 +1263,7 @@ 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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -1276,14 +1278,14 @@ async def test_presentation_exchange_verify_presentation_x(self): self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1303,7 +1305,7 @@ async def test_presentation_exchange_verify_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", @@ -1311,16 +1313,16 @@ async def test_presentation_exchange_verify_presentation_x(self): serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.CoroutineMock( return_value=mock_connection_record ) mock_mgr = mock.MagicMock( - verify_presentation=mock.AsyncMock( + verify_presentation=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1339,7 +1341,7 @@ async def test_presentation_exchange_verify_presentation_x(self): ) async def test_presentation_exchange_problem_report(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} magic_report = mock.MagicMock() @@ -1360,8 +1362,8 @@ async def test_presentation_exchange_problem_report(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -1371,7 +1373,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -1389,7 +1391,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 = mock.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -1397,7 +1399,7 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} magic_report = mock.MagicMock() @@ -1417,7 +1419,7 @@ async def test_presentation_exchange_problem_report_x(self): ) as mock_response: # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = mock.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -1437,11 +1439,11 @@ async def test_presentation_exchange_remove(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=mock.AsyncMock(), + delete_record=mock.CoroutineMock(), ) ) @@ -1450,7 +1452,7 @@ async def test_presentation_exchange_remove(self): mock_response.assert_called_once_with({}) async def test_presentation_exchange_remove_not_found(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch( @@ -1464,7 +1466,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 = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError ) @@ -1484,11 +1486,11 @@ async def test_presentation_exchange_remove_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=mock.AsyncMock( + delete_record=mock.CoroutineMock( side_effect=test_module.StorageError() ), ) 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 63e3bc6ea7..3020607be9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py @@ -1,6 +1,6 @@ from copy import deepcopy from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from marshmallow import ValidationError from pyld import jsonld @@ -602,7 +602,7 @@ async def test_create_pres(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -645,7 +645,7 @@ async def test_create_pres_pd_schema_uri(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -687,7 +687,7 @@ async def test_create_pres_prover_proof_spec(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -755,7 +755,7 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=cred_list) + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), @@ -764,7 +764,7 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -849,7 +849,7 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=cred_list) + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), @@ -858,7 +858,7 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -932,7 +932,7 @@ async def test_create_pres_one_of_filter(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=cred_list) + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), @@ -941,7 +941,7 @@ async def test_create_pres_one_of_filter(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -982,7 +982,7 @@ async def test_create_pres_no_challenge(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -1023,7 +1023,7 @@ async def test_create_pres_storage_not_found(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1070,7 +1070,7 @@ async def test_create_pres_pd_claim_format_ed255(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1113,7 +1113,7 @@ async def test_create_pres_pd_claim_format_bls12381g2(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1164,7 +1164,9 @@ async def test_verify_pres_sequence(self): with mock.patch.object( test_module, "verify_presentation", - mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), + mock.CoroutineMock( + return_value=PresentationVerificationResult(verified=True) + ), ): output = await self.handler.verify_pres(record) assert output.verified @@ -1172,7 +1174,9 @@ async def test_verify_pres_sequence(self): with mock.patch.object( test_module, "verify_presentation", - mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), + mock.CoroutineMock( + return_value=PresentationVerificationResult(verified=False) + ), ): output = await self.handler.verify_pres(record) assert output.verified == "false" @@ -1217,7 +1221,9 @@ async def test_verify_pres(self): with mock.patch.object( test_module, "verify_presentation", - mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), + mock.CoroutineMock( + return_value=PresentationVerificationResult(verified=True) + ), ) as mock_vr: output = await self.handler.verify_pres(record) assert output.verified @@ -1408,7 +1414,7 @@ async def test_create_pres_cred_no_tag_query(self): with mock.patch.object( DIFPresExchHandler, "create_vp", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -2325,7 +2331,7 @@ async def test_create_pres_catch_diferror(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=cred_list) + fetch=mock.CoroutineMock(return_value=cred_list) ) ) ), 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 0f1b42277e..57ee46f7ac 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -18,7 +18,7 @@ async def test_called(self): session = request_context.session() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -27,7 +27,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.CoroutineMock() request_context.message = V20PresAck() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -49,7 +49,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.CoroutineMock() request_context.message = V20PresAck() request_context.connection_ready = False handler = test_module.V20PresAckHandler() @@ -65,7 +65,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py index 99371ec03e..03bd117c5d 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,14 +19,16 @@ async def test_called(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.CoroutineMock() request_context.message = V20Pres() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -47,15 +49,17 @@ async def test_called_auto_verify(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() - mock_pres_mgr.return_value.verify_pres = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.CoroutineMock() + mock_pres_mgr.return_value.verify_pres = mock.CoroutineMock() request_context.message = V20Pres() request_context.connection_ready = True request_context.connection_record = mock.MagicMock() @@ -76,7 +80,9 @@ async def test_called_auto_verify_x(self): oob_record = mock.MagicMock() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) + find_oob_record_for_inbound_message=mock.CoroutineMock( + return_value=oob_record + ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -84,10 +90,10 @@ async def test_called_auto_verify_x(self): test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value = mock.MagicMock( - receive_pres=mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + receive_pres=mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ), - verify_pres=mock.AsyncMock(side_effect=test_module.LedgerError()), + verify_pres=mock.CoroutineMock(side_effect=test_module.LedgerError()), ) request_context.message = V20Pres() 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 998cd77c37..2984b2ec9f 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -19,7 +19,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock() request_context.message = V20PresProblemReport( description={ "en": "Change of plans", @@ -44,7 +44,7 @@ async def test_called_x(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.CoroutineMock( 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 87cc342853..b8de7f3e55 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -20,7 +20,7 @@ async def test_called(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( return_value=mock.MagicMock() ) request_context.message = V20PresProposal() @@ -47,10 +47,10 @@ async def test_called_auto_request(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( return_value=( mock_pres_mgr.return_value.receive_pres_proposal.return_value, "presentation_request_message", @@ -86,10 +86,10 @@ async def test_called_auto_request_x(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) - mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.CoroutineMock( side_effect=test_module.LedgerError() ) @@ -112,7 +112,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.CoroutineMock() request_context.message = V20PresProposal() request_context.connection_ready = False handler = test_module.V20PresProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py index 588d747632..9a493027a7 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -192,7 +192,7 @@ async def test_called(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -219,11 +219,11 @@ async def test_called(self): ) 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 = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock.MagicMock(auto_present=False) ) @@ -251,7 +251,7 @@ async def test_called_not_found(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -278,12 +278,12 @@ async def test_called_not_found(self): ) 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 = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( side_effect=StorageNotFoundError ) mock_px_rec_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock.MagicMock(auto_present=False) ) @@ -322,17 +322,17 @@ async def test_called_auto_present_x(self): mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) @@ -344,14 +344,14 @@ async def test_called_auto_present_x(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( side_effect=test_module.IndyHolderError() ) @@ -374,7 +374,7 @@ async def test_called_auto_present_indy(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -398,7 +398,7 @@ async def test_called_auto_present_indy(self): mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) + mock.CoroutineMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) @@ -409,14 +409,14 @@ async def test_called_auto_present_indy(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(mock_px_rec, "pres message") ) @@ -455,7 +455,7 @@ async def test_called_auto_present_dif(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -481,14 +481,14 @@ async def test_called_auto_present_dif(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -526,14 +526,14 @@ async def test_called_auto_present_no_preview(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -549,14 +549,14 @@ async def test_called_auto_present_no_preview(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -598,11 +598,11 @@ async def test_called_auto_present_pred_no_match(self): mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -610,7 +610,7 @@ async def test_called_auto_present_pred_no_match(self): mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[]) + mock.CoroutineMock(return_value=[]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) @@ -621,14 +621,14 @@ async def test_called_auto_present_pred_no_match(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( side_effect=test_indy_handler.V20PresFormatHandlerError ) request_context.connection_ready = True @@ -664,7 +664,7 @@ async def test_called_auto_present_pred_single_match(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -672,7 +672,9 @@ async def test_called_auto_present_pred_single_match(self): mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy-0"}}]) + mock.CoroutineMock( + return_value=[{"cred_info": {"referent": "dummy-0"}}] + ) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) @@ -683,14 +685,14 @@ async def test_called_auto_present_pred_single_match(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -730,7 +732,7 @@ async def test_called_auto_present_pred_multi_match(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -738,7 +740,7 @@ async def test_called_auto_present_pred_multi_match(self): mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -754,14 +756,14 @@ async def test_called_auto_present_pred_multi_match(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -809,7 +811,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( return_value=mock.MagicMock() ) ) @@ -817,7 +819,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock( + mock.CoroutineMock( return_value=[ { "cred_info": { @@ -868,14 +870,14 @@ async def test_called_auto_present_multi_cred_match_reft(self): 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.CoroutineMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -904,7 +906,7 @@ async def test_called_not_ready(self): with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_request = mock.CoroutineMock() request_context.message = V20PresRequest() request_context.connection_ready = False handler = test_module.V20PresRequestHandler() @@ -923,7 +925,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = mock.MagicMock( - find_oob_record_for_inbound_message=mock.AsyncMock( + find_oob_record_for_inbound_message=mock.CoroutineMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py index 977114228b..cf72950d84 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -128,7 +128,7 @@ async def test_save_error_state(self): await record.save(session) with mock.patch.object( - record, "save", mock.AsyncMock() + record, "save", mock.CoroutineMock() ) as mock_save, mock.patch.object( test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: 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 810858dba5..0a26daf14a 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py @@ -3,7 +3,7 @@ from copy import deepcopy from time import time -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -389,11 +389,11 @@ async def asyncSetUp(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -409,7 +409,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -418,7 +418,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -431,7 +431,7 @@ async def asyncSetUp(self): injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -439,7 +439,7 @@ async def asyncSetUp(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -454,7 +454,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -464,8 +464,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -478,7 +478,9 @@ async def asyncSetUp(self): Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) + self.verifier.verify_presentation = mock.CoroutineMock( + return_value=("true", []) + ) injector.bind_instance(IndyVerifier, self.verifier) self.manager = V20PresManager(self.profile) @@ -576,7 +578,7 @@ async def test_create_bound_request_a(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = mock.AsyncMock() + px_rec.save = mock.CoroutineMock() request_data = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -610,7 +612,7 @@ async def test_create_bound_request_b(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = mock.AsyncMock() + px_rec.save = mock.CoroutineMock() (ret_px_rec, pres_req_msg) = await self.manager.create_bound_request( pres_ex_record=px_rec, comment=comment, @@ -783,7 +785,7 @@ async def test_create_pres_indy(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -837,7 +839,7 @@ async def test_create_pres_indy_and_dif(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -894,7 +896,7 @@ async def test_create_pres_proof_req_non_revoc_interval_none(self): px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -905,7 +907,7 @@ async def test_create_pres_proof_req_non_revoc_interval_none(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex, mock.patch.object( @@ -950,7 +952,7 @@ async def test_create_pres_self_asserted(self): px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -985,8 +987,8 @@ async def test_create_pres_self_asserted(self): async def test_create_pres_no_revocation(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -1008,7 +1010,7 @@ async def test_create_pres_no_revocation(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1021,7 +1023,7 @@ async def test_create_pres_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1031,7 +1033,7 @@ async def test_create_pres_no_revocation(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) with mock.patch.object( @@ -1093,7 +1095,7 @@ async def test_create_pres_bad_revoc_state(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1107,7 +1109,7 @@ async def test_create_pres_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1117,8 +1119,8 @@ async def test_create_pres_bad_revoc_state(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( side_effect=test_indy_util_module.IndyHolderError( "Problem", {"message": "Nope"} ) @@ -1126,7 +1128,7 @@ async def test_create_pres_bad_revoc_state(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -1166,7 +1168,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": { @@ -1193,7 +1195,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = mock.AsyncMock( + self.holder.get_credential = mock.CoroutineMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1203,8 +1205,8 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = mock.AsyncMock( + self.holder.create_presentation = mock.CoroutineMock(return_value="{}") + self.holder.create_revocation_state = mock.CoroutineMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -1216,7 +1218,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock( + get_or_fetch_local_tails_path=mock.CoroutineMock( return_value="/tmp/sample/tails/path" ) ) @@ -1261,7 +1263,7 @@ async def test_no_matching_creds_for_proof_req(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = mock.AsyncMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -1269,7 +1271,7 @@ async def test_no_matching_creds_for_proof_req(self): INDY_PROOF_REQ_NAMES, preview=None, holder=self.holder ) - get_creds = mock.AsyncMock( + get_creds = mock.CoroutineMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1301,7 +1303,7 @@ async def test_no_matching_creds_indy_handler(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = mock.AsyncMock(return_value=()) + get_creds = mock.CoroutineMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with mock.patch.object( @@ -2126,7 +2128,7 @@ async def test_verify_pres(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() @@ -2186,7 +2188,7 @@ async def test_verify_pres_indy_and_dif(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() @@ -2196,14 +2198,18 @@ async def test_verify_pres_indy_and_dif(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), ), mock.patch( "aries_cloudagent.vc.vc_ld.verify.verify_presentation", - mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), + mock.CoroutineMock( + return_value=PresentationVerificationResult(verified=False) + ), ), mock.patch.object( IndyVerifier, "verify_presentation", - mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), + mock.CoroutineMock( + return_value=PresentationVerificationResult(verified=True) + ), ), mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex: @@ -2303,7 +2309,7 @@ async def test_receive_problem_report(self): ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex, mock.patch.object( self.profile, "session", @@ -2343,7 +2349,7 @@ async def test_receive_problem_report_x(self): with mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - mock.AsyncMock(), + mock.CoroutineMock(), ) as retrieve_ex: retrieve_ex.side_effect = StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py index b366b9c6ef..cbce0e26e9 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py @@ -1,6 +1,6 @@ from copy import deepcopy from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from marshmallow import ValidationError from time import time from unittest.mock import ANY @@ -132,11 +132,11 @@ def setUp(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_schema = mock.CoroutineMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.CoroutineMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -152,7 +152,7 @@ def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -161,7 +161,7 @@ def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.CoroutineMock( return_value=( { "ver": "1.0", @@ -174,7 +174,7 @@ def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -255,7 +255,7 @@ async def test_present_proof_list(self): ) 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.query = mock.CoroutineMock( return_value=[mock_pres_ex_rec_inst] ) @@ -275,7 +275,7 @@ async def test_present_proof_list_x(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.query = mock.AsyncMock( + mock_pres_ex_rec_cls.query = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -288,7 +288,7 @@ async def test_present_proof_credentials_list_not_found(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex_rec_cls.retrieve_by_id.side_effect = StorageNotFoundError() @@ -307,16 +307,16 @@ async def test_present_proof_credentials_x(self): IndyHolder, mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.CoroutineMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.CoroutineMock()) with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec ) @@ -335,7 +335,7 @@ async def test_present_proof_credentials_list_single_referent(self): IndyHolder, mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) @@ -346,7 +346,7 @@ async def test_present_proof_credentials_list_single_referent(self): test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.return_value = mock.MagicMock( - retrieve_by_id=mock.AsyncMock() + retrieve_by_id=mock.CoroutineMock() ) await test_module.present_proof_credentials_list(self.request) @@ -364,7 +364,7 @@ async def test_present_proof_credentials_list_multiple_referents(self): IndyHolder, mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - mock.AsyncMock(return_value=returned_credentials) + mock.CoroutineMock(return_value=returned_credentials) ) ), ) @@ -375,7 +375,7 @@ async def test_present_proof_credentials_list_multiple_referents(self): test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.return_value = mock.MagicMock( - retrieve_by_id=mock.AsyncMock() + retrieve_by_id=mock.CoroutineMock() ) await test_module.present_proof_credentials_list(self.request) @@ -394,7 +394,9 @@ async def test_present_proof_credentials_list_dif(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -402,7 +404,7 @@ async def test_present_proof_credentials_list_dif(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -464,7 +466,9 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -472,7 +476,7 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -550,7 +554,9 @@ async def test_present_proof_credentials_dif_no_tag_query(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -558,7 +564,7 @@ async def test_present_proof_credentials_dif_no_tag_query(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -626,7 +632,9 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -634,7 +642,7 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -702,7 +710,9 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -710,7 +720,7 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -803,12 +813,14 @@ async def test_present_proof_credentials_single_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( VCHolder, - mock.MagicMock(search_credentials=mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) with mock.patch.object( @@ -864,12 +876,14 @@ async def test_present_proof_credentials_double_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( VCHolder, - mock.MagicMock(search_credentials=mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) with mock.patch.object( @@ -922,12 +936,14 @@ async def test_present_proof_credentials_list_limit_disclosure_no_bbs(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( VCHolder, - mock.MagicMock(search_credentials=mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) with mock.patch.object( @@ -983,12 +999,14 @@ async def test_present_proof_credentials_no_ldp_vp(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( VCHolder, - mock.MagicMock(search_credentials=mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.CoroutineMock()), ) with mock.patch.object( @@ -1046,7 +1064,9 @@ async def test_present_proof_credentials_list_schema_uri(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -1054,7 +1074,7 @@ async def test_present_proof_credentials_list_schema_uri(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock(return_value=returned_credentials) + fetch=mock.CoroutineMock(return_value=returned_credentials) ) ) ), @@ -1083,7 +1103,9 @@ async def test_present_proof_credentials_list_dif_error(self): self.profile.context.injector.bind_instance( IndyHolder, mock.MagicMock( - get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) + get_credentials_for_presentation_request_by_referent=( + mock.CoroutineMock() + ) ), ) self.profile.context.injector.bind_instance( @@ -1091,7 +1113,7 @@ async def test_present_proof_credentials_list_dif_error(self): mock.MagicMock( search_credentials=mock.MagicMock( return_value=mock.MagicMock( - fetch=mock.AsyncMock( + fetch=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1144,7 +1166,7 @@ async def test_present_proof_retrieve(self): ) 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 = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} @@ -1161,7 +1183,7 @@ async def test_present_proof_retrieve_not_found(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1175,12 +1197,12 @@ async def test_present_proof_retrieve_x(self): connection_id="abc123", thread_id="thid123", serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_pres_ex_rec_inst ) @@ -1188,7 +1210,7 @@ async def test_present_proof_retrieve_x(self): await test_module.present_proof_retrieve(self.request) async def test_present_proof_send_proposal(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy-conn-id", "presentation_proposal": { @@ -1206,12 +1228,12 @@ async def test_present_proof_send_proposal(self): ) 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 = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock(is_ready=True) ) mock_px_rec_inst = mock.MagicMock() - mock_pres_mgr.return_value.create_exchange_for_proposal = mock.AsyncMock( - return_value=mock_px_rec_inst + mock_pres_mgr.return_value.create_exchange_for_proposal = ( + mock.CoroutineMock(return_value=mock_px_rec_inst) ) await test_module.present_proof_send_proposal(self.request) @@ -1220,12 +1242,12 @@ async def test_present_proof_send_proposal(self): ) async def test_present_proof_send_proposal_no_conn_record(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.retrieve_by_id = mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1233,14 +1255,14 @@ 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 = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresProposal", autospec=True ) as mock_proposal: - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock(is_ready=False) ) @@ -1248,17 +1270,21 @@ async def test_present_proof_send_proposal_not_ready(self): await test_module.present_proof_send_proposal(self.request) async def test_present_proof_send_proposal_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "ConnRecord", autospec=True ) 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 = mock.AsyncMock( - return_value=mock.MagicMock( - serialize=mock.MagicMock(side_effect=test_module.StorageError()), - save_error_state=mock.AsyncMock(), + mock_pres_mgr.return_value.create_exchange_for_proposal = ( + mock.CoroutineMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( + side_effect=test_module.StorageError() + ), + save_error_state=mock.CoroutineMock(), + ) ) ) @@ -1269,7 +1295,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: indy_proof_req}, @@ -1287,7 +1313,7 @@ async def test_present_proof_create_request(self): serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) mock_pres_mgr_inst = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_px_rec_inst ) ) @@ -1299,7 +1325,7 @@ async def test_present_proof_create_request(self): ) async def test_present_proof_create_request_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: INDY_PROOF_REQ}, @@ -1315,12 +1341,12 @@ async def test_present_proof_create_request_x(self): ) as mock_response: mock_px_rec_inst = mock.MagicMock() mock_pres_mgr_inst = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -1330,7 +1356,7 @@ async def test_present_proof_create_request_x(self): await test_module.present_proof_create_request(self.request) async def test_present_proof_send_free_request(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1349,13 +1375,13 @@ async def test_present_proof_send_free_request(self): ) 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 = mock.AsyncMock() + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock() mock_px_rec_inst = mock.MagicMock( serialize=mock.MagicMock({"thread_id": "sample-thread-id"}) ) mock_pres_mgr_inst = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock_px_rec_inst ) ) @@ -1367,12 +1393,12 @@ async def test_present_proof_send_free_request(self): ) async def test_present_proof_send_free_request_not_found(self): - self.request.json = mock.AsyncMock(return_value={"connection_id": "dummy"}) + self.request.json = mock.CoroutineMock(return_value={"connection_id": "dummy"}) with mock.patch.object( test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1380,7 +1406,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"connection_id": "dummy", "proof_request": {}} ) @@ -1388,7 +1414,7 @@ async def test_present_proof_send_free_request_not_ready(self): test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: mock_conn_rec_inst = mock.MagicMock(is_ready=False) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) @@ -1396,7 +1422,7 @@ async def test_present_proof_send_free_request_not_ready(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1414,19 +1440,19 @@ async def test_present_proof_send_free_request_x(self): test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: mock_conn_rec_inst = mock.MagicMock() - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_px_rec_inst = mock.MagicMock( serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) mock_pres_mgr_inst = mock.MagicMock( - create_exchange_for_request=mock.AsyncMock( + create_exchange_for_request=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) ) ) @@ -1436,20 +1462,20 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1469,19 +1495,19 @@ async def test_present_proof_send_bound_request(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_request = mock.MagicMock() mock_pres_mgr_inst = mock.MagicMock( - create_bound_request=mock.AsyncMock( + create_bound_request=mock.CoroutineMock( return_value=(mock_px_rec_inst, mock_pres_request) ) ) @@ -1493,20 +1519,20 @@ async def test_present_proof_send_bound_request(self): ) async def test_present_proof_send_bound_request_not_found(self): - self.request.json = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1522,10 +1548,10 @@ async def test_present_proof_send_bound_request_not_found(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1533,20 +1559,20 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1562,13 +1588,13 @@ async def test_present_proof_send_bound_request_not_ready(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock( is_ready=False, ) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) @@ -1576,13 +1602,13 @@ async def test_present_proof_send_bound_request_not_ready(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_px_rec_not_found(self): - self.request.json = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1590,20 +1616,20 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1617,7 +1643,7 @@ async def test_present_proof_send_bound_request_bad_state(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -1625,20 +1651,20 @@ 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 = mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.CoroutineMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, mock.MagicMock( - __aenter__=mock.AsyncMock(), - __aexit__=mock.AsyncMock(), + __aenter__=mock.CoroutineMock(), + __aexit__=mock.CoroutineMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1655,20 +1681,20 @@ async def test_present_proof_send_bound_request_x(self): serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - create_bound_request=mock.AsyncMock( + create_bound_request=mock.CoroutineMock( side_effect=test_module.StorageError() ) ) @@ -1678,7 +1704,7 @@ async def test_present_proof_send_bound_request_x(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_presentation(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1694,7 +1720,7 @@ async def test_present_proof_send_presentation(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1714,17 +1740,17 @@ async def test_present_proof_send_presentation(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - create_pres=mock.AsyncMock( + create_pres=mock.CoroutineMock( return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) @@ -1738,7 +1764,7 @@ async def test_present_proof_send_presentation(self): async def test_present_proof_send_presentation_dif(self): proof_req = deepcopy(DIF_PROOF_REQ) proof_req["issuer_id"] = "test123" - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "dif": proof_req, } @@ -1749,7 +1775,7 @@ async def test_present_proof_send_presentation_dif(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1769,17 +1795,17 @@ async def test_present_proof_send_presentation_dif(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - create_pres=mock.AsyncMock( + create_pres=mock.CoroutineMock( return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) @@ -1791,7 +1817,7 @@ async def test_present_proof_send_presentation_dif(self): ) async def test_present_proof_send_presentation_dif_error(self): - self.request.json = mock.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) + self.request.json = mock.CoroutineMock(return_value={"dif": DIF_PROOF_REQ}) self.request.match_info = { "pres_ex_id": "dummy", } @@ -1826,7 +1852,7 @@ async def test_present_proof_send_presentation_dif_error(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1839,17 +1865,17 @@ async def test_present_proof_send_presentation_dif_error(self): ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=px_rec_instance ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - create_pres=mock.AsyncMock(side_effect=test_module.LedgerError()) + create_pres=mock.CoroutineMock(side_effect=test_module.LedgerError()) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1857,7 +1883,7 @@ async def test_present_proof_send_presentation_dif_error(self): mock_response.assert_called_once_with(px_rec_instance.serialize()) async def test_present_proof_send_presentation_px_rec_not_found(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1874,7 +1900,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) @@ -1883,7 +1909,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_presentation_not_found(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1899,7 +1925,7 @@ async def test_present_proof_send_presentation_not_found(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1915,12 +1941,12 @@ async def test_present_proof_send_presentation_not_found(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -1928,7 +1954,7 @@ async def test_present_proof_send_presentation_not_found(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_not_ready(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1944,7 +1970,7 @@ async def test_present_proof_send_presentation_not_ready(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -1960,12 +1986,12 @@ async def test_present_proof_send_presentation_not_ready(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock(is_ready=False) ) @@ -1973,7 +1999,7 @@ async def test_present_proof_send_presentation_not_ready(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_bad_state(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -1997,7 +2023,7 @@ async def test_present_proof_send_presentation_bad_state(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -2005,7 +2031,7 @@ async def test_present_proof_send_presentation_bad_state(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_x(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "indy": { "comment": "dummy", @@ -2021,7 +2047,7 @@ async def test_present_proof_send_presentation_x(self): self.profile.context.injector.bind_instance( IndyVerifier, mock.MagicMock( - verify_presentation=mock.AsyncMock(), + verify_presentation=mock.CoroutineMock(), ), ) @@ -2040,19 +2066,19 @@ async def test_present_proof_send_presentation_x(self): serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - create_pres=mock.AsyncMock( + create_pres=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2085,16 +2111,16 @@ async def test_present_proof_verify_presentation(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - verify_pres=mock.AsyncMock(return_value=mock_px_rec_inst) + verify_pres=mock.CoroutineMock(return_value=mock_px_rec_inst) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -2107,7 +2133,7 @@ async def test_present_proof_verify_presentation_px_rec_not_found(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError("no such record") ) @@ -2128,7 +2154,7 @@ async def test_present_proof_verify_presentation_bad_state(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) @@ -2153,18 +2179,18 @@ async def test_present_proof_verify_presentation_x(self): serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=mock.AsyncMock(), + save_error_state=mock.CoroutineMock(), ) - mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.CoroutineMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = mock.MagicMock( - verify_pres=mock.AsyncMock( + verify_pres=mock.CoroutineMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2179,7 +2205,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2194,8 +2220,8 @@ async def test_present_proof_problem_report(self): ) as mock_px_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec.retrieve_by_id = mock.AsyncMock( - return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) + mock_px_rec.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock(save_error_state=mock.CoroutineMock()) ) mock_problem_report.return_value = magic_report @@ -2205,7 +2231,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2213,7 +2239,7 @@ async def test_present_proof_problem_report_bad_pres_ex_id(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -2221,7 +2247,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2233,7 +2259,7 @@ async def test_present_proof_problem_report_x(self): ) as mock_problem_report, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=test_module.StorageError() ) @@ -2248,11 +2274,11 @@ async def test_present_proof_remove(self): ) as mock_px_rec, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec.retrieve_by_id = mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=mock.AsyncMock(), + delete_record=mock.CoroutineMock(), ) ) @@ -2265,7 +2291,7 @@ async def test_present_proof_remove_px_rec_not_found(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( side_effect=StorageNotFoundError() ) @@ -2278,11 +2304,11 @@ async def test_present_proof_remove_x(self): with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.CoroutineMock( return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=mock.AsyncMock( + delete_record=mock.CoroutineMock( side_effect=test_module.StorageError() ), ) @@ -2383,7 +2409,7 @@ async def test_retrieve_uri_list_from_schema_filter(self): assert test_one_of_uri_groups == [["test123", "test321"]] async def test_send_presentation_no_specification(self): - self.request.json = mock.AsyncMock(return_value={"comment": "test"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "test"}) self.request.match_info = { "pres_ex_id": "dummy", } diff --git a/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py index a544377ce7..4e4925cd61 100644 --- a/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from unittest import mock +from aries_cloudagent.tests import mock import pytest from .. import routes as test_module @@ -41,10 +41,10 @@ async def test_on_revocation_published(profile: Profile, responder: MockResponde """Test revocation published event handler.""" mock_rec = mock.MagicMock() mock_rec.cred_rev_id = "mock" - mock_rec.delete_record = mock.AsyncMock() + mock_rec.delete_record = mock.CoroutineMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -65,7 +65,7 @@ async def test_on_revocation_published_x_not_found( ): """Test revocation published event handler.""" MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(side_effect=StorageNotFoundError) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(side_effect=StorageNotFoundError) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -83,7 +83,7 @@ async def test_on_revocation_published_x_storage_error( ): """Test revocation published event handler.""" MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(side_effect=StorageError) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(side_effect=StorageError) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -99,10 +99,10 @@ async def test_on_revocation_published_x_storage_error( async def test_on_pending_cleared(profile: Profile): """Test pending revocation cleared event.""" mock_rec = mock.MagicMock() - mock_rec.delete_record = mock.AsyncMock() + mock_rec.delete_record = mock.CoroutineMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_CLEAR_PENDING_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock"}) diff --git a/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py index 6d9fff0b16..624f831119 100644 --- a/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from unittest import mock +from aries_cloudagent.tests import mock import pytest from .. import routes as test_module @@ -41,10 +41,10 @@ async def test_on_revocation_published(profile: Profile, responder: MockResponde """Test revocation published event handler.""" mock_rec = mock.MagicMock() mock_rec.cred_rev_id = "mock" - mock_rec.delete_record = mock.AsyncMock() + mock_rec.delete_record = mock.CoroutineMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -67,10 +67,10 @@ async def test_on_revocation_published_no_notify( """Test revocation published event handler.""" mock_rec = mock.MagicMock() mock_rec.cred_rev_id = "mock" - mock_rec.delete_record = mock.AsyncMock() + mock_rec.delete_record = mock.CoroutineMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -92,7 +92,7 @@ async def test_on_revocation_published_x_not_found( ): """Test revocation published event handler.""" MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(side_effect=StorageNotFoundError) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(side_effect=StorageNotFoundError) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -110,7 +110,7 @@ async def test_on_revocation_published_x_storage_error( ): """Test revocation published event handler.""" MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(side_effect=StorageError) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(side_effect=StorageError) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_PUBLISHED_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock", "crids": ["mock"]}) @@ -126,10 +126,10 @@ async def test_on_revocation_published_x_storage_error( async def test_on_pending_cleared(profile: Profile): """Test pending revocation cleared event.""" mock_rec = mock.MagicMock() - mock_rec.delete_record = mock.AsyncMock() + mock_rec.delete_record = mock.CoroutineMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.AsyncMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) topic = f"{REVOCATION_EVENT_PREFIX}{REVOCATION_CLEAR_PENDING_EVENT}::mock" event = Event(topic, {"rev_reg_id": "mock"}) 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 a645da0bd6..0e4947738c 100644 --- a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py +++ b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock import json from ......connections.models.connection_target import ConnectionTarget @@ -36,15 +36,17 @@ async def test_handle(self): ) as mock_connection_mgr, mock.patch.object( self.context.profile, "notify", autospec=True ) as mock_notify: - mock_mgr.return_value.get_recipient = mock.AsyncMock( + mock_mgr.return_value.get_recipient = mock.CoroutineMock( return_value=RouteRecord(connection_id="dummy") ) - mock_connection_mgr.return_value.get_connection_targets = mock.AsyncMock( - return_value=[ - ConnectionTarget( - recipient_keys=["recip_key"], - ) - ] + mock_connection_mgr.return_value.get_connection_targets = ( + mock.CoroutineMock( + return_value=[ + ConnectionTarget( + recipient_keys=["recip_key"], + ) + ] + ) ) await handler.handle(self.context, responder) @@ -78,7 +80,7 @@ async def test_handle_cannot_resolve_recipient(self): with mock.patch.object( test_module, "RoutingManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.get_recipient = mock.AsyncMock( + mock_mgr.return_value.get_recipient = mock.CoroutineMock( 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 a3a6b4af35..2f6ae835f4 100644 --- a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py +++ b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from marshmallow import ValidationError @@ -71,7 +71,7 @@ async def test_get_recipient_no_verkey(self): async def test_get_recipient_duplicate_routes(self): with mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageDuplicateError() with self.assertRaises(RouteNotFoundError) as context: @@ -80,7 +80,7 @@ async def test_get_recipient_duplicate_routes(self): async def test_get_recipient_no_routes(self): with mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() + RouteRecord, "retrieve_by_recipient_key", mock.CoroutineMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(RouteNotFoundError) as context: diff --git a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py index b69fb53b47..97cd67993a 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from .....admin.request_context import AdminRequestContext @@ -12,7 +12,7 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -22,11 +22,11 @@ def setUp(self): ) async def test_connections_send_ping(self): - self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module, "Ping", mock.MagicMock() ) as mock_ping, mock.patch.object( @@ -39,11 +39,11 @@ async def test_connections_send_ping(self): assert result is json_response.return_value async def test_connections_send_ping_no_conn(self): - self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as json_response: @@ -52,11 +52,11 @@ async def test_connections_send_ping_no_conn(self): await test_module.connections_send_ping(self.request) async def test_connections_send_ping_not_ready(self): - self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) + self.request.json = mock.CoroutineMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} with mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + test_module.ConnRecord, "retrieve_by_id", mock.CoroutineMock() ) as mock_retrieve, mock.patch.object( test_module.web, "json_response", mock.MagicMock() ) as json_response: diff --git a/aries_cloudagent/resolver/default/tests/test_indy.py b/aries_cloudagent/resolver/default/tests/test_indy.py index 128684b93f..d2344a2047 100644 --- a/aries_cloudagent/resolver/default/tests/test_indy.py +++ b/aries_cloudagent/resolver/default/tests/test_indy.py @@ -2,7 +2,7 @@ import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -32,13 +32,13 @@ def resolver(): def ledger(): """Ledger fixture.""" ledger = mock.MagicMock(spec=BaseLedger) - ledger.get_all_endpoints_for_did = mock.AsyncMock( + ledger.get_all_endpoints_for_did = mock.CoroutineMock( return_value={ "endpoint": "https://github.com/", "profile": "https://example.com/profile", } ) - ledger.get_key_for_did = mock.AsyncMock(return_value="key") + ledger.get_key_for_did = mock.CoroutineMock(return_value="key") yield ledger @@ -49,7 +49,7 @@ def profile(ledger): profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock(return_value=(None, ledger)) + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, ledger)) ), ) yield profile @@ -88,7 +88,7 @@ async def test_resolve_multitenant( with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=("test_ledger_id", ledger)), + mock.CoroutineMock(return_value=("test_ledger_id", ledger)), ): assert await resolver.resolve(profile, TEST_DID0) @@ -100,7 +100,7 @@ async def test_resolve_x_no_ledger( profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) + get_ledger_for_identifier=mock.CoroutineMock(return_value=(None, None)) ), ) with pytest.raises(ResolverError): @@ -128,7 +128,7 @@ async def test_supports_updated_did_sov_rules( "linked_domains": "https://example.com", } - ledger.get_all_endpoints_for_did = mock.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.CoroutineMock(return_value=example) assert await resolver.resolve(profile, TEST_DID0) @pytest.mark.asyncio @@ -141,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 = mock.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.CoroutineMock(return_value=example) result = await resolver.resolve(profile, TEST_DID0) assert "service" not in result diff --git a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py index b9f577b368..2acace6876 100644 --- a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py +++ b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py @@ -1,6 +1,6 @@ """Test LegacyPeerDIDResolver.""" -from unittest import mock +from aries_cloudagent.tests import mock import pydid import pytest @@ -39,7 +39,7 @@ async def test_supports(self, resolver: LegacyPeerDIDResolver, profile: Profile) """Test supports.""" with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = mock.MagicMock( - fetch_did_document=mock.AsyncMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -53,7 +53,7 @@ async def test_supports_no_cache( profile.context.injector.clear_binding(BaseCache) with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = mock.MagicMock( - fetch_did_document=mock.AsyncMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -73,7 +73,7 @@ async def test_supports_x_unknown_did( """Test supports returns false for unknown DID.""" with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = mock.MagicMock( - fetch_did_document=mock.AsyncMock(side_effect=StorageNotFoundError) + fetch_did_document=mock.CoroutineMock(side_effect=StorageNotFoundError) ) assert not await resolver.supports(profile, TEST_DID2) @@ -88,7 +88,7 @@ async def test_resolve(self, resolver: LegacyPeerDIDResolver, profile: Profile): doc = object() mock_corrections.apply = mock.MagicMock(return_value=doc) mock_mgr.return_value = mock.MagicMock( - fetch_did_document=mock.AsyncMock( + fetch_did_document=mock.CoroutineMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -113,9 +113,9 @@ async def test_resolve_x_not_found( doc = object mock_corrections.apply = mock.MagicMock(return_value=doc) mock_mgr.return_value = mock.MagicMock( - fetch_did_document=mock.AsyncMock(side_effect=StorageNotFoundError) + fetch_did_document=mock.CoroutineMock(side_effect=StorageNotFoundError) ) - resolver.supports = mock.AsyncMock(return_value=True) + resolver.supports = mock.CoroutineMock(return_value=True) result = await resolver.resolve(profile, TEST_DID0) assert result == doc diff --git a/aries_cloudagent/resolver/default/tests/test_universal.py b/aries_cloudagent/resolver/default/tests/test_universal.py index c6b5fe5073..05f3b89801 100644 --- a/aries_cloudagent/resolver/default/tests/test_universal.py +++ b/aries_cloudagent/resolver/default/tests/test_universal.py @@ -3,7 +3,7 @@ import re from typing import Dict, Union -from unittest import mock +from aries_cloudagent.tests import mock import pytest from ....config.settings import Settings @@ -125,7 +125,7 @@ async def test_get_supported_did_regex(): with mock.patch.object( UniversalResolver, "_fetch_resolver_props", - mock.AsyncMock(return_value=props), + mock.CoroutineMock(return_value=props), ): pattern = await UniversalResolver()._get_supported_did_regex() assert pattern.fullmatch("match a test string") @@ -172,7 +172,7 @@ async def test_setup_endpoint_set(resolver: UniversalResolver): with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - mock.AsyncMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) @@ -192,7 +192,7 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - mock.AsyncMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) @@ -208,7 +208,7 @@ async def test_setup_endpoint_unset(resolver: UniversalResolver): with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - mock.AsyncMock(return_value="pattern"), + mock.CoroutineMock(return_value="pattern"), ): await resolver.setup(context) diff --git a/aries_cloudagent/resolver/tests/test_routes.py b/aries_cloudagent/resolver/tests/test_routes.py index ca8bb55088..bdb1c2fd73 100644 --- a/aries_cloudagent/resolver/tests/test_routes.py +++ b/aries_cloudagent/resolver/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from unittest import mock +from aries_cloudagent.tests import mock from pydid import DIDDocument from ...core.in_memory import InMemoryProfile @@ -50,8 +50,10 @@ def mock_response(): @pytest.fixture def mock_resolver(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) + did_resolver.resolve = mock.CoroutineMock(return_value=did_doc) + did_resolver.resolve_with_metadata = mock.CoroutineMock( + return_value=resolution_result + ) yield did_resolver @@ -63,7 +65,7 @@ async def test_resolver(mock_resolver, mock_response: mock.MagicMock, did_doc): session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = mock.AsyncMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -73,7 +75,7 @@ async def test_resolver(mock_resolver, mock_response: mock.MagicMock, did_doc): "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=mock.AsyncMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with mock.patch.object( @@ -96,7 +98,7 @@ async def test_resolver(mock_resolver, mock_response: mock.MagicMock, did_doc): ], ) async def test_resolver_not_found_error(mock_resolver, side_effect, error): - mock_resolver.resolve_with_metadata = mock.AsyncMock(side_effect=side_effect()) + mock_resolver.resolve_with_metadata = mock.CoroutineMock(side_effect=side_effect()) profile = InMemoryProfile.test_profile() context = profile.context @@ -104,7 +106,7 @@ 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 = mock.AsyncMock() + outbound_message_router = mock.CoroutineMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -114,7 +116,7 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=mock.AsyncMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with mock.patch.object( 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 d7cf28721d..19f4e92e20 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py @@ -4,7 +4,7 @@ from os.path import join from typing import Any, Mapping, Type -from unittest import mock +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile, InMemoryProfileSession @@ -62,13 +62,13 @@ async def asyncSetUp(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.send_revoc_reg_def = mock.AsyncMock() - self.ledger.send_revoc_reg_entry = mock.AsyncMock() + self.ledger.send_revoc_reg_def = mock.CoroutineMock() + self.ledger.send_revoc_reg_entry = mock.CoroutineMock() self.profile.context.injector.bind_instance(BaseLedger, self.ledger) TailsServer = mock.MagicMock(BaseTailsServer, autospec=True) self.tails_server = TailsServer() - self.tails_server.upload_tails_file = mock.AsyncMock( + self.tails_server.upload_tails_file = mock.CoroutineMock( return_value=(True, "http://1.2.3.4:8088/rev-reg-id") ) self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server) @@ -173,7 +173,7 @@ def handle(self): if self.handle_counter == 0: self.handle_counter = self.handle_counter + 1 return mock.MagicMock( - fetch=mock.AsyncMock( + fetch=mock.CoroutineMock( return_value=mock.MagicMock( value_json=json.dumps(mock_cred_def) ) @@ -181,7 +181,7 @@ def handle(self): ) else: return mock.MagicMock( - fetch=mock.AsyncMock( + fetch=mock.CoroutineMock( 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 = mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.CoroutineMock( return_value=( _test_rev_reg_delta, 1234567890, ) ) - self.ledger.send_revoc_reg_entry = mock.AsyncMock( + self.ledger.send_revoc_reg_entry = mock.CoroutineMock( return_value={ "result": {"...": "..."}, }, @@ -233,7 +233,7 @@ def handle(self): with mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - mock.AsyncMock( + mock.CoroutineMock( return_value=[ test_module.IssuerCredRevRecord( record_id=test_module.UUID4_EXAMPLE, @@ -247,11 +247,11 @@ def handle(self): ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - mock.AsyncMock(return_value=rec), + mock.CoroutineMock(return_value=rec), ), mock.patch.object( test_module, "generate_ledger_rrrecovery_txn", - mock.AsyncMock(return_value=rev_reg_delta), + mock.CoroutineMock(return_value=rev_reg_delta), ): assert ( _test_rev_reg_delta, @@ -278,7 +278,7 @@ async def test_generate_registry_etc(self): self.profile.context.injector.bind_instance(IndyIssuer, issuer) with mock.patch.object( - issuer, "create_and_store_revocation_registry", mock.AsyncMock() + issuer, "create_and_store_revocation_registry", mock.CoroutineMock() ) as mock_create_store_rr: mock_create_store_rr.side_effect = IndyIssuerError("Not this time") diff --git a/aries_cloudagent/revocation/tests/test_indy.py b/aries_cloudagent/revocation/tests/test_indy.py index ccdf3e2a46..256b80a04e 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -26,15 +26,15 @@ def setUp(self): Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_credential_definition = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( return_value={"value": {"revocation": True}} ) - self.ledger.get_revoc_reg_def = mock.AsyncMock() + self.ledger.get_revoc_reg_def = mock.CoroutineMock() self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, mock.MagicMock( - get_ledger_for_identifier=mock.AsyncMock( + get_ledger_for_identifier=mock.CoroutineMock( return_value=(None, self.ledger) ) ), @@ -61,7 +61,7 @@ async def test_init_issuer_registry(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ): result = await self.revoc.init_issuer_registry(CRED_DEF_ID) assert result.cred_def_id == CRED_DEF_ID @@ -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 = mock.AsyncMock(return_value=None) + self.ledger.get_credential_definition = mock.CoroutineMock(return_value=None) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) with self.assertRaises(RevocationNotSupportedError) as x_revo: @@ -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 = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( 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 = mock.AsyncMock( + self.ledger.get_credential_definition = mock.CoroutineMock( 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 = mock.AsyncMock() + rec.generate_registry = mock.CoroutineMock() with mock.patch.object( - IssuerRevRegRecord, "retrieve_by_revoc_reg_id", mock.AsyncMock() + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", mock.CoroutineMock() ) as mock_retrieve_by_rr_id: mock_retrieve_by_rr_id.return_value = rec await rec.generate_registry(self.profile, None) @@ -242,7 +242,7 @@ async def test_get_ledger_registry(self): with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - mock.AsyncMock(return_value=(None, self.ledger)), + mock.CoroutineMock(return_value=(None, self.ledger)), ), mock.patch.object( RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_from_def: diff --git a/aries_cloudagent/revocation/tests/test_manager.py b/aries_cloudagent/revocation/tests/test_manager.py index d51f41e0fc..f48cb70693 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.revocation.models.issuer_cred_rev_record import ( @@ -41,12 +41,12 @@ async def test_revoke_credential_publish(self): mock_issuer_rev_reg_record = mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, - send_entry=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), pending_pub=["2"], ) issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.revoke_credentials = mock.AsyncMock( + issuer.revoke_credentials = mock.CoroutineMock( return_value=( json.dumps( { @@ -66,24 +66,24 @@ async def test_revoke_credential_publish(self): with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve, mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): mock_retrieve.return_value = mock.MagicMock( rev_reg_id="dummy-rr-id", cred_rev_id=CRED_REV_ID ) mock_rev_reg = mock.MagicMock( - get_or_fetch_local_tails_path=mock.AsyncMock() + get_or_fetch_local_tails_path=mock.CoroutineMock() ) - revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=mock_issuer_rev_reg_record ) - revoc.return_value.get_ledger_registry = mock.AsyncMock( + revoc.return_value.get_ledger_registry = mock.CoroutineMock( return_value=mock_rev_reg ) @@ -102,7 +102,7 @@ async def test_revoke_cred_by_cxid_not_found(self): with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -123,7 +123,7 @@ async def test_revoke_credential_no_rev_reg_rec(self): ) with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: - revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=None ) @@ -135,7 +135,7 @@ 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 = mock.MagicMock(mark_pending=mock.AsyncMock()) + mock_issuer_rev_reg_record = mock.MagicMock(mark_pending=mock.CoroutineMock()) issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -152,9 +152,9 @@ async def test_revoke_credential_pend(self): ) as session, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): - revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.CoroutineMock( return_value=mock_issuer_rev_reg_record ) @@ -185,22 +185,24 @@ async def test_publish_pending_revocations_basic(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ) with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), + mock.CoroutineMock(return_value=[mock_issuer_rev_reg_record]), ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), ): issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( + side_effect=deltas + ) - issuer.revoke_credentials = mock.AsyncMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -231,33 +233,35 @@ async def test_publish_pending_revocations_1_rev_reg_all(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), 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=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - mock.AsyncMock( + mock.CoroutineMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( + side_effect=deltas + ) - issuer.revoke_credentials = mock.AsyncMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -289,33 +293,35 @@ async def test_publish_pending_revocations_1_rev_reg_some(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), 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=mock.AsyncMock(), - clear_pending=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), + clear_pending=mock.CoroutineMock(), ), ] with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - mock.AsyncMock( + mock.CoroutineMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): issuer = mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) + issuer.merge_revocation_registry_deltas = mock.CoroutineMock( + side_effect=deltas + ) - issuer.revoke_credentials = mock.AsyncMock( + issuer.revoke_credentials = mock.CoroutineMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -331,19 +337,19 @@ async def test_clear_pending(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), ] with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations() assert result == {} @@ -354,19 +360,19 @@ async def test_clear_pending_1_rev_reg_all(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), 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=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), ] with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: None}) assert result == { @@ -380,19 +386,19 @@ async def test_clear_pending_1_rev_reg_some(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), 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=mock.AsyncMock(), + clear_pending=mock.CoroutineMock(), ), ] with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: ["9"]}) assert result == { diff --git a/aries_cloudagent/revocation/tests/test_routes.py b/aries_cloudagent/revocation/tests/test_routes.py index 7c65b16e94..a8b75df27b 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -1,10 +1,9 @@ import os import shutil -import unittest from aiohttp.web import HTTPBadRequest, HTTPNotFound from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.revocation.error import RevocationError @@ -20,7 +19,7 @@ def setUp(self): setattr(self.context, "profile", self.profile) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -75,7 +74,7 @@ async def test_validate_cred_rev_rec_qs_and_revoke_req(self): ) async def test_revoke(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -88,14 +87,14 @@ async def test_revoke(self): ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = mock.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.CoroutineMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_by_cred_ex_id(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "cred_ex_id": "dummy-cxid", "publish": "false", @@ -107,14 +106,14 @@ async def test_revoke_by_cred_ex_id(self): ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = mock.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.CoroutineMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_not_found(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -127,7 +126,7 @@ async def test_revoke_not_found(self): ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = mock.AsyncMock( + mock_mgr.return_value.revoke_credential = mock.CoroutineMock( side_effect=test_module.StorageNotFoundError() ) @@ -135,14 +134,14 @@ async def test_revoke_not_found(self): await test_module.revoke(self.request) async def test_publish_revocations(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - pub_pending = mock.AsyncMock() + pub_pending = mock.CoroutineMock() mock_mgr.return_value.publish_pending_revocations = pub_pending await test_module.publish_revocations(self.request) @@ -152,26 +151,26 @@ async def test_publish_revocations(self): ) async def test_publish_revocations_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr: - pub_pending = mock.AsyncMock(side_effect=test_module.RevocationError()) + pub_pending = mock.CoroutineMock(side_effect=test_module.RevocationError()) mock_mgr.return_value.publish_pending_revocations = pub_pending with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.publish_revocations(self.request) async def test_clear_pending_revocations(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = mock.AsyncMock() + clear_pending = mock.CoroutineMock() mock_mgr.return_value.clear_pending_revocations = clear_pending await test_module.clear_pending_revocations(self.request) @@ -181,14 +180,14 @@ async def test_clear_pending_revocations(self): ) async def test_clear_pending_revocations_x(self): - self.request.json = mock.AsyncMock() + self.request.json = mock.CoroutineMock() with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = mock.AsyncMock(side_effect=test_module.StorageError()) + clear_pending = mock.CoroutineMock(side_effect=test_module.StorageError()) mock_mgr.return_value.clear_pending_revocations = clear_pending with self.assertRaises(test_module.web.HTTPBadRequest): @@ -196,7 +195,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -212,9 +211,9 @@ async def test_create_rev_reg(self): ) as mock_json_response: mock_find.return_value = True mock_indy_revoc.return_value = mock.MagicMock( - init_issuer_registry=mock.AsyncMock( + init_issuer_registry=mock.CoroutineMock( return_value=mock.MagicMock( - generate_registry=mock.AsyncMock(), + generate_registry=mock.CoroutineMock(), serialize=mock.MagicMock(return_value="dummy"), ) ) @@ -226,7 +225,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -246,7 +245,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -262,7 +261,7 @@ async def test_create_rev_reg_no_revo_support(self): ) as mock_json_response: mock_find = True mock_indy_revoc.return_value = mock.MagicMock( - init_issuer_registry=mock.AsyncMock( + init_issuer_registry=mock.CoroutineMock( side_effect=test_module.RevocationNotSupportedError( error_code="dummy" ) @@ -282,7 +281,7 @@ async def test_rev_regs_created(self): } with mock.patch.object( - test_module.IssuerRevRegRecord, "query", mock.AsyncMock() + test_module.IssuerRevRegRecord, "query", mock.CoroutineMock() ) as mock_query, mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: @@ -304,7 +303,7 @@ async def test_get_rev_reg(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value="dummy") ) @@ -327,7 +326,7 @@ async def test_get_rev_reg_not_found(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -345,11 +344,11 @@ async def test_get_rev_reg_issued(self): with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve, mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_query, mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: @@ -368,7 +367,7 @@ async def test_get_rev_reg_issued_x(self): with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -389,7 +388,7 @@ async def test_get_cred_rev_record(self): with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve, mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: @@ -409,7 +408,7 @@ async def test_get_cred_rev_record_by_cred_ex_id(self): with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve, mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: @@ -427,7 +426,7 @@ async def test_get_cred_rev_record_not_found(self): ) CRED_REV_ID = "1" - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "rev_reg_id": REV_REG_ID, "cred_rev_id": CRED_REV_ID, @@ -437,7 +436,7 @@ async def test_get_cred_rev_record_not_found(self): with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") with self.assertRaises(test_module.web.HTTPNotFound): @@ -453,7 +452,7 @@ async def test_get_active_rev_reg(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_active_issuer_rev_reg_record=mock.AsyncMock( + get_active_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( serialize=mock.MagicMock(return_value="dummy") ) @@ -474,7 +473,7 @@ async def test_get_active_rev_reg_not_found(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_active_issuer_rev_reg_record=mock.AsyncMock( + get_active_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -495,7 +494,7 @@ async def test_get_tails_file(self): test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock(tails_local_path="dummy") ) ) @@ -516,7 +515,7 @@ async def test_get_tails_file_not_found(self): test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -536,9 +535,9 @@ async def test_upload_tails_file_basic(self): ) as mock_indy_revoc, mock.patch.object( test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_upload = mock.AsyncMock() + mock_upload = mock.CoroutineMock() mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, @@ -561,7 +560,7 @@ async def test_upload_tails_file_no_local_tails_file(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=False, @@ -581,9 +580,9 @@ async def test_upload_tails_file_fail(self): with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_upload = mock.AsyncMock(side_effect=RevocationError("test")) + mock_upload = mock.CoroutineMock(side_effect=RevocationError("test")) mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, @@ -607,10 +606,10 @@ async def test_send_rev_reg_def(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - send_def=mock.AsyncMock(), - send_entry=mock.AsyncMock(), + send_def=mock.CoroutineMock(), + send_entry=mock.CoroutineMock(), serialize=mock.MagicMock(return_value="dummy"), ) ) @@ -632,7 +631,7 @@ async def test_send_rev_reg_def_not_found(self): test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -651,9 +650,9 @@ async def test_send_rev_reg_def_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - send_def=mock.AsyncMock( + send_def=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -675,9 +674,9 @@ async def test_send_rev_reg_entry(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - send_entry=mock.AsyncMock(), + send_entry=mock.CoroutineMock(), serialize=mock.MagicMock(return_value="dummy"), ) ) @@ -699,7 +698,7 @@ async def test_send_rev_reg_entry_not_found(self): test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -718,9 +717,9 @@ async def test_send_rev_reg_entry_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - send_entry=mock.AsyncMock( + send_entry=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -735,7 +734,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -747,10 +746,10 @@ async def test_update_rev_reg(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - set_tails_file_public_uri=mock.AsyncMock(), - save=mock.AsyncMock(), + set_tails_file_public_uri=mock.CoroutineMock(), + save=mock.CoroutineMock(), serialize=mock.MagicMock(return_value="dummy"), ) ) @@ -765,7 +764,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -777,7 +776,7 @@ async def test_update_rev_reg_not_found(self): test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -791,7 +790,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -801,9 +800,9 @@ async def test_update_rev_reg_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - set_tails_file_public_uri=mock.AsyncMock( + set_tails_file_public_uri=mock.CoroutineMock( side_effect=test_module.RevocationError() ), ) @@ -818,7 +817,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", } @@ -833,10 +832,10 @@ async def test_set_rev_reg_state(self): test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( return_value=mock.MagicMock( - set_state=mock.AsyncMock(), - save=mock.AsyncMock(), + set_state=mock.CoroutineMock(), + save=mock.CoroutineMock(), serialize=mock.MagicMock(return_value="dummy"), ) ) @@ -851,7 +850,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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "max_cred_num": "1000", } @@ -866,7 +865,7 @@ async def test_set_rev_reg_state_not_found(self): test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = mock.MagicMock( - get_issuer_rev_reg_record=mock.AsyncMock( + get_issuer_rev_reg_record=mock.CoroutineMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -902,7 +901,7 @@ async def test_post_process_routes(self): assert "tags" in mock_app._state["swagger_dict"] -class TestDeleteTails(unittest.TestCase): +class TestDeleteTails(IsolatedAsyncioTestCase): def setUp(self): self.rev_reg_id = "rev_reg_id_123" self.cred_def_id = "cred_def_id_456" diff --git a/aries_cloudagent/settings/tests/test_routes.py b/aries_cloudagent/settings/tests/test_routes.py index 5e9fab046e..4c103bf2ba 100644 --- a/aries_cloudagent/settings/tests/test_routes.py +++ b/aries_cloudagent/settings/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ...admin.request_context import AdminRequestContext from ...core.in_memory import InMemoryProfile @@ -43,7 +43,7 @@ async def test_get_profile_settings(mock_response): } request = mock.MagicMock( query={}, - json=mock.AsyncMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) await test_module.get_profile_settings(request) @@ -73,7 +73,7 @@ async def test_get_profile_settings(mock_response): } request = mock.MagicMock( query={}, - json=mock.AsyncMock(return_value={}), + json=mock.CoroutineMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with mock.patch.object( @@ -122,7 +122,7 @@ async def test_update_profile_settings(mock_response): } request = mock.MagicMock( query={}, - json=mock.AsyncMock( + json=mock.CoroutineMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -163,7 +163,7 @@ async def test_update_profile_settings(mock_response): } request = mock.MagicMock( query={}, - json=mock.AsyncMock( + json=mock.CoroutineMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, diff --git a/aries_cloudagent/storage/tests/test_askar_storage.py b/aries_cloudagent/storage/tests/test_askar_storage.py index 0400c3f433..a7d9883273 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase @@ -50,15 +50,15 @@ class TestAskarStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.asyncio async def test_record(self): with mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -149,7 +149,7 @@ async def test_record(self): await storage.get_record("connection", None) with mock.patch.object( - test_module.non_secrets, "get_wallet_record", mock.AsyncMock() + test_module.non_secrets, "get_wallet_record", mock.CoroutineMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -160,15 +160,15 @@ async def test_record(self): with mock.patch.object( test_module.non_secrets, "update_wallet_record_value", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_update_value, mock.patch.object( test_module.non_secrets, "update_wallet_record_tags", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_update_tags, mock.patch.object( test_module.non_secrets, "delete_wallet_record", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -213,15 +213,15 @@ async def test_record(self): @pytest.mark.asyncio async def test_storage_search_x(self): with mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -250,9 +250,9 @@ async def test_storage_search_x(self): await search.fetch(10) with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -261,13 +261,13 @@ async def test_storage_search_x(self): await search.close() with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_indy_fetch, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -277,9 +277,9 @@ async def test_storage_search_x(self): await search.close() with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index ca8136f182..3649b914cf 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 +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...storage.error import ( @@ -182,7 +182,7 @@ async def test_search(self, store_search): # search again with with iterator mystery error search = store_search.search_records(record.type, {}, None) - with mock.patch.object(search, "fetch", mock.AsyncMock()) as mock_fetch: + with mock.patch.object(search, "fetch", mock.CoroutineMock()) as mock_fetch: mock_fetch.return_value = mock.MagicMock( pop=mock.MagicMock(side_effect=IndexError()) ) diff --git a/aries_cloudagent/storage/tests/test_indy_storage.py b/aries_cloudagent/storage/tests/test_indy_storage.py index 9b41966b6b..77e4c8f3e2 100644 --- a/aries_cloudagent/storage/tests/test_indy_storage.py +++ b/aries_cloudagent/storage/tests/test_indy_storage.py @@ -9,7 +9,7 @@ import indy.wallet from indy.error import ErrorCode -from unittest import mock +from aries_cloudagent.tests import mock from ...config.injection_context import InjectionContext from ...indy.sdk.profile import IndySdkProfileManager, IndySdkProfile @@ -67,15 +67,15 @@ async def test_record(self): "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -172,7 +172,7 @@ async def test_record(self): await storage.get_record("connection", None) with mock.patch.object( - indy.non_secrets, "get_wallet_record", mock.AsyncMock() + indy.non_secrets, "get_wallet_record", mock.CoroutineMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -183,15 +183,15 @@ async def test_record(self): with mock.patch.object( indy.non_secrets, "update_wallet_record_value", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_update_value, mock.patch.object( indy.non_secrets, "update_wallet_record_tags", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_update_tags, mock.patch.object( indy.non_secrets, "delete_wallet_record", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -238,15 +238,15 @@ async def test_storage_search_x(self): "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -280,9 +280,9 @@ async def test_storage_search_x(self): await search.fetch(10) with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -291,13 +291,13 @@ async def test_storage_search_x(self): await search.close() with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - mock.AsyncMock(), + mock.CoroutineMock(), ) as mock_indy_fetch, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -306,9 +306,9 @@ async def test_storage_search_x(self): await search.close() with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -318,15 +318,15 @@ async def test_storage_search_x(self): @pytest.mark.asyncio async def test_storage_del_close(self): with mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -346,9 +346,9 @@ async def test_storage_del_close(self): storage = session.inject(BaseStorage) with mock.patch.object( - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_open_search.return_value = 1 search = storage.search_records("connection") @@ -364,9 +364,9 @@ async def test_storage_del_close(self): mock_indy_close_search.assert_awaited_with(1) with mock.patch.object( # error on close - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") mock_indy_open_search.return_value = 1 @@ -376,9 +376,9 @@ async def test_storage_del_close(self): await search.close() with mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search, mock.patch.object( asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: @@ -402,9 +402,9 @@ async def test_storage_del_close(self): await coro with mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", mock.AsyncMock() + indy.non_secrets, "open_wallet_search", mock.CoroutineMock() ) as mock_indy_open_search, mock.patch.object( - indy.non_secrets, "close_wallet_search", mock.AsyncMock() + indy.non_secrets, "close_wallet_search", mock.CoroutineMock() ) as mock_indy_close_search, mock.patch.object( asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: diff --git a/aries_cloudagent/tails/tests/test_indy.py b/aries_cloudagent/tails/tests/test_indy.py index 305ee21703..1bbdcbefe4 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -30,7 +30,9 @@ async def test_upload(self): ) indy_tails = test_module.IndyTailsServer() - with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() + ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( context, @@ -48,7 +50,7 @@ async def test_upload_indy_sdk(self): profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - get_write_ledgers=mock.AsyncMock( + get_write_ledgers=mock.CoroutineMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -59,7 +61,9 @@ async def test_upload_indy_sdk(self): profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() + ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -77,7 +81,7 @@ async def test_upload_indy_vdr(self): profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - get_write_ledgers=mock.AsyncMock( + get_write_ledgers=mock.CoroutineMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -88,7 +92,9 @@ async def test_upload_indy_vdr(self): profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() + ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -109,7 +115,9 @@ async def test_upload_x(self): ) indy_tails = test_module.IndyTailsServer() - with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: + with mock.patch.object( + test_module, "put_file", mock.CoroutineMock() + ) 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/tests/mock.py b/aries_cloudagent/tests/mock.py new file mode 100644 index 0000000000..0df4f3bd3b --- /dev/null +++ b/aries_cloudagent/tests/mock.py @@ -0,0 +1,20 @@ +"""Mock utilities.""" +from unittest.mock import AsyncMock, MagicMock, patch, create_autospec, Mock, ANY + + +def CoroutineMock(*args, **kwargs): + """Return an AsyncMock that returns a MagicMock, unless return_value is set.""" + if "return_value" in kwargs: + return AsyncMock(*args, **kwargs) + return AsyncMock(*args, **kwargs, return_value=MagicMock()) + + +__all__ = [ + "CoroutineMock", + "AsyncMock", + "MagicMock", + "patch", + "create_autospec", + "Mock", + "ANY", +] diff --git a/aries_cloudagent/transport/inbound/tests/test_http_transport.py b/aries_cloudagent/transport/inbound/tests/test_http_transport.py index 0b3b582a79..2d6baaac6c 100644 --- a/aries_cloudagent/transport/inbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ import json from aiohttp.test_utils import AioHTTPTestCase, unused_port -from unittest import mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -61,7 +61,7 @@ def receive_message( message: InboundMessage, can_respond: bool = False, ): - message.wait_processing_complete = mock.AsyncMock() + message.wait_processing_complete = mock.CoroutineMock() self.message_results.append((message.payload, message.receipt, can_respond)) if self.result_event: self.result_event.set() @@ -76,7 +76,7 @@ async def test_start_x(self): test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: mock_site.return_value = mock.MagicMock( - start=mock.AsyncMock(side_effect=OSError()) + start=mock.CoroutineMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() @@ -114,19 +114,19 @@ async def test_send_message_outliers(self): test_message = {"test": "message"} with mock.patch.object( - test_module.HttpTransport, "create_session", mock.AsyncMock() + test_module.HttpTransport, "create_session", mock.CoroutineMock() ) as mock_session: mock_session.return_value = mock.MagicMock( - receive=mock.AsyncMock( + receive=mock.CoroutineMock( return_value=mock.MagicMock( receipt=mock.MagicMock(direct_response_requested=True), - wait_processing_complete=mock.AsyncMock(), + wait_processing_complete=mock.CoroutineMock(), ) ), can_respond=True, profile=InMemoryProfile.test_profile(), clear_response=mock.MagicMock(), - wait_response=mock.AsyncMock(return_value=b"Hello world"), + wait_response=mock.CoroutineMock(return_value=b"Hello world"), response_buffer="something", ) async with self.client.post("/", data=test_message) as resp: @@ -134,7 +134,9 @@ async def test_send_message_outliers(self): assert result == "Hello world" mock_session.return_value = mock.MagicMock( - receive=mock.AsyncMock(side_effect=test_module.WireFormatParseError()), + receive=mock.CoroutineMock( + side_effect=test_module.WireFormatParseError() + ), profile=InMemoryProfile.test_profile(), ) async with self.client.post("/", data=test_message) as resp: diff --git a/aries_cloudagent/transport/inbound/tests/test_manager.py b/aries_cloudagent/transport/inbound/tests/test_manager.py index e7192211e0..7c9d8c846e 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -59,8 +59,8 @@ async def test_setup(self): async def test_start_stop(self): transport = mock.MagicMock() - transport.start = mock.AsyncMock() - transport.stop = mock.AsyncMock() + transport.start = mock.CoroutineMock() + transport.stop = mock.CoroutineMock() mgr = InboundTransportManager(self.profile, None) mgr.register_transport(transport, "transport_cls") @@ -76,7 +76,7 @@ async def test_create_session(self): test_wire_format = mock.MagicMock() self.profile.context.injector.bind_instance(BaseWireFormat, test_wire_format) - test_inbound_handler = mock.AsyncMock() + test_inbound_handler = mock.CoroutineMock() mgr = InboundTransportManager(self.profile, test_inbound_handler) test_transport = "http" test_accept = True @@ -148,7 +148,7 @@ async def test_close_return(self): async def test_dispatch_complete_undelivered(self): mgr = InboundTransportManager(self.profile, None) test_wire_format = mock.MagicMock( - parse_message=mock.AsyncMock(return_value=("payload", "receipt")) + parse_message=mock.CoroutineMock(return_value=("payload", "receipt")) ) session = await mgr.create_session( "http", wire_format=test_wire_format, accept_undelivered=True diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index 51ce83811f..9992d4d174 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 +from aries_cloudagent.tests import mock from unittest import TestCase from ....admin.server import AdminResponder @@ -90,7 +90,7 @@ async def test_parse_inbound(self): test_session_id = "session-id" test_transport_type = "transport-type" test_wire_format = mock.MagicMock() - test_wire_format.parse_message = mock.AsyncMock() + test_wire_format.parse_message = mock.CoroutineMock() test_parsed = "parsed-payload" test_receipt = mock.MagicMock() test_wire_format.parse_message.return_value = (test_parsed, test_receipt) @@ -115,10 +115,10 @@ async def test_parse_inbound(self): async def test_receive(self): self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( + self.multitenant_mgr.get_wallets_by_message = mock.CoroutineMock( return_value=[mock.MagicMock(is_managed=True)] ) - self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.CoroutineMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -137,7 +137,7 @@ async def test_receive(self): test_msg = mock.MagicMock() with mock.patch.object( - sess, "parse_inbound", mock.AsyncMock() + sess, "parse_inbound", mock.CoroutineMock() ) as encode, mock.patch.object( sess, "receive_inbound", mock.MagicMock() ) as receive: @@ -148,10 +148,10 @@ async def test_receive(self): async def test_receive_no_wallet_found(self): self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( + self.multitenant_mgr.get_wallets_by_message = mock.CoroutineMock( side_effect=ValueError("no such wallet") ) - self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.CoroutineMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -168,7 +168,7 @@ async def test_receive_no_wallet_found(self): test_msg = mock.MagicMock() with mock.patch.object( - sess, "parse_inbound", mock.AsyncMock() + sess, "parse_inbound", mock.CoroutineMock() ) as encode, mock.patch.object( sess, "receive_inbound", mock.MagicMock() ) as receive: @@ -267,7 +267,7 @@ async def test_wait_response(self): assert sess.response_event.is_set() assert sess.response_buffered - with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: + with mock.patch.object(sess, "encode_outbound", mock.CoroutineMock()) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) assert encode.awaited_once_with(test_msg) assert result is encode.return_value @@ -290,7 +290,7 @@ async def test_wait_response_x(self): assert sess.response_event.is_set() assert sess.response_buffered - with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: + with mock.patch.object(sess, "encode_outbound", mock.CoroutineMock()) as encode: encode.side_effect = WireFormatError() with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(sess.wait_response(), 0.1) @@ -302,7 +302,7 @@ async def test_wait_response_x(self): async def test_encode_response(self): test_wire_format = mock.MagicMock() - test_wire_format.encode_message = mock.AsyncMock() + test_wire_format.encode_message = mock.CoroutineMock() sess = InboundSession( profile=self.profile, inbound_handler=None, diff --git a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py index 765b725fdc..dc58cd3485 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 +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile @@ -72,7 +72,7 @@ async def test_start_x(self): test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: mock_site.return_value = mock.MagicMock( - start=mock.AsyncMock(side_effect=OSError()) + start=mock.CoroutineMock(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 c7b203c38f..707d74c05d 100644 --- a/aries_cloudagent/transport/outbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ from aiohttp.test_utils import AioHTTPTestCase from aiohttp import web -from unittest import mock +from aries_cloudagent.tests import mock from ....core.in_memory import InMemoryProfile from ....utils.stats import Collector @@ -15,7 +15,7 @@ class TestHttpTransport(AioHTTPTestCase): - async def asyncSetUpAsync(self): + async def setUpAsync(self): self.profile = InMemoryProfile.test_profile() self.message_results = [] self.headers = {} @@ -135,7 +135,7 @@ async def test_transport_coverage(self): mock_response = mock.MagicMock(status=404) mock_session.post = mock.MagicMock( return_value=mock.MagicMock( - __aenter__=mock.AsyncMock(return_value=mock_response) + __aenter__=mock.CoroutineMock(return_value=mock_response) ) ) with pytest.raises(OutboundTransportError): diff --git a/aries_cloudagent/transport/outbound/tests/test_manager.py b/aries_cloudagent/transport/outbound/tests/test_manager.py index 9f6e1c551d..d2ea9c945f 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -54,10 +54,10 @@ async def test_send_message(self): mgr.register_class(transport_cls, "transport_cls") transport = mock.MagicMock() - transport.handle_message = mock.AsyncMock() - transport.wire_format.encode_message = mock.AsyncMock() - transport.start = mock.AsyncMock() - transport.stop = mock.AsyncMock() + transport.handle_message = mock.CoroutineMock() + transport.wire_format.encode_message = mock.CoroutineMock() + transport.start = mock.CoroutineMock() + transport.stop = mock.CoroutineMock() transport.schemes = ["http"] transport.is_external = False @@ -148,7 +148,7 @@ async def test_enqueue_webhook(self): transport_cls.schemes = ["http"] transport_cls.return_value = mock.MagicMock() transport_cls.return_value.schemes = ["http"] - transport_cls.return_value.start = mock.AsyncMock() + transport_cls.return_value.start = mock.CoroutineMock() tid = mgr.register_class(transport_cls, "transport_cls") await mgr.start_transport(tid) @@ -224,7 +224,7 @@ async def test_process_loop_retry_later(self): mgr.outbound_buffer.append(mock_queued) with mock.patch.object( - test_module.asyncio, "sleep", mock.AsyncMock() + test_module.asyncio, "sleep", mock.CoroutineMock() ) as mock_sleep_x: mock_sleep_x.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -245,7 +245,7 @@ async def test_process_loop_new(self): with mock.patch.object( mgr, "deliver_queued_message", mock.MagicMock() ) as mock_deliver, mock.patch.object( - mgr.outbound_event, "wait", mock.AsyncMock() + mgr.outbound_event, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( test_module, "trace_event", mock.MagicMock() ) as mock_trace: @@ -268,7 +268,7 @@ async def test_process_loop_new_deliver(self): with mock.patch.object( mgr, "deliver_queued_message", mock.MagicMock() ) as mock_deliver, mock.patch.object( - mgr.outbound_event, "wait", mock.AsyncMock() + mgr.outbound_event, "wait", mock.CoroutineMock() ) as mock_wait, mock.patch.object( test_module, "trace_event", mock.MagicMock() ) as mock_trace: @@ -315,9 +315,9 @@ 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 = mock.AsyncMock(return_value=encoded_msg) + base_wire_format.encode_message = mock.CoroutineMock(return_value=encoded_msg) profile = InMemoryProfile.test_profile(bind={BaseWireFormat: base_wire_format}) - profile.session = mock.AsyncMock(return_value=mock.MagicMock()) + profile.session = mock.CoroutineMock(return_value=mock.MagicMock()) outbound = mock.MagicMock(payload="payload", enc_payload=None) target = mock.MagicMock() diff --git a/aries_cloudagent/transport/outbound/tests/test_ws_transport.py b/aries_cloudagent/transport/outbound/tests/test_ws_transport.py index 2840790aa8..48697cf399 100644 --- a/aries_cloudagent/transport/outbound/tests/test_ws_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_ws_transport.py @@ -10,7 +10,7 @@ class TestWsTransport(AioHTTPTestCase): - async def asyncSetUpAsync(self): + async def setUpAsync(self): self.profile = InMemoryProfile.test_profile() self.message_results = [] await super().setUpAsync() diff --git a/aries_cloudagent/transport/queue/tests/test_basic_queue.py b/aries_cloudagent/transport/queue/tests/test_basic_queue.py index 969b578c94..88d9a42b6b 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from .. import basic as test_module @@ -40,7 +40,7 @@ async def test_dequeue_x(self): 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() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_wait.return_value = ( mock.MagicMock(), @@ -68,7 +68,7 @@ async def test_dequeue_none(self): 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() + test_module.asyncio, "wait", mock.CoroutineMock() ) as mock_wait: mock_wait.return_value = ( mock.MagicMock(), diff --git a/aries_cloudagent/transport/tests/test_pack_format.py b/aries_cloudagent/transport/tests/test_pack_format.py index a8a11fb892..e1f66fbb15 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 +from aries_cloudagent.tests import mock from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix @@ -54,7 +54,9 @@ async def test_errors(self): } serializer.task_queue = None - with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: + with mock.patch.object( + serializer, "unpack", mock.CoroutineMock() + ) 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)) @@ -62,7 +64,9 @@ async def test_errors(self): serializer = PackWireFormat() serializer.task_queue = None - with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: + with mock.patch.object( + serializer, "unpack", mock.CoroutineMock() + ) as mock_unpack: mock_unpack.return_value = json.dumps([1, 2, 3]) with self.assertRaises(WireFormatParseError) as context: await serializer.parse_message(self.session, json.dumps(x_message)) @@ -89,14 +93,14 @@ async def test_pack_x(self): ) mock_wallet = mock.MagicMock( - pack_message=mock.AsyncMock(side_effect=WalletError()) + pack_message=mock.CoroutineMock(side_effect=WalletError()) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], None, ["key"]) mock_wallet = mock.MagicMock( - pack_message=mock.AsyncMock( + pack_message=mock.CoroutineMock( side_effect=[json.dumps("message").encode("utf-8"), WalletError()] ) ) diff --git a/aries_cloudagent/utils/tests/test_http.py b/aries_cloudagent/utils/tests/test_http.py index b35a49ac25..6e2ff84adb 100644 --- a/aries_cloudagent/utils/tests/test_http.py +++ b/aries_cloudagent/utils/tests/test_http.py @@ -24,7 +24,7 @@ def __exit__(self, *args): class TestTransportUtils(AioHTTPTestCase): - async def asyncSetUpAsync(self): + async def setUpAsync(self): self.fail_calls = 0 self.succeed_calls = 0 self.redirects = 0 diff --git a/aries_cloudagent/utils/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py index e8e5e676ff..0d1a5cfd88 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 +from aries_cloudagent.tests import mock from unittest import IsolatedAsyncioTestCase from ..task_queue import CompletedTask, PendingTask, TaskQueue, task_exc_info @@ -109,7 +109,7 @@ async def noop(): with mock.patch.object( queue, "drain", mock.MagicMock() ) as mock_drain, mock.patch.object( - queue, "wait_for", mock.AsyncMock() + queue, "wait_for", mock.CoroutineMock() ) as mock_wait_for: mock_drain.side_effect = [queue.loop.create_task(noop()), None] await queue.complete(cleanup=True) 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 fbca22b3e0..e920fb9774 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock +from aries_cloudagent.tests import mock from aries_cloudagent.wallet.key_type import ED25519 @@ -33,7 +33,7 @@ async def test_sign(self): with mock.patch.object( InMemoryWallet, "sign_message", - mock.AsyncMock(return_value=signed), + mock.CoroutineMock(return_value=signed), ) as sign_message: singed_ret = await key_pair.sign(b"Message") @@ -60,7 +60,7 @@ async def test_verify(self): with mock.patch.object( InMemoryWallet, "verify_message", - mock.AsyncMock(return_value=True), + mock.CoroutineMock(return_value=True), ) as verify_message: verified = await key_pair.verify(b"Message", b"signature") diff --git a/aries_cloudagent/wallet/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index e1d049af6e..1da9d7968d 100644 --- a/aries_cloudagent/wallet/tests/test_indy_wallet.py +++ b/aries_cloudagent/wallet/tests/test_indy_wallet.py @@ -7,7 +7,7 @@ import indy.did import indy.wallet import pytest -from unittest import mock +from aries_cloudagent.tests import mock from ...config.injection_context import InjectionContext from ...core.error import ProfileDuplicateError, ProfileError, ProfileNotFoundError @@ -69,7 +69,7 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): ) with mock.patch.object( - indy.did, "replace_keys_start", mock.AsyncMock() + indy.did, "replace_keys_start", mock.CoroutineMock() ) as mock_repl_start: mock_repl_start.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -79,7 +79,7 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): assert "outlier" in str(excinfo.value) with mock.patch.object( - indy.did, "replace_keys_apply", mock.AsyncMock() + indy.did, "replace_keys_apply", mock.CoroutineMock() ) as mock_repl_apply: mock_repl_apply.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -91,7 +91,7 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_signing_key_x(self, wallet: IndySdkWallet): with mock.patch.object( - indy.crypto, "create_key", mock.AsyncMock() + indy.crypto, "create_key", mock.CoroutineMock() ) as mock_create_key: mock_create_key.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -103,7 +103,7 @@ async def test_create_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_local_did_x(self, wallet: IndySdkWallet): with mock.patch.object( - indy.did, "create_and_store_my_did", mock.AsyncMock() + indy.did, "create_and_store_my_did", mock.CoroutineMock() ) as mock_create: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -115,7 +115,7 @@ 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 = mock.MagicMock( - read_only=False, update_endpoint_for_did=mock.AsyncMock() + read_only=False, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did( SOV, @@ -143,7 +143,7 @@ async def test_set_did_endpoint_ledger_with_routing_keys( ): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] mock_ledger = mock.MagicMock( - read_only=False, update_endpoint_for_did=mock.AsyncMock() + read_only=False, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did(SOV, ED25519) await wallet.set_did_endpoint( @@ -162,7 +162,7 @@ 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 = mock.MagicMock( - read_only=True, update_endpoint_for_did=mock.AsyncMock() + read_only=True, update_endpoint_for_did=mock.CoroutineMock() ) info_pub = await wallet.create_public_did( SOV, @@ -180,7 +180,7 @@ 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 mock.patch.object( - indy.crypto, "get_key_metadata", mock.AsyncMock() + indy.crypto, "get_key_metadata", mock.CoroutineMock() ) as mock_signing: mock_signing.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -192,7 +192,7 @@ async def test_get_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_get_local_did_x(self, wallet: IndySdkWallet): with mock.patch.object( - indy.did, "get_my_did_with_meta", mock.AsyncMock() + indy.did, "get_my_did_with_meta", mock.CoroutineMock() ) as mock_my: mock_my.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -215,7 +215,7 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): assert info.metadata == self.test_metadata with mock.patch.object( - indy.did, "set_did_metadata", mock.AsyncMock() + indy.did, "set_did_metadata", mock.CoroutineMock() ) as mock_set_did_metadata: mock_set_did_metadata.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -227,7 +227,7 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_verify_message_x(self, wallet: IndySdkWallet): with mock.patch.object( - indy.crypto, "crypto_verify", mock.AsyncMock() + indy.crypto, "crypto_verify", mock.CoroutineMock() ) as mock_verify: mock_verify.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -251,7 +251,7 @@ async def test_verify_message_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_pack_message_x(self, wallet: IndySdkWallet): with mock.patch.object( - indy.crypto, "pack_message", mock.AsyncMock() + indy.crypto, "pack_message", mock.CoroutineMock() ) as mock_pack: mock_pack.side_effect = test_module.IndyError( # outlier test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -316,15 +316,15 @@ async def test_mock_coverage(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: fake_wallet = IndyWalletConfig( { @@ -364,15 +364,15 @@ async def test_mock_coverage_wallet_exists_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyExistsError @@ -410,15 +410,15 @@ async def test_mock_coverage_wallet_create_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -459,15 +459,15 @@ async def test_mock_coverage_remove_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_delete.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -512,15 +512,15 @@ async def test_mock_coverage_not_found_after_creation(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -562,15 +562,15 @@ async def test_mock_coverage_open_not_found(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -610,15 +610,15 @@ async def test_mock_coverage_open_indy_already_open_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyOpenedError, {"message": "outlier"} @@ -658,15 +658,15 @@ async def test_mock_coverage_open_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -706,15 +706,15 @@ async def test_mock_coverage_open_master_secret_x(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -756,15 +756,15 @@ async def test_mock_coverage_open_master_secret_exists(self): "load_postgres_plugin", mock.MagicMock(), ) as mock_load, mock.patch.object( - indy.wallet, "create_wallet", mock.AsyncMock() + indy.wallet, "create_wallet", mock.CoroutineMock() ) as mock_create, mock.patch.object( - indy.wallet, "open_wallet", mock.AsyncMock() + indy.wallet, "open_wallet", mock.CoroutineMock() ) as mock_open, mock.patch.object( - indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + indy.anoncreds, "prover_create_master_secret", mock.CoroutineMock() ) as mock_master, mock.patch.object( - indy.wallet, "close_wallet", mock.AsyncMock() + indy.wallet, "close_wallet", mock.CoroutineMock() ) as mock_close, mock.patch.object( - indy.wallet, "delete_wallet", mock.AsyncMock() + indy.wallet, "delete_wallet", mock.CoroutineMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.AnoncredsMasterSecretDuplicateNameError diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index ee0cdc7072..7c8f46104f 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -1,4 +1,4 @@ -import mock +from aries_cloudagent.tests import mock from aiohttp.web import HTTPForbidden from unittest import IsolatedAsyncioTestCase @@ -32,7 +32,7 @@ def setUp(self): self.context.injector.bind_instance(KeyTypes, KeyTypes()) self.request_dict = { "context": self.context, - "outbound_message_router": mock.AsyncMock(), + "outbound_message_router": mock.CoroutineMock(), } self.request = mock.MagicMock( app={}, @@ -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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "method": "madeupmethod", "options": {"key_type": "bls12381g2"}, @@ -155,7 +155,7 @@ async def test_create_did_unsupported_method(self): await test_module.wallet_create_did(self.request) async def test_create_did_unsupported_key_type(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"method": "sov", "options": {"key_type": "bls12381g2"}} ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -171,7 +171,7 @@ async def test_create_did_method_requires_user_defined_did(self): ) self.did_methods.register(did_custom) - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={"method": "custom", "options": {"key_type": "ed25519"}} ) @@ -189,7 +189,7 @@ async def test_create_did_method_doesnt_support_user_defined_did(self): self.did_methods.register(did_custom) # when - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "method": "custom", "options": { @@ -446,18 +446,20 @@ async def test_set_public_did(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = mock.AsyncMock() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock() + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = 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( + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -491,11 +493,13 @@ async def test_set_public_did_no_query_did(self): async def test_set_public_did_no_ledger(self): mock_route_manager = mock.MagicMock() - mock_route_manager.mediation_record_if_id = mock.AsyncMock() - mock_route_manager.routing_info = mock.AsyncMock( + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) self.request.query = {"did": self.test_did_sov} @@ -507,16 +511,18 @@ async def test_set_public_did_not_public(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = mock.AsyncMock(return_value=None) - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock(return_value=None) + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = mock.MagicMock() - mock_route_manager.mediation_record_if_id = mock.AsyncMock() - mock_route_manager.routing_info = mock.AsyncMock( + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with self.assertRaises(test_module.web.HTTPNotFound): @@ -527,16 +533,18 @@ async def test_set_public_did_not_found(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = mock.AsyncMock(return_value=None) - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.CoroutineMock(return_value=None) + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = mock.MagicMock() - mock_route_manager.mediation_record_if_id = mock.AsyncMock() - mock_route_manager.routing_info = mock.AsyncMock( + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + 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() @@ -548,17 +556,19 @@ async def test_set_public_did_x(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.get_key_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = mock.MagicMock() - mock_route_manager.mediation_record_if_id = mock.AsyncMock() - mock_route_manager.routing_info = mock.AsyncMock( + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -580,17 +590,19 @@ async def test_set_public_did_no_wallet_did(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.get_key_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = mock.MagicMock() - mock_route_manager.mediation_record_if_id = mock.AsyncMock() - mock_route_manager.routing_info = mock.AsyncMock( + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -612,18 +624,20 @@ async def test_set_public_did_update_endpoint(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.get_key_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = 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( + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -658,16 +672,20 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.get_key_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.get_key_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) mock_route_manager = 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) + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock( + return_value=None + ) + mock_route_manager.routing_info = mock.CoroutineMock(return_value=(None, None)) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -709,12 +727,14 @@ async def test_set_public_did_with_non_sov_did(self): self.request.query = {"did": self.test_did_web} 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( + mock_route_manager.route_verkey = mock.CoroutineMock() + mock_route_manager.mediation_record_if_id = mock.CoroutineMock() + mock_route_manager.routing_info = mock.CoroutineMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) + mock_route_manager.__aenter__ = mock.CoroutineMock( + return_value=mock_route_manager + ) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with mock.patch.object( @@ -745,7 +765,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -754,8 +774,8 @@ async def test_set_did_endpoint(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.get_local_did.return_value = DIDInfo( @@ -780,7 +800,7 @@ async def test_set_did_endpoint(self): json_response.assert_called_once_with({}) async def test_set_did_endpoint_public_did_no_ledger(self): - self.request.json = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -807,7 +827,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -816,8 +836,8 @@ async def test_set_did_endpoint_x(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletError() @@ -826,7 +846,7 @@ 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 = mock.AsyncMock( + self.request.json = mock.CoroutineMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -835,8 +855,8 @@ async def test_set_did_endpoint_no_wallet_did(self): Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = mock.AsyncMock() - ledger.__aenter__ = mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.CoroutineMock() + ledger.__aenter__ = mock.CoroutineMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletNotFoundError() @@ -894,7 +914,7 @@ async def test_rotate_did_keypair(self): with mock.patch.object( test_module.web, "json_response", mock.Mock() ) as json_response: - self.wallet.get_local_did = mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -903,8 +923,8 @@ async def test_rotate_did_keypair(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = mock.AsyncMock() - self.wallet.rotate_did_keypair_apply = mock.AsyncMock() + self.wallet.rotate_did_keypair_start = mock.CoroutineMock() + self.wallet.rotate_did_keypair_apply = mock.CoroutineMock() await test_module.wallet_rotate_did_keypair(self.request) json_response.assert_called_once_with({}) @@ -923,13 +943,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 = mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( side_effect=test_module.WalletNotFoundError("Unknown DID") ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.wallet_rotate_did_keypair(self.request) - self.wallet.get_local_did = mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -944,7 +964,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 = mock.AsyncMock( + self.wallet.get_local_did = mock.CoroutineMock( return_value=DIDInfo( "did", "verkey", @@ -953,7 +973,7 @@ async def test_rotate_did_keypair_x(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = mock.AsyncMock( + self.wallet.rotate_did_keypair_start = mock.CoroutineMock( side_effect=test_module.WalletError() ) with self.assertRaises(test_module.web.HTTPBadRequest):