From e81fc79cb58f6db7067850ea96dac376e5610e08 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 25 Oct 2023 18:03:31 -0400 Subject: [PATCH 01/33] fix: drop asynctest Signed-off-by: Daniel Bluhm --- UnitTests.md | 2 +- .../admin/tests/test_request_context.py | 4 +- .../askar/didcomm/tests/test_v2.py | 2 +- aries_cloudagent/askar/tests/test_profile.py | 2 +- aries_cloudagent/askar/tests/test_store.py | 4 +- aries_cloudagent/commands/tests/test_help.py | 5 +- aries_cloudagent/commands/tests/test_init.py | 5 +- .../commands/tests/test_provision.py | 15 +- aries_cloudagent/commands/tests/test_start.py | 23 +- .../commands/tests/test_upgrade.py | 83 ++-- .../config/tests/test_argparse.py | 5 +- .../config/tests/test_default_context.py | 4 +- .../config/tests/test_injection_context.py | 4 +- .../config/tests/test_injector.py | 4 +- aries_cloudagent/config/tests/test_ledger.py | 73 ++-- aries_cloudagent/config/tests/test_logging.py | 5 +- .../config/tests/test_provider.py | 5 +- aries_cloudagent/config/tests/test_wallet.py | 81 ++-- .../models/diddoc/tests/test_diddoc.py | 4 +- .../models/tests/test_conn_record.py | 4 +- .../connections/tests/test_base_manager.py | 177 ++++---- aries_cloudagent/core/tests/test_error.py | 4 +- aries_cloudagent/core/tests/test_event_bus.py | 2 +- .../core/tests/test_goal_code_registry.py | 4 +- .../core/tests/test_oob_processor.py | 96 +++-- .../core/tests/test_plugin_registry.py | 14 +- aries_cloudagent/core/tests/test_profile.py | 6 +- .../core/tests/test_protocol_registry.py | 9 +- aries_cloudagent/holder/tests/test_routes.py | 61 ++- .../indy/credx/tests/test_cred_issuance.py | 17 +- .../indy/models/tests/test_pres_preview.py | 10 +- .../indy/sdk/tests/test_holder.py | 25 +- .../indy/sdk/tests/test_issuer.py | 7 +- .../indy/sdk/tests/test_profile.py | 6 +- aries_cloudagent/indy/sdk/tests/test_util.py | 7 +- .../indy/sdk/tests/test_verifier.py | 11 +- .../indy/sdk/tests/test_wallet_plugin.py | 5 +- aries_cloudagent/indy/tests/test_verifier.py | 10 +- .../merkel_validation/tests/test_trie.py | 2 +- .../tests/test_indy_ledger_requests.py | 20 +- .../tests/test_indy_manager.py | 40 +- .../tests/test_indy_vdr_manager.py | 40 +- .../tests/test_manager_provider.py | 5 +- .../ledger/tests/test_endpoint_type.py | 4 +- aries_cloudagent/ledger/tests/test_indy.py | 99 +++-- .../ledger/tests/test_indy_vdr.py | 24 +- .../tests/test_routes.py | 66 +-- .../tests/test_signature_decorator.py | 4 +- .../messaging/jsonld/tests/test_credential.py | 9 +- .../messaging/jsonld/tests/test_routes.py | 42 +- .../messaging/models/tests/test_base.py | 5 +- .../models/tests/test_base_record.py | 15 +- .../messaging/schemas/tests/test_routes.py | 74 ++-- .../messaging/tests/test_agent_message.py | 6 +- .../multitenant/admin/tests/test_routes.py | 112 ++--- .../tests/test_askar_profile_manager.py | 10 +- .../multitenant/tests/test_base.py | 22 +- .../multitenant/tests/test_manager.py | 10 +- .../tests/test_manager_provider.py | 4 +- .../multitenant/tests/test_route_manager.py | 28 +- .../v1_0/handlers/tests/test_menu_handler.py | 10 +- .../tests/test_menu_request_handler.py | 16 +- .../handlers/tests/test_perform_handler.py | 16 +- .../actionmenu/v1_0/tests/test_controller.py | 10 +- .../actionmenu/v1_0/tests/test_routes.py | 72 ++-- .../actionmenu/v1_0/tests/test_service.py | 8 +- .../actionmenu/v1_0/tests/test_util.py | 4 +- .../v1_0/messages/tests/test_basic_message.py | 4 +- .../basicmessage/v1_0/tests/test_routes.py | 22 +- .../handlers/tests/test_request_handler.py | 24 +- .../handlers/tests/test_response_handler.py | 12 +- .../messages/tests/test_connection_request.py | 4 +- .../tests/test_connection_response.py | 4 +- .../connections/v1_0/tests/test_manager.py | 107 +++-- .../connections/v1_0/tests/test_routes.py | 136 +++--- .../tests/test_keylist_query_handler.py | 6 +- .../tests/test_keylist_update_handler.py | 6 +- .../test_keylist_update_response_handler.py | 8 +- .../tests/test_mediation_deny_handler.py | 6 +- .../tests/test_mediation_grant_handler.py | 14 +- .../tests/test_mediation_request_handler.py | 6 +- .../v1_0/tests/test_mediation_invite_store.py | 6 +- .../v1_0/tests/test_mediation_manager.py | 10 +- .../v1_0/tests/test_route_manager.py | 98 +++-- .../v1_0/tests/test_routes.py | 127 +++--- .../handlers/tests/test_complete_handler.py | 6 +- .../tests/test_problem_report_handler.py | 8 +- .../handlers/tests/test_request_handler.py | 30 +- .../handlers/tests/test_response_handler.py | 18 +- .../v1_0/messages/tests/test_request.py | 10 +- .../v1_0/messages/tests/test_response.py | 10 +- .../didexchange/v1_0/tests/test_manager.py | 396 +++++++++--------- .../didexchange/v1_0/tests/test_routes.py | 76 ++-- .../handlers/tests/test_disclose_handler.py | 4 +- .../v1_0/handlers/tests/test_query_handler.py | 6 +- .../v1_0/models/tests/test_record.py | 9 +- .../discovery/v1_0/tests/test_manager.py | 43 +- .../discovery/v1_0/tests/test_routes.py | 22 +- .../tests/test_disclosures_handler.py | 12 +- .../handlers/tests/test_queries_handler.py | 6 +- .../v2_0/models/tests/test_record.py | 9 +- .../discovery/v2_0/tests/test_manager.py | 47 ++- .../discovery/v2_0/tests/test_routes.py | 22 +- ...t_endorsed_transaction_response_handler.py | 22 +- ...st_refused_transaction_response_handler.py | 22 +- ...est_transaction_acknowledgement_handler.py | 16 +- .../tests/test_transaction_cancel_handler.py | 16 +- .../test_transaction_job_to_send_handler.py | 16 +- .../tests/test_transaction_request_handler.py | 14 +- .../tests/test_transaction_resend_handler.py | 16 +- .../messages/tests/test_cancel_transaction.py | 4 +- .../test_endorsed_transaction_response.py | 4 +- .../test_refused_transaction_response.py | 4 +- .../tests/test_transaction_acknowledgement.py | 4 +- .../tests/test_transaction_job_to_send.py | 4 +- .../tests/test_transaction_request.py | 4 +- .../messages/tests/test_transaction_resend.py | 4 +- .../v1_0/tests/test_manager.py | 30 +- .../v1_0/tests/test_routes.py | 340 +++++++-------- .../tests/test_forward_invitation_handler.py | 12 +- .../handlers/tests/test_invitation_handler.py | 10 +- .../tests/test_invitation_request_handler.py | 10 +- .../messages/tests/test_forward_invitation.py | 4 +- .../v0_1/messages/tests/test_invitation.py | 4 +- .../messages/tests/test_invitation_request.py | 4 +- .../introduction/v0_1/tests/test_routes.py | 19 +- .../introduction/v0_1/tests/test_service.py | 4 +- .../tests/test_credential_ack_handler.py | 21 +- .../tests/test_credential_issue_handler.py | 43 +- .../tests/test_credential_offer_handler.py | 31 +- .../test_credential_problem_report_handler.py | 15 +- .../tests/test_credential_proposal_handler.py | 21 +- .../tests/test_credential_request_handler.py | 37 +- .../models/tests/test_credential_exchange.py | 7 +- .../v1_0/tests/test_manager.py | 125 +++--- .../v1_0/tests/test_routes.py | 331 +++++++-------- .../v2_0/formats/indy/tests/test_handler.py | 96 +++-- .../formats/ld_proof/tests/test_handler.py | 48 +-- .../handlers/tests/test_cred_ack_handler.py | 15 +- .../handlers/tests/test_cred_issue_handler.py | 31 +- .../handlers/tests/test_cred_offer_handler.py | 31 +- .../tests/test_cred_problem_report_handler.py | 15 +- .../tests/test_cred_proposal_handler.py | 23 +- .../tests/test_cred_request_handler.py | 31 +- .../v2_0/messages/tests/test_cred_ack.py | 7 +- .../v2_0/messages/tests/test_cred_issue.py | 5 +- .../v2_0/messages/tests/test_cred_offer.py | 6 +- .../v2_0/messages/tests/test_cred_proposal.py | 6 +- .../v2_0/messages/tests/test_cred_request.py | 6 +- .../v2_0/models/detail/tests/test_indy.py | 4 +- .../v2_0/models/detail/tests/test_ld_proof.py | 4 +- .../v2_0/models/tests/test_cred_ex_record.py | 7 +- .../v2_0/tests/test_manager.py | 83 ++-- .../v2_0/tests/test_routes.py | 333 ++++++++------- .../v1_0/handlers/tests/test_ack_handler.py | 5 +- .../tests/test_problem_report_handler.py | 6 +- .../tests/test_reuse_accept_handler.py | 6 +- .../v1_0/handlers/tests/test_reuse_handler.py | 8 +- .../v1_0/models/tests/test_invitation.py | 6 +- .../out_of_band/v1_0/tests/test_manager.py | 123 +++--- .../out_of_band/v1_0/tests/test_routes.py | 30 +- .../tests/test_presentation_ack_handler.py | 17 +- .../tests/test_presentation_handler.py | 23 +- ...est_presentation_problem_report_handler.py | 15 +- .../test_presentation_proposal_handler.py | 19 +- .../test_presentation_request_handler.py | 103 ++--- .../v1_0/models/tests/test_record.py | 7 +- .../present_proof/v1_0/tests/test_manager.py | 75 ++-- .../present_proof/v1_0/tests/test_routes.py | 223 +++++----- .../v2_0/formats/dif/tests/test_handler.py | 44 +- .../handlers/tests/test_pres_ack_handler.py | 13 +- .../v2_0/handlers/tests/test_pres_handler.py | 25 +- .../tests/test_pres_problem_report_handler.py | 15 +- .../tests/test_pres_proposal_handler.py | 21 +- .../tests/test_pres_request_handler.py | 103 ++--- .../v2_0/models/tests/test_record.py | 7 +- .../present_proof/v2_0/tests/test_manager.py | 93 ++-- .../present_proof/v2_0/tests/test_routes.py | 336 +++++++-------- .../v1_0/tests/test_routes.py | 14 +- .../v2_0/tests/test_routes.py | 18 +- .../handlers/tests/test_forward_handler.py | 14 +- .../v1_0/models/tests/test_route_record.py | 4 +- .../v1_0/tests/test_routing_manager.py | 12 +- .../protocols/tests/test_didcomm_prefix.py | 4 +- .../v1_0/messages/tests/test_trust_ping.py | 4 +- .../messages/tests/test_trust_ping_reponse.py | 4 +- .../trustping/v1_0/tests/test_routes.py | 20 +- .../resolver/default/tests/test_indy.py | 22 +- .../default/tests/test_legacy_peer.py | 14 +- .../resolver/default/tests/test_universal.py | 10 +- aries_cloudagent/resolver/tests/test_base.py | 2 +- .../resolver/tests/test_routes.py | 16 +- .../tests/test_issuer_cred_rev_record.py | 4 +- .../tests/test_issuer_rev_reg_record.py | 29 +- .../models/tests/test_revocation_registry.py | 5 +- .../revocation/tests/test_indy.py | 27 +- .../revocation/tests/test_manager.py | 96 ++--- .../revocation/tests/test_routes.py | 140 +++---- .../settings/tests/test_routes.py | 10 +- .../storage/tests/test_askar_storage.py | 48 +-- .../storage/tests/test_in_memory_storage.py | 4 +- .../storage/tests/test_indy_storage.py | 70 ++-- .../vc_holder/tests/test_indy_vc_holder.py | 2 +- .../storage/vc_holder/tests/test_vc_record.py | 4 +- aries_cloudagent/tails/tests/test_indy.py | 17 +- .../inbound/tests/test_delivery_queue.py | 4 +- .../inbound/tests/test_http_transport.py | 16 +- .../transport/inbound/tests/test_manager.py | 13 +- .../transport/inbound/tests/test_message.py | 2 +- .../transport/inbound/tests/test_session.py | 23 +- .../inbound/tests/test_ws_transport.py | 4 +- .../outbound/tests/test_http_transport.py | 6 +- .../transport/outbound/tests/test_manager.py | 27 +- .../outbound/tests/test_ws_transport.py | 2 +- .../transport/queue/tests/test_basic_queue.py | 9 +- .../transport/tests/test_pack_format.py | 14 +- .../transport/tests/test_stats.py | 5 +- .../transport/tests/test_wire_format.py | 4 +- aries_cloudagent/utils/tests/test_http.py | 2 +- .../utils/tests/test_outofband.py | 2 +- aries_cloudagent/utils/tests/test_repeat.py | 4 +- aries_cloudagent/utils/tests/test_stats.py | 4 +- .../utils/tests/test_task_queue.py | 7 +- aries_cloudagent/utils/tests/test_tracing.py | 4 +- .../crypto/tests/test_wallet_key_pair.py | 10 +- .../test_authentication_proof_purpose.py | 4 +- .../tests/test_controller_proof_purpose.py | 4 +- .../tests/test_credential_issuance_purpose.py | 4 +- .../purposes/tests/test_proof_purpose.py | 4 +- .../tests/test_bbs_bls_signature_2020.py | 6 +- .../test_bbs_bls_signature_proof_2020.py | 6 +- .../tests/test_ed25519_signature_2018.py | 10 +- .../tests/test_ed25519_signature_2020.py | 8 +- .../vc/ld_proofs/tests/test_check.py | 2 +- .../vc/ld_proofs/tests/test_ld_proofs.py | 6 +- .../vc/tests/test_bbs_mattr_interop.py | 6 +- .../vc/vc_ld/tests/test_validation_result.py | 2 +- aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py | 6 +- .../wallet/models/tests/test_wallet_record.py | 4 +- .../wallet/tests/test_did_posture.py | 4 +- .../wallet/tests/test_indy_wallet.py | 126 +++--- .../wallet/tests/test_key_pair.py | 6 +- 242 files changed, 3537 insertions(+), 3655 deletions(-) diff --git a/UnitTests.md b/UnitTests.md index bbaaa104fe..50dc1f6edd 100644 --- a/UnitTests.md +++ b/UnitTests.md @@ -130,7 +130,7 @@ class TestDidExchangeManager(AsyncTestCase, TestConfig): self.responder = MockResponder() self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + clean_finished_oob_record=async_mock.AsyncMock(return_value=None) ) self.route_manager = async_mock.MagicMock(RouteManager) diff --git a/aries_cloudagent/admin/tests/test_request_context.py b/aries_cloudagent/admin/tests/test_request_context.py index 8ab5159cf4..10c4ac5c8e 100644 --- a/aries_cloudagent/admin/tests/test_request_context.py +++ b/aries_cloudagent/admin/tests/test_request_context.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...core.profile import ProfileSession @@ -7,7 +7,7 @@ from .. import request_context as test_module -class TestAdminRequestContext(AsyncTestCase): +class TestAdminRequestContext(IsolatedAsyncioTestCase): def setUp(self): self.ctx = test_module.AdminRequestContext(InMemoryProfile.test_profile()) assert self.ctx.__class__.__name__ in str(self.ctx) diff --git a/aries_cloudagent/askar/didcomm/tests/test_v2.py b/aries_cloudagent/askar/didcomm/tests/test_v2.py index b9d5fde4d6..90706aad9c 100644 --- a/aries_cloudagent/askar/didcomm/tests/test_v2.py +++ b/aries_cloudagent/askar/didcomm/tests/test_v2.py @@ -1,6 +1,6 @@ import json -from asynctest import mock as async_mock +from unittest import mock as async_mock import pytest from aries_askar import AskarError, Key, KeyAlg, Session diff --git a/aries_cloudagent/askar/tests/test_profile.py b/aries_cloudagent/askar/tests/test_profile.py index 453952271c..c9ad71a32e 100644 --- a/aries_cloudagent/askar/tests/test_profile.py +++ b/aries_cloudagent/askar/tests/test_profile.py @@ -1,7 +1,7 @@ import asyncio import pytest -from asynctest import mock +from unittest import mock from ...askar.profile import AskarProfile from ...config.injection_context import InjectionContext diff --git a/aries_cloudagent/askar/tests/test_store.py b/aries_cloudagent/askar/tests/test_store.py index 2af479165f..5d128d1840 100644 --- a/aries_cloudagent/askar/tests/test_store.py +++ b/aries_cloudagent/askar/tests/test_store.py @@ -1,11 +1,11 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...core.error import ProfileError from ..store import AskarStoreConfig -class TestStoreConfig(AsyncTestCase): +class TestStoreConfig(IsolatedAsyncioTestCase): key_derivation_method = "Raw" key = "key" storage_type = "postgres" diff --git a/aries_cloudagent/commands/tests/test_help.py b/aries_cloudagent/commands/tests/test_help.py index d52d41929d..53a4501fbd 100644 --- a/aries_cloudagent/commands/tests/test_help.py +++ b/aries_cloudagent/commands/tests/test_help.py @@ -1,9 +1,10 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import help as command -class TestHelp(AsyncTestCase): +class TestHelp(IsolatedAsyncioTestCase): def test_exec_help(self): with async_mock.patch.object( command.ArgumentParser, "print_help" diff --git a/aries_cloudagent/commands/tests/test_init.py b/aries_cloudagent/commands/tests/test_init.py index 3af30bbb04..c9d3cde8cc 100644 --- a/aries_cloudagent/commands/tests/test_init.py +++ b/aries_cloudagent/commands/tests/test_init.py @@ -1,9 +1,10 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ... import commands as test_module -class TestInit(AsyncTestCase): +class TestInit(IsolatedAsyncioTestCase): def test_available(self): avail = test_module.available_commands() assert len(avail) == 4 diff --git a/aries_cloudagent/commands/tests/test_provision.py b/aries_cloudagent/commands/tests/test_provision.py index f8fa55ea3a..3664186bd8 100644 --- a/aries_cloudagent/commands/tests/test_provision.py +++ b/aries_cloudagent/commands/tests/test_provision.py @@ -1,6 +1,7 @@ import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...config.base import ConfigError from ...config.error import ArgsParseError @@ -10,7 +11,7 @@ ) -class TestProvision(AsyncTestCase): +class TestProvision(IsolatedAsyncioTestCase): def test_bad_calls(self): with self.assertRaises(ArgsParseError): test_module.execute([]) @@ -39,24 +40,24 @@ def test_provision_wallet(self): ) async def test_provision_ledger_configured(self): - profile = async_mock.MagicMock(close=async_mock.CoroutineMock()) + profile = async_mock.MagicMock(close=async_mock.AsyncMock()) with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ) as mock_wallet_config, async_mock.patch.object( - test_module, "ledger_config", async_mock.CoroutineMock(return_value=True) + test_module, "ledger_config", async_mock.AsyncMock(return_value=True) ) as mock_ledger_config: await test_module.provision({}) async def test_provision_config_x(self): with async_mock.patch.object( - test_module, "wallet_config", async_mock.CoroutineMock() + test_module, "wallet_config", async_mock.AsyncMock() ) 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 9f3142cdec..1d763dd8a7 100644 --- a/aries_cloudagent/commands/tests/test_start.py +++ b/aries_cloudagent/commands/tests/test_start.py @@ -1,13 +1,14 @@ import sys -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...config.error import ArgsParseError from .. import start as test_module -class TestStart(AsyncTestCase): +class TestStart(IsolatedAsyncioTestCase): def test_bad_args(self): with self.assertRaises(ArgsParseError): test_module.execute([]) @@ -17,9 +18,9 @@ def test_bad_args(self): async def test_start_shutdown_app(self): mock_conductor = async_mock.MagicMock( - setup=async_mock.CoroutineMock(), - start=async_mock.CoroutineMock(), - stop=async_mock.CoroutineMock(), + setup=async_mock.AsyncMock(), + start=async_mock.AsyncMock(), + stop=async_mock.AsyncMock(), ) await test_module.start_app(mock_conductor) await test_module.shutdown_app(mock_conductor) @@ -56,9 +57,9 @@ def test_exec_start(self): run_loop.assert_called_once() async def test_run_loop(self): - startup = async_mock.CoroutineMock() + startup = async_mock.AsyncMock() startup_call = startup() - shutdown = async_mock.CoroutineMock() + shutdown = async_mock.AsyncMock() shutdown_call = shutdown() with async_mock.patch.object( test_module, "asyncio", autospec=True @@ -80,7 +81,7 @@ async def test_run_loop(self): async_mock.MagicMock(), async_mock.MagicMock(cancel=async_mock.MagicMock()), ] - mock_asyncio.gather = async_mock.CoroutineMock() + mock_asyncio.gather = async_mock.AsyncMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = tasks @@ -93,9 +94,9 @@ async def test_run_loop(self): shutdown.assert_awaited_once() async def test_run_loop_init_x(self): - startup = async_mock.CoroutineMock(side_effect=KeyError("the front fell off")) + startup = async_mock.AsyncMock(side_effect=KeyError("the front fell off")) startup_call = startup() - shutdown = async_mock.CoroutineMock() + shutdown = async_mock.AsyncMock() shutdown_call = shutdown() with async_mock.patch.object( test_module, "asyncio", autospec=True @@ -116,7 +117,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 = async_mock.MagicMock() - mock_asyncio.gather = async_mock.CoroutineMock() + mock_asyncio.gather = async_mock.AsyncMock() 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 55451387c0..bde77c2c61 100644 --- a/aries_cloudagent/commands/tests/test_upgrade.py +++ b/aries_cloudagent/commands/tests/test_upgrade.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...connections.models.conn_record import ConnRecord @@ -14,8 +15,8 @@ from ..upgrade import UpgradeError -class TestUpgrade(AsyncTestCase): - async def setUp(self): +class TestUpgrade(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.profile.context.injector.bind_instance( @@ -54,18 +55,18 @@ async def test_upgrade_storage_from_version_included(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), + async_mock.AsyncMock(return_value=[ConnRecord()]), ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + ConnRecord, "save", async_mock.AsyncMock() ): await test_module.upgrade( settings={ @@ -78,18 +79,18 @@ async def test_upgrade_storage_missing_from_version(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), + async_mock.AsyncMock(return_value=[ConnRecord()]), ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + ConnRecord, "save", async_mock.AsyncMock() ): await test_module.upgrade(settings={}) @@ -102,8 +103,8 @@ async def test_upgrade_from_version(self): with async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + async_mock.AsyncMock(return_value=[ConnRecord()]), + ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -120,8 +121,8 @@ async def test_upgrade_all_subwallets(self): with async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + async_mock.AsyncMock(return_value=[ConnRecord()]), + ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -142,8 +143,8 @@ async def test_upgrade_specified_subwallets(self): with async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + async_mock.AsyncMock(return_value=[ConnRecord()]), + ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -159,8 +160,8 @@ async def test_upgrade_specified_subwallets(self): with async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.CoroutineMock()): + async_mock.AsyncMock(return_value=[ConnRecord()]), + ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -173,10 +174,10 @@ async def test_upgrade_callable(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( @@ -209,10 +210,10 @@ async def test_upgrade_callable_named_tag(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( @@ -247,10 +248,10 @@ async def test_upgrade_x_same_version(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ): @@ -268,18 +269,18 @@ async def test_upgrade_missing_from_version(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), + async_mock.AsyncMock(return_value=[ConnRecord()]), ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + ConnRecord, "save", async_mock.AsyncMock() ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade( @@ -299,10 +300,10 @@ async def test_upgrade_x_callable_not_set(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( @@ -334,10 +335,10 @@ async def test_upgrade_x_class_not_found(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( @@ -367,18 +368,18 @@ async def test_execute(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( ConnRecord, "query", - async_mock.CoroutineMock(return_value=[ConnRecord()]), + async_mock.AsyncMock(return_value=[ConnRecord()]), ), async_mock.patch.object( - ConnRecord, "save", async_mock.CoroutineMock() + ConnRecord, "save", async_mock.AsyncMock() ), async_mock.patch.object( asyncio, "get_event_loop", async_mock.MagicMock() ) as mock_get_event_loop: @@ -399,10 +400,10 @@ async def test_upgrade_x_invalid_record_type(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( @@ -432,10 +433,10 @@ async def test_upgrade_force(self): with async_mock.patch.object( test_module, "wallet_config", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( self.profile, - async_mock.CoroutineMock(did="public DID", verkey="verkey"), + async_mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ), async_mock.patch.object( diff --git a/aries_cloudagent/config/tests/test_argparse.py b/aries_cloudagent/config/tests/test_argparse.py index 0ddc0eec81..a6f5b2c7f2 100644 --- a/aries_cloudagent/config/tests/test_argparse.py +++ b/aries_cloudagent/config/tests/test_argparse.py @@ -1,12 +1,13 @@ from configargparse import ArgumentTypeError -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import argparse from ..util import BoundedInt, ByteSize -class TestArgParse(AsyncTestCase): +class TestArgParse(IsolatedAsyncioTestCase): async def test_groups(self): """Test optional argument parsing.""" parser = argparse.create_argument_parser() diff --git a/aries_cloudagent/config/tests/test_default_context.py b/aries_cloudagent/config/tests/test_default_context.py index 52028e9e90..722038715a 100644 --- a/aries_cloudagent/config/tests/test_default_context.py +++ b/aries_cloudagent/config/tests/test_default_context.py @@ -1,6 +1,6 @@ from tempfile import NamedTemporaryFile -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...cache.base import BaseCache from ...core.profile import ProfileManager @@ -11,7 +11,7 @@ from ..injection_context import InjectionContext -class TestDefaultContext(AsyncTestCase): +class TestDefaultContext(IsolatedAsyncioTestCase): async def test_build_context(self): """Test context init.""" diff --git a/aries_cloudagent/config/tests/test_injection_context.py b/aries_cloudagent/config/tests/test_injection_context.py index 9f0b0a2ed0..e6bd1fd4f0 100644 --- a/aries_cloudagent/config/tests/test_injection_context.py +++ b/aries_cloudagent/config/tests/test_injection_context.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..base import InjectionError from ..injection_context import InjectionContext, InjectionContextError -class TestInjectionContext(AsyncTestCase): +class TestInjectionContext(IsolatedAsyncioTestCase): def setUp(self): self.test_key = "TEST" self.test_value = "VALUE" diff --git a/aries_cloudagent/config/tests/test_injector.py b/aries_cloudagent/config/tests/test_injector.py index d44e39fa63..76da5f7992 100644 --- a/aries_cloudagent/config/tests/test_injector.py +++ b/aries_cloudagent/config/tests/test_injector.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..base import BaseProvider, BaseInjector, BaseSettings, InjectionError from ..injector import Injector @@ -27,7 +27,7 @@ def open(self): self.opened = True -class TestInjector(AsyncTestCase): +class TestInjector(IsolatedAsyncioTestCase): def setUp(self): self.test_key = "TEST" self.test_value = "VALUE" diff --git a/aries_cloudagent/config/tests/test_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index dc46041bc0..637044a1e0 100644 --- a/aries_cloudagent/config/tests/test_ledger.py +++ b/aries_cloudagent/config/tests/test_ledger.py @@ -1,5 +1,6 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import argparse from ...core.in_memory import InMemoryProfile @@ -13,16 +14,16 @@ TEST_GENESIS = "GENESIS" -class TestLedgerConfig(AsyncTestCase): +class TestLedgerConfig(IsolatedAsyncioTestCase): async def test_fetch_genesis_transactions(self): with async_mock.patch.object( - test_module, "fetch", async_mock.CoroutineMock() + test_module, "fetch", async_mock.AsyncMock() ) as mock_fetch: await test_module.fetch_genesis_transactions("http://1.2.3.4:9000/genesis") async def test_fetch_genesis_transactions_x(self): with async_mock.patch.object( - test_module, "fetch", async_mock.CoroutineMock(return_value=TEST_GENESIS) + test_module, "fetch", async_mock.AsyncMock(return_value=TEST_GENESIS) ) as mock_fetch: mock_fetch.side_effect = test_module.FetchError("404 Not Found") with self.assertRaises(test_module.ConfigError): @@ -37,7 +38,7 @@ async def test_get_genesis_url(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS), + async_mock.AsyncMock(return_value=TEST_GENESIS), ) as mock_fetch: await test_module.get_genesis_transactions(settings) self.assertEqual(settings["ledger.genesis_transactions"], TEST_GENESIS) @@ -73,7 +74,7 @@ async def test_ledger_config_no_taa_accept(self): "default_endpoint": "http://1.2.3.4:8051", } mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + get_txn_author_agreement=async_mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -81,7 +82,7 @@ async def test_ledger_config_no_taa_accept(self): }, } ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock( + get_latest_txn_author_acceptance=async_mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), read_only=False, @@ -97,7 +98,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + test_module, "accept_taa", async_mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = False assert not await test_module.ledger_config( @@ -109,7 +110,7 @@ async def test_accept_taa(self): "ledger.genesis_transactions": TEST_GENESIS, } mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + get_txn_author_agreement=async_mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -117,13 +118,13 @@ async def test_accept_taa(self): }, } ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock( + get_latest_txn_author_acceptance=async_mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), - update_endpoint_for_did=async_mock.CoroutineMock(), + update_endpoint_for_did=async_mock.AsyncMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock(set_did_endpoint=async_mock.CoroutineMock()) + mock_wallet = async_mock.MagicMock(set_did_endpoint=async_mock.AsyncMock()) session = InMemoryProfile.test_session(settings=settings) profile = session.profile @@ -136,7 +137,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + test_module, "accept_taa", async_mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = True await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -147,12 +148,12 @@ async def test_ledger_config_read_only_skip_taa_accept(self): "ledger.genesis_transactions": TEST_GENESIS, } mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock(), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), + get_txn_author_agreement=async_mock.AsyncMock(), + get_latest_txn_author_acceptance=async_mock.AsyncMock(), read_only=True, ) mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock( + set_did_endpoint=async_mock.AsyncMock( side_effect=LedgerError( "Error cannot update endpoint when ledger is in read only mode" ) @@ -170,7 +171,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + test_module, "accept_taa", async_mock.AsyncMock() ) as mock_accept_taa: with self.assertRaises(test_module.ConfigError) as x_context: await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -184,12 +185,12 @@ async def test_ledger_config_read_only_skip_profile_endpoint_publish(self): "profile_endpoint": "http://agent.ca", } mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock(), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), + get_txn_author_agreement=async_mock.AsyncMock(), + get_latest_txn_author_acceptance=async_mock.AsyncMock(), read_only=True, ) mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock(), + set_did_endpoint=async_mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -203,7 +204,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + test_module, "accept_taa", async_mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config(profile, TEST_DID, provision=True) mock_ledger.get_txn_author_agreement.assert_not_called() @@ -217,15 +218,15 @@ async def test_ledger_config_read_write_skip_taa_endpoint_publish(self): "profile_endpoint": "http://agent-profile.ca", } mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.CoroutineMock( + get_txn_author_agreement=async_mock.AsyncMock( return_value={"taa_required": False} ), - get_latest_txn_author_acceptance=async_mock.CoroutineMock(), - update_endpoint_for_did=async_mock.CoroutineMock(), + get_latest_txn_author_acceptance=async_mock.AsyncMock(), + update_endpoint_for_did=async_mock.AsyncMock(), read_only=False, ) mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.CoroutineMock(), + set_did_endpoint=async_mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -239,7 +240,7 @@ async def _get_session(): session.context.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - test_module, "accept_taa", async_mock.CoroutineMock() + test_module, "accept_taa", async_mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config( profile, @@ -339,7 +340,7 @@ async def test_load_multiple_genesis_transactions_from_config_a(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, async_mock.patch( "builtins.open", async_mock.MagicMock() ) as mock_open: @@ -436,7 +437,7 @@ async def test_load_multiple_genesis_transactions_from_config_b(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, async_mock.patch( "builtins.open", async_mock.MagicMock() ) as mock_open: @@ -500,7 +501,7 @@ async def test_load_multiple_genesis_transactions_config_error_a(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, async_mock.patch( "builtins.open", async_mock.MagicMock() ) as mock_open: @@ -567,7 +568,7 @@ async def test_load_multiple_genesis_transactions_multiple_write(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, async_mock.patch( "builtins.open", async_mock.MagicMock() ) as mock_open: @@ -628,7 +629,7 @@ async def test_load_multiple_genesis_transactions_from_config_io_x(self): with async_mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.CoroutineMock(return_value=TEST_GENESIS_TXNS), + async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), ) as mock_fetch, async_mock.patch( "builtins.open", async_mock.MagicMock() ) as mock_open: @@ -665,7 +666,7 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): with async_mock.patch.object( test_module, "use_asyncio_event_loop", async_mock.MagicMock() ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() ) as mock_prompt: mock_prompt.side_effect = EOFError() assert not await test_module.accept_taa( @@ -675,7 +676,7 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): with async_mock.patch.object( test_module, "use_asyncio_event_loop", async_mock.MagicMock() ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() ) as mock_prompt: mock_prompt.return_value = "x" assert not await test_module.accept_taa( @@ -685,10 +686,10 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): with async_mock.patch.object( test_module, "use_asyncio_event_loop", async_mock.MagicMock() ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.CoroutineMock() + test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() ) as mock_prompt: mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.CoroutineMock() + accept_txn_author_agreement=async_mock.AsyncMock() ) mock_prompt.return_value = "" assert await test_module.accept_taa( @@ -733,7 +734,7 @@ async def test_ledger_accept_taa(self): } ) mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.CoroutineMock() + accept_txn_author_agreement=async_mock.AsyncMock() ) assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False diff --git a/aries_cloudagent/config/tests/test_logging.py b/aries_cloudagent/config/tests/test_logging.py index 853b723692..88bc315e31 100644 --- a/aries_cloudagent/config/tests/test_logging.py +++ b/aries_cloudagent/config/tests/test_logging.py @@ -3,7 +3,8 @@ from io import StringIO -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from tempfile import NamedTemporaryFile from .. import logging as test_module @@ -14,7 +15,7 @@ from ...wallet.key_type import ED25519 -class TestLoggingConfigurator(AsyncTestCase): +class TestLoggingConfigurator(IsolatedAsyncioTestCase): agent_label_arg_value = "Aries Cloud Agent" transport_arg_value = "transport" host_arg_value = "host" diff --git a/aries_cloudagent/config/tests/test_provider.py b/aries_cloudagent/config/tests/test_provider.py index 6999ddfe1a..2b8d874f5d 100644 --- a/aries_cloudagent/config/tests/test_provider.py +++ b/aries_cloudagent/config/tests/test_provider.py @@ -1,7 +1,8 @@ from tempfile import NamedTemporaryFile from weakref import ref -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...utils.stats import Collector @@ -22,7 +23,7 @@ def __init__(self, *args, **kwargs): pass -class TestProvider(AsyncTestCase): +class TestProvider(IsolatedAsyncioTestCase): async def test_stats_provider_init_x(self): """Cover stats provider init error on no provider.""" with self.assertRaises(ValueError): diff --git a/aries_cloudagent/config/tests/test_wallet.py b/aries_cloudagent/config/tests/test_wallet.py index 3ff2e5a8b8..72f7d8d554 100644 --- a/aries_cloudagent/config/tests/test_wallet.py +++ b/aries_cloudagent/config/tests/test_wallet.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...core.profile import ProfileManager, ProfileSession @@ -29,16 +30,16 @@ async def open(self, context, config): return self.profile -class TestWalletConfig(AsyncTestCase): - async def setUp(self): +class TestWalletConfig(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.injector = Injector(enforce_typing=False) self.session = async_mock.MagicMock(ProfileSession)() - self.session.commit = async_mock.CoroutineMock() + self.session.commit = async_mock.AsyncMock() self.profile = async_mock.MagicMock( backend="indy", created=True, name="Test Wallet", - transaction=async_mock.CoroutineMock(return_value=self.session), + transaction=async_mock.AsyncMock(return_value=self.session), ) def _inject(cls): @@ -57,11 +58,11 @@ async def test_wallet_config_existing_replace(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( + set_public_did=async_mock.AsyncMock(), + create_local_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -70,7 +71,7 @@ async def test_wallet_config_existing_replace(self): with async_mock.patch.object( test_module, "seed_to_did", async_mock.MagicMock() ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -81,7 +82,7 @@ async def test_wallet_config_existing_open(self): backend="indy", created=False, name="Test Wallet", - transaction=async_mock.CoroutineMock(return_value=self.session), + transaction=async_mock.AsyncMock(return_value=self.session), ) self.context.injector.clear_binding(ProfileManager) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) @@ -94,11 +95,11 @@ async def test_wallet_config_existing_open(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( + set_public_did=async_mock.AsyncMock(), + create_local_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -109,7 +110,7 @@ async def test_wallet_config_existing_open(self): with async_mock.patch.object( test_module, "seed_to_did", async_mock.MagicMock() ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -125,20 +126,20 @@ async def test_wallet_config_auto_provision(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( + set_public_did=async_mock.AsyncMock(), + create_local_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - MockManager, "open", async_mock.CoroutineMock() + MockManager, "open", async_mock.AsyncMock() ) as mock_mgr_open, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_mgr_open.side_effect = test_module.ProfileNotFoundError() @@ -156,13 +157,13 @@ async def test_wallet_config_non_indy_x(self): ) self.profile.backend = "not-indy" mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -174,7 +175,7 @@ async def test_wallet_config_bad_seed_x(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -185,7 +186,7 @@ async def test_wallet_config_bad_seed_x(self): "seed_to_did", async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -198,9 +199,9 @@ async def test_wallet_config_seed_local(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock(return_value=None), + set_public_did=async_mock.AsyncMock(), + create_local_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -209,7 +210,7 @@ async def test_wallet_config_seed_local(self): with async_mock.patch.object( test_module, "seed_to_did", async_mock.MagicMock() ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -222,9 +223,9 @@ async def test_wallet_config_seed_public(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock(return_value=None), + set_public_did=async_mock.AsyncMock(), + create_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -235,15 +236,15 @@ async def test_wallet_config_seed_public(self): "seed_to_did", async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_seed_no_public_did(self): mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), - set_public_did=async_mock.CoroutineMock(), - create_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock(return_value=None), + set_public_did=async_mock.AsyncMock(), + create_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) @@ -252,7 +253,7 @@ async def test_wallet_config_seed_no_public_did(self): with async_mock.patch.object( test_module, "seed_to_did", async_mock.MagicMock() ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -265,20 +266,20 @@ async def test_wallet_config_for_key_derivation_method(self): } ) mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.CoroutineMock(), - create_local_did=async_mock.CoroutineMock( + set_public_did=async_mock.AsyncMock(), + create_local_did=async_mock.AsyncMock( return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) with async_mock.patch.object( - MockManager, "provision", async_mock.CoroutineMock() + MockManager, "provision", async_mock.AsyncMock() ) as mock_mgr_provision, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.CoroutineMock() + test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() ): mock_mgr_provision.return_value = self.profile diff --git a/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py b/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py index bc720acffb..d9d45bc271 100644 --- a/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py +++ b/aries_cloudagent/connections/models/diddoc/tests/test_diddoc.py @@ -16,13 +16,13 @@ """ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .. import DIDDoc, PublicKey, PublicKeyType, Service from ..util import canon_did, canon_ref -class TestDIDDoc(AsyncTestCase): +class TestDIDDoc(IsolatedAsyncioTestCase): async def test_basic(self): # One authn key by reference dd_in = { diff --git a/aries_cloudagent/connections/models/tests/test_conn_record.py b/aries_cloudagent/connections/models/tests/test_conn_record.py index 19f540adda..13bb06df58 100644 --- a/aries_cloudagent/connections/models/tests/test_conn_record.py +++ b/aries_cloudagent/connections/models/tests/test_conn_record.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....protocols.connections.v1_0.messages.connection_invitation import ( @@ -13,7 +13,7 @@ from ..diddoc.diddoc import DIDDoc -class TestConnRecord(AsyncTestCase): +class TestConnRecord(IsolatedAsyncioTestCase): def setUp(self): self.session = InMemoryProfile.test_session() diff --git a/aries_cloudagent/connections/tests/test_base_manager.py b/aries_cloudagent/connections/tests/test_base_manager.py index 0932b992cc..256bc5f6ab 100644 --- a/aries_cloudagent/connections/tests/test_base_manager.py +++ b/aries_cloudagent/connections/tests/test_base_manager.py @@ -2,7 +2,8 @@ from unittest.mock import call -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from pydid import DID, DIDDocument, DIDDocumentBuilder from pydid.doc.builder import ServiceBuilder from pydid.verification_method import ( @@ -53,7 +54,7 @@ from ..base_manager import BaseConnectionManager -class TestBaseConnectionManager(AsyncTestCase): +class TestBaseConnectionManager(IsolatedAsyncioTestCase): def make_did_doc(self, did, verkey): doc = DIDDoc(did=did) controller = did @@ -71,7 +72,7 @@ def make_did_doc(self, did, verkey): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.test_seed = "testseed000000000000000000000001" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" @@ -83,7 +84,7 @@ async def setUp(self): self.responder = MockResponder() self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + clean_finished_oob_record=async_mock.AsyncMock(return_value=None) ) self.route_manager = CoordinateMediationV1RouteManager() self.resolver = DIDResolver() @@ -214,7 +215,7 @@ async def test_create_did_document_mediation_svc_endpoints_overwritten(self): routing_keys=self.test_mediator_routing_keys, endpoint=self.test_mediator_endpoint, ) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=(mediation_record.routing_keys, mediation_record.endpoint) ) doc = await self.manager.create_did_document( @@ -335,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): @@ -353,11 +354,11 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -383,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -424,11 +425,11 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -453,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -490,10 +491,10 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se ], } did_doc = DIDDocument.deserialize(did_doc_json) - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( @@ -517,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -530,10 +531,10 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self ) builder.service.add(type_="LinkedData", service_endpoint=self.test_endpoint) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( method=SOV, @@ -556,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -578,11 +579,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -607,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -640,11 +641,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -669,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -702,11 +703,11 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -731,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -763,11 +764,11 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -792,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -812,9 +813,7 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_no_resolver(self) mock_conn = async_mock.MagicMock( my_did=self.test_did, - retrieve_invitation=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER.rfc23, ) @@ -837,8 +836,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): ) did_doc = builder.build() - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - self.resolver.dereference = async_mock.CoroutineMock( + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -862,9 +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=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -879,10 +876,10 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): async with self.profile.session() as session: - self.resolver.get_endpoint_for_did = async_mock.CoroutineMock( + self.resolver.get_endpoint_for_did = async_mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.get_key_for_did = async_mock.CoroutineMock( + self.resolver.get_key_for_did = async_mock.AsyncMock( return_value=self.test_target_verkey ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -916,9 +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=async_mock.CoroutineMock( - return_value=mock_oob_invite - ), + retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -990,7 +985,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): metadata=None, ) - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = async_mock.AsyncMock() self.manager.resolve_invitation.return_value = ( self.test_endpoint, [self.test_verkey], @@ -1035,7 +1030,7 @@ async def test_verification_methods_for_service(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) recip, routing = await self.manager.verification_methods_for_service( @@ -1047,7 +1042,7 @@ async def test_verification_methods_for_service(self): async def test_resolve_connection_targets_empty(self): """Test resolve connection targets.""" did = "did:sov:" + self.test_did - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), []) ) targets = await self.manager.resolve_connection_targets(did) @@ -1069,7 +1064,7 @@ async def test_resolve_connection_targets(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) targets = await self.manager.resolve_connection_targets(did) @@ -1091,7 +1086,7 @@ async def test_resolve_connection_targets_x_bad_reference(self): routing_keys=["did:example:123#some-random-id"], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertLogs() as cm: @@ -1116,7 +1111,7 @@ async def test_resolve_connection_targets_x_bad_key_material(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1138,7 +1133,7 @@ async def test_resolve_connection_targets_x_unsupported_key(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1151,7 +1146,7 @@ async def test_record_did_empty(self): service_builder.add_didcomm( self.test_endpoint, recipient_keys=[], routing_keys=[] ) - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), service_builder.services) ) await self.manager.record_did(did) @@ -1167,7 +1162,7 @@ async def test_record_did(self): self.test_endpoint, recipient_keys=[vm], routing_keys=[] ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.CoroutineMock( + self.manager.resolve_didcomm_services = async_mock.AsyncMock( return_value=(doc, doc.service) ) await self.manager.record_did(did) @@ -1201,7 +1196,7 @@ async def test_find_inbound_connection(self): with async_mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1210,7 +1205,7 @@ async def test_find_inbound_connection(self): # Second pass: in cache with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1230,7 +1225,7 @@ async def test_find_inbound_connection_no_cache(self): with async_mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: self.context.injector.clear_binding(BaseCache) mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1249,9 +1244,9 @@ async def test_resolve_inbound_connection(self): mock_conn.connection_id = "dummy" with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() + InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + self.manager, "find_connection", async_mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -1275,9 +1270,9 @@ async def test_resolve_inbound_connection_injector_error(self): mock_conn.connection_id = "dummy" with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() + InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + self.manager, "find_connection", async_mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = InjectionError() mock_mgr_find_conn.return_value = mock_conn @@ -1295,9 +1290,9 @@ async def test_resolve_inbound_connection_wallet_not_found_error(self): mock_conn.connection_id = "dummy" with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.CoroutineMock() + InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.CoroutineMock() + self.manager, "find_connection", async_mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = WalletNotFoundError() mock_mgr_find_conn.return_value = mock_conn @@ -1333,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1392,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) with async_mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn mock_conn_target_ser.return_value = {"serialized": "value"} @@ -1441,9 +1436,9 @@ async def test_get_connection_targets_from_cache(self): with async_mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.CoroutineMock() + self.manager, "fetch_connection_targets", async_mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1485,9 +1480,9 @@ async def test_get_connection_targets_no_cache(self): with async_mock.patch.object( ConnectionTarget, "serialize", autospec=True ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.CoroutineMock() + self.manager, "fetch_connection_targets", async_mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1537,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=async_mock.CoroutineMock(return_value=conn_invite), + retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1572,7 +1567,7 @@ async def test_create_static_connection_multitenant(self): ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.CoroutineMock() + self.route_manager.route_static = async_mock.AsyncMock() with async_mock.patch.object( ConnRecord, "save", autospec=True @@ -1605,13 +1600,13 @@ async def test_create_static_connection_multitenant_auto_disclose_features(self) } ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.CoroutineMock() + self.route_manager.route_static = async_mock.AsyncMock() with async_mock.patch.object( ConnRecord, "save", autospec=True ), async_mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() ) as mock_proactive_disclose_features: mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -1635,7 +1630,7 @@ async def test_create_static_connection_multitenant_mediator(self): ) default_mediator = async_mock.MagicMock() - self.route_manager.route_static = async_mock.CoroutineMock() + self.route_manager.route_static = async_mock.AsyncMock() with async_mock.patch.object( ConnRecord, "save", autospec=True @@ -1718,11 +1713,11 @@ async def test_create_static_connection_their_seed_only(self): async def test_find_connection_retrieve_by_did(self): with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1736,13 +1731,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 async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() ) as mock_proactive_disclose_features: mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1756,14 +1751,14 @@ async def test_find_connection_retrieve_by_did_auto_disclose_features(self): async def test_find_connection_retrieve_by_invitation_key(self): with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.return_value = async_mock.MagicMock( state=ConnRecord.State.RESPONSE, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1775,9 +1770,9 @@ async def test_find_connection_retrieve_by_invitation_key(self): async def test_find_connection_retrieve_none_by_invitation_key(self): with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.side_effect = StorageNotFoundError() @@ -1793,11 +1788,11 @@ async def test_get_endpoints(self): conn_id = "dummy" with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( InMemoryWallet, "get_local_did", autospec=True ) as mock_wallet_get_local_did, async_mock.patch.object( - self.manager, "get_connection_targets", async_mock.CoroutineMock() + self.manager, "get_connection_targets", async_mock.AsyncMock() ) as mock_get_conn_targets: mock_retrieve.return_value = async_mock.MagicMock() mock_wallet_get_local_did.return_value = async_mock.MagicMock( diff --git a/aries_cloudagent/core/tests/test_error.py b/aries_cloudagent/core/tests/test_error.py index 3497b6ca9d..710d450d8a 100644 --- a/aries_cloudagent/core/tests/test_error.py +++ b/aries_cloudagent/core/tests/test_error.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..error import BaseError -class TestBaseError(AsyncTestCase): +class TestBaseError(IsolatedAsyncioTestCase): async def test_base_error(self): err = BaseError() assert err.error_code is None diff --git a/aries_cloudagent/core/tests/test_event_bus.py b/aries_cloudagent/core/tests/test_event_bus.py index 26ce28dacf..c201f94b24 100644 --- a/aries_cloudagent/core/tests/test_event_bus.py +++ b/aries_cloudagent/core/tests/test_event_bus.py @@ -3,7 +3,7 @@ import pytest import re -from asynctest import mock as async_mock +from unittest import mock as async_mock from .. import event_bus as test_module from ..event_bus import EventBus, Event diff --git a/aries_cloudagent/core/tests/test_goal_code_registry.py b/aries_cloudagent/core/tests/test_goal_code_registry.py index 06d161881c..a59aed56c1 100644 --- a/aries_cloudagent/core/tests/test_goal_code_registry.py +++ b/aries_cloudagent/core/tests/test_goal_code_registry.py @@ -1,11 +1,11 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...protocols.issue_credential.v1_0.message_types import CONTROLLERS from ..goal_code_registry import GoalCodeRegistry -class TestGoalCodeRegistry(AsyncTestCase): +class TestGoalCodeRegistry(IsolatedAsyncioTestCase): test_goal_code_queries = "*" test_goal_code_queries_fail = "aries.fake.*" diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index 1db8762c89..eebdaa6931 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -1,8 +1,8 @@ import json -from asynctest import ANY -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock +from unittest.mock import ANY from ...connections.models.conn_record import ConnRecord from ...messaging.decorators.attach_decorator import AttachDecorator @@ -20,10 +20,10 @@ from ..oob_processor import OobMessageProcessor, OobMessageProcessorError -class TestOobProcessor(AsyncTestCase): - async def setUp(self): +class TestOobProcessor(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = async_mock.CoroutineMock() + self.inbound_message_router = async_mock.AsyncMock() self.oob_processor = OobMessageProcessor( inbound_message_router=self.inbound_message_router ) @@ -36,9 +36,9 @@ async def setUp(self): "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], "serviceEndpoint": "http://their-service-endpoint.com", }, - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), + save=async_mock.AsyncMock(), ) 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 = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=False, invitation=async_mock.MagicMock(requests_attach=[]), ) @@ -57,7 +57,7 @@ async def test_clean_finished_oob_record_no_multi_use_no_request_attach(self): with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + async_mock.AsyncMock(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 = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=True, invitation=async_mock.MagicMock(requests_attach=[]), ) @@ -85,7 +85,7 @@ async def test_clean_finished_oob_record_multi_use(self): with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) 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 = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=True, invitation=async_mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", @@ -139,7 +139,7 @@ async def test_find_oob_target_for_outbound_message(self): with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + async_mock.AsyncMock(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 = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=True, invitation=async_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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=mock_oob), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) 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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(side_effect=(StorageNotFoundError(),)), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=None), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=None), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE @@ -396,7 +396,7 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(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 async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED @@ -438,14 +438,12 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve, async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - delete_record=async_mock.CoroutineMock() - ) + async_mock.AsyncMock( + return_value=async_mock.MagicMock(delete_record=async_mock.AsyncMock()) ), ) as mock_retrieve_conn: self.oob_record.role = OobRecord.ROLE_SENDER @@ -478,7 +476,7 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_set(self): with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -505,7 +503,7 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -523,7 +521,7 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_matching with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -543,7 +541,7 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -561,7 +559,7 @@ async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -582,7 +580,7 @@ async def test_find_oob_record_for_inbound_message_their_service_matching_with_m with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -611,7 +609,7 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -636,7 +634,7 @@ async def test_find_oob_record_for_inbound_message_session_emit_delete( with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -662,7 +660,7 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( with async_mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(return_value=self.oob_record), + async_mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -682,7 +680,7 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( async def test_handle_message_connection(self): oob_record = async_mock.MagicMock( connection_id="the-conn-id", - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), attach_thread_id=None, their_service=None, ) @@ -712,7 +710,7 @@ async def test_handle_message_connection(self): async def test_handle_message_connectionless(self): oob_record = async_mock.MagicMock( - save=async_mock.CoroutineMock(), connection_id=None + save=async_mock.AsyncMock(), connection_id=None ) await self.oob_processor.handle_message( diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index 0bbe8c9be4..b3d75ada63 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,6 +1,8 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock, call +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest.mock import call from ...config.injection_context import InjectionContext from ...utils.classloader import ClassLoader, ModuleLoadError @@ -12,7 +14,7 @@ from ..error import ProtocolDefinitionValidationError -class TestPluginRegistry(AsyncTestCase): +class TestPluginRegistry(IsolatedAsyncioTestCase): def setUp(self): self.blocked_module = "blocked_module" self.registry = PluginRegistry(blocklist=[self.blocked_module]) @@ -36,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 = async_mock.CoroutineMock() + mod.setup = async_mock.AsyncMock() await self.registry.init_context(ctx) mod.setup.assert_awaited_once_with(ctx) @@ -46,7 +48,7 @@ async def test_register_routes(self): mod.__name__ = mod_name app = async_mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() + mod.routes.register = async_mock.AsyncMock() definition = async_mock.MagicMock() definition.versions = [ { @@ -91,7 +93,7 @@ async def test_register_routes_mod_no_version(self): mod.__name__ = mod_name app = async_mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() + mod.routes.register = async_mock.AsyncMock() with async_mock.patch.object( ClassLoader, @@ -169,7 +171,7 @@ async def test_post_process_routes_mod_no_version(self): mod.__name__ = mod_name app = async_mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.CoroutineMock() + mod.routes.register = async_mock.AsyncMock() with async_mock.patch.object( ClassLoader, diff --git a/aries_cloudagent/core/tests/test_profile.py b/aries_cloudagent/core/tests/test_profile.py index 72d4c3e0e8..9e45badeb0 100644 --- a/aries_cloudagent/core/tests/test_profile.py +++ b/aries_cloudagent/core/tests/test_profile.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...config.base import InjectionError from ...config.injection_context import InjectionContext @@ -20,7 +20,7 @@ def transaction(self, context: InjectionContext = None) -> ProfileSession: """ -class TestProfileSession(AsyncTestCase): +class TestProfileSession(IsolatedAsyncioTestCase): async def test_session_active(self): profile = MockProfile() session = ProfileSession(profile) @@ -55,7 +55,7 @@ async def test_session_active(self): await session2.rollback() -class TestProfileManagerProvider(AsyncTestCase): +class TestProfileManagerProvider(IsolatedAsyncioTestCase): async def test_basic_wallet_type(self): context = InjectionContext() provider = ProfileManagerProvider() diff --git a/aries_cloudagent/core/tests/test_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py index 2800f2c46f..154e0ac322 100644 --- a/aries_cloudagent/core/tests/test_protocol_registry.py +++ b/aries_cloudagent/core/tests/test_protocol_registry.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...utils.classloader import ClassLoader @@ -6,7 +7,7 @@ from ..protocol_registry import ProtocolRegistry -class TestProtocolRegistry(AsyncTestCase): +class TestProtocolRegistry(IsolatedAsyncioTestCase): no_type_message = {"a": "b"} unknown_type_message = {"@type": 1} test_message_type = "PROTOCOL/MESSAGE" @@ -205,9 +206,9 @@ async def test_disclosed(self): {self.test_message_type: self.test_message_handler} ) mock = async_mock.MagicMock() - mock.return_value.check_access = async_mock.CoroutineMock() + mock.return_value.check_access = async_mock.AsyncMock() mock.return_value.check_access.return_value = True - mock.return_value.determine_roles = async_mock.CoroutineMock() + mock.return_value.determine_roles = async_mock.AsyncMock() mock.return_value.determine_roles.return_value = ["ROLE"] self.registry.register_controllers({self.test_protocol: mock}) protocols = [self.test_protocol] diff --git a/aries_cloudagent/holder/tests/test_routes.py b/aries_cloudagent/holder/tests/test_routes.py index ad92934be5..e4094fe8e3 100644 --- a/aries_cloudagent/holder/tests/test_routes.py +++ b/aries_cloudagent/holder/tests/test_routes.py @@ -1,6 +1,7 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -30,7 +31,7 @@ ) -class TestHolderRoutes(AsyncTestCase): +class TestHolderRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context @@ -49,7 +50,7 @@ async def test_credentials_get(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_credential=async_mock.CoroutineMock( + get_credential=async_mock.AsyncMock( return_value=json.dumps({"hello": "world"}) ) ), @@ -67,7 +68,7 @@ async def test_credentials_get_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_credential=async_mock.CoroutineMock( + get_credential=async_mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -84,7 +85,7 @@ async def test_credentials_revoked(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock(return_value=False) + credential_revoked=async_mock.AsyncMock(return_value=False) ), ) @@ -109,7 +110,7 @@ async def test_credentials_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock( + credential_revoked=async_mock.AsyncMock( side_effect=test_module.WalletNotFoundError("no such cred") ) ), @@ -127,7 +128,7 @@ async def test_credentials_x_ledger(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - credential_revoked=async_mock.CoroutineMock( + credential_revoked=async_mock.AsyncMock( side_effect=test_module.LedgerError("down for maintenance") ) ), @@ -141,7 +142,7 @@ async def test_attribute_mime_types_get(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_mime_type=async_mock.CoroutineMock( + get_mime_type=async_mock.AsyncMock( side_effect=[None, {"a": "application/jpeg"}] ) ), @@ -162,7 +163,7 @@ async def test_credentials_remove(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - delete_credential=async_mock.CoroutineMock(return_value=None) + delete_credential=async_mock.AsyncMock(return_value=None) ), ) @@ -178,7 +179,7 @@ async def test_credentials_remove_not_found(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - delete_credential=async_mock.CoroutineMock( + delete_credential=async_mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -191,9 +192,7 @@ async def test_credentials_list(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_credentials=async_mock.CoroutineMock( - return_value=[{"hello": "world"}] - ) + get_credentials=async_mock.AsyncMock(return_value=[{"hello": "world"}]) ), ) @@ -209,7 +208,7 @@ async def test_credentials_list_x_holder(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_credentials=async_mock.CoroutineMock( + get_credentials=async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ) ), @@ -223,9 +222,7 @@ async def test_w3c_cred_get(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ) + retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD) ), ) @@ -240,7 +237,7 @@ async def test_w3c_cred_get_not_found_x(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + retrieve_credential_by_id=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -254,7 +251,7 @@ async def test_w3c_cred_get_storage_x(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + retrieve_credential_by_id=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ), @@ -268,10 +265,8 @@ async def test_w3c_cred_remove(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ), - delete_credential=async_mock.CoroutineMock(return_value=None), + retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD), + delete_credential=async_mock.AsyncMock(return_value=None), ), ) @@ -287,7 +282,7 @@ async def test_w3c_cred_remove_not_found_x(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( + retrieve_credential_by_id=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -301,10 +296,8 @@ async def test_w3c_cred_remove_storage_x(self): self.profile.context.injector.bind_instance( VCHolder, async_mock.MagicMock( - retrieve_credential_by_id=async_mock.CoroutineMock( - return_value=VC_RECORD - ), - delete_credential=async_mock.CoroutineMock( + retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD), + delete_credential=async_mock.AsyncMock( side_effect=test_module.StorageError() ), ), @@ -314,7 +307,7 @@ async def test_w3c_cred_remove_storage_x(self): await test_module.w3c_cred_remove(self.request) async def test_w3c_creds_list(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -330,7 +323,7 @@ async def test_w3c_creds_list(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=[VC_RECORD]) + fetch=async_mock.AsyncMock(return_value=[VC_RECORD]) ) ) ), @@ -343,7 +336,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -359,7 +352,7 @@ async def test_w3c_creds_list_not_found_x(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -371,7 +364,7 @@ async def test_w3c_creds_list_not_found_x(self): await test_module.w3c_creds_list(self.request) async def test_w3c_creds_list_storage_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -387,7 +380,7 @@ async def test_w3c_creds_list_storage_x(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( 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 33ff63b930..331efbf929 100644 --- a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py +++ b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py @@ -2,7 +2,8 @@ import tempfile import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager from ....config.injection_context import InjectionContext @@ -42,21 +43,19 @@ @pytest.mark.askar @pytest.mark.indy_credx -class TestIndyCredxIssuance(AsyncTestCase): - async def setUp(self): +class TestIndyCredxIssuance(IsolatedAsyncioTestCase): + async def asyncSetUp(self): context = InjectionContext(enforce_typing=False) mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( - return_value={"value": {}} - ), - get_revoc_reg_delta=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock(return_value={"value": {}}), + get_revoc_reg_delta=async_mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.CoroutineMock(return_value=mock_ledger) + mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) self.ledger = mock_ledger self.holder_profile = await AskarProfileManager().provision( @@ -79,7 +78,7 @@ async def setUp(self): self.issuer_profile._context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, mock_ledger) ) ), diff --git a/aries_cloudagent/indy/models/tests/test_pres_preview.py b/aries_cloudagent/indy/models/tests/test_pres_preview.py index 5f5809b889..7601b3fda1 100644 --- a/aries_cloudagent/indy/models/tests/test_pres_preview.py +++ b/aries_cloudagent/indy/models/tests/test_pres_preview.py @@ -5,8 +5,8 @@ from time import time from unittest import TestCase -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile from ....ledger.multiple_ledger.ledger_requests_executor import ( @@ -351,7 +351,7 @@ def test_eq(self): @pytest.mark.indy -class TestIndyPresPreviewAsync(AsyncTestCase): +class TestIndyPresPreviewAsync(IsolatedAsyncioTestCase): """Presentation preview tests""" @pytest.mark.asyncio @@ -408,7 +408,7 @@ async def test_to_indy_proof_request_revo_default_interval(self): mock_get_ledger.return_value = ( None, async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), @@ -455,7 +455,7 @@ async def test_to_indy_proof_request_revo(self): mock_get_ledger.return_value = ( None, async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), diff --git a/aries_cloudagent/indy/sdk/tests/test_holder.py b/aries_cloudagent/indy/sdk/tests/test_holder.py index c67cfd375c..dc4b0e39f3 100644 --- a/aries_cloudagent/indy/sdk/tests/test_holder.py +++ b/aries_cloudagent/indy/sdk/tests/test_holder.py @@ -1,7 +1,8 @@ import json import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase import indy.anoncreds @@ -13,18 +14,18 @@ @pytest.mark.indy -class TestIndySdkHolder(AsyncTestCase): +class TestIndySdkHolder(IsolatedAsyncioTestCase): def setUp(self): mock_ledger = async_mock.MagicMock( get_credential_definition=async_mock.MagicMock(return_value={"value": {}}), - get_revoc_reg_delta=async_mock.CoroutineMock( + get_revoc_reg_delta=async_mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.CoroutineMock(return_value=mock_ledger) + mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) self.ledger = mock_ledger self.wallet = async_mock.MagicMock() @@ -74,7 +75,7 @@ async def test_store_credential_with_mime_types(self, mock_store_cred): test_module, "IndySdkStorage", async_mock.MagicMock() ) as mock_storage: mock_storage.return_value = async_mock.MagicMock( - add_record=async_mock.CoroutineMock() + add_record=async_mock.AsyncMock() ) mock_store_cred.return_value = "cred_id" @@ -346,7 +347,7 @@ async def test_get_credential_x(self, mock_get_cred): async def test_credential_revoked(self): with async_mock.patch.object( # no creds revoked - self.holder, "get_credential", async_mock.CoroutineMock() + self.holder, "get_credential", async_mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -359,7 +360,7 @@ async def test_credential_revoked(self): assert not result with async_mock.patch.object( # cred not revocable - self.holder, "get_credential", async_mock.CoroutineMock() + self.holder, "get_credential", async_mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -371,7 +372,7 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( return_value=( { "value": { @@ -383,7 +384,7 @@ async def test_credential_revoked(self): ) ) with async_mock.patch.object( # cred not revoked - self.holder, "get_credential", async_mock.CoroutineMock() + self.holder, "get_credential", async_mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -396,7 +397,7 @@ async def test_credential_revoked(self): assert not result with async_mock.patch.object( # cred revoked - self.holder, "get_credential", async_mock.CoroutineMock() + self.holder, "get_credential", async_mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -578,9 +579,9 @@ async def test_create_revocation_state(self): } with async_mock.patch.object( - test_module, "create_tails_reader", async_mock.CoroutineMock() + test_module, "create_tails_reader", async_mock.AsyncMock() ) as mock_create_tails_reader, async_mock.patch.object( - indy.anoncreds, "create_revocation_state", async_mock.CoroutineMock() + indy.anoncreds, "create_revocation_state", async_mock.AsyncMock() ) as mock_create_rr_state: mock_create_rr_state.return_value = json.dumps(rr_state) diff --git a/aries_cloudagent/indy/sdk/tests/test_issuer.py b/aries_cloudagent/indy/sdk/tests/test_issuer.py index b977512fef..51932914c6 100644 --- a/aries_cloudagent/indy/sdk/tests/test_issuer.py +++ b/aries_cloudagent/indy/sdk/tests/test_issuer.py @@ -1,7 +1,8 @@ import json import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from indy.error import ( AnoncredsRevocationRegistryFullError, @@ -35,8 +36,8 @@ @pytest.mark.indy -class TestIndySdkIssuer(AsyncTestCase): - async def setUp(self): +class TestIndySdkIssuer(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = InjectionContext() self.context.injector.bind_instance( IndySdkLedgerPool, IndySdkLedgerPool("name") diff --git a/aries_cloudagent/indy/sdk/tests/test_profile.py b/aries_cloudagent/indy/sdk/tests/test_profile.py index 9440adc605..cf0675cd95 100644 --- a/aries_cloudagent/indy/sdk/tests/test_profile.py +++ b/aries_cloudagent/indy/sdk/tests/test_profile.py @@ -1,6 +1,6 @@ import logging -from asynctest import mock as async_mock +from unittest import mock as async_mock import pytest from ....config.injection_context import InjectionContext @@ -20,7 +20,7 @@ async def open_wallet(): handle=1, master_secret_id="master-secret", ) - with async_mock.patch.object(opened, "close", async_mock.CoroutineMock()): + with async_mock.patch.object(opened, "close", async_mock.AsyncMock()): yield opened @@ -86,7 +86,7 @@ async def test_properties(profile: IndySdkProfile): with pytest.raises(ProfileError): await profile.remove() - with async_mock.patch.object(profile.opened, "close", async_mock.CoroutineMock()): + with async_mock.patch.object(profile.opened, "close", async_mock.AsyncMock()): 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 be3f5ee36b..0e7a35a7d2 100644 --- a/aries_cloudagent/indy/sdk/tests/test_util.py +++ b/aries_cloudagent/indy/sdk/tests/test_util.py @@ -4,7 +4,8 @@ import indy.blob_storage -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...util import indy_client_dir, generate_pr_nonce @@ -12,7 +13,7 @@ @pytest.mark.indy -class TestIndyUtils(AsyncTestCase): +class TestIndyUtils(IsolatedAsyncioTestCase): TAILS_HASH = "8UW1Sz5cqoUnK9hqQk7nvtKK65t7Chu3ui866J23sFyJ" def tearDown(self): @@ -27,7 +28,7 @@ async def test_tails_reader(self): print("1234123412431234", file=f) with async_mock.patch.object( - indy.blob_storage, "open_reader", async_mock.CoroutineMock() + indy.blob_storage, "open_reader", async_mock.AsyncMock() ) as mock_blob_open_reader: result = await create_tails_reader(tails_local) assert result == mock_blob_open_reader.return_value diff --git a/aries_cloudagent/indy/sdk/tests/test_verifier.py b/aries_cloudagent/indy/sdk/tests/test_verifier.py index d4abc1bdd1..a5b6cfcab2 100644 --- a/aries_cloudagent/indy/sdk/tests/test_verifier.py +++ b/aries_cloudagent/indy/sdk/tests/test_verifier.py @@ -3,7 +3,8 @@ from copy import deepcopy -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from indy.error import IndyError from ....core.in_memory import InMemoryProfile @@ -291,10 +292,10 @@ @pytest.mark.indy -class TestIndySdkVerifier(AsyncTestCase): +class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock( return_value={ "...": "...", "value": { @@ -328,7 +329,7 @@ async def test_verify_presentation(self, mock_verify): mock_verify.return_value = "val" with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.CoroutineMock() + self.verifier, "pre_verify", async_mock.AsyncMock() ) as mock_pre_verify, async_mock.patch.object( self.verifier, "non_revoc_intervals", async_mock.MagicMock() ) as mock_non_revox, async_mock.patch.object( @@ -363,7 +364,7 @@ async def test_verify_presentation_x_indy(self, mock_verify): mock_verify.side_effect = IndyError(error_code=1) with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.CoroutineMock() + self.verifier, "pre_verify", async_mock.AsyncMock() ) as mock_pre_verify, async_mock.patch.object( self.verifier, "non_revoc_intervals", async_mock.MagicMock() ) as mock_non_revox, async_mock.patch.object( diff --git a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py index ab5e9dea96..b90c6d0a59 100644 --- a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py +++ b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py @@ -1,10 +1,11 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import wallet_plugin as test_module -class TestWalletCrypto(AsyncTestCase): +class TestWalletCrypto(IsolatedAsyncioTestCase): def setUp(self): test_module.LOADED = False diff --git a/aries_cloudagent/indy/tests/test_verifier.py b/aries_cloudagent/indy/tests/test_verifier.py index 90b75b92a6..e31ecefdf2 100644 --- a/aries_cloudagent/indy/tests/test_verifier.py +++ b/aries_cloudagent/indy/tests/test_verifier.py @@ -3,8 +3,8 @@ from copy import deepcopy from time import time -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ...core.in_memory import InMemoryProfile from ...ledger.multiple_ledger.ledger_requests_executor import ( @@ -307,10 +307,10 @@ async def verify_presentation( @pytest.mark.indy -class TestIndySdkVerifier(AsyncTestCase): +class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock( return_value={ "...": "...", "value": { @@ -380,7 +380,7 @@ async def test_check_timestamps(self): mock_get_ledger.return_value = ( None, async_mock.MagicMock( - get_credential_definition=async_mock.CoroutineMock( + get_credential_definition=async_mock.AsyncMock( return_value={ "...": "...", "value": {"no": "revocation"}, diff --git a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py index bf2f27f1da..87f1555361 100644 --- a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py +++ b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ..domain_txn_handler import ( prepare_for_state_read, diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py index f087660fa5..4199f395d1 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile @@ -13,8 +13,8 @@ from ..ledger_requests_executor import IndyLedgerRequestsExecutor -class TestIndyLedgerRequestsExecutor(AsyncTestCase): - async def setUp(self): +class TestIndyLedgerRequestsExecutor(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) @@ -32,15 +32,13 @@ async def setUp(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, async_mock.MagicMock( - extract_did_from_identifier=async_mock.CoroutineMock( + extract_did_from_identifier=async_mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.CoroutineMock( + lookup_did_in_configured_ledgers=async_mock.AsyncMock( return_value=("test_prod_1", self.ledger) ), - get_ledger_inst_by_id=async_mock.CoroutineMock( - return_value=self.ledger - ), + get_ledger_inst_by_id=async_mock.AsyncMock(return_value=self.ledger), ), ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -71,10 +69,10 @@ async def test_get_ledger_for_identifier_x(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, async_mock.MagicMock( - extract_did_from_identifier=async_mock.CoroutineMock( + extract_did_from_identifier=async_mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.CoroutineMock( + lookup_did_in_configured_ledgers=async_mock.AsyncMock( side_effect=MultipleLedgerManagerError ), ), diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py index ba384b561d..a239c69f95 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py @@ -3,8 +3,8 @@ import pytest import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from collections import OrderedDict @@ -24,12 +24,12 @@ @pytest.mark.indy -class TestMultiIndyLedgerManager(AsyncTestCase): - async def setUp(self): +class TestMultiIndyLedgerManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) 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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_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 b61813db8e..a7635b215f 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py @@ -2,8 +2,8 @@ import json import pytest -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from copy import deepcopy from collections import OrderedDict @@ -56,12 +56,12 @@ @pytest.mark.indy_vdr -class TestMultiIndyVDRLedgerManager(AsyncTestCase): - async def setUp(self): +class TestMultiIndyVDRLedgerManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -175,7 +175,7 @@ async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -212,7 +212,7 @@ async def test_get_ledger_by_did_self_cert_b( non_production_ledgers=self.non_production_ledger, ) with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -249,9 +249,9 @@ async def test_get_ledger_by_did_not_self_cert( } ) with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -280,7 +280,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) @@ -301,7 +301,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -350,7 +350,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) @@ -376,9 +376,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -414,7 +414,7 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( non_production_ledgers=self.non_production_ledger, ) with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY @@ -451,9 +451,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = get_nym_reply @@ -478,9 +478,9 @@ async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock() + test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() ) as mock_verify_spv_proof: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY @@ -502,7 +502,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 async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_build_get_nym_req.return_value = async_mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py index 9adb82e5ad..e0b25fd860 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py @@ -1,6 +1,7 @@ import pytest -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager from ....config.injection_context import InjectionContext @@ -56,7 +57,7 @@ ] -class TestMultiIndyLedgerManagerProvider(AsyncTestCase): +class TestMultiIndyLedgerManagerProvider(IsolatedAsyncioTestCase): async def test_provide_invalid_manager(self): profile = InMemoryProfile.test_profile() provider = MultiIndyLedgerManagerProvider(profile) diff --git a/aries_cloudagent/ledger/tests/test_endpoint_type.py b/aries_cloudagent/ledger/tests/test_endpoint_type.py index 799103864a..027e65a811 100644 --- a/aries_cloudagent/ledger/tests/test_endpoint_type.py +++ b/aries_cloudagent/ledger/tests/test_endpoint_type.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..endpoint_type import EndpointType -class TestEndpointType(AsyncTestCase): +class TestEndpointType(IsolatedAsyncioTestCase): async def test_endpoint_type(self): assert EndpointType.ENDPOINT is EndpointType.get("endpoint") assert EndpointType.PROFILE is EndpointType.get("PROFILE") diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index 7b3012a9d6..037c0d957f 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -5,7 +5,8 @@ from os import path -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...cache.in_memory import InMemoryCache @@ -45,7 +46,7 @@ @pytest.mark.indy -class TestIndySdkLedgerPoolProvider(AsyncTestCase): +class TestIndySdkLedgerPoolProvider(IsolatedAsyncioTestCase): async def test_provide(self): provider = IndySdkLedgerPoolProvider() mock_injector = async_mock.MagicMock( @@ -61,8 +62,8 @@ async def test_provide(self): @pytest.mark.indy -class TestIndySdkLedger(AsyncTestCase): - async def setUp(self): +class TestIndySdkLedger(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_did_info = DIDInfo( did=self.test_did, @@ -76,7 +77,7 @@ async def setUp(self): context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile( - async_mock.CoroutineMock(), + async_mock.AsyncMock(), context, ) self.session = await self.profile.session() @@ -298,7 +299,7 @@ async def test_submit_signed( with self.assertRaises(BadLedgerRequestError): await ledger._submit("{}", True) - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -345,11 +346,11 @@ async def test_submit_signed_taa_accept( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True), self.profile ) - ledger.get_latest_txn_author_acceptance = async_mock.CoroutineMock( + ledger.get_latest_txn_author_acceptance = async_mock.AsyncMock( return_value={ "text": "sample", "version": "0.0", @@ -558,7 +559,7 @@ async def test_send_schema( r'{"op":"REPLY","result":{"txnMetadata":{"seqNo": 1}}}' ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) + future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, async_mock.patch.object( @@ -573,7 +574,7 @@ async def test_send_schema( issuer, "schema_name", "schema_version", [1, 2, 3] ) - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -628,7 +629,7 @@ async def test_send_schema_already_exists( mock_create_config, mock_set_proto, ): - # mock_did = async_mock.CoroutineMock() + # mock_did = async_mock.AsyncMock() mock_wallet = async_mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) @@ -636,7 +637,7 @@ async def test_send_schema_already_exists( issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - mock_add_record = async_mock.CoroutineMock() + mock_add_record = async_mock.AsyncMock() future = asyncio.Future() future.set_result( async_mock.MagicMock( @@ -693,11 +694,11 @@ async def test_send_schema_ledger_transaction_error_already_exists( issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.CoroutineMock( + ledger._submit = async_mock.AsyncMock( side_effect=LedgerTransactionError("UnauthorizedClientRequest") ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) + future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, async_mock.patch.object( @@ -777,7 +778,7 @@ async def test_send_schema_issuer_error( mock_is_ledger_read_only.return_value = False issuer = async_mock.MagicMock(IndyIssuer) - issuer.create_schema = async_mock.CoroutineMock( + issuer.create_schema = async_mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -822,7 +823,7 @@ async def test_send_schema_ledger_transaction_error( issuer = async_mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.CoroutineMock( + ledger._submit = async_mock.AsyncMock( side_effect=LedgerTransactionError("Some other error message") ) with async_mock.patch.object( @@ -876,9 +877,9 @@ async def test_send_schema_no_seq_no( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: - mock_wallet.get_public_did = async_mock.CoroutineMock() + mock_wallet.get_public_did = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -905,7 +906,7 @@ async def test_check_existing_schema( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -948,7 +949,7 @@ async def test_get_schema( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -996,7 +997,7 @@ async def test_get_schema_not_found( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1060,7 +1061,7 @@ async def test_get_schema_by_seq_no( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1128,7 +1129,7 @@ async def test_get_schema_by_wrong_seq_no( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -1192,7 +1193,7 @@ async def test_send_credential_definition( tag = "default" ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) + future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, async_mock.patch.object( @@ -1361,7 +1362,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(async_mock.MagicMock(add_record=async_mock.CoroutineMock())) + future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did, async_mock.patch.object( @@ -1415,7 +1416,7 @@ async def test_send_credential_definition_no_such_schema( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1459,7 +1460,7 @@ async def test_send_credential_definition_offer_exception( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1505,7 +1506,7 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1545,7 +1546,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_fetch_cred_def.return_value = {} issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( + issuer.credential_definition_in_wallet = async_mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -1554,7 +1555,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1595,10 +1596,10 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_fetch_cred_def.return_value = {} issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( + issuer.credential_definition_in_wallet = async_mock.AsyncMock( return_value=False ) - issuer.create_and_store_credential_definition = async_mock.CoroutineMock( + issuer.create_and_store_credential_definition = async_mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -1607,7 +1608,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1648,10 +1649,10 @@ async def test_send_credential_definition_read_only( mock_fetch_cred_def.return_value = {} issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( + issuer.credential_definition_in_wallet = async_mock.AsyncMock( return_value=False ) - issuer.create_and_store_credential_definition = async_mock.CoroutineMock( + issuer.create_and_store_credential_definition = async_mock.AsyncMock( return_value=("cred-def-id", "cred-def-json") ) ledger = IndySdkLedger( @@ -1662,7 +1663,7 @@ async def test_send_credential_definition_read_only( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1703,7 +1704,7 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_fetch_cred_def.return_value = cred_def issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.CoroutineMock( + issuer.credential_definition_in_wallet = async_mock.AsyncMock( return_value=False ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -1712,7 +1713,7 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( @@ -1889,7 +1890,7 @@ async def test_get_credential_definition( with async_mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.CoroutineMock() + mock_wallet_get_public_did.return_value = async_mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), @@ -2360,7 +2361,7 @@ async def test_update_endpoint_for_did_calls_attr_json( ) as mock_wallet_get_public_did, async_mock.patch.object( ledger, "_construct_attr_json", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=json.dumps( { "endpoint": { @@ -2375,7 +2376,7 @@ async def test_update_endpoint_for_did_calls_attr_json( ) as mock_construct_attr_json, async_mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.CoroutineMock(return_value={}), + async_mock.AsyncMock(return_value={}), ), async_mock.patch.object( ledger, "did_to_nym" ): @@ -2416,7 +2417,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 async_mock.patch.object( - ledger, "get_all_endpoints_for_did", async_mock.CoroutineMock() + ledger, "get_all_endpoints_for_did", async_mock.AsyncMock() ) as mock_get_all: mock_get_all.return_value = None response = await ledger.update_endpoint_for_did( @@ -2475,7 +2476,7 @@ async def test_update_endpoint_of_type_profile_for_did( # ledger = async_mock.patch.object( # ledger, # "is_ledger_read_only", - # async_mock.CoroutineMock(return_value=False), + # async_mock.AsyncMock(return_value=False), # ) with async_mock.patch.object( IndySdkWallet, "get_public_did" @@ -2593,9 +2594,7 @@ async def test_register_nym( ) mock_wallet_get_public_did.return_value = self.test_did_info mock_wallet_get_local_did.return_value = self.test_did_info - mock_wallet_replace_local_did_metadata.return_value = ( - async_mock.CoroutineMock() - ) + mock_wallet_replace_local_did_metadata.return_value = async_mock.AsyncMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2657,8 +2656,8 @@ async def test_register_nym_no_public_did( ): mock_wallet = async_mock.MagicMock( type="indy", - get_local_did=async_mock.CoroutineMock(), - replace_local_did_metadata=async_mock.CoroutineMock(), + get_local_did=async_mock.AsyncMock(), + replace_local_did_metadata=async_mock.AsyncMock(), ) mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) @@ -2736,9 +2735,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 = ( - async_mock.CoroutineMock() - ) + mock_wallet_replace_local_did_metadata.return_value = async_mock.AsyncMock() 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 335c856efb..a820d5f8c2 100644 --- a/aries_cloudagent/ledger/tests/test_indy_vdr.py +++ b/aries_cloudagent/ledger/tests/test_indy_vdr.py @@ -2,7 +2,7 @@ import indy_vdr import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ...core.in_memory import InMemoryProfile @@ -48,7 +48,7 @@ async def close(): with async_mock.patch.object(ledger.pool, "open", open), async_mock.patch.object( ledger.pool, "close", close ), async_mock.patch.object( - ledger, "is_ledger_read_only", async_mock.CoroutineMock(return_value=False) + ledger, "is_ledger_read_only", async_mock.AsyncMock(return_value=False) ): yield ledger @@ -104,7 +104,7 @@ async def test_fetch_txn_author_agreement( with async_mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.CoroutineMock( + async_mock.AsyncMock( side_effect=[ {"data": {"aml": ".."}}, {"data": {"text": "text", "version": "1.0"}}, @@ -227,7 +227,7 @@ async def test_send_schema( with async_mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=None), + async_mock.AsyncMock(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 async_mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( issuer.create_schema.return_value[0], {"schema": "result"}, @@ -321,11 +321,11 @@ async def test_send_schema_ledger_read_only( with async_mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=False), + async_mock.AsyncMock(return_value=False), ), async_mock.patch.object( ledger, "is_ledger_read_only", - async_mock.CoroutineMock(return_value=True), + async_mock.AsyncMock(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 async_mock.patch.object( ledger, "check_existing_schema", - async_mock.CoroutineMock(return_value=False), + async_mock.AsyncMock(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 async_mock.patch.object( ledger, "_construct_attr_json", - async_mock.CoroutineMock( + async_mock.AsyncMock( 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, async_mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.CoroutineMock(return_value={}), + async_mock.AsyncMock(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 async_mock.patch.object( ledger, "get_schema", - async_mock.CoroutineMock(return_value={"id": S_ID}), + async_mock.AsyncMock(return_value={"id": S_ID}), ) as mock_get_schema: s_id_short = await ledger.credential_definition_id2schema_id( f"55GkHamhTU1ZbTbV2ab9DE:3:CL:{SEQ_NO}:tag" @@ -1034,7 +1034,7 @@ async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): with async_mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.CoroutineMock( + async_mock.AsyncMock( side_effect=[ {"data": json.dumps({"seqNo": 1234})}, {"data": {"txn": {"data": {"role": "101", "alias": "Billy"}}}}, diff --git a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py index 3a0cccb1b2..b8cdb22a10 100644 --- a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py +++ b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -20,22 +20,22 @@ CRED_DEF_ID = "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag" -class TestCredentialDefinitionRoutes(AsyncTestCase): +class TestCredentialDefinitionRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.create_and_send_credential_definition = async_mock.CoroutineMock( + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_credential_definition = async_mock.AsyncMock( return_value=( CRED_DEF_ID, {"cred": "def", "signed_txn": "..."}, True, ) ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( 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 = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.CoroutineMock( + self.storage.find_all_records = async_mock.AsyncMock( return_value=[async_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": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -64,7 +64,7 @@ def setUp(self): ) async def test_send_credential_definition(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( 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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( 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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( + create_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -140,7 +140,7 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): async def test_send_credential_definition_create_transaction_for_endorser_storage_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( 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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( 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 = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( + create_record=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -180,7 +180,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag async def test_send_credential_definition_create_transaction_for_endorser_not_found_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -194,7 +194,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,7 +206,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo async def test_send_credential_definition_create_transaction_for_endorser_base_model_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -220,7 +220,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -232,7 +232,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_info_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -246,10 +246,10 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_definitions_send_credential_definition( @@ -259,7 +259,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_did_x( self, ): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -273,10 +273,10 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "endorser_name": ("name"), } @@ -288,7 +288,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end ) async def test_send_credential_definition_no_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -304,7 +304,7 @@ async def test_send_credential_definition_no_ledger(self): ) async def test_send_credential_definition_ledger_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -314,7 +314,7 @@ async def test_send_credential_definition_ledger_x(self): self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.__aenter__ = async_mock.CoroutineMock( + self.ledger.__aenter__ = async_mock.AsyncMock( side_effect=test_module.LedgerError("oops") ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -336,7 +336,7 @@ async def test_get_credential_definition(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -363,7 +363,7 @@ async def test_get_credential_definition_multitenant(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request @@ -380,7 +380,7 @@ async def test_get_credential_definition_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, None) ) ), diff --git a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py index de863ca4b9..e6028978dc 100644 --- a/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py +++ b/aries_cloudagent/messaging/decorators/tests/test_signature_decorator.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....wallet.key_type import ED25519 from ....core.in_memory import InMemoryProfile @@ -9,7 +9,7 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestSignatureDecorator(AsyncTestCase): +class TestSignatureDecorator(IsolatedAsyncioTestCase): async def test_init(self): decorator = SignatureDecorator() assert decorator.signature_type is None diff --git a/aries_cloudagent/messaging/jsonld/tests/test_credential.py b/aries_cloudagent/messaging/jsonld/tests/test_credential.py index 85f0eb2a26..3a8cc08917 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_credential.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_credential.py @@ -3,7 +3,8 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....vc.ld_proofs import DocumentLoader @@ -27,7 +28,7 @@ from .document_loader import custom_document_loader -class TestCredential(AsyncTestCase): +class TestCredential(IsolatedAsyncioTestCase): async def test_did_key(self): did_key = test_module.did_key(TEST_VERKEY) assert did_key.startswith("did:key:z") @@ -52,8 +53,8 @@ async def test_verify_jws_header(self): ) -class TestOps(AsyncTestCase): - async def setUp(self): +class TestOps(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.wallet = InMemoryWallet(InMemoryProfile.test_profile()) await self.wallet.create_signing_key(ED25519, TEST_SEED) diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index ec41daf578..ed4541fc52 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -2,8 +2,8 @@ import json from aiohttp import web -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from pyld import jsonld import pytest @@ -60,14 +60,14 @@ def did_doc(): @pytest.fixture def mock_resolver(did_doc): did_resolver = DIDResolver(async_mock.MagicMock()) - did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + did_resolver.resolve = async_mock.AsyncMock(return_value=did_doc) yield did_resolver @pytest.fixture def mock_sign_credential(): temp = test_module.sign_credential - sign_credential = async_mock.CoroutineMock(return_value="fake_signage") + sign_credential = async_mock.AsyncMock(return_value="fake_signage") test_module.sign_credential = sign_credential yield test_module.sign_credential test_module.sign_credential = temp @@ -76,7 +76,7 @@ def mock_sign_credential(): @pytest.fixture def mock_verify_credential(): temp = test_module.verify_credential - verify_credential = async_mock.CoroutineMock(return_value="fake_verify") + verify_credential = async_mock.AsyncMock(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 = async_mock.CoroutineMock() + outbound_message_router = async_mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -93,7 +93,7 @@ def mock_sign_request(mock_sign_credential): request = async_mock.MagicMock( match_info={}, query={}, - json=async_mock.CoroutineMock( + json=async_mock.AsyncMock( 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 = async_mock.CoroutineMock() + outbound_message_router = async_mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -146,7 +146,7 @@ def _mock_verify_request(request_body=request_body): request = async_mock.MagicMock( match_info={}, query={}, - json=async_mock.CoroutineMock(return_value=request_body), + json=async_mock.AsyncMock(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 = async_mock.CoroutineMock(side_effect=error()) + test_module.sign_credential = async_mock.AsyncMock(side_effect=error()) await test_module.sign(mock_sign_request) assert "error" in mock_response.call_args[0][0] @@ -183,7 +183,7 @@ async def test_sign_bad_req_error(mock_sign_request, mock_response, error): @pytest.mark.parametrize("error", [WalletError]) @pytest.mark.asyncio async def test_sign_bad_req_http_error(mock_sign_request, mock_response, error): - test_module.sign_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.sign_credential = async_mock.AsyncMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.sign(mock_sign_request) @@ -206,7 +206,7 @@ async def test_verify(mock_verify_request, mock_response): ) @pytest.mark.asyncio async def test_verify_bad_req_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.verify_credential = async_mock.AsyncMock(side_effect=error()) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -220,7 +220,7 @@ async def test_verify_bad_req_error(mock_verify_request, mock_response, error): ) @pytest.mark.asyncio async def test_verify_bad_req_http_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.CoroutineMock(side_effect=error()) + test_module.verify_credential = async_mock.AsyncMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.verify(mock_verify_request()) @@ -229,7 +229,7 @@ async def test_verify_bad_req_http_error(mock_verify_request, mock_response, err async def test_verify_bad_ver_meth_deref_req_error( mock_resolver, mock_verify_request, mock_response ): - mock_resolver.dereference = async_mock.CoroutineMock(side_effect=ResolverError) + mock_resolver.dereference = async_mock.AsyncMock(side_effect=ResolverError) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -268,8 +268,8 @@ def test_post_process_routes(): assert "tags" in mock_app._state["swagger_dict"] -class TestJSONLDRoutes(AsyncTestCase): - async def setUp(self): +class TestJSONLDRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = AdminRequestContext.test_context() self.context.profile.context.injector.bind_instance( DocumentLoader, custom_document_loader @@ -280,7 +280,7 @@ async def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -333,7 +333,7 @@ async def test_verify_credential(self): }, } - self.request.json = async_mock.CoroutineMock(return_value=POSTED_REQUEST) + self.request.json = async_mock.AsyncMock(return_value=POSTED_REQUEST) with async_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 = async_mock.CoroutineMock(return_value=POSTED_REQUEST) + self.request.json = async_mock.AsyncMock(return_value=POSTED_REQUEST) with async_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 = async_mock.CoroutineMock(return_value=posted_request_x) + self.request.json = async_mock.AsyncMock(return_value=posted_request_x) with async_mock.patch.object( test_module.web, "json_response", async_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 = async_mock.CoroutineMock(return_value=posted_request) + self.request.json = async_mock.AsyncMock(return_value=posted_request) with async_mock.patch.object( jsonld, "compact", async_mock.MagicMock() ) as mock_compact, async_mock.patch.object( diff --git a/aries_cloudagent/messaging/models/tests/test_base.py b/aries_cloudagent/messaging/models/tests/test_base.py index 9cc6eaf868..dca01ebf14 100644 --- a/aries_cloudagent/messaging/models/tests/test_base.py +++ b/aries_cloudagent/messaging/models/tests/test_base.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, INCLUDE, fields, validates_schema, ValidationError @@ -68,7 +69,7 @@ def validate_fields(self, data, **kwargs): raise ValidationError("") -class TestBase(AsyncTestCase): +class TestBase(IsolatedAsyncioTestCase): def test_model_validate_fails(self): model = ModelImpl(attr="string") with self.assertRaises(ValidationError): diff --git a/aries_cloudagent/messaging/models/tests/test_base_record.py b/aries_cloudagent/messaging/models/tests/test_base_record.py index 803c16e023..ee1c038a6f 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -1,6 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields from ....cache.base import BaseCache @@ -65,7 +66,7 @@ class UnencTestImpl(BaseRecord): TAG_NAMES = {"~a", "~b", "c"} -class TestBaseRecord(AsyncTestCase): +class TestBaseRecord(IsolatedAsyncioTestCase): def test_init_undef(self): with self.assertRaises(TypeError): BaseRecord() @@ -85,11 +86,11 @@ def test_from_storage_values(self): async def test_post_save_new(self): session = InMemoryProfile.test_session() mock_storage = async_mock.MagicMock() - mock_storage.add_record = async_mock.CoroutineMock() + mock_storage.add_record = async_mock.AsyncMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() with async_mock.patch.object( - record, "post_save", async_mock.CoroutineMock() + record, "post_save", async_mock.AsyncMock() ) as post_save: await record.save(session, reason="reason", event=True) post_save.assert_called_once_with(session, True, None, True) @@ -98,14 +99,14 @@ async def test_post_save_new(self): async def test_post_save_exist(self): session = InMemoryProfile.test_session() mock_storage = async_mock.MagicMock() - mock_storage.update_record = async_mock.CoroutineMock() + mock_storage.update_record = async_mock.AsyncMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() last_state = "last_state" record._last_state = last_state record._id = "id" with async_mock.patch.object( - record, "post_save", async_mock.CoroutineMock() + record, "post_save", async_mock.AsyncMock() ) as post_save: await record.save(session, reason="reason", event=False) post_save.assert_called_once_with(session, False, last_state, False) @@ -151,7 +152,7 @@ async def test_save_x(self): session, "inject", async_mock.MagicMock() ) as mock_inject: mock_inject.return_value = async_mock.MagicMock( - add_record=async_mock.CoroutineMock(side_effect=ZeroDivisionError()) + add_record=async_mock.AsyncMock(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 f5347a6b2b..3482da421f 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -19,17 +19,17 @@ SCHEMA_ID = "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0" -class TestSchemaRoutes(AsyncTestCase): +class TestSchemaRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.create_and_send_schema = async_mock.CoroutineMock( + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_schema = async_mock.AsyncMock( return_value=(SCHEMA_ID, {"schema": "def", "signed_txn": "..."}) ) - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( 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 = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.CoroutineMock( + self.storage.find_all_records = async_mock.AsyncMock( return_value=[async_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": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -57,7 +57,7 @@ def setUp(self): ) async def test_send_schema(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( 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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( 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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( + create_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) ) ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -139,7 +139,7 @@ async def test_send_schema_create_transaction_for_endorser(self): ) async def test_send_schema_create_transaction_for_endorser_storage_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -153,17 +153,17 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.CoroutineMock( + create_record=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -175,7 +175,7 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_not_found_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -189,7 +189,7 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -197,7 +197,7 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_base_model_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -211,7 +211,7 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -219,7 +219,7 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -233,16 +233,16 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(se } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -256,10 +256,10 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel } with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "endorser_name": ("name"), } @@ -269,7 +269,7 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel await test_module.schemas_send_schema(self.request) async def test_send_schema_no_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -282,7 +282,7 @@ async def test_send_schema_no_ledger(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_x_ledger(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -290,7 +290,7 @@ async def test_send_schema_x_ledger(self): } ) self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.create_and_send_schema = async_mock.CoroutineMock( + self.ledger.create_and_send_schema = async_mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -309,7 +309,7 @@ async def test_get_schema(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -334,7 +334,7 @@ async def test_get_schema_multitenant(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_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 @@ -349,7 +349,7 @@ async def test_get_schema_on_seq_no(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -366,13 +366,13 @@ async def test_get_schema_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, None) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -384,13 +384,13 @@ async def test_get_schema_x_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) diff --git a/aries_cloudagent/messaging/tests/test_agent_message.py b/aries_cloudagent/messaging/tests/test_agent_message.py index bafe0c2703..12105fcbfe 100644 --- a/aries_cloudagent/messaging/tests/test_agent_message.py +++ b/aries_cloudagent/messaging/tests/test_agent_message.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields @@ -48,7 +48,7 @@ class Meta: message_type = "basic-message" -class TestAgentMessage(AsyncTestCase): +class TestAgentMessage(IsolatedAsyncioTestCase): """Tests agent message.""" def test_init(self): @@ -194,7 +194,7 @@ async def test_add_tracing(self): assert msg._trace -class TestAgentMessageSchema(AsyncTestCase): +class TestAgentMessageSchema(IsolatedAsyncioTestCase): """Tests agent message schema.""" def test_init_x(self): diff --git a/aries_cloudagent/multitenant/admin/tests/test_routes.py b/aries_cloudagent/multitenant/admin/tests/test_routes.py index 312997c4b6..e64e6a32bf 100644 --- a/aries_cloudagent/multitenant/admin/tests/test_routes.py +++ b/aries_cloudagent/multitenant/admin/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from marshmallow.exceptions import ValidationError from ...base import BaseMultitenantManager, MultitenantManagerError @@ -11,12 +11,12 @@ from .. import routes as test_module -class TestMultitenantRoutes(AsyncTestCase): - async def setUp(self): +class TestMultitenantRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.mock_multitenant_mgr = async_mock.MagicMock( - __aexit__=async_mock.CoroutineMock(), autospec=True + __aexit__=async_mock.AsyncMock(), autospec=True ) - self.mock_multitenant_mgr.__aenter__ = async_mock.CoroutineMock( + self.mock_multitenant_mgr.__aenter__ = async_mock.AsyncMock( return_value=self.mock_multitenant_mgr ) @@ -27,7 +27,7 @@ async def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -82,7 +82,7 @@ async def test_wallets_list(self): ) ), ] - mock_wallet_record.query = async_mock.CoroutineMock() + mock_wallet_record.query = async_mock.AsyncMock() 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 async_mock.patch.object( test_module, "WalletRecord", autospec=True ) as mock_wallet_record: - mock_wallet_record.query = async_mock.CoroutineMock() + mock_wallet_record.query = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + mock_wallet_record.query = async_mock.AsyncMock() 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 = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: wallet_mock = async_mock.MagicMock( @@ -166,11 +166,11 @@ async def test_wallet_create_tenant_settings(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( 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 = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: wallet_mock = async_mock.MagicMock( @@ -218,11 +218,11 @@ async def test_wallet_create(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( return_value="test_token" ) print(self.request["context"]) @@ -247,7 +247,7 @@ async def test_wallet_create(self): async def test_wallet_create_x(self): body = {} - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) self.mock_multitenant_mgr.create_wallet.side_effect = MultitenantManagerError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -270,11 +270,11 @@ async def test_wallet_create_optional_default_fields(self): "label": "my_test_label", "image_url": "https://image.com", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock() + self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock() + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -297,11 +297,11 @@ async def test_wallet_create_raw_key_derivation(self): "wallet_key": "test", "wallet_key_derivation": "RAW", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.CoroutineMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock() + self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock() + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -329,7 +329,7 @@ async def test_wallet_update_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -349,7 +349,7 @@ async def test_wallet_update_tenant_settings(self): } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( return_value=wallet_mock ) @@ -371,7 +371,7 @@ async def test_wallet_update(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -388,7 +388,7 @@ async def test_wallet_update(self): } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( return_value=wallet_mock ) @@ -408,7 +408,7 @@ async def test_wallet_update_no_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -423,7 +423,7 @@ async def test_wallet_update_no_wallet_webhook_urls(self): } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( return_value=wallet_mock ) @@ -444,7 +444,7 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: settings = { @@ -461,7 +461,7 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( return_value=wallet_mock ) @@ -482,10 +482,10 @@ async def test_wallet_update_wallet_settings_x(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( side_effect=test_module.WalletSettingsError("bad settings") ) @@ -496,7 +496,7 @@ async def test_wallet_update_wallet_settings_x(self): async def test_wallet_update_no_params(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {} - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_update(self.request) @@ -504,8 +504,8 @@ async def test_wallet_update_no_params(self): async def test_wallet_update_not_found(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {"label": "test-label"} - self.request.json = async_mock.CoroutineMock(return_value=body) - self.mock_multitenant_mgr.update_wallet = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock(return_value=body) + self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -520,7 +520,7 @@ async def test_wallet_get(self): ) with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -535,7 +535,7 @@ async def test_wallet_get_not_found(self): self.request.match_info = {"wallet_id": "dummy"} with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.side_effect = StorageNotFoundError() @@ -550,7 +550,7 @@ async def test_wallet_get_x(self): ) with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -566,13 +566,13 @@ async def test_wallet_create_token_managed(self): ) with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( return_value="test_token" ) @@ -585,7 +585,7 @@ async def test_wallet_create_token_managed(self): async def test_wallet_create_token_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"wallet_key": "dummy_key"} ) mock_wallet_record = async_mock.MagicMock() @@ -594,13 +594,13 @@ async def test_wallet_create_token_unmanaged(self): ) with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.CoroutineMock( + self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( return_value="test_token" ) @@ -613,7 +613,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"wallet_key": "dummy_key"} ) mock_wallet_record = async_mock.MagicMock() @@ -623,7 +623,7 @@ async def test_wallet_create_token_managed_wallet_key_provided_throws(self): mock_wallet_record.requires_external_key = False with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) 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 async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = async_mock.MagicMock() @@ -658,9 +658,9 @@ async def test_wallet_remove_managed(self): with async_mock.patch.object( test_module.web, "json_response" ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() await test_module.wallet_remove(self.request) @@ -671,16 +671,16 @@ async def test_wallet_remove_managed(self): async def test_wallet_remove_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"wallet_key": "dummy_key"} ) with async_mock.patch.object( test_module.web, "json_response" ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() await test_module.wallet_remove(self.request) @@ -691,7 +691,7 @@ async def test_wallet_remove_unmanaged(self): async def test_wallet_remove_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"wallet_key": "dummy_key"} ) @@ -699,7 +699,7 @@ async def test_wallet_remove_managed_wallet_key_provided_throws(self): mock_wallet_record.requires_external_key = False with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -710,10 +710,10 @@ async def test_wallet_remove_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - self.mock_multitenant_mgr.remove_wallet = async_mock.CoroutineMock() + self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() ): 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 5e2c8c1384..4453a9286c 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -1,7 +1,7 @@ import asyncio -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -10,14 +10,14 @@ from ..askar_profile_manager import AskarProfileMultitenantManager -class TestAskarProfileMultitenantManager(AsyncTestCase): +class TestAskarProfileMultitenantManager(IsolatedAsyncioTestCase): DEFAULT_MULTIENANT_WALLET_NAME = "multitenant_sub_wallet" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) 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 b908b6b0a1..b4455d9865 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -1,7 +1,7 @@ from datetime import datetime -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock import jwt from .. import base as test_module @@ -44,12 +44,12 @@ def open_profiles(self): """Do nothing.""" -class TestBaseMultitenantManager(AsyncTestCase): - async def setUp(self): +class TestBaseMultitenantManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) 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 = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.CoroutineMock() + mock_route_manager.route_verkey = async_mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with async_mock.patch.object( @@ -247,7 +247,7 @@ async def test_create_wallet_adds_wallet_route(self): ) mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.CoroutineMock() + mock_route_manager.route_verkey = async_mock.AsyncMock() with async_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=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) 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=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -683,9 +683,9 @@ async def test_get_profile_for_key(self): with async_mock.patch.object( self.manager, "_get_wallet_by_key", - async_mock.CoroutineMock(return_value=mock_wallet), + async_mock.AsyncMock(return_value=mock_wallet), ), async_mock.patch.object( - self.manager, "get_wallet_profile", async_mock.CoroutineMock() + self.manager, "get_wallet_profile", async_mock.AsyncMock() ) as mock_get_wallet_profile: profile = await self.manager.get_profile_for_key( self.context, "test-verkey" diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index 8a8dcafe3e..a0a78d2b66 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ...core.in_memory import InMemoryProfile from ...messaging.responder import BaseResponder @@ -7,12 +7,12 @@ from ..manager import MultitenantManager -class TestMultitenantManager(AsyncTestCase): - async def setUp(self): +class TestMultitenantManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock()) + self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MultitenantManager(self.profile) diff --git a/aries_cloudagent/multitenant/tests/test_manager_provider.py b/aries_cloudagent/multitenant/tests/test_manager_provider.py index 8a22a7da6e..bacf0c18e6 100644 --- a/aries_cloudagent/multitenant/tests/test_manager_provider.py +++ b/aries_cloudagent/multitenant/tests/test_manager_provider.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...config.base import InjectionError @@ -6,7 +6,7 @@ from ...core.in_memory import InMemoryProfile -class TestProfileManagerProvider(AsyncTestCase): +class TestProfileManagerProvider(IsolatedAsyncioTestCase): async def test_provide_manager(self): profile = InMemoryProfile.test_profile() provider = MultitenantManagerProvider(profile) diff --git a/aries_cloudagent/multitenant/tests/test_route_manager.py b/aries_cloudagent/multitenant/tests/test_route_manager.py index 2aebc0b2e9..b6b62e0ad2 100644 --- a/aries_cloudagent/multitenant/tests/test_route_manager.py +++ b/aries_cloudagent/multitenant/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from asynctest import mock +from unittest 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.CoroutineMock(return_value=None) + route_manager, "get_base_wallet_mediator", mock.AsyncMock(return_value=None) ), mock.patch.object( - RoutingManager, "create_route_record", mock.CoroutineMock() + RoutingManager, "create_route_record", mock.AsyncMock() ) 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.CoroutineMock(return_value=base_mediation_record), + mock.AsyncMock(return_value=base_mediation_record), ), mock.patch.object( - RoutingManager, "create_route_record", mock.CoroutineMock() + RoutingManager, "create_route_record", mock.AsyncMock() ) 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.CoroutineMock(return_value=base_mediation_record), + mock.AsyncMock(return_value=base_mediation_record), ), mock.patch.object( - RoutingManager, "create_route_record", mock.CoroutineMock() + RoutingManager, "create_route_record", mock.AsyncMock() ) as mock_create_route_record: keylist_update = await route_manager._route_for_key( sub_profile, @@ -195,9 +195,7 @@ 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.CoroutineMock() - ): + with mock.patch.object(RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock()): keylist_update = await route_manager._route_for_key( sub_profile, TEST_VERKEY, @@ -221,7 +219,7 @@ async def test_route_for_key_skip_if_exists_and_absent( with mock.patch.object( RouteRecord, "retrieve_by_recipient_key", - mock.CoroutineMock(side_effect=StorageNotFoundError), + mock.AsyncMock(side_effect=StorageNotFoundError), ): keylist_update = await route_manager._route_for_key( sub_profile, @@ -327,7 +325,7 @@ async def test_routing_info_with_base_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.CoroutineMock(return_value=base_mediation_record), + mock.AsyncMock(return_value=base_mediation_record), ): keys, endpoint = await route_manager.routing_info(sub_profile, None) assert keys == base_mediation_record.routing_keys @@ -355,7 +353,7 @@ async def test_routing_info_with_base_mediator_and_sub_mediator( with mock.patch.object( route_manager, "get_base_wallet_mediator", - mock.CoroutineMock(return_value=base_mediation_record), + mock.AsyncMock(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] @@ -367,10 +365,10 @@ async def test_connection_from_recipient_key( sub_profile: Profile, base_route_manager: BaseWalletRouteManager ): manager = mock.MagicMock() - manager.get_profile_for_key = mock.CoroutineMock(return_value=sub_profile) + manager.get_profile_for_key = mock.AsyncMock(return_value=sub_profile) sub_profile.context.injector.bind_instance(BaseMultitenantManager, manager) with mock.patch.object( - RouteManager, "connection_from_recipient_key", mock.CoroutineMock() + RouteManager, "connection_from_recipient_key", mock.AsyncMock() ) 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 082dfab66a..4fa58a8d18 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,13 +7,13 @@ from .. import menu_handler as handler -class TestMenuHandler(AsyncTestCase): +class TestMenuHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.connection_record = async_mock.MagicMock() request_context.connection_record.connection_id = "dummy" - handler.save_connection_menu = async_mock.CoroutineMock() + handler.save_connection_menu = async_mock.AsyncMock() responder = MockResponder() request_context.message = handler.Menu() diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py index dcf578581f..4d0a626af5 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,8 +7,8 @@ from .. import menu_request_handler as handler -class TestMenuRequestHandler(AsyncTestCase): - async def setUp(self): +class TestMenuRequestHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): @@ -23,9 +21,7 @@ async def test_called(self): responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.CoroutineMock( - return_value="menu" - ) + self.menu_service.get_active_menu = async_mock.AsyncMock(return_value="menu") handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) @@ -46,7 +42,7 @@ async def test_called_no_active_menu(self): responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.CoroutineMock(return_value=None) + self.menu_service.get_active_menu = async_mock.AsyncMock(return_value=None) handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py index 76d3b38d04..0e56a5d698 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,8 +7,8 @@ from .. import perform_handler as handler -class TestPerformHandler(AsyncTestCase): - async def setUp(self): +class TestPerformHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): @@ -23,7 +21,7 @@ async def test_called(self): responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.CoroutineMock( + self.menu_service.perform_menu_action = async_mock.AsyncMock( return_value="perform" ) @@ -46,9 +44,7 @@ async def test_called_no_active_menu(self): responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.CoroutineMock( - return_value=None - ) + self.menu_service.perform_menu_action = async_mock.AsyncMock(return_value=None) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index 533e506f26..b8f9274222 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,13 +1,13 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....core.in_memory import InMemoryProfile from .....messaging.request_context import RequestContext from .. import controller as test_module -class TestActionMenuController(AsyncTestCase): - async def setUp(self): +class TestActionMenuController(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.context = RequestContext(self.session.profile) @@ -17,7 +17,7 @@ async def test_controller(self): self.context.injector.bind_instance( test_module.BaseMenuService, self.menu_service ) - self.context.inject = async_mock.CoroutineMock(return_value=self.menu_service) + self.context.inject = async_mock.AsyncMock(return_value=self.menu_service) controller = test_module.Controller("protocol") diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index f766d9a77f..0e5be07b1c 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -7,13 +7,13 @@ from .. import routes as test_module -class TestActionMenuRoutes(AsyncTestCase): +class TestActionMenuRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -23,22 +23,22 @@ def setUp(self): ) async def test_actionmenu_close(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock() - test_module.save_connection_menu = async_mock.CoroutineMock() + test_module.retrieve_connection_menu = async_mock.AsyncMock() + test_module.save_connection_menu = async_mock.AsyncMock() with async_mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_close(self.request) mock_response.assert_called_once_with({}) async def test_actionmenu_close_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock() - test_module.save_connection_menu = async_mock.CoroutineMock( + test_module.retrieve_connection_menu = async_mock.AsyncMock() + test_module.save_connection_menu = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -46,29 +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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock( - return_value=None - ) + test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.actionmenu_close(self.request) async def test_actionmenu_fetch(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.CoroutineMock( - return_value=None - ) + test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) with async_mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_fetch(self.request) mock_response.assert_called_once_with({"result": None}) async def test_actionmenu_perform(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -78,7 +74,7 @@ async def test_actionmenu_perform(self): ) as mock_perform, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() res = await test_module.actionmenu_perform(self.request) mock_response.assert_called_once_with({}) @@ -88,7 +84,7 @@ async def test_actionmenu_perform(self): ) async def test_actionmenu_perform_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -97,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 = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -105,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -114,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 = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_perform(self.request) async def test_actionmenu_request(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -131,7 +127,7 @@ async def test_actionmenu_request(self): ) as menu_request, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() res = await test_module.actionmenu_request(self.request) mock_response.assert_called_once_with({}) @@ -141,7 +137,7 @@ async def test_actionmenu_request(self): ) async def test_actionmenu_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -150,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 = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -158,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -167,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 = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_request(self.request) async def test_actionmenu_send(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -184,7 +180,7 @@ async def test_actionmenu_send(self): ) as mock_menu, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() mock_menu.deserialize = async_mock.MagicMock() res = await test_module.actionmenu_send(self.request) @@ -195,7 +191,7 @@ async def test_actionmenu_send(self): ) async def test_actionmenu_send_deserialize_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -203,7 +199,7 @@ async def test_actionmenu_send_deserialize_x(self): ) as mock_conn_record, async_mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() mock_menu.deserialize = async_mock.MagicMock( side_effect=test_module.BaseModelError("cannot deserialize") ) @@ -212,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -223,7 +219,7 @@ async def test_actionmenu_send_no_conn_record(self): mock_menu.deserialize = async_mock.MagicMock() # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_record.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -231,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( @@ -242,7 +238,7 @@ async def test_actionmenu_send_conn_not_ready(self): mock_menu.deserialize = async_mock.MagicMock() # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_record.retrieve_by_id = async_mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py index 4573997115..fe9c1e0a50 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....core.event_bus import EventBus, MockEventBus from .....core.in_memory import InMemoryProfile @@ -8,8 +8,8 @@ from .. import driver_service as test_module -class TestActionMenuService(AsyncTestCase): - async def setUp(self): +class TestActionMenuService(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.context = RequestContext(self.session.profile) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py index 370d88e621..89f54a1b42 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_util.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....core.event_bus import EventBus, MockEventBus from .....admin.request_context import AdminRequestContext @@ -9,7 +9,7 @@ from ..models.menu_option import MenuOption -class TestActionMenuUtil(AsyncTestCase): +class TestActionMenuUtil(IsolatedAsyncioTestCase): async def test_save_retrieve_delete_connection_menu(self): context = AdminRequestContext.test_context() diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py index fa602a21d1..d7a83dc159 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -46,7 +46,7 @@ def test_serialize(self, mock_basic_message_schema_load): assert msg_dict is mock_basic_message_schema_load.return_value -class TestBasicMessageSchema(AsyncTestCase): +class TestBasicMessageSchema(IsolatedAsyncioTestCase): """Test basic message schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py index ca730021b0..652b1fdffd 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -7,13 +7,13 @@ from .. import routes as test_module -class TestBasicMessageRoutes(AsyncTestCase): - async def setUp(self): +class TestBasicMessageRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -24,7 +24,7 @@ async def setUp(self): self.test_conn_id = "connection-id" async def test_connections_send_message(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} with async_mock.patch.object( @@ -34,14 +34,14 @@ async def test_connections_send_message(self): ) as mock_basic_message, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = async_mock.AsyncMock() res = await test_module.connections_send_message(self.request) mock_response.assert_called_once_with({}) mock_basic_message.assert_called_once() async def test_connections_send_message_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} with async_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 = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} with async_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 = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = async_mock.AsyncMock() 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 7fa1d3ab31..034dd35705 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......core.profile import ProfileSession from ......connections.models import connection_target @@ -77,7 +77,7 @@ class TestRequestHandler: @pytest.mark.asyncio @async_mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() 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 = async_mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() 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 = async_mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() request_context.message = ConnectionRequest() with async_mock.patch.object( connection_record, "metadata_get", - async_mock.CoroutineMock(return_value={"id": "test-mediation-id"}), + async_mock.AsyncMock(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 = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = ConnectionRequest() storage: BaseStorage = session.inject(BaseStorage) with async_mock.patch.object( storage, "find_record", - async_mock.CoroutineMock(raises=StorageNotFoundError), + async_mock.AsyncMock(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 @async_mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() 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 e0fc85ab73..8c0fe1ecfa 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -69,7 +69,7 @@ class TestResponseHandler: @pytest.mark.asyncio @async_mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -83,7 +83,7 @@ async def test_called(self, mock_conn_mgr, request_context): @async_mock.patch.object(handler, "ConnectionManager") async def test_called_auto_ping(self, mock_conn_mgr, request_context): request_context.update_settings({"auto_ping_connection": True}) - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() 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 @async_mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() 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/messages/tests/test_connection_request.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py index 51b77702e5..a5faf19f1b 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import ( DIDDoc, @@ -104,7 +104,7 @@ def test_serialize(self, mock_connection_request_schema_dump): ) -class TestConnectionRequestSchema(AsyncTestCase, TestConfig): +class TestConnectionRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test connection request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py index 0fadf94ff4..616f6f20c4 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......wallet.key_type import ED25519 from ......connections.models.diddoc import ( @@ -100,7 +100,7 @@ def test_serialize(self, mock_connection_response_schema_dump): ) -class TestConnectionResponseSchema(AsyncTestCase, TestConfig): +class TestConnectionResponseSchema(IsolatedAsyncioTestCase, TestConfig): async def test_make_model(self): connection_response = ConnectionResponse( connection=ConnectionDetail(did=self.test_did, did_doc=self.make_did_doc()) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index ee8bfd1a66..134a0b0170 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache @@ -28,7 +29,7 @@ from ..models.connection_detail import ConnectionDetail -class TestConnectionManager(AsyncTestCase): +class TestConnectionManager(IsolatedAsyncioTestCase): def make_did_doc(self, did, verkey): doc = DIDDoc(did=did) controller = did @@ -46,7 +47,7 @@ def make_did_doc(self, did, verkey): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.test_seed = "testseed000000000000000000000001" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" @@ -58,13 +59,13 @@ async def setUp(self): self.responder = MockResponder() self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + clean_finished_oob_record=async_mock.AsyncMock(return_value=None) ) self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = async_mock.AsyncMock( return_value=None ) self.resolver = DIDResolver() @@ -135,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 = async_mock.CoroutineMock() + self.route_manager.route_verkey = async_mock.AsyncMock() with async_mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: @@ -265,7 +266,7 @@ async def test_create_invitation_multi_use_metadata_transfers_to_connection(self assert await new_conn_rec.metadata_get_all(session) == {"test": "value"} async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -291,7 +292,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) mock_get_default_mediator.assert_not_called() async def test_create_invitation_mediation_using_default(self): - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -306,7 +307,7 @@ async def test_create_invitation_mediation_using_default(self): with async_mock.patch.object( self.route_manager, "mediation_record_if_id", - async_mock.CoroutineMock(return_value=mediation_record), + async_mock.AsyncMock(return_value=mediation_record), ): _, invite = await self.manager.create_invitation( routing_keys=[self.test_verkey], @@ -430,7 +431,7 @@ async def test_create_request_multitenant(self): ) as create_did_document, async_mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + async_mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -483,7 +484,7 @@ async def test_create_request_mediation_id(self): ) as create_local_did, async_mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + async_mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -534,7 +535,7 @@ async def test_create_request_default_mediator(self): ) as create_local_did, async_mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + async_mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -586,7 +587,7 @@ async def test_receive_request_public_did_oob_invite(self): ) as mock_conn_retrieve_by_id, async_mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -626,7 +627,7 @@ async def test_receive_request_public_did_unsolicited_fails(self): ) as mock_conn_retrieve_by_id, async_mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -650,8 +651,8 @@ async def test_receive_request_public_did_conn_invite(self): ) mock_connection_record = async_mock.MagicMock() - mock_connection_record.save = async_mock.CoroutineMock() - mock_connection_record.attach_request = async_mock.CoroutineMock() + mock_connection_record.save = async_mock.AsyncMock() + mock_connection_record.attach_request = async_mock.AsyncMock() self.context.update_settings({"public_invites": True}) with async_mock.patch.object( @@ -667,7 +668,7 @@ async def test_receive_request_public_did_conn_invite(self): ), async_mock.patch.object( ConnRecord, "retrieve_by_invitation_msg_id", - async_mock.CoroutineMock(return_value=mock_connection_record), + async_mock.AsyncMock(return_value=mock_connection_record), ) as mock_conn_retrieve_by_invitation_msg_id: conn_rec = await self.manager.receive_request(mock_request, receipt) assert conn_rec @@ -703,7 +704,7 @@ async def test_receive_request_public_did_unsolicited(self): ) as mock_conn_retrieve_by_id, async_mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -829,7 +830,7 @@ async def test_receive_request_public_did_no_auto_accept(self): ) as mock_conn_retrieve_by_id, async_mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -850,7 +851,7 @@ async def test_create_response(self): ) as mock_conn_save, async_mock.patch.object( ConnectionResponse, "sign_field", autospec=True ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.CoroutineMock() + conn_rec, "metadata_get", async_mock.AsyncMock() ): await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -873,7 +874,7 @@ async def test_create_response_multitenant(self): ), async_mock.patch.object( ConnRecord, "save", autospec=True ), async_mock.patch.object( - ConnRecord, "metadata_get", async_mock.CoroutineMock(return_value=False) + ConnRecord, "metadata_get", async_mock.AsyncMock(return_value=False) ), async_mock.patch.object( ConnRecord, "retrieve_request", autospec=True ), async_mock.patch.object( @@ -885,7 +886,7 @@ async def test_create_response_multitenant(self): ) as create_did_document, async_mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + async_mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -947,7 +948,7 @@ async def test_create_response_mediation(self): ), async_mock.patch.object( ConnRecord, "save", autospec=True ), async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) + record, "metadata_get", async_mock.AsyncMock(return_value=False) ), async_mock.patch.object( ConnectionManager, "create_did_document", autospec=True ) as create_did_document, async_mock.patch.object( @@ -955,7 +956,7 @@ async def test_create_response_mediation(self): ) as create_local_did, async_mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.CoroutineMock(return_value=[mediation_record]), + async_mock.AsyncMock(return_value=[mediation_record]), ), async_mock.patch.object( record, "retrieve_request", autospec=True ), async_mock.patch.object( @@ -998,7 +999,7 @@ async def test_create_response_auto_send_mediation_request(self): ) as mock_conn_save, async_mock.patch.object( ConnectionResponse, "sign_field", autospec=True ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.CoroutineMock(return_value=True) + conn_rec, "metadata_get", async_mock.AsyncMock(return_value=True) ): await self.manager.create_response(conn_rec) @@ -1014,7 +1015,7 @@ async def test_accept_response_find_by_thread_id(self): mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = async_mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = async_mock.AsyncMock( return_value="sig_verkey" ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) @@ -1022,16 +1023,16 @@ async def test_accept_response_find_by_thread_id(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + MediationManager, "get_default_mediator", async_mock.AsyncMock() ): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=self.test_target_did, did_doc=async_mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1046,7 +1047,7 @@ 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 = async_mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = async_mock.AsyncMock( return_value="sig_verkey" ) @@ -1055,19 +1056,19 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + MediationManager, "get_default_mediator", async_mock.AsyncMock() ): mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( did=self.test_target_did, did_doc=async_mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=False), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(return_value=False), connection_id="test-conn-id", invitation_key="test-invitation-id", ) @@ -1091,9 +1092,9 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1114,7 +1115,7 @@ async def test_accept_response_find_by_thread_id_bad_state(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 @@ -1135,7 +1136,7 @@ async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=self.test_target_did, @@ -1159,7 +1160,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=self.test_target_did, @@ -1177,24 +1178,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 = async_mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( - side_effect=ValueError - ) + mock_response.verify_signed_field = async_mock.AsyncMock(side_effect=ValueError) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + MediationManager, "get_default_mediator", async_mock.AsyncMock() ): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=self.test_target_did, did_doc=async_mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1208,7 +1207,7 @@ async def test_accept_response_auto_send_mediation_request(self): mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = async_mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.CoroutineMock( + mock_response.verify_signed_field = async_mock.AsyncMock( return_value="sig_verkey" ) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) @@ -1216,16 +1215,16 @@ async def test_accept_response_auto_send_mediation_request(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.CoroutineMock() + MediationManager, "get_default_mediator", async_mock.AsyncMock() ): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=self.test_target_did, did_doc=async_mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=True), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(return_value=True), connection_id="test-conn-id", invitation_key="test-invitation-key", ) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index bed4e604bf..e0d6c156f8 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -1,8 +1,8 @@ import json from unittest.mock import ANY -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -13,13 +13,13 @@ from .. import routes as test_module -class TestConnectionRoutes(AsyncTestCase): - async def setUp(self): +class TestConnectionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -45,7 +45,7 @@ async def test_connections_list(self): with async_mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.query = async_mock.CoroutineMock() + mock_conn_rec.query = async_mock.AsyncMock() mock_conn_rec.Role = ConnRecord.Role mock_conn_rec.State = async_mock.MagicMock( COMPLETED=STATE_COMPLETED, @@ -134,7 +134,7 @@ async def test_connections_list_x(self): COMPLETED=STATE_COMPLETED, get=async_mock.MagicMock(return_value=ConnRecord.State.COMPLETED), ) - mock_conn_rec.query = async_mock.CoroutineMock( + mock_conn_rec.query = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -147,7 +147,7 @@ async def test_connections_retrieve(self): mock_conn_rec.serialize = async_mock.MagicMock(return_value={"hello": "world"}) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -166,7 +166,7 @@ async def test_connections_endpoints(self): test_module.web, "json_response" ) as mock_response: mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( + get_endpoints=async_mock.AsyncMock( return_value=("localhost:8080", "1.2.3.4:8081") ) ) @@ -188,16 +188,14 @@ async def test_connections_endpoints_x(self): test_module.web, "json_response" ) as mock_response: mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( - side_effect=StorageNotFoundError() - ) + get_endpoints=async_mock.AsyncMock(side_effect=StorageNotFoundError()) ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_endpoints(self.request) mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.CoroutineMock( + get_endpoints=async_mock.AsyncMock( side_effect=test_module.WalletError() ) ) @@ -210,9 +208,9 @@ async def test_connections_metadata(self): mock_conn_rec = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() ) as mock_metadata_get_all, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -229,11 +227,11 @@ async def test_connections_metadata_get_single(self): self.request.query = {"key": "test"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_get", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get", async_mock.AsyncMock() ) as mock_metadata_get, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -249,9 +247,9 @@ async def test_connections_metadata_x(self): mock_conn_rec = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() ) as mock_metadata_get_all, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -268,16 +266,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 = async_mock.MagicMock() - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() + mock_conn_rec, "metadata_set", async_mock.AsyncMock() ) as mock_metadata_set, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -291,16 +289,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 = async_mock.MagicMock() - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.CoroutineMock() + mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() + mock_conn_rec, "metadata_set", async_mock.AsyncMock() ) as mock_metadata_set, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -318,7 +316,7 @@ async def test_connections_retrieve_not_found(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -333,7 +331,7 @@ async def test_connections_retrieve_x(self): ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -349,7 +347,7 @@ async def test_connections_create_invitation(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -362,7 +360,7 @@ async def test_connections_create_invitation(self): ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( return_value=( async_mock.MagicMock( # connection record connection_id="dummy", alias="conn-alias" @@ -398,7 +396,7 @@ async def test_connections_create_invitation(self): async def test_connections_create_invitation_x(self): self.context.update_settings({"public_invites": True}) - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -409,7 +407,7 @@ async def test_connections_create_invitation_x(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -425,7 +423,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -435,7 +433,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -443,7 +441,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): async def test_connections_create_invitation_public_forbidden(self): self.context.update_settings({"public_invites": False}) - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -455,7 +453,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -471,7 +469,7 @@ async def test_connections_receive_invitation(self): ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_invitation = async_mock.AsyncMock( return_value=mock_conn_rec ) @@ -479,7 +477,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -505,7 +503,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -520,7 +518,7 @@ async def test_connections_receive_invitation_x_bad_mediation_id(self): ) as mock_inv_deser, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_conn_mgr.return_value.receive_invitation = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -538,14 +536,14 @@ async def test_connections_accept_invitation(self): mock_conn_rec.serialize = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_request = async_mock.AsyncMock() await test_module.connections_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -554,7 +552,7 @@ async def test_connections_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -565,11 +563,11 @@ async def test_connections_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -581,11 +579,11 @@ async def test_connections_accept_invitation_x_bad_mediation_id(self): self.request.query["mediation_id"] = "some-id" with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -602,14 +600,14 @@ async def test_connections_accept_request(self): mock_conn_rec.serialize = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() await test_module.connections_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -618,7 +616,7 @@ async def test_connections_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -629,13 +627,13 @@ async def test_connections_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_response = async_mock.CoroutineMock( + mock_conn_mgr.return_value.create_response = async_mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -645,10 +643,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 = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.CoroutineMock() + mock_conn_rec.delete_record = async_mock.AsyncMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -664,10 +662,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 = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.CoroutineMock() + mock_conn_rec.delete_record = async_mock.AsyncMock() assert (await cache.get("conn_rec_state::dummy")) == "active" with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -683,7 +681,7 @@ async def test_connections_remove_not_found(self): mock_conn_rec = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -693,13 +691,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 = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + delete_record=async_mock.AsyncMock(side_effect=test_module.StorageError()) ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -707,7 +703,7 @@ async def test_connections_remove_x(self): await test_module.connections_remove(self.request) async def test_connections_create_static(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -739,10 +735,8 @@ async def test_connections_create_static(self): ) as mock_conn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_static_connection = ( - async_mock.CoroutineMock( - return_value=(mock_my_info, mock_their_info, mock_conn_rec) - ) + mock_conn_mgr.return_value.create_static_connection = async_mock.AsyncMock( + return_value=(mock_my_info, mock_their_info, mock_conn_rec) ) await test_module.connections_create_static(self.request) @@ -758,7 +752,7 @@ async def test_connections_create_static(self): ) async def test_connections_create_static_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -788,8 +782,8 @@ async def test_connections_create_static_x(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_static_connection = ( - async_mock.CoroutineMock(side_effect=test_module.WalletError()) + mock_conn_mgr.return_value.create_static_connection = async_mock.AsyncMock( + side_effect=test_module.WalletError() ) with self.assertRaises(test_module.web.HTTPBadRequest): diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py index 064c06dd4e..9fb4e64433 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_query_handler.py @@ -1,6 +1,6 @@ """Test handler for keylist-query message.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -20,10 +20,10 @@ TEST_VERKEY_DIDKEY = "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL" -class TestKeylistQueryHandler(AsyncTestCase): +class TestKeylistQueryHandler(IsolatedAsyncioTestCase): """Test handler for keylist-query message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py index f2a6830e5d..922ef80b98 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_handler.py @@ -1,6 +1,6 @@ """Test handler for keylist-update message.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -19,10 +19,10 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestKeylistUpdateHandler(AsyncTestCase): +class TestKeylistUpdateHandler(IsolatedAsyncioTestCase): """Test handler for keylist-update message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py index b5774c5723..7399ce0d3c 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py @@ -3,8 +3,8 @@ from functools import partial from typing import AsyncGenerator import pytest -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......connections.models.conn_record import ConnRecord @@ -26,10 +26,10 @@ TEST_ROUTE_VERKEY = "did:key:z6MknxTj6Zj1VrDWc1ofaZtmCVv2zNXpD58Xup4ijDGoQhya" -class TestKeylistUpdateResponseHandler(AsyncTestCase): +class TestKeylistUpdateResponseHandler(IsolatedAsyncioTestCase): """Test handler for keylist-update-response message.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.updated = [ diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py index 08a8b42c97..6437002428 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_deny_handler.py @@ -1,6 +1,6 @@ """Test mediate deny message handler.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -13,10 +13,10 @@ TEST_CONN_ID = "conn-id" -class TestMediationDenyHandler(AsyncTestCase): +class TestMediationDenyHandler(IsolatedAsyncioTestCase): """Test mediate deny message handler.""" - async def setUp(self): + async def asyncSetUp(self): """Setup test dependencies.""" self.context = RequestContext.test_context() self.session = await self.context.session() diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py index d3a39dbebb..62abea7057 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py @@ -1,7 +1,7 @@ """Test mediate grant message handler.""" import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from aries_cloudagent.core.profile import ProfileSession @@ -84,7 +84,7 @@ async def test_handler_connection_has_set_to_default_meta( with async_mock.patch.object( context.connection_record, "metadata_get", - async_mock.CoroutineMock(return_value=True), + async_mock.AsyncMock(return_value=True), ), async_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(), async_mock.CoroutineMock() - responder.send = async_mock.CoroutineMock() + handler, responder = MediationGrantHandler(), async_mock.AsyncMock() + responder.send = async_mock.AsyncMock() profile = context.profile profile.context.update_settings( {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - multitenant_mgr = async_mock.CoroutineMock() + multitenant_mgr = async_mock.AsyncMock() profile.context.injector.bind_instance(BaseMultitenantManager, multitenant_mgr) default_base_mediator = MediationRecord(routing_keys=["key1", "key2"]) - multitenant_mgr.get_default_mediator = async_mock.CoroutineMock() + multitenant_mgr.get_default_mediator = async_mock.AsyncMock() 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 async_mock.patch.object( context.connection_record, "metadata_get", - async_mock.CoroutineMock(return_value=False), + async_mock.AsyncMock(return_value=False), ), async_mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py index d3c342ec07..e32fe4f9da 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_request_handler.py @@ -1,6 +1,6 @@ """Test mediate request message handler.""" import pytest -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -19,10 +19,10 @@ TEST_VERKEY = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" -class TestMediationRequestHandler(AsyncTestCase): +class TestMediationRequestHandler(IsolatedAsyncioTestCase): """Test mediate request message handler.""" - async def setUp(self): + async def asyncSetUp(self): """setup dependencies of messaging""" self.context = RequestContext.test_context() self.context.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py index 6cf8857a9f..4bf2015bc7 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py @@ -1,6 +1,6 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from unittest import TestCase -from asynctest import mock as async_mock +from unittest import mock as async_mock from aries_cloudagent.protocols.coordinate_mediation.mediation_invite_store import ( MediationInviteStore, @@ -47,7 +47,7 @@ def test_unused_should_create_unused_record(self): assert not MediationInviteRecord.unused("some_other_invite").used -class TestMediationInviteStore(AsyncTestCase): +class TestMediationInviteStore(IsolatedAsyncioTestCase): def setUp(self): self.storage = async_mock.MagicMock(spec=BaseStorage) self.mediation_invite_store = MediationInviteStore(self.storage) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py index 5848c59063..e1ac4abb64 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py @@ -2,7 +2,7 @@ import logging from typing import AsyncIterable, Iterable -from asynctest import mock as async_mock +from unittest import mock as async_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 async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve: await manager.set_default_mediator_by_id("test") @@ -405,7 +405,7 @@ async def test_store_update_results( ] with async_mock.patch.object( - RouteRecord, "query", async_mock.CoroutineMock() + RouteRecord, "query", async_mock.AsyncMock() ) as mock_route_rec_query, async_mock.patch.object( test_module.LOGGER, "error", async_mock.MagicMock() ) as mock_logger_error: @@ -415,12 +415,12 @@ async def test_store_update_results( mock_logger_error.assert_called_once() with async_mock.patch.object( - RouteRecord, "query", async_mock.CoroutineMock() + RouteRecord, "query", async_mock.AsyncMock() ) as mock_route_rec_query, async_mock.patch.object( test_module.LOGGER, "error", async_mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.return_value = [ - async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) + async_mock.MagicMock(delete_record=async_mock.AsyncMock()) ] * 2 await manager.store_update_results(TEST_CONN_ID, results) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py index f543efe386..04d9f1db7f 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_route_manager.py @@ -1,4 +1,4 @@ -from asynctest import mock +from unittest 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.CoroutineMock() - routing_info = mock.CoroutineMock() + _route_for_key = mock.AsyncMock() + routing_info = mock.AsyncMock() @pytest.fixture @@ -51,10 +51,8 @@ def profile(mock_responder: MockResponder): @pytest.fixture def route_manager(): manager = MockRouteManager() - manager._route_for_key = mock.CoroutineMock( - return_value=mock.MagicMock(KeylistUpdate) - ) - manager.routing_info = mock.CoroutineMock(return_value=([], None)) + manager._route_for_key = mock.AsyncMock(return_value=mock.MagicMock(KeylistUpdate)) + manager.routing_info = mock.AsyncMock(return_value=([], None)) yield manager @@ -66,8 +64,8 @@ def mediation_route_manager(): @pytest.fixture def conn_record(): record = ConnRecord(connection_id="12345") - record.metadata_get = mock.CoroutineMock(return_value={}) - record.metadata_set = mock.CoroutineMock() + record.metadata_get = mock.AsyncMock(return_value={}) + record.metadata_set = mock.AsyncMock() yield record @@ -80,9 +78,9 @@ async def test_get_or_create_my_did_no_did( with mock.patch.object( InMemoryWallet, "create_local_did", - mock.CoroutineMock(return_value=mock_did_info), + mock.AsyncMock(return_value=mock_did_info), ) as mock_create_local_did, mock.patch.object( - conn_record, "save", mock.CoroutineMock() + conn_record, "save", mock.AsyncMock() ) as mock_save: info = await route_manager.get_or_create_my_did(profile, conn_record) assert mock_did_info == info @@ -97,7 +95,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.CoroutineMock(return_value=mock_did_info) + InMemoryWallet, "get_local_did", mock.AsyncMock(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 @@ -112,9 +110,9 @@ async def test_mediation_record_for_connection_mediation_id( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.CoroutineMock() + route_manager, "save_mediator_for_connection", mock.AsyncMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, mediation_record.mediation_id @@ -135,9 +133,9 @@ async def test_mediation_record_for_connection_mediation_metadata( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.CoroutineMock() + route_manager, "save_mediator_for_connection", mock.AsyncMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, "another-mediation-id" @@ -155,9 +153,9 @@ async def test_mediation_record_for_connection_default( with mock.patch.object( route_manager, "mediation_record_if_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_mediation_record_if_id, mock.patch.object( - route_manager, "save_mediator_for_connection", mock.CoroutineMock() + route_manager, "save_mediator_for_connection", mock.AsyncMock() ): assert await route_manager.mediation_records_for_connection( profile, conn_record, None, or_default=True @@ -175,7 +173,7 @@ async def test_mediation_record_if_id_with_id( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_retrieve_by_id: actual = await route_manager.mediation_record_if_id( profile, mediation_id=mediation_record.mediation_id @@ -194,7 +192,7 @@ async def test_mediation_record_if_id_with_id_bad_state( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ): with pytest.raises(RouteManagerError): await route_manager.mediation_record_if_id( @@ -212,9 +210,9 @@ async def test_mediation_record_if_id_with_id_and_default( with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_retrieve_by_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.CoroutineMock() + MediationManager, "get_default_mediator", mock.AsyncMock() ) as mock_get_default_mediator: actual = await route_manager.mediation_record_if_id( profile, mediation_id=mediation_record.mediation_id, or_default=True @@ -233,11 +231,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.CoroutineMock() + MediationRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id, mock.patch.object( MediationManager, "get_default_mediator", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ) as mock_get_default_mediator: actual = await route_manager.mediation_record_if_id( profile, mediation_id=None, or_default=True @@ -253,9 +251,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.CoroutineMock(return_value=None) + MediationRecord, "retrieve_by_id", mock.AsyncMock(return_value=None) ) as mock_retrieve_by_id, mock.patch.object( - MediationManager, "get_default_mediator", mock.CoroutineMock(return_value=None) + MediationManager, "get_default_mediator", mock.AsyncMock(return_value=None) ) as mock_get_default_mediator: assert ( await route_manager.mediation_record_if_id( @@ -276,7 +274,7 @@ async def test_route_connection_as_invitee( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.CoroutineMock(return_value=mock_did_info), + mock.AsyncMock(return_value=mock_did_info), ): await route_manager.route_connection_as_invitee( profile, conn_record, [mediation_record] @@ -296,7 +294,7 @@ async def test_route_connection_as_inviter( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.CoroutineMock(return_value=mock_did_info), + mock.AsyncMock(return_value=mock_did_info), ): await route_manager.route_connection_as_inviter( profile, conn_record, [mediation_record] @@ -321,11 +319,11 @@ async def test_route_connection_state_inviter_replace_key_none( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.CoroutineMock(return_value=mock_did_info), + mock.AsyncMock(return_value=mock_did_info), ), mock.patch.object( InMemoryWallet, "get_public_did", - mock.CoroutineMock( + mock.AsyncMock( return_value=DIDInfo( TEST_RECORD_DID, TEST_RECORD_VERKEY, @@ -355,9 +353,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.CoroutineMock() + route_manager, "route_connection_as_invitee", mock.AsyncMock() ) as mock_route_connection_as_invitee, mock.patch.object( - route_manager, "route_connection_as_inviter", mock.CoroutineMock() + route_manager, "route_connection_as_inviter", mock.AsyncMock() ) as mock_route_connection_as_inviter: await route_manager.route_connection(profile, conn_record, [mediation_record]) mock_route_connection_as_invitee.assert_called_once() @@ -372,9 +370,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.CoroutineMock() + route_manager, "route_connection_as_invitee", mock.AsyncMock() ) as mock_route_connection_as_invitee, mock.patch.object( - route_manager, "route_connection_as_inviter", mock.CoroutineMock() + route_manager, "route_connection_as_inviter", mock.AsyncMock() ) as mock_route_connection_as_inviter: await route_manager.route_connection(profile, conn_record, [mediation_record]) mock_route_connection_as_inviter.assert_called_once() @@ -401,7 +399,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.CoroutineMock() + route_manager, "save_mediator_for_connection", mock.AsyncMock() ): await route_manager.route_invitation(profile, conn_record, mediation_record) route_manager._route_for_key.assert_called_once() @@ -413,7 +411,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.CoroutineMock() + route_manager, "save_mediator_for_connection", mock.AsyncMock() ): with pytest.raises(ValueError): await route_manager.route_invitation(profile, conn_record, mediation_record) @@ -446,7 +444,7 @@ async def test_route_static( with mock.patch.object( route_manager, "get_or_create_my_did", - mock.CoroutineMock(return_value=mock_did_info), + mock.AsyncMock(return_value=mock_did_info), ): await route_manager.route_static(profile, conn_record, mediation_record) route_manager._route_for_key.assert_called_once_with( @@ -466,10 +464,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.CoroutineMock(return_value=session) - session.__aexit__ = mock.CoroutineMock() + session.__aenter__ = mock.AsyncMock(return_value=session) + session.__aexit__ = mock.AsyncMock() with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.CoroutineMock() + MediationRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: await route_manager.save_mediator_for_connection( profile, conn_record, mediation_record @@ -491,12 +489,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.CoroutineMock(return_value=session) - session.__aexit__ = mock.CoroutineMock() + session.__aenter__ = mock.AsyncMock(return_value=session) + session.__aexit__ = mock.AsyncMock() with mock.patch.object( MediationRecord, "retrieve_by_id", - mock.CoroutineMock(return_value=mediation_record), + mock.AsyncMock(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 @@ -516,7 +514,7 @@ async def test_save_mediator_for_connection_no_mediator( conn_record: ConnRecord, ): with mock.patch.object( - MediationRecord, "retrieve_by_id", mock.CoroutineMock() + MediationRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: await route_manager.save_mediator_for_connection(profile, conn_record) mock_retrieve_by_id.assert_not_called() @@ -530,7 +528,7 @@ async def test_connection_from_recipient_key_invite( with mock.patch.object( ConnRecord, "retrieve_by_tag_filter", - mock.CoroutineMock(return_value=conn_record), + mock.AsyncMock(return_value=conn_record), ): result = await route_manager.connection_from_recipient_key(profile, TEST_VERKEY) assert conn_record == result @@ -542,14 +540,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.CoroutineMock() + mock_wallet.get_local_did_for_verkey = mock.AsyncMock() 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.CoroutineMock(return_value=conn_record) + ConnRecord, "retrieve_by_did", mock.AsyncMock(return_value=conn_record) ): result = await route_manager.connection_from_recipient_key(profile, TEST_VERKEY) assert conn_record == result @@ -591,9 +589,7 @@ 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.CoroutineMock() - ): + with mock.patch.object(RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock()): keylist_update = await mediation_route_manager._route_for_key( profile, TEST_VERKEY, @@ -617,7 +613,7 @@ async def test_mediation_route_for_key_skip_if_exists_and_absent( with mock.patch.object( RouteRecord, "retrieve_by_recipient_key", - mock.CoroutineMock(side_effect=StorageNotFoundError), + mock.AsyncMock(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 d4b3a83c99..fb9702eb54 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -9,12 +10,12 @@ from .....wallet.did_method import DIDMethods -class TestCoordinateMediationRoutes(AsyncTestCase): +class TestCoordinateMediationRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.context = AdminRequestContext.test_context(profile=self.profile) - self.outbound_message_router = async_mock.CoroutineMock() + self.outbound_message_router = async_mock.AsyncMock() self.request_dict = { "context": self.context, "outbound_message_router": self.outbound_message_router, @@ -25,7 +26,7 @@ def setUp(self): "conn_id": "test-conn-id", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=async_mock.AsyncMock(return_value={}), __getitem__=lambda _, k: self.request_dict[k], ) serialized = { @@ -40,7 +41,7 @@ def setUp(self): self.mock_record = async_mock.MagicMock( **serialized, serialize=async_mock.MagicMock(return_value=serialized), - save=async_mock.CoroutineMock() + save=async_mock.AsyncMock() ) def test_mediation_sort_key(self): @@ -68,7 +69,7 @@ async def test_list_mediation_requests(self): with async_mock.patch.object( test_module.MediationRecord, "query", - async_mock.CoroutineMock(return_value=[self.mock_record]), + async_mock.AsyncMock(return_value=[self.mock_record]), ) as mock_query, async_mock.patch.object( test_module.web, "json_response" ) as json_response, async_mock.patch.object( @@ -90,7 +91,7 @@ async def test_list_mediation_requests_filters(self): with async_mock.patch.object( test_module.MediationRecord, "query", - async_mock.CoroutineMock(return_value=[self.mock_record]), + async_mock.AsyncMock(return_value=[self.mock_record]), ) as mock_query, async_mock.patch.object( test_module.web, "json_response" ) as json_response, async_mock.patch.object( @@ -115,7 +116,7 @@ async def test_list_mediation_requests_x(self): test_module, "MediationRecord", async_mock.MagicMock( - query=async_mock.CoroutineMock(side_effect=test_module.StorageError()) + query=async_mock.AsyncMock(side_effect=test_module.StorageError()) ), ) as mock_med_rec: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -125,7 +126,7 @@ async def test_list_mediation_requests_no_records(self): with async_mock.patch.object( test_module, "MediationRecord", - async_mock.MagicMock(query=async_mock.CoroutineMock(return_value=[])), + async_mock.MagicMock(query=async_mock.AsyncMock(return_value=[])), ) as mock_med_rec, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -134,7 +135,7 @@ async def test_list_mediation_requests_no_records(self): async def test_retrieve_mediation_request(self): with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -149,7 +150,7 @@ async def test_retrieve_mediation_request_x_not_found(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -161,7 +162,7 @@ async def test_retrieve_mediation_request_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -171,9 +172,9 @@ async def test_retrieve_mediation_request_x_storage_error(self): async def test_delete_mediation_request(self): with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_mediation_record_retrieve, async_mock.patch.object( - self.mock_record, "delete_record", async_mock.CoroutineMock() + self.mock_record, "delete_record", async_mock.AsyncMock() ) as mock_delete_record, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -189,7 +190,7 @@ async def test_delete_mediation_request_x_not_found(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -201,7 +202,7 @@ async def test_delete_mediation_request_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( @@ -219,11 +220,11 @@ async def test_request_mediation(self): ) as mock_response, async_mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.CoroutineMock(return_value=False), + async_mock.AsyncMock(return_value=False), ) as mock_mediation_record_exists, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: - mock_med_mgr.return_value.prepare_request = async_mock.CoroutineMock( + mock_med_mgr.return_value.prepare_request = async_mock.AsyncMock( return_value=( self.mock_record, async_mock.MagicMock( # mediation request @@ -243,7 +244,7 @@ async def test_request_mediation_x_conn_not_ready(self): with async_mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=async_mock.MagicMock(is_ready=False)), + async_mock.AsyncMock(return_value=async_mock.MagicMock(is_ready=False)), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -254,11 +255,11 @@ async def test_request_mediation_x_already_exists(self): body = {} self.request.json.return_value = body with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.CoroutineMock(return_value=True), + async_mock.AsyncMock(return_value=True), ) as mock_exists_for_conn, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -271,7 +272,7 @@ async def test_request_mediation_x_conn_not_found(self): with async_mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPNotFound ): @@ -283,7 +284,7 @@ async def test_request_mediation_x_storage_error(self): with async_mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ): @@ -294,7 +295,7 @@ async def test_mediation_request_grant_role_server(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -309,7 +310,7 @@ async def test_mediation_request_grant_role_client_x(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) @@ -317,7 +318,7 @@ async def test_mediation_request_grant_x_rec_not_found(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_grant(self.request) @@ -325,7 +326,7 @@ async def test_mediation_request_grant_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) @@ -334,7 +335,7 @@ async def test_mediation_request_deny_role_server(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -347,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 async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_mediation_record_retrieve, async_mock.patch.object( test_module.web, "json_response" ): @@ -361,7 +362,7 @@ async def test_mediation_request_deny_x_rec_not_found(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_deny(self.request) @@ -369,7 +370,7 @@ async def test_mediation_request_deny_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) @@ -389,7 +390,7 @@ async def test_get_keylist(self): with async_mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(return_value=query_results), + async_mock.AsyncMock(return_value=query_results), ) as mock_query, async_mock.patch.object( self.profile, "session", @@ -411,7 +412,7 @@ async def test_get_keylist_no_matching_records(self): with async_mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(return_value=[]), + async_mock.AsyncMock(return_value=[]), ) as mock_query, async_mock.patch.object( self.profile, "session", @@ -427,7 +428,7 @@ async def test_get_keylist_storage_error(self): with async_mock.patch.object( test_module.RouteRecord, "query", - async_mock.CoroutineMock(side_effect=test_module.StorageError), + async_mock.AsyncMock(side_effect=test_module.StorageError), ) as mock_query, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_keylist(self.request) @@ -462,7 +463,7 @@ async def test_send_keylist_update(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( state=MediationRecord.STATE_GRANTED, connection_id="test-conn-id" ) @@ -504,7 +505,7 @@ async def test_send_keylist_update_bad_mediation_state(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( state=MediationRecord.STATE_DENIED, connection_id="test-conn-id" ) @@ -529,7 +530,7 @@ async def test_send_keylist_update_x_no_mediation_rec(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_update(self.request) @@ -546,7 +547,7 @@ async def test_send_keylist_update_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_update(self.request) @@ -557,11 +558,11 @@ async def test_send_keylist_query(self, mock_manager): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_retrieve_by_id, async_mock.patch.object( mock_manager.return_value, "prepare_keylist_query", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_prepare_keylist_query, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -579,7 +580,7 @@ async def test_send_keylist_query_x_no_mediation_record(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_query(self.request) @@ -587,7 +588,7 @@ async def test_send_keylist_query_x_storage_error(self): with async_mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_query(self.request) @@ -598,7 +599,7 @@ async def test_get_default_mediator(self): ) as json_response, async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -613,7 +614,7 @@ async def test_get_empty_default_mediator(self): ) as json_response, async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=None), + async_mock.AsyncMock(return_value=None), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -628,7 +629,7 @@ async def test_get_default_mediator_storage_error(self): ) as json_response, async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageNotFoundError()), + async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mgr_get_default_record: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_default_mediator(self.request) @@ -641,11 +642,11 @@ async def test_set_default_mediator(self): with async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_mgr_get_default_record, async_mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -663,11 +664,11 @@ async def test_set_default_mediator_storage_error(self): with async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_mgr_get_default_record, async_mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -679,11 +680,11 @@ async def test_clear_default_mediator(self): with async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(return_value=self.mock_record), + async_mock.AsyncMock(return_value=self.mock_record), ) as mock_mgr_get_default_record, async_mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -698,11 +699,11 @@ async def test_clear_default_mediator_storage_error(self): with async_mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.CoroutineMock(side_effect=test_module.StorageError()), + async_mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_mgr_get_default_record, async_mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -718,13 +719,13 @@ async def test_update_keylist_for_connection(self): mock_route_manager = async_mock.MagicMock(RouteManager) mock_keylist_update = async_mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = async_mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module.web, "json_response" ) as json_response: @@ -740,15 +741,15 @@ async def test_update_keylist_for_connection_not_found(self): mock_route_manager = async_mock.MagicMock(RouteManager) mock_keylist_update = async_mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = async_mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with async_mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + async_mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPNotFound): await test_module.update_keylist_for_connection(self.request) @@ -762,15 +763,15 @@ async def test_update_keylist_for_connection_storage_error(self): mock_route_manager = async_mock.MagicMock(RouteManager) mock_keylist_update = async_mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.CoroutineMock( + mock_route_manager.route_connection = async_mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.CoroutineMock() + mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) with async_mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageError), + async_mock.AsyncMock(side_effect=StorageError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.update_keylist_for_connection(self.request) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py index 945a6de809..4cad2ad869 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -27,7 +27,7 @@ class TestDIDXCompleteHandler: @pytest.mark.asyncio @async_mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.CoroutineMock() + mock_conn_mgr.return_value.accept_complete = async_mock.AsyncMock() 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 @async_mock.patch.object(test_module, "DIDXManager") async def test_x(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.CoroutineMock( + mock_conn_mgr.return_value.accept_complete = async_mock.AsyncMock( 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 e851c2d8c7..38d63d3aea 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,4 +1,4 @@ -from asynctest import mock as async_mock +from unittest import mock as async_mock import pytest from .. import problem_report_handler as test_module @@ -21,7 +21,7 @@ class TestDIDXProblemReportHandler: @pytest.mark.asyncio @async_mock.patch.object(test_module, "DIDXManager") async def test_called(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.CoroutineMock() + manager.return_value.receive_problem_report = async_mock.AsyncMock() request_context.message = DIDXProblemReport() request_context.connection_record = async_mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() @@ -33,7 +33,7 @@ async def test_called(self, manager, request_context): @pytest.mark.asyncio @async_mock.patch.object(test_module, "DIDXManager") async def test_called_no_conn(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.CoroutineMock() + manager.return_value.receive_problem_report = async_mock.AsyncMock() 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 = async_mock.CoroutineMock( + manager.return_value.receive_problem_report = async_mock.AsyncMock( 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 dada5723a3..b822cc5b11 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py @@ -1,5 +1,5 @@ -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......connections.models import conn_record, connection_target from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service @@ -22,7 +22,7 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestDIDXRequestHandler(AsyncTestCase): +class TestDIDXRequestHandler(IsolatedAsyncioTestCase): """Class unit testing request handler.""" def did_doc(self): @@ -52,7 +52,7 @@ def did_doc(self): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.ctx = RequestContext.test_context() self.ctx.message_receipt = MessageReceipt( recipient_did="dummy", @@ -93,7 +93,7 @@ async def setUp(self): @async_mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock() 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 = async_mock.MagicMock() mock_conn_rec.accept = conn_record.ConnRecord.ACCEPT_AUTO - mock_conn_rec.save = async_mock.CoroutineMock() - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_conn_rec.save = async_mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=mock_conn_rec ) - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() 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 = async_mock.CoroutineMock( + test_exist_conn.metadata_get = async_mock.AsyncMock( return_value={"id": "mediation-test-id"} ) test_exist_conn.accept = conn_record.ConnRecord.ACCEPT_AUTO - test_exist_conn.save = async_mock.CoroutineMock() - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + test_exist_conn.save = async_mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=test_exist_conn ) - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() 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( @async_mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) @@ -189,7 +189,7 @@ async def test_problem_report(self, mock_didx_mgr): @async_mock.patch.object(test_module, "DIDXManager") @async_mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc(self, mock_conn_target, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( 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 = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( 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 fa4fe5ad12..85136440be 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -30,7 +30,7 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestDIDXResponseHandler(AsyncTestCase): +class TestDIDXResponseHandler(IsolatedAsyncioTestCase): def did_doc(self): doc = DIDDoc(did=TEST_DID) controller = TEST_DID @@ -58,7 +58,7 @@ def did_doc(self): doc.set(service) return doc - async def setUp(self): + async def asyncSetUp(self): self.ctx = RequestContext.test_context() self.ctx.message_receipt = MessageReceipt() @@ -80,7 +80,7 @@ async def setUp(self): @pytest.mark.asyncio @async_mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -95,7 +95,7 @@ async def test_called(self, mock_didx_mgr): @async_mock.patch.object(test_module, "DIDXManager") async def test_called_auto_ping(self, mock_didx_mgr): self.ctx.update_settings({"auto_ping_connection": True}) - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock() 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 @async_mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( 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 = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( 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 = async_mock.CoroutineMock( + mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py index 3b769d56c4..835b7afcb3 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_request.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile @@ -49,8 +49,8 @@ def make_did_doc(self): return doc -class TestDIDXRequest(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDIDXRequest(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet @@ -123,10 +123,10 @@ def test_method_other_than_indy(self): assert request.serialize() == new_request.serialize() -class TestDIDXRequestSchema(AsyncTestCase, TestConfig): +class TestDIDXRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test request schema.""" - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet diff --git a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py index 3be60ca51e..b13711e078 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/messages/tests/test_response.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ......core.in_memory import InMemoryProfile @@ -46,8 +46,8 @@ def make_did_doc(self): return doc -class TestDIDXResponse(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDIDXResponse(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet @@ -101,10 +101,10 @@ def test_serialize(self, mock_response_schema_dump): assert response_dict is mock_response_schema_dump.return_value -class TestDIDXResponseSchema(AsyncTestCase, TestConfig): +class TestDIDXResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test response schema.""" - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.session.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.wallet = self.session.wallet diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index 4372ca4296..a5098e2beb 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from pydid import DIDDocument from .. import manager as test_module @@ -68,22 +68,22 @@ def make_did_doc(self, did, verkey): return doc -class TestDidExchangeManager(AsyncTestCase, TestConfig): - async def setUp(self): +class TestDidExchangeManager(IsolatedAsyncioTestCase, TestConfig): + async def asyncSetUp(self): self.responder = MockResponder() self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.CoroutineMock(return_value=None) + clean_finished_oob_record=async_mock.AsyncMock(return_value=None) ) self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = async_mock.AsyncMock( return_value=None ) - self.route_manager.mediation_record_for_connection = async_mock.CoroutineMock( + self.route_manager.mediation_record_for_connection = async_mock.AsyncMock( return_value=None ) @@ -113,16 +113,16 @@ async def setUp(self): ) self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.get_endpoint_for_did = async_mock.CoroutineMock( + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.get_endpoint_for_did = async_mock.AsyncMock( return_value=TestConfig.test_endpoint ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.resolver = async_mock.MagicMock() did_doc = DIDDocument.deserialize(DOC) - self.resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) + self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) assert did_doc.verification_method - self.resolver.dereference_verification_method = async_mock.CoroutineMock( + self.resolver.dereference_verification_method = async_mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -131,7 +131,7 @@ async def setUp(self): self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) - self.multitenant_mgr.get_default_mediator = async_mock.CoroutineMock( + self.multitenant_mgr.get_default_mediator = async_mock.AsyncMock( return_value=None ) @@ -189,7 +189,7 @@ async def test_receive_invitation(self): invi_msg = invi_rec.invitation mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation(invi_msg) @@ -218,7 +218,7 @@ async def test_receive_invitation_oob_public_did(self): invi_msg.services = [public_did_info.did] mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation( @@ -280,7 +280,7 @@ async def test_create_request_implicit(self): await mediation_record.save(session) with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: @@ -357,7 +357,7 @@ async def test_create_request_implicit_x_public_already_connected(self): ED25519, ) with self.assertRaises(DIDXManagerError) as context, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_retrieve_by_did: await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -377,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=async_mock.CoroutineMock( + retrieve_invitation=async_mock.AsyncMock( return_value=async_mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={}) @@ -403,7 +403,7 @@ async def test_create_request_multitenant(self): with async_mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: @@ -419,7 +419,7 @@ async def test_create_request_multitenant(self): ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -430,12 +430,12 @@ async def test_create_request_multitenant(self): their_role=ConnRecord.Role.RESPONDER.rfc160, alias="Bob", my_did=None, - retrieve_invitation=async_mock.CoroutineMock( + retrieve_invitation=async_mock.AsyncMock( return_value=async_mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) ) @@ -472,7 +472,7 @@ async def test_create_request_mediation_id(self): await record.attach_invitation(session, invi) with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={}) @@ -497,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=async_mock.CoroutineMock( + retrieve_invitation=async_mock.AsyncMock( return_value=async_mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) with async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={}) @@ -525,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=async_mock.CoroutineMock( + retrieve_invitation=async_mock.AsyncMock( return_value=async_mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) request = await self.manager.create_request(mock_conn_rec, use_public_did=True) @@ -582,9 +582,9 @@ async def test_receive_request_explicit_public_did(self): ) as mock_response, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: @@ -600,11 +600,11 @@ async def test_receive_request_explicit_public_did(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + metadata_get=async_mock.AsyncMock(return_value=True), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO @@ -612,11 +612,11 @@ async def test_receive_request_explicit_public_did(self): mock_conn_rec_cls.State.get = async_mock.MagicMock( return_value=STATE_REQUEST ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -629,7 +629,7 @@ async def test_receive_request_explicit_public_did(self): ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) mock_response.return_value = async_mock.MagicMock( @@ -668,7 +668,7 @@ async def test_receive_request_invi_not_found(self): with async_mock.patch.object( test_module, "ConnRecord", async_mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError) as context: @@ -722,11 +722,11 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) as mock_response, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() + self.manager, "record_did", async_mock.AsyncMock() ), async_mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: @@ -742,11 +742,11 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + metadata_get=async_mock.AsyncMock(return_value=True), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO @@ -754,11 +754,11 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): mock_conn_rec_cls.State.get = async_mock.MagicMock( return_value=STATE_REQUEST ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -771,7 +771,7 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) mock_response.return_value = async_mock.MagicMock( @@ -819,11 +819,11 @@ 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=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + metadata_get=async_mock.AsyncMock(return_value=True), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO @@ -831,11 +831,11 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): mock_conn_rec_cls.State.get = async_mock.MagicMock( return_value=STATE_REQUEST ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( - return_value=async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record @@ -860,7 +860,7 @@ async def test_receive_request_public_did_x_not_public(self): did=TestConfig.test_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock(return_value="dummy-did-doc") ), @@ -929,20 +929,20 @@ async def test_receive_request_public_did_x_wrong_did(self): ) as mock_did_doc_from_json, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + async_mock.AsyncMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), ): mock_conn_record = async_mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_did_doc_from_json.return_value = async_mock.MagicMock( did="wrong-did" @@ -994,20 +994,20 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): ) as mock_did_posture, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(side_effect=DIDXManagerError), + async_mock.AsyncMock(side_effect=DIDXManagerError), ): mock_conn_record = async_mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_did_posture.get = async_mock.MagicMock( @@ -1030,7 +1030,7 @@ async def test_receive_request_public_did_no_public_invites(self): did=TestConfig.test_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock(return_value="dummy-did-doc") ), @@ -1054,7 +1054,7 @@ async def test_receive_request_public_did_no_public_invites(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( test_module.DIDDoc, "from_json", async_mock.MagicMock() ) as mock_did_doc_from_json: @@ -1108,24 +1108,24 @@ async def test_receive_request_public_did_no_auto_accept(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_conn_record = async_mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=mock_conn_record) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=mock_conn_record ) mock_did_posture.get = async_mock.MagicMock( @@ -1154,7 +1154,7 @@ async def test_receive_request_implicit_public_did_not_enabled(self): did=TestConfig.test_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock(return_value="dummy-did-doc") ), @@ -1189,16 +1189,16 @@ async def test_receive_request_implicit_public_did_not_enabled(self): ) as mock_did_posture, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_did_posture.get = async_mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=None) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=None ) with self.assertRaises(DIDXManagerError) as context: @@ -1217,7 +1217,7 @@ async def test_receive_request_implicit_public_did(self): did=TestConfig.test_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock(return_value="dummy-did-doc") ), @@ -1255,27 +1255,27 @@ async def test_receive_request_implicit_public_did(self): ) as mock_did_posture, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): mock_did_posture.get = async_mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = ( - async_mock.CoroutineMock(return_value=None) + mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + return_value=None ) mock_conn_record = async_mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - metadata_get_all=async_mock.CoroutineMock(return_value={}), - metadata_get=async_mock.CoroutineMock(return_value=True), - save=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + metadata_get_all=async_mock.AsyncMock(return_value={}), + metadata_get=async_mock.AsyncMock(return_value=True), + save=async_mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record @@ -1315,12 +1315,10 @@ async def test_receive_request_peer_did(self): is_multiuse_invitation=True, state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.REQUESTER.rfc23, - save=async_mock.CoroutineMock(), - attach_request=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + attach_request=async_mock.AsyncMock(), accept=ConnRecord.ACCEPT_MANUAL, - metadata_get_all=async_mock.CoroutineMock( - return_value={"test": "value"} - ), + metadata_get_all=async_mock.AsyncMock(return_value={"test": "value"}), ) mock_conn_rec_state_request = ConnRecord.State.REQUEST @@ -1343,26 +1341,26 @@ async def test_receive_request_peer_did(self): ) as mock_response, async_mock.patch.object( self.manager, "verify_diddoc", - async_mock.CoroutineMock(return_value=DIDDoc(TestConfig.test_did)), + async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( return_value=mock_conn ) mock_conn_rec_cls.return_value = async_mock.MagicMock( accept=ConnRecord.ACCEPT_AUTO, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.CoroutineMock(), - retrieve_request=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), - metadata_set=async_mock.CoroutineMock(), + attach_request=async_mock.AsyncMock(), + retrieve_request=async_mock.AsyncMock(), + save=async_mock.AsyncMock(), + metadata_set=async_mock.AsyncMock(), ) mock_did_doc.from_json = async_mock.MagicMock( return_value=async_mock.MagicMock(did=TestConfig.test_did) ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) mock_response.return_value = async_mock.MagicMock( @@ -1389,7 +1387,7 @@ async def test_receive_request_peer_did_not_found_x(self): did=TestConfig.test_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock(return_value="dummy-did-doc") ), @@ -1408,7 +1406,7 @@ async def test_receive_request_peer_did_not_found_x(self): with async_mock.patch.object( test_module, "ConnRecord", async_mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError): @@ -1427,9 +1425,9 @@ async def test_create_response(self): ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() + conn_rec, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, async_mock.patch.object( @@ -1437,14 +1435,14 @@ async def test_create_response(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock() ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -1488,13 +1486,13 @@ async def test_create_response_mediation_id(self): ) as mock_conn_retrieve_request, async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) + record, "metadata_get", async_mock.AsyncMock(return_value=False) ), async_mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) await self.manager.create_response( @@ -1540,7 +1538,7 @@ async def test_create_response_mediation_id_invalid_conn_state(self): ) as mock_conn_retrieve_request, async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.CoroutineMock(return_value=False) + record, "metadata_get", async_mock.AsyncMock(return_value=False) ): with self.assertRaises(DIDXManagerError) as context: await self.manager.create_response( @@ -1563,11 +1561,11 @@ async def test_create_response_multitenant(self): with async_mock.patch.object( test_module.ConnRecord, "retrieve_request" ), async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() + conn_rec, "save", async_mock.AsyncMock() ), async_mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: @@ -1583,7 +1581,7 @@ async def test_create_response_multitenant(self): ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -1598,9 +1596,9 @@ async def test_create_response_conn_rec_my_did(self): ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() + conn_rec, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, async_mock.patch.object( @@ -1608,9 +1606,9 @@ async def test_create_response_conn_rec_my_did(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc, async_mock.patch.object( - InMemoryWallet, "get_local_did", async_mock.CoroutineMock() + InMemoryWallet, "get_local_did", async_mock.AsyncMock() ) as mock_get_loc_did: mock_get_loc_did.return_value = self.did_info mock_create_did_doc.return_value = async_mock.MagicMock( @@ -1618,7 +1616,7 @@ async def test_create_response_conn_rec_my_did(self): ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -1648,9 +1646,9 @@ async def test_create_response_use_public_did(self): ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() + conn_rec, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, async_mock.patch.object( @@ -1658,14 +1656,14 @@ async def test_create_response_use_public_did(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock() ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -1679,9 +1677,9 @@ async def test_create_response_use_public_did_x_no_public_did(self): ) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.CoroutineMock() + conn_rec, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module, "DIDDoc", autospec=True ) as mock_did_doc, async_mock.patch.object( @@ -1689,14 +1687,14 @@ async def test_create_response_use_public_did_x_no_public_did(self): ) as mock_attach_deco, async_mock.patch.object( test_module, "DIDXResponse", autospec=True ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.CoroutineMock() + self.manager, "create_did_document", async_mock.AsyncMock() ) as mock_create_did_doc: mock_create_did_doc.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock() ) mock_attach_deco.data_base64 = async_mock.MagicMock( return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.CoroutineMock()) + data=async_mock.MagicMock(sign=async_mock.AsyncMock()) ) ) @@ -1712,7 +1710,7 @@ async def test_accept_response_find_by_thread_id(self): mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1729,9 +1727,9 @@ async def test_accept_response_find_by_thread_id(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser: @@ -1742,7 +1740,7 @@ async def test_accept_response_find_by_thread_id(self): did=TestConfig.test_target_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1751,13 +1749,13 @@ async def test_accept_response_find_by_thread_id(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1770,7 +1768,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 = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1788,13 +1786,13 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() ) as mock_proactive_disclose_features: mock_did_doc_deser.return_value = async_mock.MagicMock( did=TestConfig.test_target_did @@ -1803,7 +1801,7 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): did=TestConfig.test_target_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1812,13 +1810,13 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1832,7 +1830,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 = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1846,9 +1844,9 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser: @@ -1860,7 +1858,7 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel did=TestConfig.test_target_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1869,8 +1867,8 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(return_value=False), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(return_value=False), connection_id="test-conn-id", ) @@ -1884,7 +1882,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 = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1898,9 +1896,9 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1914,7 +1912,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 = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -1928,7 +1926,7 @@ async def test_accept_response_find_by_thread_id_bad_state(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 @@ -1951,13 +1949,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() + self.manager, "record_did", async_mock.AsyncMock() ): mock_did_doc_deser.return_value = async_mock.MagicMock( did=TestConfig.test_target_did @@ -1965,13 +1963,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1992,13 +1990,13 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.CoroutineMock() + self.manager, "record_did", async_mock.AsyncMock() ): mock_did_doc_deser.return_value = async_mock.MagicMock( did=TestConfig.test_target_did @@ -2006,13 +2004,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 = async_mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), - metadata_get=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), + metadata_get=async_mock.AsyncMock(), connection_id="test-conn-id", ) mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) with self.assertRaises(DIDXManagerError) as context: @@ -2025,7 +2023,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 = async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -2039,9 +2037,9 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): with async_mock.patch.object( ConnRecord, "save", autospec=True ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id, async_mock.patch.object( DIDDoc, "deserialize", async_mock.MagicMock() ) as mock_did_doc_deser: @@ -2052,7 +2050,7 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): did=TestConfig.test_target_did, did_doc_attach=async_mock.MagicMock( data=async_mock.MagicMock( - verify=async_mock.CoroutineMock(return_value=True), + verify=async_mock.AsyncMock(return_value=True), signed=async_mock.MagicMock( decode=async_mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) @@ -2061,11 +2059,11 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) with self.assertRaises(DIDXManagerError): @@ -2076,9 +2074,9 @@ async def test_accept_complete(self): receipt = MessageReceipt(sender_did=TestConfig.test_target_did) with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.CoroutineMock() + mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED @@ -2087,11 +2085,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 async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.CoroutineMock() + V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.CoroutineMock() + mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED mock_proactive_disclose_features.assert_called_once() @@ -2101,7 +2099,7 @@ async def test_accept_complete_x_not_found(self): receipt = MessageReceipt(sender_did=TestConfig.test_target_did) with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() with self.assertRaises(DIDXManagerError): @@ -2115,7 +2113,7 @@ async def test_reject_invited(self): state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() reason = "He doesn't like you!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2128,7 +2126,7 @@ async def test_reject_requested(self): state=ConnRecord.State.REQUEST.rfc23, their_role=ConnRecord.Role.REQUESTER, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() reason = "I don't like you either! You just watch yourself!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2140,7 +2138,7 @@ async def test_reject_invalid(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() reason = "I'll be careful." with self.assertRaises(DIDXManagerError) as context: await self.manager.reject(mock_conn, reason=reason) @@ -2153,7 +2151,7 @@ async def test_receive_problem_report(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() report = DIDXProblemReport( description={ "code": ProblemReportReason.REQUEST_NOT_ACCEPTED.value, @@ -2170,7 +2168,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 = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() report = DIDXProblemReport() with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2183,7 +2181,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 = async_mock.CoroutineMock() + mock_conn.abandon = async_mock.AsyncMock() report = DIDXProblemReport(description={"code": "something random"}) with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2261,7 +2259,7 @@ async def test_resolve_did_document_error(self): with async_mock.patch.object( self.resolver, "resolve", - async_mock.CoroutineMock(side_effect=ResolverError()), + async_mock.AsyncMock(side_effect=ResolverError()), ): with self.assertRaises(DIDXManagerError) as ctx: await self.manager.get_resolved_did_document(public_did_info.did) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py index ff5ad5c52c..c851d9d805 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -7,14 +7,14 @@ from ....coordinate_mediation.v1_0.route_manager import RouteManager -class TestDIDExchangeConnRoutes(AsyncTestCase): - async def setUp(self): +class TestDIDExchangeConnRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -33,7 +33,7 @@ async def test_didx_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock(save=async_mock.CoroutineMock()) + mock_conn_rec = async_mock.MagicMock(save=async_mock.AsyncMock()) mock_conn_rec.serialize = async_mock.MagicMock() with async_mock.patch.object( @@ -44,7 +44,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 = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_request = async_mock.AsyncMock() await test_module.didx_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -53,7 +53,7 @@ async def test_didx_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -64,11 +64,11 @@ async def test_didx_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr: - mock_didx_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -88,13 +88,9 @@ async def test_didx_create_request_implicit(self): ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value="mock serialization" - ) - ) + mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( + return_value=async_mock.MagicMock( + serialize=async_mock.MagicMock(return_value="mock serialization") ) ) @@ -114,8 +110,8 @@ async def test_didx_create_request_implicit_not_found_x(self): ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock(side_effect=StorageNotFoundError("not found")) + mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( + side_effect=StorageNotFoundError("not found") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -134,10 +130,8 @@ async def test_didx_create_request_implicit_wallet_x(self): ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = ( - async_mock.CoroutineMock( - side_effect=test_module.WalletError("wallet error") - ) + mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( + side_effect=test_module.WalletError("wallet error") ) with self.assertRaises(test_module.web.HTTPBadRequest) as context: @@ -150,7 +144,7 @@ async def test_didx_receive_request_implicit(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() mock_conn_rec = async_mock.MagicMock() mock_conn_rec.serialize = async_mock.MagicMock() @@ -162,7 +156,7 @@ async def test_didx_receive_request_implicit(self): ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=mock_conn_rec ) @@ -175,7 +169,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module.DIDXRequest, "deserialize", async_mock.MagicMock() @@ -184,7 +178,7 @@ async def test_didx_receive_request_implicit_not_found_x(self): ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( side_effect=StorageNotFoundError("tricorder must be broken") ) @@ -198,7 +192,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module.DIDXRequest, "deserialize", async_mock.MagicMock() @@ -222,14 +216,14 @@ async def test_didx_accept_request(self): mock_conn_rec.serialize = async_mock.MagicMock() with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock() + mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() await test_module.didx_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -238,7 +232,7 @@ async def test_didx_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -249,13 +243,13 @@ async def test_didx_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_response = async_mock.CoroutineMock( + mock_didx_mgr.return_value.create_response = async_mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -264,25 +258,25 @@ async def test_didx_accept_request_x(self): async def test_didx_reject(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.CoroutineMock() + mock_didx_mgr.return_value.reject = async_mock.AsyncMock() await test_module.didx_reject(self.request) async def test_didx_reject_x_not_found(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -291,16 +285,16 @@ async def test_didx_reject_x_not_found(self): async def test_didx_reject_x_bad_conn_state(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.CoroutineMock(return_value={"reason": "asdf"}) + self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.CoroutineMock( + mock_didx_mgr.return_value.reject = async_mock.AsyncMock( 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 e6786435eb..721c3c6c82 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_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 async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=discovery_record), + async_mock.AsyncMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py index 98bf973cec..ee3ca03496 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_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 async_mock.patch.object( - ProtocolRegistry, "protocols_matching_query", async_mock.CoroutineMock() + ProtocolRegistry, "protocols_matching_query", async_mock.AsyncMock() ) as mock_query_match, async_mock.patch.object( - ProtocolRegistry, "prepare_disclosed", async_mock.CoroutineMock() + ProtocolRegistry, "prepare_disclosed", async_mock.AsyncMock() ) as mock_prepare_disclosed: mock_prepare_disclosed.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py index 9e3f0401e6..df9ea4c8a8 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......storage.error import StorageDuplicateError, StorageNotFoundError @@ -11,7 +12,7 @@ from ..discovery_record import V10DiscoveryExchangeRecord -class TestV10DiscoveryExchangeRecord(AsyncTestCase): +class TestV10DiscoveryExchangeRecord(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_record(self): @@ -92,7 +93,7 @@ async def test_exists_for_connection_id_not_found(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( @@ -105,7 +106,7 @@ async def test_exists_for_connection_id_duplicate(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py index 8864a31e15..7ded2bc195 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py @@ -2,7 +2,8 @@ import logging import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....storage.error import StorageNotFoundError @@ -20,12 +21,12 @@ ) -class TestV10DiscoveryManager(AsyncTestCase): +class TestV10DiscoveryManager(IsolatedAsyncioTestCase): @pytest.fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context @@ -55,7 +56,7 @@ async def test_receive_disclosure(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True ) as save_ex, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -76,13 +77,13 @@ async def test_receive_disclosure_retreive_by_conn(self): ) as save_ex, async_mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = True @@ -105,9 +106,9 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): ) as save_ex, async_mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -128,9 +129,9 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) as save_ex, async_mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -147,7 +148,7 @@ async def test_check_if_disclosure_received(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V10DiscoveryExchangeRecord(), @@ -160,19 +161,19 @@ async def test_create_and_send_query_with_connection(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_connection_id, async_mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + self.responder, "send", async_mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V10DiscoveryExchangeRecord() @@ -188,13 +189,13 @@ async def test_create_and_send_query_with_connection_no_responder(self): with async_mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -209,7 +210,7 @@ async def test_create_and_send_query_with_no_connection(self): with async_mock.patch.object( V10DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclose() received_ex_rec = await self.manager.create_and_send_query(query="*") diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py index 7dfed0bb20..7922044c28 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext @@ -11,14 +11,14 @@ from ..models.discovery_record import V10DiscoveryExchangeRecord -class TestDiscoveryRoutes(AsyncTestCase): - async def setUp(self): +class TestDiscoveryRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -28,7 +28,7 @@ async def setUp(self): ) async def test_query_features(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_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 5808a40dae..b6dc14c5f1 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from aries_cloudagent.storage.error import StorageNotFoundError @@ -64,7 +64,7 @@ async def test_disclosures(self, request_context): with async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=discovery_record), + async_mock.AsyncMock(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 async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + async_mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_get_rec_thread_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(return_value=discovery_record), + async_mock.AsyncMock(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 async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + async_mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_get_rec_thread_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + async_mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py index cb503650ad..ee557182c6 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_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 async_mock.patch.object( - V20DiscoveryMgr, "execute_protocol_query", async_mock.CoroutineMock() + V20DiscoveryMgr, "execute_protocol_query", async_mock.AsyncMock() ) as mock_exec_protocol_query, async_mock.patch.object( - V20DiscoveryMgr, "execute_goal_code_query", async_mock.CoroutineMock() + V20DiscoveryMgr, "execute_goal_code_query", async_mock.AsyncMock() ) as mock_goal_code_protocol_query: mock_exec_protocol_query.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py index 478acc8d2b..8e50df1d19 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......storage.error import StorageDuplicateError, StorageNotFoundError @@ -11,7 +12,7 @@ from ..discovery_record import V20DiscoveryExchangeRecord -class TestV20DiscoveryExchangeRecord(AsyncTestCase): +class TestV20DiscoveryExchangeRecord(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_record(self): @@ -149,7 +150,7 @@ async def test_exists_for_connection_id_not_found(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( @@ -162,7 +163,7 @@ async def test_exists_for_connection_id_duplicate(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py index 7d4a47f155..10bad1b6d3 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py @@ -2,7 +2,8 @@ import logging import pytest -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....storage.error import StorageNotFoundError @@ -20,12 +21,12 @@ ) -class TestV20DiscoveryManager(AsyncTestCase): +class TestV20DiscoveryManager(IsolatedAsyncioTestCase): @pytest.fixture(autouse=True) def inject_fixtures(self, caplog): self._caplog = caplog - async def setUp(self): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context @@ -61,7 +62,7 @@ async def test_receive_disclosure(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True ) as save_ex, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -82,11 +83,11 @@ async def test_receive_disclosure_retreive_by_conn(self): ) as save_ex, async_mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: @@ -111,7 +112,7 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): ) as save_ex, async_mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: @@ -134,9 +135,9 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) as save_ex, async_mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.CoroutineMock() + V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -153,9 +154,9 @@ async def test_proactive_disclosure(self): with async_mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + self.responder, "send", async_mock.AsyncMock() ) as mock_send: mock_receive_query.return_value = Disclosures() await self.manager.proactive_disclose_features("test123") @@ -166,9 +167,9 @@ async def test_proactive_disclosure_no_responder(self): with async_mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + self.responder, "send", async_mock.AsyncMock() ) as mock_send: self._caplog.set_level(logging.WARNING) mock_receive_query.return_value = Disclosures() @@ -181,7 +182,7 @@ async def test_check_if_disclosure_received(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V20DiscoveryExchangeRecord(), @@ -206,19 +207,19 @@ async def test_create_and_send_query_with_connection(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_by_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.CoroutineMock() + self.responder, "send", async_mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V20DiscoveryExchangeRecord() @@ -234,13 +235,13 @@ async def test_create_and_send_query_with_connection_no_responder(self): with async_mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_exists_for_connection_id, async_mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.CoroutineMock() + V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -266,7 +267,7 @@ async def test_create_and_send_query_with_no_connection(self): with async_mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclosures() received_ex_rec = await self.manager.create_and_send_query( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py index 61efeef9ce..a4a4c83f21 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext @@ -11,14 +11,14 @@ from ..models.discovery_record import V20DiscoveryExchangeRecord -class TestDiscoveryRoutes(AsyncTestCase): - async def setUp(self): +class TestDiscoveryRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -28,7 +28,7 @@ async def setUp(self): ) async def test_query_features(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_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 d6f8fe5ca6..d4e9e008d2 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,7 +9,7 @@ from ...messages.endorsed_transaction_response import EndorsedTransactionResponse -class TestEndorsedTransactionResponseHandler(AsyncTestCase): +class TestEndorsedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -20,9 +18,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() @@ -42,9 +38,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = False handler = test_module.EndorsedTransactionResponseHandler() @@ -62,10 +56,8 @@ async def test_called_x(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py index 33f00c5da5..d17d7c9fa0 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,7 +9,7 @@ from ...messages.refused_transaction_response import RefusedTransactionResponse -class TestRefusedTransactionResponseHandler(AsyncTestCase): +class TestRefusedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -20,9 +18,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = True handler = test_module.RefusedTransactionResponseHandler() @@ -42,9 +38,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock() - ) + mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = False handler = test_module.RefusedTransactionResponseHandler() @@ -62,10 +56,8 @@ async def test_called_x(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = RefusedTransactionResponse() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py index ed4a864727..e3203af42b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord from ......messaging.request_context import RequestContext @@ -12,7 +10,7 @@ from ...messages.transaction_acknowledgement import TransactionAcknowledgement -class TestTransactionAcknowledgementHandler(AsyncTestCase): +class TestTransactionAcknowledgementHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -21,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 = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( @@ -46,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 = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_ready = False @@ -65,9 +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 = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py index bc144c16d6..ee445b31df 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,7 +10,7 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionCancelHandler(AsyncTestCase): +class TestTransactionCancelHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -21,7 +19,7 @@ async def test_called(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( @@ -46,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_cancel_transaction = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = CancelTransaction() request_context.connection_ready = False @@ -65,9 +63,7 @@ async def test_called_x(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py index 41c66d4a78..53658c7f75 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -11,7 +9,7 @@ from ...messages.transaction_job_to_send import TransactionJobToSend -class TestTransactionJobToSendHandler(AsyncTestCase): +class TestTransactionJobToSendHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -21,7 +19,7 @@ async def test_called(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.set_transaction_their_job = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = TransactionJobToSend() request_context.connection_ready = True @@ -42,10 +40,8 @@ async def test_called_x(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + mock_tran_mgr.return_value.set_transaction_their_job = async_mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionJobToSend() request_context.connection_ready = True diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py index 61c525e5f5..36fa24cb8b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,7 +10,7 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionRequestHandler(AsyncTestCase): +class TestTransactionRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -20,7 +18,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -43,7 +41,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_ready = False handler = test_module.TransactionRequestHandler() @@ -60,7 +58,7 @@ async def test_called_x(self): with async_mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionRequest() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py index e0e9ccbcde..af949ca173 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py @@ -1,7 +1,5 @@ -from asynctest import ( - mock as async_mock, - TestCase as AsyncTestCase, -) +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,7 +10,7 @@ from ......connections.models.conn_record import ConnRecord -class TestTransactionResendHandler(AsyncTestCase): +class TestTransactionResendHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -21,7 +19,7 @@ async def test_called(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = TransactionResend() request_context.connection_record = ConnRecord( @@ -46,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_resend = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = TransactionResend() request_context.connection_ready = False @@ -65,9 +63,7 @@ async def test_called_x(self): test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.CoroutineMock( - side_effect=test_module.TransactionManagerError() - ) + async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = TransactionResend() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py index a233649b62..8e6743e7aa 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +64,7 @@ def test_serialize(self, mock_cancel_transaction_schema_dump): ) -class TestCancelTransactionSchema(AsyncTestCase, TestConfig): +class TestCancelTransactionSchema(IsolatedAsyncioTestCase, TestConfig): """Test cancel transaction schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py index 9ca343c73c..069823a76f 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -96,7 +96,7 @@ def test_serialize(self, mock_endorsed_transaction_response_schema_dump): ) -class TestEndorsedTransactionResponseSchema(AsyncTestCase, TestConfig): +class TestEndorsedTransactionResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test endorsed transaction response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py index 071668d371..b81116dd43 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -90,7 +90,7 @@ def test_serialize(self, mock_refused_transaction_response_schema_dump): ) -class TestRefusedTransactionResponseSchema(AsyncTestCase, TestConfig): +class TestRefusedTransactionResponseSchema(IsolatedAsyncioTestCase, TestConfig): """Test refused transaction response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py index 09bc6b0a1e..aed0666b75 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from unittest import mock, TestCase from .....didcomm_prefix import DIDCommPrefix @@ -65,7 +65,7 @@ def test_serialize(self, mock_transaction_acknowledgement_schema_dump): ) -class TestTransactionAcknowledgementSchema(AsyncTestCase, TestConfig): +class TestTransactionAcknowledgementSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction acknowledgement schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py index bfd1ae18e7..808316f62f 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +64,7 @@ def test_serialize(self, mock_transaction_job_to_send_schema_dump): ) -class TestTransactionJobToSendSchema(AsyncTestCase, TestConfig): +class TestTransactionJobToSendSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction job to send schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py index 8bbb69ae12..13cc506836 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -108,7 +108,7 @@ def test_serialize(self, mock_transaction_request_schema_dump): ) -class TestTransactionRequestSchema(AsyncTestCase, TestConfig): +class TestTransactionRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py index 666a52435c..7bc8be1932 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -64,7 +64,7 @@ def test_serialize(self, mock_transaction_resend_schema_dump): ) -class TestTransactionResendSchema(AsyncTestCase, TestConfig): +class TestTransactionResendSchema(IsolatedAsyncioTestCase, TestConfig): """Test transaction resend schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index df10ffe4ee..e7c5059d39 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -2,8 +2,8 @@ import json import uuid -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -25,8 +25,8 @@ CRED_DEF_ID = f"{TEST_DID}:3:CL:12:tag1" -class TestTransactionManager(AsyncTestCase): - async def setUp(self): +class TestTransactionManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): sigs = [ ( "2iNTeFy44WK9zpsPfcwfu489aHWroYh3v8mme9tPyNKn" @@ -103,10 +103,10 @@ async def setUp(self): self.test_refuser_did = "AGDEjaMunDtFtBVrn1qPKQ" self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.txn_endorse = async_mock.CoroutineMock( + self.ledger.txn_endorse = async_mock.AsyncMock( return_value=self.test_endorsed_message ) - self.ledger.register_nym = async_mock.CoroutineMock(return_value=(True, {})) + self.ledger.register_nym = async_mock.AsyncMock(return_value=(True, {})) self.context = AdminRequestContext.test_context() self.profile = self.context.profile @@ -476,11 +476,11 @@ async def test_complete_transaction(self): future = asyncio.Future() future.set_result( async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.CoroutineMock()) + return_value=async_mock.MagicMock(add_record=async_mock.AsyncMock()) ) ) self.ledger.get_indy_storage = future - self.ledger.txn_submit = async_mock.CoroutineMock( + self.ledger.txn_submit = async_mock.AsyncMock( return_value=json.dumps( { "result": { @@ -497,7 +497,7 @@ async def test_complete_transaction(self): ConnRecord, "retrieve_by_id" ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( TransactionJob.TRANSACTION_ENDORSER.name @@ -762,13 +762,13 @@ async def test_receive_transaction_resend(self): async def test_set_transaction_my_job(self): conn_record = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=async_mock.AsyncMock(), ) for i in range(2): @@ -779,16 +779,16 @@ async def test_set_transaction_their_job(self): mock_receipt = async_mock.MagicMock() with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=async_mock.AsyncMock(), ) for i in range(2): @@ -799,7 +799,7 @@ async def test_set_transaction_their_job_conn_not_found(self): mock_receipt = async_mock.MagicMock() with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_did", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index 4d6e3b0897..791ba0aa1c 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -1,8 +1,8 @@ import asyncio import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -21,8 +21,8 @@ CRED_DEF_ID = f"{TEST_DID}:3:CL:12:tag1" -class TestEndorseTransactionRoutes(AsyncTestCase): - async def setUp(self): +class TestEndorseTransactionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) @@ -36,11 +36,11 @@ async def setUp(self): ) self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.txn_endorse = async_mock.CoroutineMock( + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.txn_endorse = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.txn_submit = async_mock.CoroutineMock( + self.ledger.txn_submit = async_mock.AsyncMock( return_value=json.dumps( { "result": { @@ -53,18 +53,18 @@ async def setUp(self): future = asyncio.Future() future.set_result( async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.CoroutineMock()) + return_value=async_mock.MagicMock(add_record=async_mock.AsyncMock()) ) ) self.ledger.get_indy_storage = future - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value={"id": SCHEMA_ID, "...": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -77,7 +77,7 @@ async def setUp(self): async def test_transactions_list(self): with async_mock.patch.object( - TransactionRecord, "query", async_mock.CoroutineMock() + TransactionRecord, "query", async_mock.AsyncMock() ) as mock_query, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -92,7 +92,7 @@ async def test_transactions_list(self): async def test_transactions_list_x(self): with async_mock.patch.object( - TransactionRecord, "query", async_mock.CoroutineMock() + TransactionRecord, "query", async_mock.AsyncMock() ) as mock_query, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -105,7 +105,7 @@ async def test_transactions_retrieve(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: @@ -120,7 +120,7 @@ async def test_transactions_retrieve_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError() @@ -131,7 +131,7 @@ async def test_transactions_retrieve_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.BaseModelError() @@ -142,22 +142,22 @@ async def test_transaction_create_request(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + create_request=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -167,7 +167,7 @@ async def test_transaction_create_request(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -189,13 +189,13 @@ async def test_transaction_create_request_not_found_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,18 +206,18 @@ async def test_transaction_create_request_base_model_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -237,20 +237,20 @@ async def test_transaction_create_request_no_jobs_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + create_request=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -260,7 +260,7 @@ async def test_transaction_create_request_no_jobs_x(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -273,20 +273,20 @@ async def test_transaction_create_request_no_my_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + create_request=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -296,7 +296,7 @@ async def test_transaction_create_request_no_my_job_x(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -315,20 +315,20 @@ async def test_transaction_create_request_no_their_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + create_request=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -338,7 +338,7 @@ async def test_transaction_create_request_no_their_job_x(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -357,18 +357,18 @@ async def test_transaction_create_request_my_wrong_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -388,25 +388,25 @@ async def test_transaction_create_request_mgr_create_request_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.CoroutineMock( + create_request=async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -429,7 +429,7 @@ async def test_endorse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -442,9 +442,9 @@ async def test_endorse_transaction_response(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -455,7 +455,7 @@ async def test_endorse_transaction_response(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + create_endorse_response=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -465,7 +465,7 @@ async def test_endorse_transaction_response(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -491,7 +491,7 @@ async def skip_test_endorse_transaction_response_no_endorser_did_info_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None) + get_public_did=async_mock.AsyncMock(return_value=None) ), ) with async_mock.patch.object( @@ -508,7 +508,7 @@ async def test_endorse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -521,7 +521,7 @@ async def test_endorse_transaction_response_not_found_x(self): ) with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", @@ -537,7 +537,7 @@ async def test_endorse_transaction_response_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -550,9 +550,9 @@ async def test_endorse_transaction_response_base_model_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", @@ -572,7 +572,7 @@ async def test_endorse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -585,16 +585,16 @@ async def test_endorse_transaction_response_no_jobs_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -609,7 +609,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -622,9 +622,9 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -633,7 +633,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + create_endorse_response=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -643,7 +643,7 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -664,7 +664,7 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -677,16 +677,16 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -707,7 +707,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -718,14 +718,14 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ), ) - self.ledger.txn_endorse = async_mock.CoroutineMock( + self.ledger.txn_endorse = async_mock.AsyncMock( side_effect=test_module.LedgerError() ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -734,7 +734,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + create_endorse_response=async_mock.AsyncMock( return_value=( async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -744,7 +744,7 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -765,7 +765,7 @@ async def test_endorse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -778,9 +778,9 @@ async def test_endorse_transaction_response_txn_mgr_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -791,12 +791,12 @@ async def test_endorse_transaction_response_txn_mgr_x(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.CoroutineMock( + create_endorse_response=async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -817,7 +817,7 @@ async def test_refuse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -830,9 +830,9 @@ async def test_refuse_transaction_response(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -843,7 +843,7 @@ async def test_refuse_transaction_response(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.CoroutineMock( + create_refuse_response=async_mock.AsyncMock( return_value=( async_mock.MagicMock( # transaction connection_id="dummy", @@ -854,7 +854,7 @@ async def test_refuse_transaction_response(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -875,7 +875,7 @@ async def test_refuse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -888,7 +888,7 @@ async def test_refuse_transaction_response_not_found_x(self): ) with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", @@ -905,7 +905,7 @@ async def test_refuse_transaction_response_conn_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -918,9 +918,9 @@ async def test_refuse_transaction_response_conn_base_model_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", @@ -940,7 +940,7 @@ async def test_refuse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -953,16 +953,16 @@ async def test_refuse_transaction_response_no_jobs_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -977,7 +977,7 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -990,16 +990,16 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( self.context.profile, "session", async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1020,7 +1020,7 @@ async def test_refuse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock( + get_public_did=async_mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -1033,9 +1033,9 @@ async def test_refuse_transaction_response_txn_mgr_x(self): ) with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( @@ -1046,12 +1046,12 @@ async def test_refuse_transaction_response_txn_mgr_x(self): async_mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.CoroutineMock( + create_refuse_response=async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1070,16 +1070,16 @@ async def test_cancel_transaction(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.CoroutineMock( + cancel_transaction=async_mock.AsyncMock( return_value=( async_mock.MagicMock( # transaction connection_id="dummy", @@ -1090,7 +1090,7 @@ async def test_cancel_transaction(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1109,7 +1109,7 @@ async def test_cancel_transaction_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1120,9 +1120,9 @@ async def test_cancel_transaction_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() mock_txn_rec_retrieve.return_value = async_mock.MagicMock( @@ -1136,12 +1136,12 @@ async def test_cancel_transaction_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1154,12 +1154,12 @@ async def test_cancel_transaction_wrong_my_job_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1178,21 +1178,21 @@ async def test_cancel_transaction_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.CoroutineMock( + cancel_transaction=async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1211,16 +1211,16 @@ async def test_transaction_resend(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.CoroutineMock( + transaction_resend=async_mock.AsyncMock( return_value=( async_mock.MagicMock( # transaction connection_id="dummy", @@ -1231,7 +1231,7 @@ async def test_transaction_resend(self): ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1250,7 +1250,7 @@ async def test_transaction_resend_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1261,9 +1261,9 @@ async def test_transaction_resend_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() mock_txn_rec_retrieve.return_value = async_mock.MagicMock( @@ -1277,12 +1277,12 @@ async def test_transaction_resend_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1295,12 +1295,12 @@ async def test_transaction_resend_my_wrong_job_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1320,21 +1320,21 @@ async def test_transaction_resend_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.CoroutineMock( + transaction_resend=async_mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1353,17 +1353,17 @@ async def test_set_endorser_role(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_txn_mgr.return_value = async_mock.MagicMock( - set_transaction_my_job=async_mock.CoroutineMock() + set_transaction_my_job=async_mock.AsyncMock() ) mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1381,7 +1381,7 @@ async def test_set_endorser_role_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1392,7 +1392,7 @@ async def test_set_endorser_role_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1403,12 +1403,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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1418,7 +1418,7 @@ async def test_set_endorser_info(self): ), } ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=async_mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1435,12 +1435,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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( side_effect=[ { "transaction_my_job": ( @@ -1457,7 +1457,7 @@ async def test_set_endorser_info_no_prior_value(self): }, ] ), - metadata_set=async_mock.CoroutineMock(), + metadata_set=async_mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1473,7 +1473,7 @@ async def test_set_endorser_info_not_found_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1485,7 +1485,7 @@ async def test_set_endorser_info_base_model_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1497,10 +1497,10 @@ async def test_set_endorser_info_no_transaction_jobs_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock(return_value=None) + metadata_get=async_mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.set_endorser_info(self.request) @@ -1510,10 +1510,10 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): self.request.query = {"endorser_did": "did", "endorser_name": "name"} with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1528,10 +1528,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 async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.CoroutineMock( + metadata_get=async_mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1547,19 +1547,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 async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value.complete_transaction = async_mock.CoroutineMock() + mock_txn_mgr.return_value.complete_transaction = async_mock.AsyncMock() mock_txn_mgr.return_value.complete_transaction.return_value = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( serialize=async_mock.MagicMock(return_value={"...": "..."}) ), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) mock_txn_rec_retrieve.return_value = async_mock.MagicMock( @@ -1576,7 +1576,7 @@ async def test_transaction_write_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1587,7 +1587,7 @@ async def test_transaction_write_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1597,7 +1597,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 async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.return_value = async_mock.MagicMock( serialize=async_mock.MagicMock(return_value={"...": "..."}), @@ -1613,12 +1613,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 async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.CoroutineMock() + TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_txn_rec_retrieve, async_mock.patch.object( test_module, "TransactionManager", async_mock.MagicMock() ) as mock_txn_mgr: mock_txn_mgr.return_value = async_mock.MagicMock( - complete_transaction=async_mock.CoroutineMock( + complete_transaction=async_mock.AsyncMock( 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 bb19cea6de..3b3f0ceadd 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -21,8 +21,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestForwardInvitationHandler(AsyncTestCase): - async def setUp(self): +class TestForwardInvitationHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True @@ -45,7 +45,7 @@ async def test_handle(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.receive_invitation = async_mock.AsyncMock( return_value=ConnRecord(connection_id="dummy") ) @@ -59,7 +59,7 @@ async def test_handle_x(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.receive_invitation = async_mock.AsyncMock( side_effect=test_module.ConnectionManagerError("oops") ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py index 7e92953531..5ddd695a72 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -20,8 +20,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestInvitationHandler(AsyncTestCase): - async def setUp(self): +class TestInvitationHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = Invitation( @@ -47,7 +47,7 @@ async def test_handle(self): self.context, "inject_or", async_mock.MagicMock() ) as mock_ctx_inject: mock_ctx_inject.return_value = async_mock.MagicMock( - return_invitation=async_mock.CoroutineMock() + return_invitation=async_mock.AsyncMock() ) await handler.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py index 3bf7fe259d..186c86b50b 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -21,8 +21,8 @@ TEST_IMAGE_URL = "http://aries.ca/images/sample.png" -class TestInvitationRequestHandler(AsyncTestCase): - async def setUp(self): +class TestInvitationRequestHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = InvitationRequest( @@ -60,7 +60,7 @@ async def test_handle_auto_accept(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_mgr.return_value.create_invitation = async_mock.AsyncMock( return_value=(mock_conn_rec, conn_invitation) ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py index e4b3c26f37..7739071f07 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.v1_0.messages.connection_invitation import ConnectionInvitation from .....didcomm_prefix import DIDCommPrefix @@ -68,7 +68,7 @@ def test_serialize(self, mock_invitation_schema_dump): assert invitation_dict is mock_invitation_schema_dump.return_value -class TestForwardInvitationSchema(AsyncTestCase, TestConfig): +class TestForwardInvitationSchema(IsolatedAsyncioTestCase, TestConfig): """Test forward invitation schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py index 1e5b848ba9..b3aaa7cbd0 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation.py @@ -1,6 +1,6 @@ from unittest import mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.v1_0.messages.connection_invitation import ConnectionInvitation @@ -8,7 +8,7 @@ from ...message_types import PROTOCOL_PACKAGE -class TestInvitation(AsyncTestCase): +class TestInvitation(IsolatedAsyncioTestCase): def setUp(self): self.label = "Label" self.test_did = "55GkHamhTU1ZbTbV2ab9DE" diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py index 8d4513014d..eb807e6e22 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from unittest import mock, TestCase @@ -57,7 +57,7 @@ def test_serialize(self, mock_invitation_schema_dump): assert request_dict is mock_invitation_schema_dump.return_value -class TestInvitationRequestSchema(AsyncTestCase, TestConfig): +class TestInvitationRequestSchema(IsolatedAsyncioTestCase, TestConfig): """Test invitation request schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py index 0aacbb20d5..1787ffa28d 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py @@ -1,17 +1,18 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext from .. import routes as test_module -class TestIntroductionRoutes(AsyncTestCase): - async def setUp(self): +class TestIntroductionRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -21,7 +22,7 @@ async def setUp(self): ) async def test_introduction_start_no_service(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -43,7 +44,7 @@ async def test_introduction_start_no_service(self): await test_module.introduction_start(self.request) async def test_introduction_start(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -69,7 +70,7 @@ async def test_introduction_start(self): test_module.web, "json_response" ) as mock_response: mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.CoroutineMock() + start_introduction=async_mock.AsyncMock() ) await test_module.introduction_start(self.request) @@ -83,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -107,7 +108,7 @@ async def test_introduction_start_x(self): self.context, "inject_or", async_mock.MagicMock() ) as mock_ctx_inject: mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.CoroutineMock( + start_introduction=async_mock.AsyncMock( side_effect=test_module.IntroductionError() ) ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py index ea758821a8..1d791b551f 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_service.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -23,7 +23,7 @@ TEST_ENDPOINT = "http://localhost" -class TestIntroductionService(AsyncTestCase): +class TestIntroductionService(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = RequestContext(self.profile) diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py index ae0c31f0e6..85b0f31510 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -11,12 +12,12 @@ from .. import credential_ack_handler as test_module -class TestCredentialAckHandler(AsyncTestCase): +class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -28,9 +29,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = True handler = test_module.CredentialAckHandler() @@ -54,9 +53,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() @@ -72,7 +69,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) @@ -82,9 +79,7 @@ async def test_called_no_connection_no_oob(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py index 0f831927a1..d96a7f2688 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import credential_issue_handler as test_module -class TestCredentialIssueHandler(AsyncTestCase): +class TestCredentialIssueHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = True handler = test_module.CredentialIssueHandler() @@ -50,7 +51,7 @@ async def test_called_auto_store(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -60,12 +61,12 @@ async def test_called_auto_store(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock(), - store_credential=async_mock.CoroutineMock(), - send_credential_ack=async_mock.CoroutineMock( + receive_credential=async_mock.AsyncMock(), + store_credential=async_mock.AsyncMock(), + send_credential_ack=async_mock.AsyncMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) ), ) @@ -91,7 +92,7 @@ async def test_called_auto_store_x(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -101,18 +102,18 @@ async def test_called_auto_store_x(self): test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock( + receive_credential=async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ), - store_credential=async_mock.CoroutineMock( + store_credential=async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ), - send_credential_ack=async_mock.CoroutineMock( + send_credential_ack=async_mock.AsyncMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) ), ) @@ -123,7 +124,7 @@ async def test_called_auto_store_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( handler._logger, "exception", async_mock.MagicMock() ) as mock_log_exc: @@ -138,7 +139,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = False handler = test_module.CredentialIssueHandler() @@ -154,7 +155,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) @@ -164,7 +165,7 @@ async def test_called_no_connection_no_oob(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() request_context.message = CredentialIssue() handler = test_module.CredentialIssueHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py index a9aedbb0a9..4e0697663c 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import credential_offer_handler as test_module -class TestCredentialOfferHandler(AsyncTestCase): +class TestCredentialOfferHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = True handler = test_module.CredentialOfferHandler() @@ -51,7 +52,7 @@ async def test_called_auto_request(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -60,8 +61,8 @@ async def test_called_auto_request(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( return_value=(None, "credential_request_message") ) request_context.message = CredentialOffer() @@ -91,7 +92,7 @@ async def test_called_auto_request_x(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -100,12 +101,12 @@ async def test_called_auto_request_x(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,7 +116,7 @@ async def test_called_auto_request_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( handler._logger, "exception", async_mock.MagicMock() ) as mock_log_exc: @@ -130,7 +131,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() @@ -149,7 +150,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) @@ -159,7 +160,7 @@ async def test_no_conn_no_oob(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py index 2187e6258c..bd5bcb64d3 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,7 +13,7 @@ from .. import credential_problem_report_handler as test_module -class TestCredentialProblemReportHandler(AsyncTestCase): +class TestCredentialProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -22,9 +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 = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock() request_context.message = CredentialProblemReport( description={ "en": "Change of plans", @@ -50,10 +49,8 @@ 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 = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = CredentialProblemReport( description={ diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py index 911f056d43..51cb64533e 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import credential_proposal_handler as test_module -class TestCredentialProposalHandler(AsyncTestCase): +class TestCredentialProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False @@ -42,11 +43,11 @@ async def test_called_auto_offer(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( return_value=(None, "credential_offer_message") ) request_context.message = CredentialProposal() @@ -73,13 +74,13 @@ async def test_called_auto_offer_x(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,7 +90,7 @@ async def test_called_auto_offer_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( handler._logger, "exception", async_mock.MagicMock() ) as mock_log_exc: @@ -104,7 +105,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock() request_context.message = CredentialProposal() request_context.connection_ready = False handler = test_module.CredentialProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py index b74bf445ef..0ed5e7f66d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -14,7 +15,7 @@ CD_ID = "LjgpST2rjsoxYegQDRm7EL:3:CL:18:tag" -class TestCredentialRequestHandler(AsyncTestCase): +class TestCredentialRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -22,7 +23,7 @@ async def test_called(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -31,7 +32,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False @@ -57,7 +58,7 @@ async def test_called_auto_issue(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -76,11 +77,11 @@ async def test_called_auto_issue(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( return_value=(None, "credential_issue_message") ) request_context.message = CredentialRequest() @@ -112,7 +113,7 @@ async def test_called_auto_issue_x(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -131,13 +132,13 @@ async def test_called_auto_issue_x(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.CoroutineMock() + cred_ex_rec, "save_error_state", async_mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -147,7 +148,7 @@ async def test_called_auto_issue_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( handler._logger, "exception", async_mock.MagicMock() ) as mock_log_exc: @@ -161,7 +162,7 @@ async def test_called_auto_issue_no_preview(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -174,11 +175,11 @@ async def test_called_auto_issue_no_preview(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( return_value=(None, "credential_issue_message") ) @@ -206,7 +207,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = CredentialRequest() request_context.connection_ready = False handler = test_module.CredentialRequestHandler() @@ -225,7 +226,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) @@ -235,7 +236,7 @@ async def test_called_no_connection_no_oob(self): with async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = CredentialRequest() handler = test_module.CredentialRequestHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py index d1df7d7f71..ac20adde83 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -29,7 +30,7 @@ ) -class TestV10CredentialExchange(AsyncTestCase): +class TestV10CredentialExchange(IsolatedAsyncioTestCase): """Test de/serialization.""" async def test_serde(self): @@ -78,7 +79,7 @@ async def test_save_error_state(self): await record.save(session) with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() + record, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module.LOGGER, "exception", async_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 66cf6315a5..0396176a9d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -3,7 +3,8 @@ from copy import deepcopy from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....cache.base import BaseCache @@ -49,8 +50,8 @@ ) -class TestCredentialManager(AsyncTestCase): - async def setUp(self): +class TestCredentialManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context @@ -63,22 +64,20 @@ async def setUp(self): Ledger = async_mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -163,7 +162,7 @@ async def test_create_proposal(self): ) ) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( return_value=SCHEMA_ID ) @@ -201,7 +200,7 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( return_value=SCHEMA_ID ) @@ -299,7 +298,7 @@ async def test_create_free_offer(self): self.context.injector.bind_instance(BaseCache, self.cache) issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -381,7 +380,7 @@ async def test_create_free_offer_attr_mismatch(self): self.context.injector.bind_instance(BaseCache, self.cache) issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -439,7 +438,7 @@ async def test_create_bound_offer(self): ) as set_cached_key: get_cached_key.return_value = None issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -510,7 +509,7 @@ async def test_create_bound_offer_no_cred_def(self): ) as set_cached_key: get_cached_key.return_value = None issuer = async_mock.MagicMock() - issuer.create_credential_offer = async_mock.CoroutineMock( + issuer.create_credential_offer = async_mock.AsyncMock( return_value=INDY_OFFER ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -560,7 +559,7 @@ async def test_receive_offer_proposed(self): ) as save_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + async_mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -599,7 +598,7 @@ async def test_receive_free_offer(self): ) as save_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(side_effect=StorageNotFoundError), + async_mock.AsyncMock(side_effect=StorageNotFoundError), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -645,13 +644,13 @@ async def test_create_request(self): V10CredentialExchange, "save", autospec=True ) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.CoroutineMock( + holder.create_credential_request = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -716,13 +715,13 @@ async def test_create_request_no_cache(self): V10CredentialExchange, "save", autospec=True ) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.CoroutineMock( + holder.create_credential_request = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -785,7 +784,7 @@ async def test_receive_request(self): ) as save_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + async_mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_request(request, mock_conn, None) @@ -825,7 +824,7 @@ async def test_receive_request_no_connection_cred_request(self): ) as mock_save, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_exchange cx_rec = await self.manager.receive_request(request, mock_conn, mock_oob) @@ -865,7 +864,7 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): ) as mock_save, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = (StorageNotFoundError(),) with self.assertRaises(CredentialManagerError): @@ -909,7 +908,7 @@ async def test_issue_credential_revocable(self): issuer = async_mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1000" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -919,7 +918,7 @@ async def test_issue_credential_revocable(self): ) as revoc, async_mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( return_value=( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, @@ -927,7 +926,7 @@ async def test_issue_credential_revocable(self): async_mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", - get_or_fetch_local_tails_path=async_mock.CoroutineMock(), + get_or_fetch_local_tails_path=async_mock.AsyncMock(), max_creds=10, ), ) @@ -996,18 +995,18 @@ async def test_issue_credential_non_revocable(self): issuer = async_mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(cred), None) ) self.context.injector.bind_instance(IndyIssuer, issuer) Ledger = async_mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=CRED_DEF_NR ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) self.context.injector.clear_binding(BaseLedger) self.context.injector.bind_instance(BaseLedger, self.ledger) with async_mock.patch.object( @@ -1015,7 +1014,7 @@ async def test_issue_credential_non_revocable(self): ) as save_ex, async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1067,7 +1066,7 @@ async def test_issue_credential_fills_rr(self): issuer = async_mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(cred), stored_exchange.revocation_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -1079,24 +1078,22 @@ async def test_issue_credential_fills_rr(self): ) as save_ex: revoc.return_value = async_mock.MagicMock( get_or_create_active_registry=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=async_mock.AsyncMock(), ), async_mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", max_creds=1000, - get_or_fetch_local_tails_path=( - async_mock.CoroutineMock() - ), + get_or_fetch_local_tails_path=(async_mock.AsyncMock()), ), ) ) ), - handle_full_registry=async_mock.CoroutineMock(), + handle_full_registry=async_mock.AsyncMock(), ) (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1171,14 +1168,14 @@ async def test_issue_credential_no_active_rr_no_retries(self): issuer = async_mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1186,17 +1183,17 @@ async def test_issue_credential_no_active_rr_no_retries(self): with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( side_effect=[ None, ( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=async_mock.AsyncMock(), ), async_mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(async_mock.AsyncMock()), ), ), ] @@ -1237,14 +1234,14 @@ async def test_issue_credential_no_active_rr_retry(self): issuer = async_mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1252,7 +1249,7 @@ async def test_issue_credential_no_active_rr_retry(self): with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( return_value=None ) with self.assertRaises(CredentialManagerError) as context: @@ -1283,7 +1280,7 @@ async def test_receive_credential(self): ) as save_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(return_value=stored_exchange), + async_mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_credential(issue, connection_id) @@ -1335,15 +1332,15 @@ async def test_store_credential(self): cred_id = "cred-id" holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) - holder.get_credential = async_mock.CoroutineMock( + holder.store_credential = async_mock.AsyncMock(return_value=cred_id) + holder.get_credential = async_mock.AsyncMock( return_value=json.dumps(INDY_CRED_INFO) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1357,7 +1354,7 @@ async def test_store_credential(self): ) as delete_ex: mock_rev_reg.from_definition = async_mock.MagicMock( return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + get_or_fetch_local_tails_path=async_mock.AsyncMock() ) ) ret_exchange = await self.manager.store_credential( @@ -1438,21 +1435,21 @@ async def test_store_credential_no_preview(self): await stored_exchange.save(self.session) cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=cred_def ) cred_id = "cred-id" holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) - holder.get_credential = async_mock.CoroutineMock( + holder.store_credential = async_mock.AsyncMock(return_value=cred_id) + holder.get_credential = async_mock.AsyncMock( return_value=json.dumps(cred_info_no_rev) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1508,20 +1505,20 @@ async def test_store_credential_holder_store_indy_error(self): await stored_exchange.save(self.session) cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=cred_def ) cred_id = "cred-id" holder = async_mock.MagicMock() - holder.store_credential = async_mock.CoroutineMock( + holder.store_credential = async_mock.AsyncMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1589,7 +1586,7 @@ async def test_receive_credential_ack(self): ) as delete_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange ret_exchange = await self.manager.receive_credential_ack(ack, connection_id) @@ -1628,7 +1625,7 @@ async def test_receive_problem_report(self): ) as save_ex, async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1654,7 +1651,7 @@ async def test_receive_problem_report_x(self): with async_mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py index 129f7eceb1..2224c2031a 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext from .....wallet.base import BaseWallet @@ -8,13 +9,13 @@ from . import CRED_DEF_ID -class TestCredentialRoutes(AsyncTestCase): - async def setUp(self): +class TestCredentialRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -34,7 +35,7 @@ async def test_credential_exchange_list(self): with async_mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.query = async_mock.CoroutineMock() + mock_cred_ex.query = async_mock.AsyncMock() mock_cred_ex.query.return_value = [mock_cred_ex] mock_cred_ex.serialize = async_mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} @@ -60,7 +61,7 @@ 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 = async_mock.CoroutineMock( + mock_cred_ex.query = async_mock.AsyncMock( side_effect=test_module.StorageError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -74,7 +75,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex mock_cred_ex.serialize = async_mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} @@ -95,7 +96,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 = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -109,7 +110,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex mock_cred_ex.serialize = async_mock.MagicMock( side_effect=test_module.BaseModelError() @@ -118,7 +119,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -129,13 +130,11 @@ async def test_credential_exchange_create(self): ), async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cred_ex_record = async_mock.MagicMock() @@ -153,7 +152,7 @@ async def test_credential_exchange_create(self): ) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -164,13 +163,11 @@ async def test_credential_exchange_create_x(self): ), async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cred_ex_record = async_mock.MagicMock() @@ -186,7 +183,7 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id} ) @@ -195,7 +192,7 @@ async def test_credential_exchange_create_no_proposal(self): assert "credential_proposal" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -206,13 +203,11 @@ async def test_credential_exchange_send(self): ), async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cred_ex_record = async_mock.MagicMock() @@ -232,7 +227,7 @@ async def test_credential_exchange_send(self): async def test_credential_exchange_send_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id} ) @@ -244,7 +239,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -254,7 +249,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -270,7 +265,7 @@ async def test_credential_exchange_send_not_ready(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -291,7 +286,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -304,18 +299,18 @@ async def test_credential_exchange_send_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_cred_offer = async_mock.MagicMock() mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + create_offer=async_mock.AsyncMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) ), - prepare_send=async_mock.CoroutineMock( + prepare_send=async_mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -330,7 +325,7 @@ async def test_credential_exchange_send_proposal(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -355,7 +350,7 @@ async def test_credential_exchange_send_proposal(self): ) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -365,7 +360,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -380,7 +375,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -392,7 +387,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -402,7 +397,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 = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_proposal.return_value = ( @@ -416,7 +411,7 @@ async def test_credential_exchange_send_proposal_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) @@ -429,7 +424,7 @@ async def test_credential_exchange_send_proposal_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record @@ -439,7 +434,7 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -458,9 +453,7 @@ async def test_credential_exchange_create_free_offer(self): ) as mock_credential_manager, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_cred_ex_record = async_mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, @@ -474,7 +467,7 @@ async def test_credential_exchange_create_free_offer(self): ) async def test_credential_exchange_create_free_offer_no_cred_def_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -487,14 +480,14 @@ async def test_credential_exchange_create_free_offer_no_cred_def_id(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_preview(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.json.return_value = {"comment": "comment", "cred_def_id": "dummy"} with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -506,14 +499,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] = async_mock.MagicMock( - get_public_did=async_mock.CoroutineMock(return_value=None), + get_public_did=async_mock.AsyncMock(return_value=None), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_deser_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -528,9 +521,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): ) as mock_conn_rec, async_mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_cred_ex_record = async_mock.MagicMock() mock_credential_manager.return_value.create_offer.side_effect = ( test_module.BaseModelError() @@ -540,7 +531,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -559,10 +550,10 @@ async def test_credential_exchange_create_free_offer_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + create_offer=async_mock.AsyncMock( return_value=( mock_cred_ex_record, async_mock.MagicMock(), @@ -573,7 +564,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -590,9 +581,7 @@ async def test_credential_exchange_send_free_offer(self): ) as mock_credential_manager, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_cred_ex_record = async_mock.MagicMock() @@ -608,7 +597,7 @@ async def test_credential_exchange_send_free_offer(self): ) async def test_credential_exchange_send_free_offer_no_cred_def_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "credential_preview": "dummy", @@ -618,7 +607,7 @@ async def test_credential_exchange_send_free_offer_no_cred_def_id(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_preview(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "cred_def_id": CRED_DEF_ID, @@ -628,7 +617,7 @@ async def test_credential_exchange_send_free_offer_no_preview(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -642,13 +631,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -658,7 +645,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.json.return_value["auto_issue"] = True with async_mock.patch.object( @@ -667,12 +654,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 = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -682,7 +667,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -703,11 +688,11 @@ async def test_credential_exchange_send_free_offer_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + create_offer=async_mock.AsyncMock( return_value=( mock_cred_ex_record, async_mock.MagicMock(), @@ -719,7 +704,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -731,14 +716,12 @@ async def test_credential_exchange_send_bound_offer(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_cred_ex_record = async_mock.MagicMock() @@ -754,7 +737,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -762,14 +745,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -781,21 +764,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 = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cred_ex.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -805,7 +786,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -813,10 +794,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 = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cred_ex.STATE_ACKED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) @@ -824,7 +805,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -836,18 +817,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -857,7 +836,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -869,7 +848,7 @@ async def test_credential_exchange_send_request(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -888,7 +867,7 @@ async def test_credential_exchange_send_request(self): ) async def test_credential_exchange_send_request_no_conn(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -902,12 +881,12 @@ async def test_credential_exchange_send_request_no_conn(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_oob_rec.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -931,7 +910,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -939,14 +918,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -958,20 +937,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = async_mock.MagicMock( state=mock_cred_ex.STATE_OFFER_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -981,7 +958,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -993,18 +970,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = ( - async_mock.CoroutineMock() - ) + mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1014,7 +989,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1026,7 +1001,7 @@ async def test_credential_exchange_issue(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) @@ -1045,7 +1020,7 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1053,20 +1028,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = async_mock.MagicMock( connection_id="dummy", serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1076,17 +1051,17 @@ 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 = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cred_ex_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) mock_credential_manager.return_value.issue_credential = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) mock_credential_manager.return_value.issue_credential.return_value = ( async_mock.MagicMock(), @@ -1097,7 +1072,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1107,17 +1082,17 @@ async def test_credential_exchange_issue_not_ready(self): ) as mock_credential_manager, async_mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.issue_credential = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) mock_credential_manager.return_value.issue_credential.return_value = ( async_mock.MagicMock(), @@ -1128,13 +1103,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = async_mock.MagicMock( connection_id="dummy", serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1144,14 +1119,14 @@ 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 = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cred_ex_rec ) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.CoroutineMock( + mock_issue_cred = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) mock_credential_manager.return_value.issue_credential = mock_issue_cred @@ -1160,13 +1135,13 @@ async def test_credential_exchange_issue_rev_reg_full(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cred_ex_rec = async_mock.MagicMock( connection_id="dummy", serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1175,11 +1150,11 @@ async def test_credential_exchange_issue_deser_x(self): ) as mock_credential_manager, async_mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cred_ex_rec ) mock_credential_manager.return_value = async_mock.MagicMock( - issue_credential=async_mock.CoroutineMock( + issue_credential=async_mock.AsyncMock( return_value=( mock_cred_ex_rec, async_mock.MagicMock(), @@ -1190,7 +1165,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1202,7 +1177,7 @@ async def test_credential_exchange_store(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) @@ -1224,7 +1199,7 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1238,7 +1213,7 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) @@ -1260,7 +1235,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1268,14 +1243,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1287,15 +1262,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 = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cred_ex.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1311,7 +1286,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1323,20 +1298,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 = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1353,17 +1328,15 @@ async def test_credential_exchange_store_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_cred_ex_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_credential_manager.return_value = async_mock.MagicMock( - store_credential=async_mock.CoroutineMock( - return_value=mock_cred_ex_record - ), - send_credential_ack=async_mock.CoroutineMock( + store_credential=async_mock.AsyncMock(return_value=mock_cred_ex_record), + send_credential_ack=async_mock.AsyncMock( return_value=(mock_cred_ex_record, async_mock.MagicMock()) ), ) @@ -1379,10 +1352,10 @@ async def test_credential_exchange_remove(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.delete_record = async_mock.CoroutineMock() + mock_cred_ex.delete_record = async_mock.AsyncMock() await test_module.credential_exchange_remove(self.request) @@ -1396,7 +1369,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 = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1412,19 +1385,17 @@ async def test_credential_exchange_remove_x(self): ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) mock_rec = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock( + delete_record=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( - return_value=mock_rec - ) + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock(return_value=mock_rec) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1441,9 +1412,9 @@ async def test_credential_exchange_problem_report(self): ) as mock_problem_report, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_problem_report.return_value = magic_report @@ -1457,7 +1428,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1465,7 +1436,7 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): with async_mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1473,7 +1444,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1485,9 +1456,9 @@ async def test_credential_exchange_problem_report_x(self): ) as mock_problem_report, async_mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock( + save_error_state=async_mock.AsyncMock( 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 66ac360d3e..5594d6625a 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py @@ -1,8 +1,8 @@ from copy import deepcopy from time import time import json -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from marshmallow import ValidationError from .. import handler as test_module @@ -193,8 +193,8 @@ } -class TestV20IndyCredFormatHandler(AsyncTestCase): - async def setUp(self): +class TestV20IndyCredFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context @@ -205,22 +205,20 @@ async def setUp(self): # Ledger Ledger = async_mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -298,7 +296,7 @@ async def test_check_uniqueness(self): with async_mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_indy_query: mock_indy_query.return_value = [] await self.handler._check_uniqueness("dummy-cx-id") @@ -306,7 +304,7 @@ async def test_check_uniqueness(self): with async_mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_indy_query: mock_indy_query.return_value = [async_mock.MagicMock()] with self.assertRaises(V20CredFormatError) as context: @@ -389,7 +387,7 @@ async def test_create_offer(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -455,7 +453,7 @@ async def test_create_offer_no_cache(self): await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -517,13 +515,13 @@ async def test_create_offer_attr_mismatch(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + async_mock.AsyncMock(return_value=(None, self.ledger)), ): with self.assertRaises(V20CredFormatError): await self.handler.create_offer(cred_proposal) @@ -541,7 +539,7 @@ async def test_create_offer_no_matching_sent_cred_def(self): filters_attach=[AttachDecorator.data_base64({}, ident="0")], ) - self.issuer.create_credential_offer = async_mock.CoroutineMock( + self.issuer.create_credential_offer = async_mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -577,12 +575,12 @@ async def test_create_request(self): ) cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} - self.holder.create_credential_request = async_mock.CoroutineMock( + self.holder.create_credential_request = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) @@ -617,7 +615,7 @@ async def test_create_request(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + async_mock.AsyncMock(return_value=(None, self.ledger)), ): await self.handler.create_request( cred_ex_record, {"holder_did": holder_did} @@ -646,7 +644,7 @@ async def test_create_request_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_OFFER_RECEIVED) with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.CoroutineMock() + self.handler, "_check_uniqueness", async_mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -721,21 +719,21 @@ async def test_issue_credential_revocable(self): ) cred_rev_id = "1000" - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( return_value=( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), async_mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(async_mock.AsyncMock()), max_creds=10, ), ) @@ -809,10 +807,10 @@ async def test_issue_credential_non_revocable(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED), None) ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=CRED_DEF_NR ) self.context.injector.bind_instance( @@ -822,7 +820,7 @@ async def test_issue_credential_non_revocable(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (cred_format, attachment) = await self.handler.issue_credential( cred_ex_record, retries=0 @@ -850,7 +848,7 @@ async def test_issue_credential_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_REQUEST_RECEIVED) with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.CoroutineMock() + self.handler, "_check_uniqueness", async_mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -907,14 +905,14 @@ async def test_issue_credential_no_active_rr_no_retries(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( return_value=() ) with self.assertRaises(V20CredFormatError) as context: @@ -967,24 +965,24 @@ async def test_issue_credential_no_active_rr_retry(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( side_effect=[ None, ( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=async_mock.AsyncMock(), ), async_mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(async_mock.AsyncMock()), ), ), ] @@ -1040,21 +1038,21 @@ async def test_issue_credential_rr_full(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.CoroutineMock( + self.issuer.create_credential = async_mock.AsyncMock( side_effect=test_module.IndyIssuerRevocationRegistryFullError("Nope") ) with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.CoroutineMock( + revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( return_value=( async_mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.CoroutineMock(), + set_state=async_mock.AsyncMock(), ), async_mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.CoroutineMock()), + get_or_fetch_local_tails_path=(async_mock.AsyncMock()), ), ) ) @@ -1138,9 +1136,9 @@ async def test_store_credential(self): cred_id = "cred-id" - self.holder.store_credential = async_mock.CoroutineMock(return_value=cred_id) + self.holder.store_credential = async_mock.AsyncMock(return_value=cred_id) stored_cred = {"stored": "cred"} - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps(stored_cred) ) @@ -1149,7 +1147,7 @@ async def test_store_credential(self): ) as mock_rev_reg: mock_rev_reg.from_definition = async_mock.MagicMock( return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + get_or_fetch_local_tails_path=async_mock.AsyncMock() ) ) with self.assertRaises(V20CredFormatError) as context: @@ -1162,7 +1160,7 @@ async def test_store_credential(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_mock.patch.object( test_module, "RevocationRegistry", autospec=True ) as mock_rev_reg, async_mock.patch.object( @@ -1170,12 +1168,12 @@ async def test_store_credential(self): ) as mock_get_detail_record: mock_rev_reg.from_definition = async_mock.MagicMock( return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + get_or_fetch_local_tails_path=async_mock.AsyncMock() ) ) mock_get_detail_record.return_value = async_mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) self.ledger.get_credential_definition.reset_mock() @@ -1259,7 +1257,7 @@ async def test_store_credential_holder_store_indy_error(self): ) cred_id = "cred-id" - self.holder.store_credential = async_mock.CoroutineMock( + self.holder.store_credential = async_mock.AsyncMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) @@ -1270,10 +1268,10 @@ async def test_store_credential_holder_store_indy_error(self): ) as mock_rev_reg: mock_get_detail_record.return_value = async_mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) mock_rev_reg.return_value = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + get_or_fetch_local_tails_path=async_mock.AsyncMock() ) with self.assertRaises(test_module.IndyHolderError) as context: await self.handler.store_credential(stored_cx_rec, cred_id) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index f17202fd31..f636e33375 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,7 +1,7 @@ from copy import deepcopy from .......vc.ld_proofs.error import LinkedDataProofException -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from unittest.mock import patch from marshmallow import ValidationError @@ -131,8 +131,8 @@ } -class TestV20LDProofCredFormatHandler(AsyncTestCase): - async def setUp(self): +class TestV20LDProofCredFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.holder = async_mock.MagicMock() self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) @@ -240,7 +240,7 @@ async def test_assert_can_issue_with_id_and_proof_type(self): with async_mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_did_info: did_info = DIDInfo( did=TEST_DID_SOV, @@ -279,7 +279,7 @@ async def test_assert_can_issue_with_id_and_proof_type(self): assert "Issuer did did:key:notfound not found" in str(context.exception) async def test_get_did_info_for_did_sov(self): - self.wallet.get_local_did = async_mock.CoroutineMock() + self.wallet.get_local_did = async_mock.AsyncMock() did_info = await self.handler._did_info_for_did(TEST_DID_SOV) self.wallet.get_local_did.assert_called_once_with( @@ -300,11 +300,11 @@ async def test_get_suite_for_detail(self): with async_mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_can_issue, async_mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_did_info: suite = await self.handler._get_suite_for_detail(detail) @@ -456,7 +456,7 @@ async def test_create_offer(self): with async_mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_can_issue, patch.object( test_module, "get_properties_without_context", return_value=[] ): @@ -496,7 +496,7 @@ async def test_create_offer_adds_bbs_context(self): with async_mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -521,7 +521,7 @@ async def test_create_offer_adds_ed25519_2020_context(self): with async_mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -543,7 +543,7 @@ async def test_create_offer_x_wrong_attributes(self): with async_mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ), patch.object( test_module, "get_properties_without_context", @@ -792,9 +792,9 @@ async def test_issue_credential(self): with async_mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) + test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) ) as mock_issue, async_mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -845,9 +845,9 @@ async def test_issue_credential_adds_bbs_context(self): with async_mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) + test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) ) as mock_issue, async_mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -889,9 +889,9 @@ async def test_issue_credential_adds_ed25519_2020_context(self): with async_mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.CoroutineMock(return_value=LD_PROOF_VC) + test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) ) as mock_issue, async_mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", @@ -1143,16 +1143,16 @@ async def test_store_credential(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.CoroutineMock() + self.holder.store_credential = async_mock.AsyncMock() with async_mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_get_suite, async_mock.patch.object( test_module, "verify_credential", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=DocumentVerificationResult(verified=True) ), ) as mock_verify_credential, async_mock.patch.object( @@ -1206,16 +1206,16 @@ async def test_store_credential_x_not_verified(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.CoroutineMock() + self.holder.store_credential = async_mock.AsyncMock() with async_mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_get_suite, async_mock.patch.object( test_module, "verify_credential", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=DocumentVerificationResult(verified=False) ), ) as mock_verify_credential, async_mock.patch.object( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py index f4283168fa..5b8168bb00 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,14 +11,14 @@ from .. import cred_ack_handler as test_module -class TestCredentialAckHandler(AsyncTestCase): +class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -26,9 +27,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = True handler = test_module.V20CredAckHandler() @@ -53,7 +52,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_cred_ack = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_cred_ack = async_mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = False handler = test_module.V20CredAckHandler() @@ -71,7 +70,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py index 2a47af1d5d..3c48ef0c0b 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import cred_issue_handler as test_module -class TestCredentialIssueHandler(AsyncTestCase): +class TestCredentialIssueHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = True handler_inst = test_module.V20CredIssueHandler() @@ -50,7 +51,7 @@ async def test_called_auto_store(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -60,9 +61,9 @@ async def test_called_auto_store(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock(), - store_credential=async_mock.CoroutineMock(), - send_cred_ack=async_mock.CoroutineMock(return_value="cred_ack_message"), + receive_credential=async_mock.AsyncMock(), + store_credential=async_mock.AsyncMock(), + send_cred_ack=async_mock.AsyncMock(return_value="cred_ack_message"), ) request_context.message = V20CredIssue() request_context.connection_ready = True @@ -86,7 +87,7 @@ async def test_called_auto_store_x(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -96,18 +97,18 @@ async def test_called_auto_store_x(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.CoroutineMock( + receive_credential=async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ), - store_credential=async_mock.CoroutineMock( + store_credential=async_mock.AsyncMock( side_effect=[ test_module.IndyHolderError, test_module.StorageError(), ] ), - send_cred_ack=async_mock.CoroutineMock(), + send_cred_ack=async_mock.AsyncMock(), ) request_context.message = V20CredIssue() @@ -127,7 +128,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = False handler_inst = test_module.V20CredIssueHandler() @@ -143,7 +144,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py index 66e295ce34..659c63dee7 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import cred_offer_handler as test_module -class TestV20CredOfferHandler(AsyncTestCase): +class TestV20CredOfferHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): request_context.connection_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = True handler_inst = test_module.V20CredOfferHandler() @@ -51,7 +52,7 @@ async def test_called_auto_request(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -60,8 +61,8 @@ async def test_called_auto_request(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( return_value=(None, "cred_request_message") ) request_context.message = V20CredOffer() @@ -91,7 +92,7 @@ async def test_called_auto_request_x(self): request_context.connection_record.my_did = "dummy" mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -100,12 +101,12 @@ async def test_called_auto_request_x(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,9 +116,9 @@ async def test_called_auto_request_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + handler._logger, "exception", async_mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -130,7 +131,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = False handler_inst = test_module.V20CredOfferHandler() @@ -149,7 +150,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py index fa5195fce9..ab38598f83 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import cred_problem_report_handler as test_module -class TestCredProblemReportHandler(AsyncTestCase): +class TestCredProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,9 +19,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock() request_context.connection_ready = True request_context.message = V20CredProblemReport( description={ @@ -47,10 +46,8 @@ 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 = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = V20CredProblemReport( description={ diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py index daaf4c0d79..b28c0be8ab 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import cred_proposal_handler as test_module -class TestV20CredProposalHandler(AsyncTestCase): +class TestV20CredProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False @@ -42,11 +43,11 @@ async def test_called_auto_offer(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( return_value=(None, "cred_offer_message") ) request_context.message = V20CredProposal() @@ -73,13 +74,13 @@ async def test_called_auto_offer_x(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,9 +90,9 @@ async def test_called_auto_offer_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + handler._logger, "exception", async_mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -104,7 +105,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock() request_context.message = V20CredProposal() request_context.connection_ready = False handler_inst = test_module.V20CredProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py index 25edba8b36..7a31325246 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -13,7 +14,7 @@ CD_ID = "LjgpST2rjsoxYegQDRm7EL:3:CL:18:tag" -class TestV20CredRequestHandler(AsyncTestCase): +class TestV20CredRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -21,7 +22,7 @@ async def test_called(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -30,7 +31,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False @@ -53,7 +54,7 @@ async def test_called_auto_issue(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -64,11 +65,11 @@ async def test_called_auto_issue(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( return_value=(None, "cred_issue_message") ) request_context.message = V20CredRequest() @@ -99,7 +100,7 @@ async def test_called_auto_issue_x(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -108,13 +109,13 @@ async def test_called_auto_issue_x(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.CoroutineMock() + cred_ex_rec, "save_error_state", async_mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock( + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -124,9 +125,9 @@ async def test_called_auto_issue_x(self): responder = MockResponder() with async_mock.patch.object( - responder, "send_reply", async_mock.CoroutineMock() + responder, "send_reply", async_mock.AsyncMock() ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.CoroutineMock() + handler._logger, "exception", async_mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -139,7 +140,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = V20CredRequest() request_context.connection_ready = False handler = test_module.V20CredRequestHandler() @@ -158,7 +159,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py index ec4e33c4bf..422fd2ab1e 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -8,7 +9,7 @@ from ..cred_ack import V20CredAck -class TestV20CredAck(AsyncTestCase): +class TestV20CredAck(IsolatedAsyncioTestCase): """Credential ack tests.""" async def test_init_type(self): @@ -42,7 +43,7 @@ async def test_serialize(self): assert cred_ack_dict is mock_dump.return_value -class TestCredentialAckSchema(AsyncTestCase): +class TestCredentialAckSchema(IsolatedAsyncioTestCase): """Test credential ack schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py index a0f2d70639..527585209c 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -12,7 +13,7 @@ from ..cred_issue import V20CredIssue -class TestV20CredIssue(AsyncTestCase): +class TestV20CredIssue(IsolatedAsyncioTestCase): """Credential issue tests""" INDY_CRED = { diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py index 3334aa5c59..73a7db3831 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_offer.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -12,7 +12,7 @@ from ..inner.cred_preview import V20CredAttrSpec, V20CredPreview -class TestV20CredOffer(AsyncTestCase): +class TestV20CredOffer(IsolatedAsyncioTestCase): """Credential offer tests""" indy_offer = { @@ -132,7 +132,7 @@ async def test_serde(self): V20CredOffer.deserialize(obj) -class TestV20CredOfferSchema(AsyncTestCase): +class TestV20CredOfferSchema(IsolatedAsyncioTestCase): """Test credential cred offer schema""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py index e45778f008..6dafd7027b 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_proposal.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -25,7 +25,7 @@ } -class TestV20CredProposal(AsyncTestCase): +class TestV20CredProposal(IsolatedAsyncioTestCase): """Credential proposal tests.""" async def test_init(self): @@ -234,7 +234,7 @@ async def test_serialize_minimal(self): } -class TestV20CredProposalSchema(AsyncTestCase): +class TestV20CredProposalSchema(IsolatedAsyncioTestCase): """Test credential proposal schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py index 607a3ff445..d813d9cc35 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_request.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator from ......messaging.models.base import BaseModelError @@ -11,7 +11,7 @@ from ..cred_request import V20CredRequest -class TestV20CredRequest(AsyncTestCase): +class TestV20CredRequest(IsolatedAsyncioTestCase): """Credential request tests""" indy_cred_req = { @@ -137,7 +137,7 @@ async def test_serde(self): V20CredRequest.deserialize(obj) -class TestV20CredRequestSchema(AsyncTestCase): +class TestV20CredRequestSchema(IsolatedAsyncioTestCase): """Test credential request schema""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py index 94510d1e06..1045f49003 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_indy.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..indy import V20CredExRecordIndy -class TestV20CredExRecordIndy(AsyncTestCase): +class TestV20CredExRecordIndy(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecordIndy( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py index 0c6e1ad2a1..ed9cb903f1 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/detail/tests/test_ld_proof.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..ld_proof import V20CredExRecordLDProof -class TestV20CredExRecordLDProof(AsyncTestCase): +class TestV20CredExRecordLDProof(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecordLDProof(cred_ex_ld_proof_id="dummy-0", cred_ex_id="abc") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py index d46fd498d7..91a92f4c37 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator @@ -36,7 +37,7 @@ } -class TestV20CredExRecord(AsyncTestCase): +class TestV20CredExRecord(IsolatedAsyncioTestCase): async def test_record(self): same = [ V20CredExRecord( @@ -126,7 +127,7 @@ async def test_save_error_state(self): await record.save(session) with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() + record, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module.LOGGER, "exception", async_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 b1ed8216ea..e711de9d29 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py @@ -1,7 +1,8 @@ import json -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache from .....cache.in_memory import InMemoryCache @@ -78,8 +79,8 @@ ) -class TestV20CredManager(AsyncTestCase): - async def setUp(self): +class TestV20CredManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context @@ -89,15 +90,13 @@ async def setUp(self): Ledger = async_mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value=CRED_DEF ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( - return_value=REV_REG_DEF - ) - self.ledger.__aenter__ = async_mock.CoroutineMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) @@ -162,7 +161,7 @@ async def test_create_proposal(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.CoroutineMock( + mock_handler.return_value.create_proposal = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -205,7 +204,7 @@ async def test_create_proposal_no_preview(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.CoroutineMock( + mock_handler.return_value.create_proposal = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -256,7 +255,7 @@ async def test_receive_proposal(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_proposal = async_mock.CoroutineMock() + mock_handler.return_value.receive_proposal = async_mock.AsyncMock() cred_proposal = V20CredProposal( credential_preview=cred_preview, @@ -329,7 +328,7 @@ async def test_create_free_offer(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.CoroutineMock( + mock_handler.return_value.create_offer = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -405,7 +404,7 @@ async def test_create_bound_offer(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.CoroutineMock( + mock_handler.return_value.create_offer = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -515,11 +514,11 @@ async def test_receive_offer_proposed(self): ) as mock_save, async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(return_value=stored_cx_rec), + async_mock.AsyncMock(return_value=stored_cx_rec), ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.CoroutineMock() + mock_handler.return_value.receive_offer = async_mock.AsyncMock() cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -570,11 +569,11 @@ async def test_receive_free_offer(self): with async_mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.CoroutineMock() + mock_handler.return_value.receive_offer = async_mock.AsyncMock() mock_retrieve.side_effect = (StorageNotFoundError(),) cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -625,7 +624,7 @@ async def test_create_bound_request(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.CoroutineMock( + mock_handler.return_value.create_request = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -712,7 +711,7 @@ async def test_create_free_request(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.CoroutineMock( + mock_handler.return_value.create_request = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -782,12 +781,12 @@ async def test_receive_request(self): with async_mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = async_mock.AsyncMock() # mock_retrieve.return_value = stored_cx_rec cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -832,12 +831,12 @@ async def test_receive_request_no_connection_cred_request(self): with async_mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.return_value = stored_cx_rec - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = async_mock.AsyncMock() cx_rec = await self.manager.receive_request( cred_request, mock_conn, mock_oob @@ -881,12 +880,12 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): with async_mock.patch.object( V20CredExRecord, "save", autospec=True ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.CoroutineMock() + mock_handler.return_value.receive_request = async_mock.AsyncMock() cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -972,7 +971,7 @@ async def test_issue_credential(self): issuer = async_mock.MagicMock() cred_rev_id = "1000" - issuer.create_credential = async_mock.CoroutineMock( + issuer.create_credential = async_mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -982,7 +981,7 @@ async def test_issue_credential(self): ) as mock_save, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.issue_credential = async_mock.CoroutineMock( + mock_handler.return_value.issue_credential = async_mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -1090,11 +1089,11 @@ async def test_receive_cred(self): ) as mock_save, async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_credential = async_mock.CoroutineMock() + mock_handler.return_value.receive_credential = async_mock.AsyncMock() mock_retrieve.return_value = stored_cx_rec ret_cx_rec = await self.manager.receive_credential( cred_issue, @@ -1158,7 +1157,7 @@ async def test_receive_cred_x_extra_formats(self): with async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1196,7 +1195,7 @@ async def test_receive_cred_x_no_formats(self): with async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1241,7 +1240,7 @@ async def test_store_credential(self): ) as mock_delete, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.store_credential = async_mock.CoroutineMock() + mock_handler.return_value.store_credential = async_mock.AsyncMock() ret_cx_rec = await self.manager.store_credential( stored_cx_rec, cred_id=cred_id @@ -1318,7 +1317,7 @@ async def test_receive_cred_ack(self): ) as mock_save, async_mock.patch.object( V20CredExRecord, "delete_record", autospec=True ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True ) as mock_delete: @@ -1340,13 +1339,13 @@ async def test_receive_cred_ack(self): mock_delete.assert_called_once() async def test_delete_cred_ex_record(self): - stored_cx_rec = async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) - stored_indy = async_mock.MagicMock(delete_record=async_mock.CoroutineMock()) + stored_cx_rec = async_mock.MagicMock(delete_record=async_mock.AsyncMock()) + stored_indy = async_mock.MagicMock(delete_record=async_mock.AsyncMock()) with async_mock.patch.object( V20CredExRecord, "delete_record", autospec=True ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_id", async_mock.CoroutineMock() + V20CredExRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module, "V20CredFormat", async_mock.MagicMock() ) as mock_cred_format: @@ -1354,7 +1353,7 @@ async def test_delete_cred_ex_record(self): mock_cred_format.Format = [ async_mock.MagicMock( detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.CoroutineMock( + query_by_cred_ex_id=async_mock.AsyncMock( return_value=[ stored_indy, stored_indy, @@ -1364,7 +1363,7 @@ async def test_delete_cred_ex_record(self): ), async_mock.MagicMock( detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.CoroutineMock(return_value=[]) + query_by_cred_ex_id=async_mock.AsyncMock(return_value=[]) ) ), ] @@ -1390,7 +1389,7 @@ async def test_receive_problem_report(self): ) as save_ex, async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1422,7 +1421,7 @@ async def test_receive_problem_report_x(self): with async_mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py index 845f21555c..385898da58 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py @@ -1,5 +1,6 @@ from .....vc.ld_proofs.error import LinkedDataProofException -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -14,13 +15,13 @@ ) -class TestV20CredRoutes(AsyncTestCase): - async def setUp(self): +class TestV20CredRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -92,7 +93,7 @@ async def test_credential_exchange_list(self): with async_mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.query = async_mock.CoroutineMock(return_value=[mock_cx_rec]) + mock_cx_rec.query = async_mock.AsyncMock(return_value=[mock_cx_rec]) mock_cx_rec.serialize = async_mock.MagicMock( return_value={"hello": "world"} ) @@ -126,7 +127,7 @@ 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 = async_mock.CoroutineMock( + mock_cx_rec.query = async_mock.AsyncMock( side_effect=test_module.StorageError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -142,12 +143,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = async_mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -178,12 +179,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = async_mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"in": "dy"}) @@ -214,7 +215,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 = async_mock.CoroutineMock( + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -230,13 +231,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec mock_cx_rec.serialize = async_mock.MagicMock( side_effect=test_module.BaseModelError() ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( return_value=None ) @@ -244,7 +245,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -255,11 +256,11 @@ async def test_credential_exchange_create(self): ) as mock_cred_preview_deser, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cx_rec = async_mock.MagicMock() @@ -275,7 +276,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -286,11 +287,11 @@ async def test_credential_exchange_create_x(self): ) as mock_cred_preview_deser, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cred_mgr.return_value.prepare_send.side_effect = ( @@ -303,7 +304,7 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": { @@ -317,7 +318,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -328,11 +329,11 @@ async def test_credential_exchange_send(self): ) as mock_cred_preview_deser, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) mock_cx_rec = async_mock.MagicMock() @@ -348,7 +349,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -362,12 +363,12 @@ async def test_credential_exchange_send_request_no_conn_no_holder_did(self): ) as mock_cred_ex, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_oob_rec.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) @@ -394,7 +395,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -407,7 +408,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -423,7 +424,7 @@ async def test_credential_exchange_send_not_ready(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -447,7 +448,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -460,17 +461,17 @@ async def test_credential_exchange_send_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_cred_offer = async_mock.MagicMock() - mock_cred_mgr.return_value = async_mock.CoroutineMock( - create_offer=async_mock.CoroutineMock( + mock_cred_mgr.return_value = async_mock.AsyncMock( + create_offer=async_mock.AsyncMock( return_value=( - async_mock.CoroutineMock(), - async_mock.CoroutineMock(), + async_mock.AsyncMock(), + async_mock.AsyncMock(), ) ), - prepare_send=async_mock.CoroutineMock( + prepare_send=async_mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -485,7 +486,7 @@ async def test_credential_exchange_send_proposal(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -511,7 +512,7 @@ async def test_credential_exchange_send_proposal(self): async def test_credential_exchange_send_proposal_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "comment", "connection_id": connection_id, @@ -523,7 +524,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -533,7 +534,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -548,7 +549,7 @@ async def test_credential_exchange_send_proposal_x(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -565,7 +566,7 @@ async def test_credential_exchange_send_proposal_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec @@ -573,7 +574,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -583,7 +584,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 = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_cred_mgr.return_value.create_proposal.return_value = ( @@ -594,7 +595,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -612,7 +613,7 @@ async def test_credential_exchange_create_free_offer(self): ) as mock_cred_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cx_rec = async_mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, @@ -624,7 +625,7 @@ async def test_credential_exchange_create_free_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_free_offer_no_filter(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -638,7 +639,7 @@ async def test_credential_exchange_create_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -657,10 +658,10 @@ async def test_credential_exchange_create_free_offer_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_cred_mgr.return_value = async_mock.MagicMock( - create_offer=async_mock.CoroutineMock( + create_offer=async_mock.AsyncMock( return_value=( mock_cx_rec, async_mock.MagicMock(), @@ -671,7 +672,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -688,7 +689,7 @@ async def test_credential_exchange_send_free_offer(self): ) as mock_cred_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cx_rec = async_mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, @@ -699,7 +700,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "comment", "credential_preview": { @@ -713,7 +714,7 @@ async def test_credential_exchange_send_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -729,11 +730,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -743,7 +744,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": True, "credential_preview": { @@ -759,10 +760,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 = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -772,7 +773,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -793,10 +794,10 @@ async def test_credential_exchange_send_free_offer_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_cred_mgr.return_value = async_mock.CoroutineMock( - create_offer=async_mock.CoroutineMock( + mock_cred_mgr.return_value = async_mock.AsyncMock( + create_offer=async_mock.AsyncMock( return_value=( mock_cx_rec, async_mock.MagicMock(), @@ -808,7 +809,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -820,12 +821,12 @@ async def test_credential_exchange_send_bound_offer(self): ) as mock_cx_rec_cls, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cx_rec = async_mock.MagicMock() @@ -839,7 +840,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -851,12 +852,12 @@ async def test_credential_exchange_send_bound_offer_linked_data_error(self): ) as mock_cx_rec_cls, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cx_rec = async_mock.MagicMock() @@ -870,7 +871,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -878,14 +879,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -897,19 +898,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 = async_mock.CoroutineMock( + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cx_rec.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -919,7 +920,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -927,10 +928,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 = async_mock.CoroutineMock( + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cx_rec.STATE_DONE, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) @@ -938,7 +939,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 = async_mock.CoroutineMock(return_value={}) + self.request.json = async_mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -950,16 +951,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -969,7 +970,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -981,7 +982,7 @@ async def test_credential_exchange_send_request(self): ) as mock_cx_rec_cls, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) @@ -998,7 +999,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1006,14 +1007,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1025,18 +1026,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = async_mock.MagicMock( state=mock_cx_rec.STATE_OFFER_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1046,7 +1047,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1058,16 +1059,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1077,7 +1078,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1090,7 +1091,7 @@ async def test_credential_exchange_send_free_request(self): ) as mock_cred_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() mock_cx_rec = async_mock.MagicMock() @@ -1104,16 +1105,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 = async_mock.CoroutineMock( - return_value={"comment": "comment"} - ) + self.request.json = async_mock.AsyncMock(return_value={"comment": "comment"}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send_free_request(self.request) assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_request_no_conn_record(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1125,11 +1124,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 = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() mock_cred_mgr.return_value.create_request.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1139,7 +1138,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1151,10 +1150,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 = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock() + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() mock_cred_mgr.return_value.create_request.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1164,7 +1163,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } @@ -1177,7 +1176,7 @@ async def test_credential_exchange_send_free_request_x(self): ) as mock_cred_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.CoroutineMock( + mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1192,7 +1191,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1206,13 +1205,13 @@ async def test_credential_exchange_issue(self): ) as mock_response, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) mock_cx_rec = async_mock.MagicMock() - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1237,7 +1236,7 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1245,20 +1244,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = async_mock.MagicMock( conn_id="dummy", serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1268,16 +1267,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 = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cx_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() mock_cred_mgr.return_value.issue_credential.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1287,7 +1286,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1297,16 +1296,16 @@ async def test_credential_exchange_issue_not_ready(self): ) as mock_cred_mgr, async_mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.issue_credential = async_mock.CoroutineMock() + mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() mock_cred_mgr.return_value.issue_credential.return_value = ( async_mock.MagicMock(), async_mock.MagicMock(), @@ -1316,13 +1315,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = async_mock.MagicMock( conn_id="dummy", serialize=async_mock.MagicMock(), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1332,14 +1331,14 @@ 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 = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cx_rec ) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.CoroutineMock( + mock_issue_cred = async_mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) mock_cred_mgr.return_value.issue_credential = mock_issue_cred @@ -1348,13 +1347,13 @@ async def test_credential_exchange_issue_rev_reg_full(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} mock_cx_rec = async_mock.MagicMock( connection_id="dummy", serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1363,18 +1362,18 @@ async def test_credential_exchange_issue_deser_x(self): ) as mock_cred_mgr, async_mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_cx_rec ) mock_cred_mgr.return_value = async_mock.MagicMock( - issue_credential=async_mock.CoroutineMock( + issue_credential=async_mock.AsyncMock( return_value=( mock_cx_rec, async_mock.MagicMock(), ) ) ) - mock_cred_mgr.return_value.get_detail_record = async_mock.CoroutineMock( + mock_cred_mgr.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1387,7 +1386,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1401,11 +1400,11 @@ async def test_credential_exchange_store(self): ) as mock_response, async_mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1433,7 +1432,7 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1451,7 +1450,7 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) as mock_ld_proof_get_detail_record, async_mock.patch.object( IndyCredFormatHandler, "get_detail_record", autospec=True ) as mock_indy_get_detail_record: - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) @@ -1480,7 +1479,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1488,14 +1487,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1507,15 +1506,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 = async_mock.CoroutineMock( + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_cx_rec.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1529,7 +1528,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1541,20 +1540,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 = async_mock.CoroutineMock() + mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} with async_mock.patch.object( @@ -1573,12 +1572,12 @@ async def test_credential_exchange_store_x(self): serialize=async_mock.MagicMock( side_effect=test_module.BaseModelError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_cx_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - mock_handler.return_value.get_detail_record = async_mock.CoroutineMock( + mock_handler.return_value.get_detail_record = async_mock.AsyncMock( side_effect=[ async_mock.MagicMock( # indy serialize=async_mock.MagicMock(return_value={"...": "..."}) @@ -1588,8 +1587,8 @@ async def test_credential_exchange_store_x(self): ) mock_cred_mgr.return_value = async_mock.MagicMock( - store_credential=async_mock.CoroutineMock(return_value=mock_cx_rec), - send_cred_ack=async_mock.CoroutineMock( + store_credential=async_mock.AsyncMock(return_value=mock_cx_rec), + send_cred_ack=async_mock.AsyncMock( return_value=( mock_cx_rec, async_mock.MagicMock(), @@ -1609,7 +1608,7 @@ async def test_credential_exchange_remove(self): test_module.web, "json_response" ) as mock_response: mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock() + delete_cred_ex_record=async_mock.AsyncMock() ) await test_module.credential_exchange_remove(self.request) @@ -1622,7 +1621,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 = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock( + delete_cred_ex_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1637,7 +1636,7 @@ async def test_credential_exchange_remove_x(self): test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.CoroutineMock( + delete_cred_ex_record=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1646,7 +1645,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1661,9 +1660,9 @@ async def test_credential_exchange_problem_report(self): ) as mock_problem_report, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_problem_report.return_value = magic_report @@ -1677,7 +1676,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1687,7 +1686,7 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): ) as mock_cred_mgr_cls, async_mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1695,7 +1694,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} @@ -1707,9 +1706,9 @@ async def test_credential_exchange_problem_report_x(self): ) as mock_problem_report, async_mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock( + save_error_state=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) diff --git a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py index eb63e04b37..c92888d24d 100644 --- a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py +++ b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import ack_handler as test_module -class TestNotificationAckHandler(AsyncTestCase): +class TestNotificationAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py index c8b69357cb..b6b001bfd0 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,7 +1,7 @@ """Test Problem Report Handler.""" import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -38,7 +38,7 @@ class TestOOBProblemReportHandler: @pytest.mark.asyncio @async_mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_problem_report = async_mock.AsyncMock() 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 @async_mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_problem_report = async_mock.AsyncMock() 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 f403a1ce17..1c3567c43c 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py @@ -1,7 +1,7 @@ """Test Reuse Accept Message Handler.""" import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -39,7 +39,7 @@ class TestHandshakeReuseAcceptHandler: @async_mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() @@ -55,7 +55,7 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): @async_mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context, connection_record): mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) mock_oob_mgr.return_value.receive_reuse_accepted_message.side_effect = ( OutOfBandManagerError("error") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py index d4d94f546c..860743bd99 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py @@ -1,7 +1,7 @@ """Test Reuse Message Handler.""" import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -31,7 +31,7 @@ class TestHandshakeReuseHandler: @pytest.mark.asyncio @async_mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() 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 @async_mock.patch.object(test_module, "OutOfBandManager") async def test_reuse_accepted(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() 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 @async_mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.CoroutineMock() + mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() mock_oob_mgr.return_value.receive_reuse_message.side_effect = ( OutOfBandManagerError("error") ) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py b/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py index 9581e6a923..aafb44f9c0 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/models/tests/test_invitation.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -11,7 +11,7 @@ TEST_DID = "did:sov:55GkHamhTU1ZbTbV2ab9DE" -class TestInvitationRecord(AsyncTestCase): +class TestInvitationRecord(IsolatedAsyncioTestCase): def test_invitation_record(self): """Test invitation record.""" invi_rec = InvitationRecord(invi_msg_id="12345") @@ -28,7 +28,7 @@ def test_invitation_record(self): assert invi_rec != another -class TestInvitationRecordSchema(AsyncTestCase): +class TestInvitationRecordSchema(IsolatedAsyncioTestCase): def test_make_record(self): """Test making record.""" invi = InvitationMessage( diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 25abf93193..90b8d70078 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -6,7 +6,8 @@ from typing import List from unittest.mock import ANY -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord from .....connections.models.connection_target import ConnectionTarget @@ -308,10 +309,10 @@ def make_did_doc(self, did, verkey): return doc -class TestOOBManager(AsyncTestCase, TestConfig): +class TestOOBManager(IsolatedAsyncioTestCase, TestConfig): def setUp(self): self.responder = MockResponder() - self.responder.send = async_mock.CoroutineMock() + self.responder.send = async_mock.AsyncMock() self.test_mediator_routing_keys = [ "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR" @@ -320,7 +321,7 @@ def setUp(self): self.test_mediator_endpoint = "http://mediator.example.com" self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.CoroutineMock( + self.route_manager.routing_info = async_mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) @@ -339,7 +340,7 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseResponder, self.responder) self.profile.context.injector.bind_instance( - EventBus, async_mock.MagicMock(notify=async_mock.CoroutineMock()) + EventBus, async_mock.MagicMock(notify=async_mock.AsyncMock()) ) self.mt_mgr = async_mock.MagicMock() self.mt_mgr = async_mock.create_autospec(MultitenantManager) @@ -351,7 +352,7 @@ def setUp(self): ) self.manager = OutOfBandManager(self.profile) assert self.manager.profile - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = async_mock.AsyncMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -365,7 +366,7 @@ def setUp(self): their_role=ConnRecord.Role.REQUESTER, state=ConnRecord.State.COMPLETED, their_public_did=self.their_public_did, - save=async_mock.CoroutineMock(), + save=async_mock.AsyncMock(), ) async def test_create_invitation_handshake_succeeds(self): @@ -465,7 +466,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) MediationManager, "get_default_mediator_id", ) as mock_get_default_mediator, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.CoroutineMock() + mock_conn_rec, "metadata_set", async_mock.AsyncMock() ) as mock_metadata_set: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -507,7 +508,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): ) as mock_wallet_get_public_did, async_mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -541,7 +542,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): ) as mock_wallet_get_public_did, async_mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -575,11 +576,11 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): ) as mock_wallet_get_public_did, async_mock.patch.object( test_module.V10CredentialExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_cxid_v1, async_mock.patch.object( test_module.V20CredExRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_cxid_v2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -617,7 +618,7 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): ) as mock_wallet_get_public_did, async_mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_pxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -652,11 +653,11 @@ async def test_create_invitation_attachment_present_proof_v2_0(self): ) as mock_wallet_get_public_did, async_mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_pxid_1, async_mock.patch.object( test_module.V20PresExRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_pxid_2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -853,7 +854,7 @@ async def test_wait_for_conn_rec_active_retrieve_by_id(self): with async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( connection_id="the-retrieved-connection-id" ) @@ -872,7 +873,7 @@ async def test_create_handshake_reuse_msg(self): ) as oob_mgr_fetch_conn, async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=self.test_conn_rec), + async_mock.AsyncMock(return_value=self.test_conn_rec), ): oob_mgr_fetch_conn.return_value = ConnectionTarget( did=TestConfig.test_did, @@ -947,8 +948,8 @@ async def test_receive_reuse_message_existing_found(self): self.profile, "notify", autospec=True ) as mock_notify: mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=False, ) @@ -1004,8 +1005,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 = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), multi_use=True, ) @@ -1052,8 +1053,8 @@ async def test_receive_reuse_accepted(self): OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), ) await self.manager.receive_reuse_accepted_message( @@ -1126,9 +1127,9 @@ async def test_receive_problem_report(self): OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.CoroutineMock(), - delete_record=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + emit_event=async_mock.AsyncMock(), + delete_record=async_mock.AsyncMock(), + save=async_mock.AsyncMock(), ) await self.manager.receive_problem_report( @@ -1181,9 +1182,9 @@ async def test_receive_invitation_with_valid_mediation(self): ) await mediation_record.save(session) with async_mock.patch.object( - DIDXManager, "receive_invitation", async_mock.CoroutineMock() + DIDXManager, "receive_invitation", async_mock.AsyncMock() ) as mock_didx_recv_invi, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1212,11 +1213,11 @@ async def test_receive_invitation_with_invalid_mediation(self): with async_mock.patch.object( DIDXManager, "receive_invitation", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_didx_recv_invi, async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1226,7 +1227,7 @@ async def test_receive_invitation_with_invalid_mediation(self): mock_didx_recv_invi.return_value = mock_conn mock_retrieve_conn_by_id.return_value = mock_conn invi_msg = invite.invitation - self.route_manager.mediation_record_if_id = async_mock.CoroutineMock( + self.route_manager.mediation_record_if_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) await self.manager.receive_invitation( @@ -1249,10 +1250,10 @@ async def test_receive_invitation_didx_services_with_service_block(self): with async_mock.patch.object( test_module, "DIDXManager", autospec=True ) as didx_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve_conn_by_id: didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + receive_invitation=async_mock.AsyncMock(return_value=mock_conn) ) mock_retrieve_conn_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1278,10 +1279,10 @@ async def test_receive_invitation_connection_protocol(self): with async_mock.patch.object( test_module, "ConnectionManager", autospec=True ) as conn_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_conn_retrieve_by_id: conn_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + receive_invitation=async_mock.AsyncMock(return_value=mock_conn) ) mock_conn_retrieve_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1367,11 +1368,11 @@ async def test_existing_conn_record_public_did(self): with async_mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as oob_mgr_find_existing_conn, async_mock.patch.object( - OobRecord, "save", async_mock.CoroutineMock() + OobRecord, "save", async_mock.AsyncMock() ) as oob_record_save, async_mock.patch.object( - OobRecord, "retrieve_by_id", async_mock.CoroutineMock() + OobRecord, "retrieve_by_id", async_mock.AsyncMock() ) as oob_record_retrieve_by_id, async_mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True ) as oob_mgr_fetch_conn: @@ -1414,15 +1415,15 @@ async def test_receive_invitation_handshake_reuse(self): with async_mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as handle_handshake_reuse, async_mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as perform_handshake, async_mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(return_value=test_exist_conn), + async_mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1462,19 +1463,19 @@ async def test_receive_invitation_handshake_reuse_failed(self): with async_mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as handle_handshake_reuse, async_mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as perform_handshake, async_mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(return_value=test_exist_conn), + async_mock.AsyncMock(return_value=test_exist_conn), ), async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=test_exist_conn), + async_mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1485,8 +1486,8 @@ async def test_receive_invitation_handshake_reuse_failed(self): ) mock_oob = async_mock.MagicMock( - delete_record=async_mock.CoroutineMock(), - emit_event=async_mock.CoroutineMock(), + delete_record=async_mock.AsyncMock(), + emit_event=async_mock.AsyncMock(), ) perform_handshake.return_value = mock_oob @@ -1528,10 +1529,10 @@ async def test_receive_invitation_services_with_service_did(self): ) as didx_mgr_cls, async_mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_conn), + async_mock.AsyncMock(return_value=mock_conn), ): didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.CoroutineMock(return_value=mock_conn) + receive_invitation=async_mock.AsyncMock(return_value=mock_conn) ) oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1549,9 +1550,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = async_mock.MagicMock( - handle_message=async_mock.CoroutineMock() - ) + mock_oob_processor = async_mock.MagicMock(handle_message=async_mock.AsyncMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1563,11 +1562,11 @@ async def test_request_attach_oob_message_processor_connectionless(self): with async_mock.patch.object( InMemoryWallet, "create_signing_key", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_signing_key, async_mock.patch.object( OutOfBandManager, "_service_decorator_from_service", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( verkey="a-verkey", metadata={}, key_type=ED25519 @@ -1613,7 +1612,7 @@ async def test_request_attach_oob_message_processor_connection(self): ] mock_oob_processor = async_mock.MagicMock( - handle_message=async_mock.CoroutineMock() + handle_message=async_mock.AsyncMock() ) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor @@ -1622,7 +1621,7 @@ async def test_request_attach_oob_message_processor_connection(self): with async_mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn oob_invitation = InvitationMessage( @@ -1660,7 +1659,7 @@ async def test_request_attach_wait_for_conn_rec_active(self): ) as mock_wait_for_conn_rec_active, async_mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn mock_wait_for_conn_rec_active.return_value = None @@ -1686,7 +1685,7 @@ async def test_request_attach_wait_for_conn_rec_active(self): async def test_service_decorator_from_service_did(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = async_mock.AsyncMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -1719,7 +1718,7 @@ async def test_service_decorator_from_service_object(self): async def test_service_decorator_from_service_str_empty_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = async_mock.AsyncMock() self.manager.resolve_invitation.return_value = ( "", # empty endpoint [TestConfig.test_verkey], @@ -1733,7 +1732,7 @@ async def test_service_decorator_from_service_str_empty_endpoint(self): async def test_service_decorator_from_service_str_none_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.CoroutineMock() + self.manager.resolve_invitation = async_mock.AsyncMock() self.manager.resolve_invitation.return_value = ( None, # None endpoint [TestConfig.test_verkey], @@ -1797,9 +1796,9 @@ async def test_delete_stale_connection_by_invitation(self): ) ] with async_mock.patch.object( - ConnRecord, "query", async_mock.CoroutineMock() + ConnRecord, "query", async_mock.AsyncMock() ) as mock_connrecord_query, async_mock.patch.object( - ConnRecord, "delete_record", async_mock.CoroutineMock() + ConnRecord, "delete_record", async_mock.AsyncMock() ) as mock_connrecord_delete: mock_connrecord_query.return_value = records await self.manager.delete_stale_connection_by_invitation("test123") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py index a8127be26c..03e4422e1f 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord @@ -7,13 +7,13 @@ from .. import routes as test_module -class TestOutOfBandRoutes(AsyncTestCase): - async def setUp(self): +class TestOutOfBandRoutes(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -33,14 +33,14 @@ async def test_invitation_create(self): "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object( test_module, "OutOfBandManager", autospec=True ) as mock_oob_mgr, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_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 = async_mock.CoroutineMock(return_value=body) + self.request.json = async_mock.AsyncMock(return_value=body) with async_mock.patch.object( test_module, "OutOfBandManager", autospec=True ) as mock_oob_mgr, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "attachments": async_mock.MagicMock(), "handshake_protocols": [23], @@ -122,7 +122,7 @@ async def test_invitation_create_x(self): ) as mock_oob_mgr, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() expected_connection_record = ConnRecord(connection_id="some-id") with async_mock.patch.object( @@ -141,7 +141,7 @@ async def test_invitation_receive(self): ), async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.receive_invitation = async_mock.AsyncMock( 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "OutOfBandManager", autospec=True @@ -165,7 +165,7 @@ async def test_invitation_receive_x(self): ) as mock_invi_deser, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.CoroutineMock( + mock_oob_mgr.return_value.receive_invitation = async_mock.AsyncMock( side_effect=test_module.StorageError("cannot write") ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py index db233adc17..458b71b077 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,14 +11,14 @@ from .. import presentation_ack_handler as test_module -class TestPresentationAckHandler(AsyncTestCase): +class TestPresentationAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() session = request_context.session() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -26,9 +27,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_presentation_ack = async_mock.AsyncMock() request_context.message = PresentationAck() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -50,9 +49,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_presentation_ack = async_mock.AsyncMock() request_context.message = PresentationAck() request_context.connection_ready = False handler = test_module.PresentationAckHandler() @@ -68,7 +65,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py index 28b4747502..4855579113 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import presentation_handler as test_module -class TestPresentationHandler(AsyncTestCase): +class TestPresentationHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_presentation = async_mock.AsyncMock() request_context.message = Presentation() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -48,7 +49,7 @@ async def test_called_auto_verify(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -57,8 +58,8 @@ async def test_called_auto_verify(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.CoroutineMock() - mock_pres_mgr.return_value.verify_presentation = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_presentation = async_mock.AsyncMock() + mock_pres_mgr.return_value.verify_presentation = async_mock.AsyncMock() request_context.message = Presentation() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -79,7 +80,7 @@ async def test_called_auto_verify_x(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -89,12 +90,12 @@ async def test_called_auto_verify_x(self): test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value = async_mock.MagicMock( - receive_presentation=async_mock.CoroutineMock( + receive_presentation=async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ), - verify_presentation=async_mock.CoroutineMock( + verify_presentation=async_mock.AsyncMock( 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 a726dc349c..f4c3b39e25 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,7 +13,7 @@ from .. import presentation_problem_report_handler as test_module -class TestPresentationProblemReportHandler(AsyncTestCase): +class TestPresentationProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -22,9 +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 = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock() request_context.message = PresentationProblemReport( description={ "en": "Change of plans", @@ -50,10 +49,8 @@ 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 = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = PresentationProblemReport( description={ diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py index 95c963f704..254b92d647 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import presentation_proposal_handler as test_module -class TestPresentationProposalHandler(AsyncTestCase): +class TestPresentationProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -19,7 +20,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) request_context.message = PresentationProposal() @@ -46,10 +47,10 @@ async def test_called_auto_request(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_proposal.return_value, "presentation_request_message", @@ -85,12 +86,12 @@ async def test_called_auto_request_x(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -113,7 +114,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock() request_context.message = PresentationProposal() request_context.connection_ready = False handler = test_module.PresentationProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py index 83329461a4..2446afc031 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -63,7 +64,7 @@ ) -class TestPresentationRequestHandler(AsyncTestCase): +class TestPresentationRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.connection_record = async_mock.MagicMock() @@ -75,7 +76,7 @@ async def test_called(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -102,11 +103,11 @@ async def test_called(self): ) as mock_pres_mgr, async_mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -135,7 +136,7 @@ async def test_called_not_found(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -162,12 +163,12 @@ async def test_called_not_found(self): ) as mock_pres_mgr, async_mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( side_effect=StorageNotFoundError ) mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -226,12 +227,12 @@ async def test_called_auto_present(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.CoroutineMock( + get_credentials_for_presentation_request_by_referent=async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) @@ -244,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -310,17 +311,17 @@ async def test_called_auto_present_x(self): mock_px_rec = async_mock.MagicMock( presentation_proposal_dict=presentation_proposal, auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) @@ -334,14 +335,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -390,13 +391,13 @@ async def test_called_auto_present_no_preview(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -413,14 +414,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -470,13 +471,13 @@ async def test_called_auto_present_pred_no_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=[]) + async_mock.AsyncMock(return_value=[]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -488,14 +489,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -541,13 +542,13 @@ async def test_called_auto_present_pred_single_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy-0"}}] ) ) @@ -561,14 +562,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -618,13 +619,13 @@ async def test_called_auto_present_pred_multi_match(self): px_rec_instance = test_module.V10PresentationExchange(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -641,14 +642,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -718,13 +719,13 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ { "cred_info": { @@ -772,14 +773,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -839,7 +840,7 @@ async def test_called_auto_present_bait_and_switch(self): auto_present=True, ) - by_reft = async_mock.CoroutineMock( + by_reft = async_mock.AsyncMock( return_value=[ { "cred_info": { @@ -873,7 +874,7 @@ async def test_called_auto_present_bait_and_switch(self): request_context.injector.bind_instance(IndyHolder, mock_holder) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -885,14 +886,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 = async_mock.CoroutineMock( + mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -918,7 +919,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_request = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock() request_context.message = PresentationRequest() request_context.connection_ready = False handler = test_module.PresentationRequestHandler() @@ -937,7 +938,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py index 0498a89a8e..a55fc8e04b 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......indy.models.pres_preview import ( @@ -85,7 +86,7 @@ class Meta: model_class = BasexRecordImpl -class TestRecord(AsyncTestCase): +class TestRecord(IsolatedAsyncioTestCase): async def test_record(self): presentation_proposal = PresentationProposal( comment="Hello World", presentation_proposal=PRES_PREVIEW @@ -130,7 +131,7 @@ async def test_save_error_state(self): await record.save(session) with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() + record, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module.LOGGER, "exception", async_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 97f77aac9e..18c14e9c13 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py @@ -2,7 +2,8 @@ from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import ( V10CredentialExchange, @@ -213,20 +214,20 @@ PRES.assign_thread_id("dummy") -class TestPresentationManager(AsyncTestCase): - async def setUp(self): +class TestPresentationManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -242,7 +243,7 @@ async def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -251,7 +252,7 @@ async def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -264,14 +265,14 @@ async def setUp(self): injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), ) Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": { @@ -286,7 +287,7 @@ async def setUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -296,8 +297,8 @@ async def setUp(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -310,7 +311,7 @@ async def setUp(self): Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.CoroutineMock( + self.verifier.verify_presentation = async_mock.AsyncMock( return_value=("true", []) ) injector.bind_instance(IndyVerifier, self.verifier) @@ -392,7 +393,7 @@ async def test_create_bound_request(self): presentation_proposal_dict=proposal.serialize(), role=V10PresentationExchange.ROLE_VERIFIER, ) - exchange.save = async_mock.CoroutineMock() + exchange.save = async_mock.AsyncMock() (ret_exchange, pres_req_msg) = await self.manager.create_bound_request( presentation_exchange_record=exchange, name=PROOF_REQ_NAME, @@ -458,7 +459,7 @@ async def test_create_presentation(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -501,7 +502,7 @@ async def test_create_presentation_proof_req_non_revoc_interval_none(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -562,7 +563,7 @@ async def test_create_presentation_self_asserted(self): exchange_in.presentation_request = indy_proof_req more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -595,10 +596,10 @@ async def test_create_presentation_self_asserted(self): async def test_create_presentation_no_revocation(self): Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -615,7 +616,7 @@ async def test_create_presentation_no_revocation(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -628,7 +629,7 @@ async def test_create_presentation_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -638,7 +639,7 @@ async def test_create_presentation_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) with async_mock.patch.object( @@ -681,7 +682,7 @@ async def test_create_presentation_bad_revoc_state(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -695,7 +696,7 @@ async def test_create_presentation_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -705,14 +706,14 @@ async def test_create_presentation_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( side_effect=IndyHolderError("Problem", {"message": "Nope"}) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -749,7 +750,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": { @@ -776,7 +777,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -786,8 +787,8 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -799,7 +800,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -837,7 +838,7 @@ async def test_no_matching_creds_for_proof_req(self): nonce=PROOF_REQ_NONCE, profile=self.profile, ) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = async_mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -845,7 +846,7 @@ async def test_no_matching_creds_for_proof_req(self): indy_proof_req, holder=self.holder ) - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1369,7 +1370,7 @@ async def test_receive_problem_report(self): ) as save_ex, async_mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex, async_mock.patch.object( self.profile, "session", @@ -1409,7 +1410,7 @@ async def test_receive_problem_report_x(self): with async_mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py index 77e3ea1ca7..b3b7a2e848 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py @@ -1,6 +1,7 @@ import importlib -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from marshmallow import ValidationError @@ -14,13 +15,13 @@ from .. import routes as test_module -class TestProofRoutes(AsyncTestCase): +class TestProofRoutes(IsolatedAsyncioTestCase): def setUp(self): self.context = AdminRequestContext.test_context() self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -70,7 +71,7 @@ async def test_presentation_exchange_list(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.CoroutineMock() + mock_presentation_exchange.query = async_mock.AsyncMock() mock_presentation_exchange.query.return_value = [mock_presentation_exchange] mock_presentation_exchange.serialize = async_mock.MagicMock() mock_presentation_exchange.serialize.return_value = { @@ -103,7 +104,7 @@ async def test_presentation_exchange_list_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.CoroutineMock( + mock_presentation_exchange.query = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -123,7 +124,7 @@ async def test_presentation_exchange_credentials_list_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock() + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_presentation_exchange.retrieve_by_id.side_effect = StorageNotFoundError @@ -142,11 +143,11 @@ async def test_presentation_exchange_credentials_x(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(side_effect=test_module.IndyHolderError()) + async_mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.CoroutineMock()) + mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) with async_mock.patch( ( @@ -174,7 +175,7 @@ async def test_presentation_exchange_credentials_list_single_referent(self): self.profile.context.injector.bind_instance( IndyHolder, async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.CoroutineMock( + get_credentials_for_presentation_request_by_referent=async_mock.AsyncMock( return_value=returned_credentials ) ), @@ -212,7 +213,7 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + async_mock.AsyncMock(return_value=returned_credentials) ) ), ) @@ -250,7 +251,7 @@ async def test_presentation_exchange_retrieve(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock() mock_pres_ex.retrieve_by_id.return_value = mock_pres_ex mock_pres_ex.serialize = async_mock.MagicMock() mock_pres_ex.serialize.return_value = {"thread_id": "sample-thread-id"} @@ -276,7 +277,7 @@ async def test_presentation_exchange_retrieve_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex.retrieve_by_id.side_effect = StorageNotFoundError @@ -290,7 +291,7 @@ async def test_presentation_exchange_retrieve_x(self): mock_pres_ex_rec = async_mock.MagicMock( connection_id="abc123", thread_id="thid123", - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch( ( @@ -302,7 +303,7 @@ async def test_presentation_exchange_retrieve_x(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( return_value=mock_pres_ex_rec ) mock_pres_ex_rec.serialize = async_mock.MagicMock( @@ -313,7 +314,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -330,7 +331,7 @@ async def test_presentation_exchange_send_proposal(self): mock_presentation_exchange_record = async_mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock(return_value=mock_presentation_exchange_record) + async_mock.AsyncMock(return_value=mock_presentation_exchange_record) ) mock_preview.return_value.deserialize.return_value = async_mock.MagicMock() @@ -344,7 +345,7 @@ async def test_presentation_exchange_send_proposal(self): ) async def test_presentation_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -354,7 +355,7 @@ async def test_presentation_exchange_send_proposal_no_conn_record(self): importlib.reload(test_module) # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -362,7 +363,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -380,14 +381,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 = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = async_mock.AsyncMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", @@ -404,12 +405,12 @@ async def test_presentation_exchange_send_proposal_x(self): mock_presentation_exchange_record = async_mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) @@ -418,7 +419,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"comment": "dummy", "proof_request": {}} ) @@ -446,7 +447,7 @@ async def test_presentation_exchange_create_request(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.CoroutineMock() + mock_generate_nonce = async_mock.AsyncMock() mock_attach_decorator.data_base64 = async_mock.MagicMock( return_value=mock_attach_decorator @@ -456,7 +457,7 @@ async def test_presentation_exchange_create_request(self): "thread_id": "sample-thread-id" } mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=mock_presentation_exchange ) ) @@ -471,7 +472,7 @@ async def test_presentation_exchange_create_request(self): ) async def test_presentation_exchange_create_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"comment": "dummy", "proof_request": {}} ) @@ -501,12 +502,12 @@ async def test_presentation_exchange_create_request_x(self): mock_presentation_exchange_record = async_mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) @@ -515,7 +516,7 @@ async def test_presentation_exchange_create_request_x(self): await test_module.presentation_exchange_create_request(self.request) async def test_presentation_exchange_send_free_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -550,7 +551,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 = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_attach_decorator.data_base64 = async_mock.MagicMock( @@ -562,7 +563,7 @@ async def test_presentation_exchange_send_free_request(self): } mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=mock_presentation_exchange ) ) @@ -577,7 +578,7 @@ async def test_presentation_exchange_send_free_request(self): ) async def test_presentation_exchange_send_free_request_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": "dummy"} ) @@ -588,14 +589,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 = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = async_mock.AsyncMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": "dummy", "proof_request": {}} ) @@ -607,7 +608,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): importlib.reload(test_module) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) @@ -615,7 +616,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -649,21 +650,21 @@ async def test_presentation_exchange_send_free_request_x(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.CoroutineMock() + mock_generate_nonce = async_mock.AsyncMock() mock_presentation_exchange_record = async_mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_attach_decorator.data_base64 = async_mock.MagicMock( @@ -674,20 +675,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -719,7 +720,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=mock_presentation_exchange ) mock_presentation_exchange.serialize = async_mock.MagicMock() @@ -727,12 +728,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 = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + create_bound_request=async_mock.AsyncMock( return_value=(mock_presentation_exchange, mock_presentation_request) ) ) @@ -747,7 +748,7 @@ async def test_presentation_exchange_send_bound_request(self): ) async def test_presentation_exchange_send_bound_request_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -780,18 +781,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=mock_presentation_exchange ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock() + mock_connection_record.retrieve_by_id = async_mock.AsyncMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_not_ready(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -824,12 +825,12 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=mock_presentation_exchange ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) @@ -837,13 +838,13 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -851,7 +852,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -865,7 +866,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -874,7 +875,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -908,7 +909,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=mock_presentation_exchange ) mock_presentation_exchange.serialize = async_mock.MagicMock() @@ -916,12 +917,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 = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + create_bound_request=async_mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -936,7 +937,7 @@ async def test_presentation_exchange_send_bound_request_x(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_presentation(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -948,14 +949,14 @@ async def test_presentation_exchange_send_presentation(self): self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -981,7 +982,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", @@ -991,11 +992,11 @@ async def test_presentation_exchange_send_presentation(self): ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.CoroutineMock( + create_presentation=async_mock.AsyncMock( return_value=(mock_presentation_exchange, async_mock.MagicMock()) ) ) @@ -1010,13 +1011,13 @@ async def test_presentation_exchange_send_presentation(self): ) async def test_presentation_exchange_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1024,7 +1025,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -1053,14 +1054,14 @@ async def test_presentation_exchange_send_presentation_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1068,7 +1069,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -1097,7 +1098,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", @@ -1105,7 +1106,7 @@ async def test_presentation_exchange_send_presentation_not_ready(self): ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) @@ -1113,7 +1114,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -1126,7 +1127,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -1135,7 +1136,7 @@ async def test_presentation_exchange_send_presentation_bad_state(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -1171,22 +1172,22 @@ async def test_presentation_exchange_send_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ), ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.CoroutineMock( + create_presentation=async_mock.AsyncMock( side_effect=test_module.LedgerError() ) ) @@ -1225,7 +1226,7 @@ async def test_presentation_exchange_verify_presentation(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", @@ -1236,11 +1237,11 @@ async def test_presentation_exchange_verify_presentation(self): ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock( + verify_presentation=async_mock.AsyncMock( return_value=mock_presentation_exchange.retrieve_by_id.return_value ) ) @@ -1255,13 +1256,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1271,7 +1272,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -1284,7 +1285,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) @@ -1299,14 +1300,14 @@ async def test_presentation_exchange_verify_presentation_x(self): self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1326,7 +1327,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 = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", @@ -1334,16 +1335,16 @@ async def test_presentation_exchange_verify_presentation_x(self): serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.CoroutineMock( + mock_connection_record.retrieve_by_id = async_mock.AsyncMock( return_value=mock_connection_record ) mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock( + verify_presentation=async_mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1362,7 +1363,7 @@ async def test_presentation_exchange_verify_presentation_x(self): ) async def test_presentation_exchange_problem_report(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} magic_report = async_mock.MagicMock() @@ -1383,9 +1384,9 @@ async def test_presentation_exchange_problem_report(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_problem_report.return_value = magic_report @@ -1396,7 +1397,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -1414,7 +1415,7 @@ async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1422,7 +1423,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} magic_report = async_mock.MagicMock() @@ -1442,7 +1443,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 = async_mock.CoroutineMock( + mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -1462,11 +1463,11 @@ async def test_presentation_exchange_remove(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.CoroutineMock(), + delete_record=async_mock.AsyncMock(), ) ) @@ -1477,7 +1478,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch( @@ -1491,7 +1492,7 @@ async def test_presentation_exchange_remove_not_found(self): importlib.reload(test_module) # Emulate storage not found (bad pres ex id) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1511,11 +1512,11 @@ async def test_presentation_exchange_remove_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.CoroutineMock( + mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.CoroutineMock( + delete_record=async_mock.AsyncMock( 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 8986ff42ac..3377dc39ca 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py @@ -1,6 +1,6 @@ from copy import deepcopy -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from marshmallow import ValidationError from pyld import jsonld @@ -363,8 +363,8 @@ } -class TestDIFFormatHandler(AsyncTestCase): - async def setUp(self): +class TestDIFFormatHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.holder = async_mock.MagicMock() self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) @@ -604,7 +604,7 @@ async def test_create_pres(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -647,7 +647,7 @@ async def test_create_pres_pd_schema_uri(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -689,7 +689,7 @@ async def test_create_pres_prover_proof_spec(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -757,7 +757,7 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + fetch=async_mock.AsyncMock(return_value=cred_list) ) ) ), @@ -766,7 +766,7 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -851,7 +851,7 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + fetch=async_mock.AsyncMock(return_value=cred_list) ) ) ), @@ -860,7 +860,7 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -934,7 +934,7 @@ async def test_create_pres_one_of_filter(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + fetch=async_mock.AsyncMock(return_value=cred_list) ) ) ), @@ -943,7 +943,7 @@ async def test_create_pres_one_of_filter(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -984,7 +984,7 @@ async def test_create_pres_no_challenge(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -1025,7 +1025,7 @@ async def test_create_pres_storage_not_found(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1072,7 +1072,7 @@ async def test_create_pres_pd_claim_format_ed255(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1115,7 +1115,7 @@ async def test_create_pres_pd_claim_format_bls12381g2(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1166,7 +1166,7 @@ async def test_verify_pres_sequence(self): with async_mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=PresentationVerificationResult(verified=True) ), ): @@ -1176,7 +1176,7 @@ async def test_verify_pres_sequence(self): with async_mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=PresentationVerificationResult(verified=False) ), ): @@ -1223,7 +1223,7 @@ async def test_verify_pres(self): with async_mock.patch.object( test_module, "verify_presentation", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=PresentationVerificationResult(verified=True) ), ) as mock_vr: @@ -1416,7 +1416,7 @@ async def test_create_pres_cred_no_tag_query(self): with async_mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -2335,7 +2335,7 @@ async def test_create_pres_catch_diferror(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock(return_value=cred_list) + fetch=async_mock.AsyncMock(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 928a2df6be..438a833bb3 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,14 +11,14 @@ from .. import pres_ack_handler as test_module -class TestV20PresAckHandler(AsyncTestCase): +class TestV20PresAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() session = request_context.session() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -26,7 +27,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_ack = async_mock.AsyncMock() request_context.message = V20PresAck() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -48,7 +49,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_ack = async_mock.AsyncMock() request_context.message = V20PresAck() request_context.connection_ready = False handler = test_module.V20PresAckHandler() @@ -64,7 +65,7 @@ async def test_called_no_connection_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py index b28027c263..76b31a36d1 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......messaging.request_context import RequestContext @@ -10,7 +11,7 @@ from .. import pres_handler as test_module -class TestV20PresHandler(AsyncTestCase): +class TestV20PresHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,7 +19,7 @@ async def test_called(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -27,7 +28,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres = async_mock.AsyncMock() request_context.message = V20Pres() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -48,7 +49,7 @@ async def test_called_auto_verify(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -57,8 +58,8 @@ async def test_called_auto_verify(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.CoroutineMock() - mock_pres_mgr.return_value.verify_pres = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres = async_mock.AsyncMock() + mock_pres_mgr.return_value.verify_pres = async_mock.AsyncMock() request_context.message = V20Pres() request_context.connection_ready = True request_context.connection_record = async_mock.MagicMock() @@ -79,7 +80,7 @@ async def test_called_auto_verify_x(self): oob_record = async_mock.MagicMock() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=oob_record ) ) @@ -89,14 +90,12 @@ async def test_called_auto_verify_x(self): test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value = async_mock.MagicMock( - receive_pres=async_mock.CoroutineMock( + receive_pres=async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ), - verify_pres=async_mock.CoroutineMock( - side_effect=test_module.LedgerError() - ), + verify_pres=async_mock.AsyncMock(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 170a826e14..8b3e3175d6 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import pres_problem_report_handler as test_module -class TestV20PresProblemReportHandler(AsyncTestCase): +class TestV20PresProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() @@ -18,9 +19,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock() request_context.message = V20PresProblemReport( description={ "en": "Change of plans", @@ -45,10 +44,8 @@ async def test_called_x(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = ( - async_mock.CoroutineMock( - side_effect=test_module.StorageError("Disk full") - ) + mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + side_effect=test_module.StorageError("Disk full") ) request_context.message = V20PresProblemReport( description={ diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py index 033742133e..6f1295d08e 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -9,7 +10,7 @@ from .. import pres_proposal_handler as test_module -class TestV20PresProposalHandler(AsyncTestCase): +class TestV20PresProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.connection_record = async_mock.MagicMock() @@ -19,7 +20,7 @@ async def test_called(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) request_context.message = V20PresProposal() @@ -46,10 +47,10 @@ async def test_called_auto_request(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_pres_proposal.return_value, "presentation_request_message", @@ -85,12 +86,12 @@ async def test_called_auto_request_x(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -113,9 +114,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = ( - async_mock.CoroutineMock() - ) + mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock() request_context.message = V20PresProposal() request_context.connection_ready = False handler = test_module.V20PresProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py index 786d78bee5..efc8a3dbde 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor from ......indy.holder import IndyHolder @@ -179,7 +180,7 @@ } -class TestPresRequestHandler(AsyncTestCase): +class TestPresRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.connection_record = async_mock.MagicMock() @@ -191,7 +192,7 @@ async def test_called(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -218,11 +219,11 @@ async def test_called(self): ) as mock_pres_mgr, async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=async_mock.MagicMock(auto_present=False) ) @@ -250,7 +251,7 @@ async def test_called_not_found(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -277,12 +278,12 @@ async def test_called_not_found(self): ) as mock_pres_mgr, async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( side_effect=StorageNotFoundError ) mock_px_rec_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=async_mock.MagicMock(auto_present=False) ) @@ -323,17 +324,17 @@ async def test_called_auto_present_x(self): mock_px_rec = async_mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) @@ -347,14 +348,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -379,7 +380,7 @@ async def test_called_auto_present_indy(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -403,7 +404,7 @@ async def test_called_auto_present_indy(self): mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) @@ -416,14 +417,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(mock_px_rec, "pres message") ) @@ -464,7 +465,7 @@ async def test_called_auto_present_dif(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -490,14 +491,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -537,14 +538,14 @@ async def test_called_auto_present_no_preview(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -560,14 +561,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -611,11 +612,11 @@ async def test_called_auto_present_pred_no_match(self): mock_px_rec = async_mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -623,7 +624,7 @@ async def test_called_auto_present_pred_no_match(self): mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=[]) + async_mock.AsyncMock(return_value=[]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) @@ -634,14 +635,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( side_effect=test_indy_handler.V20PresFormatHandlerError ) request_context.connection_ready = True @@ -677,7 +678,7 @@ async def test_called_auto_present_pred_single_match(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -685,7 +686,7 @@ async def test_called_auto_present_pred_single_match(self): mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy-0"}}] ) ) @@ -698,14 +699,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -745,7 +746,7 @@ async def test_called_auto_present_pred_multi_match(self): px_rec_instance = test_module.V20PresExRecord(auto_present=True) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -753,7 +754,7 @@ async def test_called_auto_present_pred_multi_match(self): mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -769,14 +770,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -826,7 +827,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( return_value=async_mock.MagicMock() ) ) @@ -834,7 +835,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): mock_holder = async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ { "cred_info": { @@ -885,14 +886,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 = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock( + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.CoroutineMock( + mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -921,7 +922,7 @@ async def test_called_not_ready(self): with async_mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_request = async_mock.CoroutineMock() + mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock() request_context.message = V20PresRequest() request_context.connection_ready = False handler = test_module.V20PresRequestHandler() @@ -940,7 +941,7 @@ async def test_no_conn_no_oob(self): request_context.message_receipt = MessageReceipt() mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.CoroutineMock( + find_oob_record_for_inbound_message=async_mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py index ba27e20f45..4bfbbbd249 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile from ......messaging.decorators.attach_decorator import AttachDecorator @@ -67,7 +68,7 @@ class Meta: model_class = BasexRecordImpl -class TestRecord(AsyncTestCase): +class TestRecord(IsolatedAsyncioTestCase): async def test_record(self): pres_proposal = V20PresProposal( comment="Hello World", @@ -127,7 +128,7 @@ async def test_save_error_state(self): await record.save(session) with async_mock.patch.object( - record, "save", async_mock.CoroutineMock() + record, "save", async_mock.AsyncMock() ) as mock_save, async_mock.patch.object( test_module.LOGGER, "exception", async_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 51da3c6450..9e2e5ade6a 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py @@ -3,7 +3,8 @@ from copy import deepcopy from time import time -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile from .....indy.holder import IndyHolder @@ -381,20 +382,20 @@ } -class TestV20PresManager(AsyncTestCase): - async def setUp(self): +class TestV20PresManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -410,7 +411,7 @@ async def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -419,7 +420,7 @@ async def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -432,7 +433,7 @@ async def setUp(self): injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -440,7 +441,7 @@ async def setUp(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": { @@ -455,7 +456,7 @@ async def setUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -465,8 +466,8 @@ async def setUp(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -479,7 +480,7 @@ async def setUp(self): Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.CoroutineMock( + self.verifier.verify_presentation = async_mock.AsyncMock( return_value=("true", []) ) injector.bind_instance(IndyVerifier, self.verifier) @@ -581,7 +582,7 @@ async def test_create_bound_request_a(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.CoroutineMock() + px_rec.save = async_mock.AsyncMock() request_data = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -615,7 +616,7 @@ async def test_create_bound_request_b(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.CoroutineMock() + px_rec.save = async_mock.AsyncMock() (ret_px_rec, pres_req_msg) = await self.manager.create_bound_request( pres_ex_record=px_rec, comment=comment, @@ -788,7 +789,7 @@ async def test_create_pres_indy(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -842,7 +843,7 @@ async def test_create_pres_indy_and_dif(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -899,7 +900,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 = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -910,7 +911,7 @@ async def test_create_pres_proof_req_non_revoc_interval_none(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex, async_mock.patch.object( @@ -955,7 +956,7 @@ async def test_create_pres_self_asserted(self): px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -990,10 +991,10 @@ async def test_create_pres_self_asserted(self): async def test_create_pres_no_revocation(self): Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -1015,7 +1016,7 @@ async def test_create_pres_no_revocation(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1028,7 +1029,7 @@ async def test_create_pres_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1038,7 +1039,7 @@ async def test_create_pres_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) with async_mock.patch.object( @@ -1100,7 +1101,7 @@ async def test_create_pres_bad_revoc_state(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1114,7 +1115,7 @@ async def test_create_pres_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1124,8 +1125,8 @@ async def test_create_pres_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( side_effect=test_indy_util_module.IndyHolderError( "Problem", {"message": "Nope"} ) @@ -1133,7 +1134,7 @@ async def test_create_pres_bad_revoc_state(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -1173,7 +1174,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): Holder = async_mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": { @@ -1200,7 +1201,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.CoroutineMock( + self.holder.get_credential = async_mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1210,8 +1211,8 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.CoroutineMock(return_value="{}") - self.holder.create_revocation_state = async_mock.CoroutineMock( + self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = async_mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -1223,7 +1224,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): self.profile.context.injector.bind_instance(IndyHolder, self.holder) more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock( + get_or_fetch_local_tails_path=async_mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) @@ -1268,7 +1269,7 @@ async def test_no_matching_creds_for_proof_req(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = async_mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -1276,7 +1277,7 @@ async def test_no_matching_creds_for_proof_req(self): INDY_PROOF_REQ_NAMES, preview=None, holder=self.holder ) - get_creds = async_mock.CoroutineMock( + get_creds = async_mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1308,7 +1309,7 @@ async def test_no_matching_creds_indy_handler(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.CoroutineMock(return_value=()) + get_creds = async_mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with async_mock.patch.object( @@ -2133,7 +2134,7 @@ async def test_verify_pres(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_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() @@ -2193,7 +2194,7 @@ async def test_verify_pres_indy_and_dif(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_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() @@ -2203,16 +2204,16 @@ async def test_verify_pres_indy_and_dif(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", self.ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ), async_mock.patch( "aries_cloudagent.vc.vc_ld.verify.verify_presentation", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=PresentationVerificationResult(verified=False) ), ), async_mock.patch.object( IndyVerifier, "verify_presentation", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=PresentationVerificationResult(verified=True) ), ), async_mock.patch.object( @@ -2314,7 +2315,7 @@ async def test_receive_problem_report(self): ) as save_ex, async_mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex, async_mock.patch.object( self.profile, "session", @@ -2354,7 +2355,7 @@ async def test_receive_problem_report_x(self): with async_mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py index 0d13acc826..fa794969ac 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py @@ -1,6 +1,6 @@ from copy import deepcopy -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from marshmallow import ValidationError from time import time from unittest.mock import ANY @@ -124,7 +124,7 @@ } -class TestPresentProofRoutes(AsyncTestCase): +class TestPresentProofRoutes(IsolatedAsyncioTestCase): def setUp(self): self.context = AdminRequestContext.test_context() self.profile = self.context.profile @@ -132,13 +132,13 @@ def setUp(self): Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.CoroutineMock( + self.ledger.get_schema = async_mock.AsyncMock( return_value=async_mock.MagicMock() ) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_def = async_mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -154,7 +154,7 @@ def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -163,7 +163,7 @@ def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( return_value=( { "ver": "1.0", @@ -176,7 +176,7 @@ def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -259,7 +259,7 @@ async def test_present_proof_list(self): ) as mock_pres_ex_rec_cls, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.query = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.query = async_mock.AsyncMock( return_value=[mock_pres_ex_rec_inst] ) @@ -279,7 +279,7 @@ async def test_present_proof_list_x(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.query = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.query = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -292,7 +292,7 @@ async def test_present_proof_credentials_list_not_found(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex_rec_cls.retrieve_by_id.side_effect = StorageNotFoundError() @@ -311,16 +311,16 @@ async def test_present_proof_credentials_x(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(side_effect=test_module.IndyHolderError()) + async_mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.CoroutineMock()) + mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec ) @@ -339,7 +339,7 @@ async def test_present_proof_credentials_list_single_referent(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + async_mock.AsyncMock(return_value=returned_credentials) ) ), ) @@ -350,7 +350,7 @@ async def test_present_proof_credentials_list_single_referent(self): test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.CoroutineMock() + retrieve_by_id=async_mock.AsyncMock() ) await test_module.present_proof_credentials_list(self.request) @@ -368,7 +368,7 @@ async def test_present_proof_credentials_list_multiple_referents(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock(return_value=returned_credentials) + async_mock.AsyncMock(return_value=returned_credentials) ) ), ) @@ -379,7 +379,7 @@ async def test_present_proof_credentials_list_multiple_referents(self): test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.CoroutineMock() + retrieve_by_id=async_mock.AsyncMock() ) await test_module.present_proof_credentials_list(self.request) @@ -399,7 +399,7 @@ async def test_present_proof_credentials_list_dif(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -408,9 +408,7 @@ async def test_present_proof_credentials_list_dif(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -477,7 +475,7 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -486,9 +484,7 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -567,7 +563,7 @@ async def test_present_proof_credentials_dif_no_tag_query(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -576,9 +572,7 @@ async def test_present_proof_credentials_dif_no_tag_query(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -647,7 +641,7 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -656,9 +650,7 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -727,7 +719,7 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -736,9 +728,7 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -832,13 +822,13 @@ async def test_present_proof_credentials_single_ldp_vp_error(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), ) with async_mock.patch.object( @@ -895,13 +885,13 @@ async def test_present_proof_credentials_double_ldp_vp_error(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), ) with async_mock.patch.object( @@ -955,13 +945,13 @@ async def test_present_proof_credentials_list_limit_disclosure_no_bbs(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), ) with async_mock.patch.object( @@ -1018,13 +1008,13 @@ async def test_present_proof_credentials_no_ldp_vp(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.CoroutineMock()), + async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), ) with async_mock.patch.object( @@ -1083,7 +1073,7 @@ async def test_present_proof_credentials_list_schema_uri(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -1092,9 +1082,7 @@ async def test_present_proof_credentials_list_schema_uri(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( - return_value=returned_credentials - ) + fetch=async_mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -1124,7 +1112,7 @@ async def test_present_proof_credentials_list_dif_error(self): IndyHolder, async_mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.CoroutineMock() + async_mock.AsyncMock() ) ), ) @@ -1133,7 +1121,7 @@ async def test_present_proof_credentials_list_dif_error(self): async_mock.MagicMock( search_credentials=async_mock.MagicMock( return_value=async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1186,7 +1174,7 @@ async def test_present_proof_retrieve(self): ) as mock_pres_ex_rec_cls, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} @@ -1203,7 +1191,7 @@ async def test_present_proof_retrieve_not_found(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1217,12 +1205,12 @@ async def test_present_proof_retrieve_x(self): connection_id="abc123", thread_id="thid123", serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_pres_ex_rec_inst ) @@ -1230,7 +1218,7 @@ async def test_present_proof_retrieve_x(self): await test_module.present_proof_retrieve(self.request) async def test_present_proof_send_proposal(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": "dummy-conn-id", "presentation_proposal": { @@ -1248,12 +1236,12 @@ async def test_present_proof_send_proposal(self): ) as mock_pres_ex_rec_cls, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock(is_ready=True) ) mock_px_rec_inst = async_mock.MagicMock() mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock(return_value=mock_px_rec_inst) + async_mock.AsyncMock(return_value=mock_px_rec_inst) ) await test_module.present_proof_send_proposal(self.request) @@ -1262,12 +1250,12 @@ async def test_present_proof_send_proposal(self): ) async def test_present_proof_send_proposal_no_conn_record(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1275,14 +1263,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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec_cls, async_mock.patch.object( test_module, "V20PresProposal", autospec=True ) as mock_proposal: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock(is_ready=False) ) @@ -1290,7 +1278,7 @@ 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 = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "ConnRecord", autospec=True @@ -1298,12 +1286,12 @@ async def test_present_proof_send_proposal_x(self): test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) @@ -1315,7 +1303,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: indy_proof_req}, @@ -1335,7 +1323,7 @@ async def test_present_proof_create_request(self): ) ) mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1347,7 +1335,7 @@ async def test_present_proof_create_request(self): ) async def test_present_proof_create_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: INDY_PROOF_REQ}, @@ -1363,12 +1351,12 @@ async def test_present_proof_create_request_x(self): ) as mock_response: mock_px_rec_inst = async_mock.MagicMock() mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) @@ -1378,7 +1366,7 @@ async def test_present_proof_create_request_x(self): await test_module.present_proof_create_request(self.request) async def test_present_proof_send_free_request(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1397,13 +1385,13 @@ async def test_present_proof_send_free_request(self): ) as mock_pres_ex_rec_cls, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock() + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock() mock_px_rec_inst = async_mock.MagicMock( serialize=async_mock.MagicMock({"thread_id": "sample-thread-id"}) ) mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1415,14 +1403,14 @@ async def test_present_proof_send_free_request(self): ) async def test_present_proof_send_free_request_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": "dummy"} ) with async_mock.patch.object( test_module, "ConnRecord", async_mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1430,7 +1418,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"connection_id": "dummy", "proof_request": {}} ) @@ -1438,7 +1426,7 @@ async def test_present_proof_send_free_request_not_ready(self): test_module, "ConnRecord", async_mock.MagicMock() ) as mock_conn_rec_cls: mock_conn_rec_inst = async_mock.MagicMock(is_ready=False) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1446,7 +1434,7 @@ async def test_present_proof_send_free_request_not_ready(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1464,7 +1452,7 @@ async def test_present_proof_send_free_request_x(self): test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: mock_conn_rec_inst = async_mock.MagicMock() - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_px_rec_inst = async_mock.MagicMock( @@ -1473,12 +1461,12 @@ async def test_present_proof_send_free_request_x(self): ) ) mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.CoroutineMock( + create_exchange_for_request=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) ) ) @@ -1488,20 +1476,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1521,19 +1509,19 @@ async def test_present_proof_send_bound_request(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_request = async_mock.MagicMock() mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + create_bound_request=async_mock.AsyncMock( return_value=(mock_px_rec_inst, mock_pres_request) ) ) @@ -1545,20 +1533,20 @@ async def test_present_proof_send_bound_request(self): ) async def test_present_proof_send_bound_request_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1574,10 +1562,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1585,20 +1573,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1614,13 +1602,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock( is_ready=False, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1628,13 +1616,13 @@ async def test_present_proof_send_bound_request_not_ready(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1642,20 +1630,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1669,7 +1657,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -1677,20 +1665,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 = async_mock.CoroutineMock(return_value={"trace": False}) + self.request.json = async_mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(), - __aexit__=async_mock.CoroutineMock(), + __aenter__=async_mock.AsyncMock(), + __aexit__=async_mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1707,20 +1695,20 @@ async def test_present_proof_send_bound_request_x(self): serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.CoroutineMock( + create_bound_request=async_mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1730,7 +1718,7 @@ async def test_present_proof_send_bound_request_x(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_presentation(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1746,7 +1734,7 @@ async def test_present_proof_send_presentation(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1766,17 +1754,17 @@ async def test_present_proof_send_presentation(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( + create_pres=async_mock.AsyncMock( return_value=(mock_px_rec_inst, async_mock.MagicMock()) ) ) @@ -1790,7 +1778,7 @@ async def test_present_proof_send_presentation(self): async def test_present_proof_send_presentation_dif(self): proof_req = deepcopy(DIF_PROOF_REQ) proof_req["issuer_id"] = "test123" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "dif": proof_req, } @@ -1801,7 +1789,7 @@ async def test_present_proof_send_presentation_dif(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1821,17 +1809,17 @@ async def test_present_proof_send_presentation_dif(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( + create_pres=async_mock.AsyncMock( return_value=(mock_px_rec_inst, async_mock.MagicMock()) ) ) @@ -1843,9 +1831,7 @@ async def test_present_proof_send_presentation_dif(self): ) async def test_present_proof_send_presentation_dif_error(self): - self.request.json = async_mock.CoroutineMock( - return_value={"dif": DIF_PROOF_REQ} - ) + self.request.json = async_mock.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) self.request.match_info = { "pres_ex_id": "dummy", } @@ -1880,7 +1866,7 @@ async def test_present_proof_send_presentation_dif_error(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1893,19 +1879,17 @@ async def test_present_proof_send_presentation_dif_error(self): ) as mock_px_rec_cls, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=px_rec_instance ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( - side_effect=test_module.LedgerError() - ) + create_pres=async_mock.AsyncMock(side_effect=test_module.LedgerError()) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1913,7 +1897,7 @@ async def test_present_proof_send_presentation_dif_error(self): mock_response.assert_called_once_with(px_rec_instance.serialize()) async def test_present_proof_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1930,7 +1914,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -1939,7 +1923,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_presentation_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1955,7 +1939,7 @@ async def test_present_proof_send_presentation_not_found(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -1971,12 +1955,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1984,7 +1968,7 @@ async def test_present_proof_send_presentation_not_found(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_not_ready(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2000,7 +1984,7 @@ async def test_present_proof_send_presentation_not_ready(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -2016,12 +2000,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock(is_ready=False) ) @@ -2029,7 +2013,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2053,7 +2037,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2061,7 +2045,7 @@ async def test_present_proof_send_presentation_bad_state(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_x(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2077,7 +2061,7 @@ async def test_present_proof_send_presentation_x(self): self.profile.context.injector.bind_instance( IndyVerifier, async_mock.MagicMock( - verify_presentation=async_mock.CoroutineMock(), + verify_presentation=async_mock.AsyncMock(), ), ) @@ -2096,19 +2080,19 @@ async def test_present_proof_send_presentation_x(self): serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.CoroutineMock( + create_pres=async_mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2141,16 +2125,16 @@ async def test_present_proof_verify_presentation(self): return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.CoroutineMock(return_value=mock_px_rec_inst) + verify_pres=async_mock.AsyncMock(return_value=mock_px_rec_inst) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -2163,7 +2147,7 @@ async def test_present_proof_verify_presentation_px_rec_not_found(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -2184,7 +2168,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 = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2209,18 +2193,18 @@ async def test_present_proof_verify_presentation_x(self): serialize=async_mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.CoroutineMock(), + save_error_state=async_mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_px_rec_inst ) mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.CoroutineMock( + mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( return_value=mock_conn_rec_inst ) mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.CoroutineMock( + verify_pres=async_mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2235,7 +2219,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2250,9 +2234,9 @@ async def test_present_proof_problem_report(self): ) as mock_px_rec, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( - save_error_state=async_mock.CoroutineMock() + save_error_state=async_mock.AsyncMock() ) ) mock_problem_report.return_value = magic_report @@ -2263,7 +2247,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2271,7 +2255,7 @@ async def test_present_proof_problem_report_bad_pres_ex_id(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -2279,7 +2263,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} @@ -2291,7 +2275,7 @@ async def test_present_proof_problem_report_x(self): ) as mock_problem_report, async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -2306,11 +2290,11 @@ async def test_present_proof_remove(self): ) as mock_px_rec, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.CoroutineMock(), + delete_record=async_mock.AsyncMock(), ) ) @@ -2323,7 +2307,7 @@ async def test_present_proof_remove_px_rec_not_found(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -2336,11 +2320,11 @@ async def test_present_proof_remove_x(self): with async_mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.CoroutineMock( + mock_px_rec.retrieve_by_id = async_mock.AsyncMock( return_value=async_mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.CoroutineMock( + delete_record=async_mock.AsyncMock( side_effect=test_module.StorageError() ), ) @@ -2441,7 +2425,7 @@ async def test_retrieve_uri_list_from_schema_filter(self): assert test_one_of_uri_groups == [["test123", "test321"]] async def test_send_presentation_no_specification(self): - self.request.json = async_mock.CoroutineMock(return_value={"comment": "test"}) + self.request.json = async_mock.AsyncMock(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 b4805d8059..a544377ce7 100644 --- a/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from asynctest import mock +from unittest 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.CoroutineMock() + mock_rec.delete_record = mock.AsyncMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock(side_effect=StorageNotFoundError) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock(side_effect=StorageError) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock() + mock_rec.delete_record = mock.AsyncMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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 6fe38c848b..6d9fff0b16 100644 --- a/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/revocation_notification/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ """Test routes.py""" -from asynctest import mock +from unittest 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.CoroutineMock() + mock_rec.delete_record = mock.AsyncMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock() + mock_rec.delete_record = mock.AsyncMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock(side_effect=StorageNotFoundError) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock(side_effect=StorageError) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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.CoroutineMock() + mock_rec.delete_record = mock.AsyncMock() MockRec = mock.MagicMock() - MockRec.query_by_rev_reg_id = mock.CoroutineMock(return_value=[mock_rec]) + MockRec.query_by_rev_reg_id = mock.AsyncMock(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 03e3b2993e..6cac3fcb96 100644 --- a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py +++ b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock import json from ......connections.models.connection_target import ConnectionTarget @@ -18,8 +18,8 @@ TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" -class TestForwardHandler(AsyncTestCase): - async def setUp(self): +class TestForwardHandler(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.connection_ready = True self.context.message = Forward(to="sample-did", msg={"msg": "sample-message"}) @@ -36,11 +36,11 @@ async def test_handle(self): ) as mock_connection_mgr, async_mock.patch.object( self.context.profile, "notify", autospec=True ) as mock_notify: - mock_mgr.return_value.get_recipient = async_mock.CoroutineMock( + mock_mgr.return_value.get_recipient = async_mock.AsyncMock( return_value=RouteRecord(connection_id="dummy") ) mock_connection_mgr.return_value.get_connection_targets = ( - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ ConnectionTarget( recipient_keys=["recip_key"], @@ -80,7 +80,7 @@ async def test_handle_cannot_resolve_recipient(self): with async_mock.patch.object( test_module, "RoutingManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.get_recipient = async_mock.CoroutineMock( + mock_mgr.return_value.get_recipient = async_mock.AsyncMock( side_effect=test_module.RoutingManagerError() ) diff --git a/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py b/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py index 7b650a03d8..22846bcd3d 100644 --- a/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py +++ b/aries_cloudagent/protocols/routing/v1_0/models/tests/test_route_record.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from marshmallow.exceptions import ValidationError from ..route_record import RouteRecordSchema -class TestConnRecord(AsyncTestCase): +class TestConnRecord(IsolatedAsyncioTestCase): async def test_route_record_validation_fails_no_connection_wallet(self): schema = schema = RouteRecordSchema() diff --git a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py index 047ab6652c..2abf1a81e5 100644 --- a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py +++ b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py @@ -1,5 +1,5 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from marshmallow import ValidationError @@ -18,8 +18,8 @@ TEST_ROUTE_VERKEY = "9WCgWKUaAJj3VWxxtzvvMQN3AoFxoBtBDo9ntwJnVVCC" -class TestRoutingManager(AsyncTestCase): - async def setUp(self): +class TestRoutingManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.context = RequestContext.test_context() self.context.message_receipt = MessageReceipt(sender_verkey=TEST_VERKEY) self.transaction = await self.context.transaction() # for coverage @@ -71,7 +71,7 @@ async def test_get_recipient_no_verkey(self): async def test_get_recipient_duplicate_routes(self): with async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.CoroutineMock() + RouteRecord, "retrieve_by_recipient_key", async_mock.AsyncMock() ) 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 async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.CoroutineMock() + RouteRecord, "retrieve_by_recipient_key", async_mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(RouteNotFoundError) as context: diff --git a/aries_cloudagent/protocols/tests/test_didcomm_prefix.py b/aries_cloudagent/protocols/tests/test_didcomm_prefix.py index 4328d539d0..daa403a9c9 100644 --- a/aries_cloudagent/protocols/tests/test_didcomm_prefix.py +++ b/aries_cloudagent/protocols/tests/test_didcomm_prefix.py @@ -1,11 +1,11 @@ from os import environ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..didcomm_prefix import DIDCommPrefix -class TestDIDCommPrefix(AsyncTestCase): +class TestDIDCommPrefix(IsolatedAsyncioTestCase): def test_didcomm_prefix(self): DIDCommPrefix.set({}) assert environ.get("DIDCOMM_PREFIX") == DIDCommPrefix.OLD.value diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py index dcb21280a3..2bc01de8af 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -52,7 +52,7 @@ def test_serialize(self, mock_ping_schema_load): assert msg_dict is mock_ping_schema_load.return_value -class TestPingSchema(AsyncTestCase): +class TestPingSchema(IsolatedAsyncioTestCase): """Test ping schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py index b05a8aaf02..b0b6badbcf 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py @@ -1,6 +1,6 @@ from unittest import mock, TestCase -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -51,7 +51,7 @@ def test_serialize(self, mock_ping_schema_load): assert msg_dict is mock_ping_schema_load.return_value -class TestPingResponseSchema(AsyncTestCase): +class TestPingResponseSchema(IsolatedAsyncioTestCase): """Test ping response schema.""" async def test_make_model(self): diff --git a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py index 4cded73a3a..7534548007 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py @@ -1,18 +1,18 @@ -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from .....admin.request_context import AdminRequestContext from .. import routes as test_module -class TestTrustpingRoutes(AsyncTestCase): +class TestTrustpingRoutes(IsolatedAsyncioTestCase): def setUp(self): self.session_inject = {} self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -22,13 +22,13 @@ def setUp(self): ) async def test_connections_send_ping(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"comment": "some comment"} ) self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module, "Ping", async_mock.MagicMock() ) as mock_ping, async_mock.patch.object( @@ -41,13 +41,13 @@ 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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"comment": "some comment"} ) self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module.web, "json_response", async_mock.MagicMock() ) as json_response: @@ -56,13 +56,13 @@ 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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={"comment": "some comment"} ) self.request.match_info = {"conn_id": "dummy"} with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.CoroutineMock() + test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() ) as mock_retrieve, async_mock.patch.object( test_module.web, "json_response", async_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 424b85658d..e614ee832c 100644 --- a/aries_cloudagent/resolver/default/tests/test_indy.py +++ b/aries_cloudagent/resolver/default/tests/test_indy.py @@ -2,7 +2,7 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -32,13 +32,13 @@ def resolver(): def ledger(): """Ledger fixture.""" ledger = async_mock.MagicMock(spec=BaseLedger) - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( + ledger.get_all_endpoints_for_did = async_mock.AsyncMock( return_value={ "endpoint": "https://github.com/", "profile": "https://example.com/profile", } ) - ledger.get_key_for_did = async_mock.CoroutineMock(return_value="key") + ledger.get_key_for_did = async_mock.AsyncMock(return_value="key") yield ledger @@ -49,9 +49,7 @@ def profile(ledger): profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( - return_value=(None, ledger) - ) + get_ledger_for_identifier=async_mock.AsyncMock(return_value=(None, ledger)) ), ) yield profile @@ -90,7 +88,7 @@ async def test_resolve_multitenant( with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=("test_ledger_id", ledger)), + async_mock.AsyncMock(return_value=("test_ledger_id", ledger)), ): assert await resolver.resolve(profile, TEST_DID0) @@ -102,7 +100,7 @@ async def test_resolve_x_no_ledger( profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, None) ) ), @@ -132,9 +130,7 @@ async def test_supports_updated_did_sov_rules( "linked_domains": "https://example.com", } - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( - return_value=example - ) + ledger.get_all_endpoints_for_did = async_mock.AsyncMock(return_value=example) assert await resolver.resolve(profile, TEST_DID0) @pytest.mark.asyncio @@ -147,9 +143,7 @@ async def test_supports_updated_did_sov_rules_no_endpoint_url( "types": ["DIDComm", "did-communication", "endpoint"], } - ledger.get_all_endpoints_for_did = async_mock.CoroutineMock( - return_value=example - ) + ledger.get_all_endpoints_for_did = async_mock.AsyncMock(return_value=example) result = await resolver.resolve(profile, TEST_DID0) assert "service" not in result diff --git a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py index 3f21da0657..c447859c07 100644 --- a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py +++ b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py @@ -1,6 +1,6 @@ """Test LegacyPeerDIDResolver.""" -from asynctest import mock as async_mock +from unittest import mock as async_mock import pydid import pytest @@ -39,7 +39,7 @@ async def test_supports(self, resolver: LegacyPeerDIDResolver, profile: Profile) """Test supports.""" with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + fetch_did_document=async_mock.AsyncMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -53,7 +53,7 @@ async def test_supports_no_cache( profile.context.injector.clear_binding(BaseCache) with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + fetch_did_document=async_mock.AsyncMock( 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 async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + fetch_did_document=async_mock.AsyncMock( side_effect=StorageNotFoundError ) ) @@ -90,7 +90,7 @@ async def test_resolve(self, resolver: LegacyPeerDIDResolver, profile: Profile): doc = object() mock_corrections.apply = async_mock.MagicMock(return_value=doc) mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + fetch_did_document=async_mock.AsyncMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -115,11 +115,11 @@ async def test_resolve_x_not_found( doc = object mock_corrections.apply = async_mock.MagicMock(return_value=doc) mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.CoroutineMock( + fetch_did_document=async_mock.AsyncMock( side_effect=StorageNotFoundError ) ) - resolver.supports = async_mock.CoroutineMock(return_value=True) + resolver.supports = async_mock.AsyncMock(return_value=True) result = await resolver.resolve(profile, TEST_DID0) assert result == doc diff --git a/aries_cloudagent/resolver/default/tests/test_universal.py b/aries_cloudagent/resolver/default/tests/test_universal.py index 96e5d0827f..ac60dcede2 100644 --- a/aries_cloudagent/resolver/default/tests/test_universal.py +++ b/aries_cloudagent/resolver/default/tests/test_universal.py @@ -3,7 +3,7 @@ import re from typing import Dict, Union -from asynctest import mock as async_mock +from unittest import mock as async_mock import pytest from ....config.settings import Settings @@ -125,7 +125,7 @@ async def test_get_supported_did_regex(): with async_mock.patch.object( UniversalResolver, "_fetch_resolver_props", - async_mock.CoroutineMock(return_value=props), + async_mock.AsyncMock(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 async_mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + async_mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) @@ -192,7 +192,7 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): with async_mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + async_mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) @@ -208,7 +208,7 @@ async def test_setup_endpoint_unset(resolver: UniversalResolver): with async_mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.CoroutineMock(return_value="pattern"), + async_mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) diff --git a/aries_cloudagent/resolver/tests/test_base.py b/aries_cloudagent/resolver/tests/test_base.py index 2108468458..b3e3cfa13f 100644 --- a/aries_cloudagent/resolver/tests/test_base.py +++ b/aries_cloudagent/resolver/tests/test_base.py @@ -3,7 +3,7 @@ import pytest import re -from asynctest import mock as async_mock +from unittest import mock as async_mock from pydid import DIDDocument from ..base import BaseDIDResolver, DIDMethodNotSupported, ResolverType diff --git a/aries_cloudagent/resolver/tests/test_routes.py b/aries_cloudagent/resolver/tests/test_routes.py index 01c213572b..50e3813af1 100644 --- a/aries_cloudagent/resolver/tests/test_routes.py +++ b/aries_cloudagent/resolver/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from pydid import DIDDocument from ...core.in_memory import InMemoryProfile @@ -50,8 +50,8 @@ def mock_response(): @pytest.fixture def mock_resolver(resolution_result): did_resolver = async_mock.MagicMock() - did_resolver.resolve = async_mock.CoroutineMock(return_value=did_doc) - did_resolver.resolve_with_metadata = async_mock.CoroutineMock( + did_resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + did_resolver.resolve_with_metadata = async_mock.AsyncMock( return_value=resolution_result ) yield did_resolver @@ -65,7 +65,7 @@ async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_ session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = async_mock.CoroutineMock() + outbound_message_router = async_mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -75,7 +75,7 @@ async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_ "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=async_mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with async_mock.patch.object( @@ -98,7 +98,7 @@ async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_ ], ) async def test_resolver_not_found_error(mock_resolver, side_effect, error): - mock_resolver.resolve_with_metadata = async_mock.CoroutineMock( + mock_resolver.resolve_with_metadata = async_mock.AsyncMock( side_effect=side_effect() ) @@ -108,7 +108,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 = async_mock.CoroutineMock() + outbound_message_router = async_mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, @@ -118,7 +118,7 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.CoroutineMock(return_value={}), + json=async_mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with async_mock.patch.object( diff --git a/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py index ecc19d4b5f..25d756317e 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_cred_rev_record.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....storage.base import StorageNotFoundError @@ -10,7 +10,7 @@ REV_REG_ID = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:0" -class TestIssuerCredRevRecord(AsyncTestCase): +class TestIssuerCredRevRecord(IsolatedAsyncioTestCase): def setUp(self): self.session = InMemoryProfile.test_session() diff --git a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py index bc292daeb4..9329dc7c99 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py @@ -4,7 +4,8 @@ from os.path import join from typing import Any, Mapping, Type -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile, InMemoryProfileSession from ....core.profile import Profile, ProfileSession @@ -52,8 +53,8 @@ } -class TestIssuerRevRegRecord(AsyncTestCase): - async def setUp(self): +class TestIssuerRevRegRecord(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile( settings={"tails_server_base_url": "http://1.2.3.4:8088"}, ) @@ -61,13 +62,13 @@ async def setUp(self): Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.send_revoc_reg_def = async_mock.CoroutineMock() - self.ledger.send_revoc_reg_entry = async_mock.CoroutineMock() + self.ledger.send_revoc_reg_def = async_mock.AsyncMock() + self.ledger.send_revoc_reg_entry = async_mock.AsyncMock() self.profile.context.injector.bind_instance(BaseLedger, self.ledger) TailsServer = async_mock.MagicMock(BaseTailsServer, autospec=True) self.tails_server = TailsServer() - self.tails_server.upload_tails_file = async_mock.CoroutineMock( + self.tails_server.upload_tails_file = async_mock.AsyncMock( return_value=(True, "http://1.2.3.4:8088/rev-reg-id") ) self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server) @@ -172,7 +173,7 @@ def handle(self): if self.handle_counter == 0: self.handle_counter = self.handle_counter + 1 return async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( return_value=async_mock.MagicMock( value_json=json.dumps(mock_cred_def) ) @@ -180,7 +181,7 @@ def handle(self): ) else: return async_mock.MagicMock( - fetch=async_mock.CoroutineMock( + fetch=async_mock.AsyncMock( return_value=async_mock.MagicMock( value_json=json.dumps(mock_reg_rev_def_private), ), @@ -213,13 +214,13 @@ def handle(self): "ver": "1.0", "value": {"accum": "ACCUM", "issued": [1, 2], "revoked": [3, 4]}, } - self.ledger.get_revoc_reg_delta = async_mock.CoroutineMock( + self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( return_value=( _test_rev_reg_delta, 1234567890, ) ) - self.ledger.send_revoc_reg_entry = async_mock.CoroutineMock( + self.ledger.send_revoc_reg_entry = async_mock.AsyncMock( return_value={ "result": {"...": "..."}, }, @@ -232,7 +233,7 @@ def handle(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.CoroutineMock( + async_mock.AsyncMock( return_value=[ test_module.IssuerCredRevRecord( record_id=test_module.UUID4_EXAMPLE, @@ -246,11 +247,11 @@ def handle(self): ), async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(return_value=rec), + async_mock.AsyncMock(return_value=rec), ), async_mock.patch.object( test_module, "generate_ledger_rrrecovery_txn", - async_mock.CoroutineMock(return_value=rev_reg_delta), + async_mock.AsyncMock(return_value=rev_reg_delta), ): assert ( _test_rev_reg_delta, @@ -277,7 +278,7 @@ async def test_generate_registry_etc(self): self.profile.context.injector.bind_instance(IndyIssuer, issuer) with async_mock.patch.object( - issuer, "create_and_store_revocation_registry", async_mock.CoroutineMock() + issuer, "create_and_store_revocation_registry", async_mock.AsyncMock() ) as mock_create_store_rr: mock_create_store_rr.side_effect = IndyIssuerError("Not this time") diff --git a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py index ddba588969..4ee40798e5 100644 --- a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py +++ b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from copy import deepcopy from pathlib import Path from shutil import rmtree @@ -40,7 +41,7 @@ } -class TestRevocationRegistry(AsyncTestCase): +class TestRevocationRegistry(IsolatedAsyncioTestCase): def tearDown(self): rmtree(TAILS_DIR, ignore_errors=True) diff --git a/aries_cloudagent/revocation/tests/test_indy.py b/aries_cloudagent/revocation/tests/test_indy.py index 32c2215dc6..dd3d97f255 100644 --- a/aries_cloudagent/revocation/tests/test_indy.py +++ b/aries_cloudagent/revocation/tests/test_indy.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -18,22 +19,22 @@ from ..models.revocation_registry import RevocationRegistry -class TestIndyRevocation(AsyncTestCase): +class TestIndyRevocation(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context Ledger = async_mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": True}} ) - self.ledger.get_revoc_reg_def = async_mock.CoroutineMock() + self.ledger.get_revoc_reg_def = async_mock.AsyncMock() self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, async_mock.MagicMock( - get_ledger_for_identifier=async_mock.CoroutineMock( + get_ledger_for_identifier=async_mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -60,7 +61,7 @@ async def test_init_issuer_registry(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + async_mock.AsyncMock(return_value=(None, self.ledger)), ): result = await self.revoc.init_issuer_registry(CRED_DEF_ID) assert result.cred_def_id == CRED_DEF_ID @@ -73,9 +74,7 @@ async def test_init_issuer_registry_no_cred_def(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( - return_value=None - ) + self.ledger.get_credential_definition = async_mock.AsyncMock(return_value=None) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) with self.assertRaises(RevocationNotSupportedError) as x_revo: @@ -86,7 +85,7 @@ async def test_init_issuer_registry_bad_size(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {"revocation": "..."}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -119,7 +118,7 @@ async def test_init_issuer_registry_no_revocation(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.CoroutineMock( + self.ledger.get_credential_definition = async_mock.AsyncMock( return_value={"value": {}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -133,10 +132,10 @@ async def test_get_issuer_rev_reg_record(self): rec = await self.revoc.init_issuer_registry(CRED_DEF_ID) rec.revoc_reg_id = "dummy" - rec.generate_registry = async_mock.CoroutineMock() + rec.generate_registry = async_mock.AsyncMock() with async_mock.patch.object( - IssuerRevRegRecord, "retrieve_by_revoc_reg_id", async_mock.CoroutineMock() + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", async_mock.AsyncMock() ) as mock_retrieve_by_rr_id: mock_retrieve_by_rr_id.return_value = rec await rec.generate_registry(self.profile, None) @@ -243,7 +242,7 @@ async def test_get_ledger_registry(self): with async_mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.CoroutineMock(return_value=(None, self.ledger)), + async_mock.AsyncMock(return_value=(None, self.ledger)), ), async_mock.patch.object( RevocationRegistry, "from_definition", async_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 b987913c97..eb0356d8cd 100644 --- a/aries_cloudagent/revocation/tests/test_manager.py +++ b/aries_cloudagent/revocation/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from asynctest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from aries_cloudagent.revocation.models.issuer_cred_rev_record import ( IssuerCredRevRecord, @@ -30,8 +30,8 @@ TAILS_LOCAL = f"{TAILS_DIR}/{TAILS_HASH}" -class TestRevocationManager(AsyncTestCase): - async def setUp(self): +class TestRevocationManager(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.manager = RevocationManager(self.profile) @@ -41,12 +41,12 @@ async def test_revoke_credential_publish(self): mock_issuer_rev_reg_record = async_mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), pending_pub=["2"], ) issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = async_mock.AsyncMock( return_value=( json.dumps( { @@ -66,24 +66,24 @@ async def test_revoke_credential_publish(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve, async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc, async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): mock_retrieve.return_value = async_mock.MagicMock( rev_reg_id="dummy-rr-id", cred_rev_id=CRED_REV_ID ) mock_rev_reg = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.CoroutineMock() + get_or_fetch_local_tails_path=async_mock.AsyncMock() ) - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) - revoc.return_value.get_ledger_registry = async_mock.CoroutineMock( + revoc.return_value.get_ledger_registry = async_mock.AsyncMock( return_value=mock_rev_reg ) @@ -102,7 +102,7 @@ async def test_revoke_cred_by_cxid_not_found(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -125,7 +125,7 @@ async def test_revoke_credential_no_rev_reg_rec(self): with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as revoc: - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( return_value=None ) @@ -138,7 +138,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 = async_mock.MagicMock( - mark_pending=async_mock.CoroutineMock() + mark_pending=async_mock.AsyncMock() ) issuer = async_mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -156,9 +156,9 @@ async def test_revoke_credential_pend(self): ) as session, async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - revoc.return_value.get_issuer_rev_reg_record = async_mock.CoroutineMock( + revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) @@ -189,24 +189,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=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), ) with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=[mock_issuer_rev_reg_record]), + async_mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), ), async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_record), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = async_mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -237,35 +237,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=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), ), async_mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), ), ] with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ), async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock( + async_mock.AsyncMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = async_mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -297,35 +297,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=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), ), async_mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.CoroutineMock(), - clear_pending=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), + clear_pending=async_mock.AsyncMock(), ), ] with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ), async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.CoroutineMock( + async_mock.AsyncMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.CoroutineMock( + issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( side_effect=deltas ) - issuer.revoke_credentials = async_mock.CoroutineMock( + issuer.revoke_credentials = async_mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -341,19 +341,19 @@ async def test_clear_pending(self): revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), async_mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), ] with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations() assert result == {} @@ -364,19 +364,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=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), async_mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), ] with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: None}) assert result == { @@ -390,19 +390,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=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), async_mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["99"], - clear_pending=async_mock.CoroutineMock(), + clear_pending=async_mock.AsyncMock(), ), ] with async_mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.CoroutineMock(return_value=mock_issuer_rev_reg_records), + async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: ["9"]}) assert result == { diff --git a/aries_cloudagent/revocation/tests/test_routes.py b/aries_cloudagent/revocation/tests/test_routes.py index b715d59970..b0d86f7563 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -3,8 +3,8 @@ import unittest from aiohttp.web import HTTPBadRequest, HTTPNotFound -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.revocation.error import RevocationError @@ -13,14 +13,14 @@ from .. import routes as test_module -class TestRevocationRoutes(AsyncTestCase): +class TestRevocationRoutes(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context setattr(self.context, "profile", self.profile) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.CoroutineMock(), + "outbound_message_router": async_mock.AsyncMock(), } self.request = async_mock.MagicMock( app={}, @@ -75,7 +75,7 @@ async def test_validate_cred_rev_rec_qs_and_revoke_req(self): ) async def test_revoke(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -88,14 +88,14 @@ async def test_revoke(self): ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock() + mock_mgr.return_value.revoke_credential = async_mock.AsyncMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_by_cred_ex_id(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "cred_ex_id": "dummy-cxid", "publish": "false", @@ -107,14 +107,14 @@ async def test_revoke_by_cred_ex_id(self): ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock() + mock_mgr.return_value.revoke_credential = async_mock.AsyncMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_not_found(self): - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -127,7 +127,7 @@ async def test_revoke_not_found(self): ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.CoroutineMock( + mock_mgr.return_value.revoke_credential = async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -135,14 +135,14 @@ async def test_revoke_not_found(self): await test_module.revoke(self.request) async def test_publish_revocations(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - pub_pending = async_mock.CoroutineMock() + pub_pending = async_mock.AsyncMock() mock_mgr.return_value.publish_pending_revocations = pub_pending await test_module.publish_revocations(self.request) @@ -152,12 +152,12 @@ async def test_publish_revocations(self): ) async def test_publish_revocations_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr: - pub_pending = async_mock.CoroutineMock( + pub_pending = async_mock.AsyncMock( side_effect=test_module.RevocationError() ) mock_mgr.return_value.publish_pending_revocations = pub_pending @@ -166,14 +166,14 @@ async def test_publish_revocations_x(self): await test_module.publish_revocations(self.request) async def test_clear_pending_revocations(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.CoroutineMock() + clear_pending = async_mock.AsyncMock() mock_mgr.return_value.clear_pending_revocations = clear_pending await test_module.clear_pending_revocations(self.request) @@ -183,16 +183,14 @@ async def test_clear_pending_revocations(self): ) async def test_clear_pending_revocations_x(self): - self.request.json = async_mock.CoroutineMock() + self.request.json = async_mock.AsyncMock() with async_mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr, async_mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.CoroutineMock( - side_effect=test_module.StorageError() - ) + clear_pending = async_mock.AsyncMock(side_effect=test_module.StorageError()) mock_mgr.return_value.clear_pending_revocations = clear_pending with self.assertRaises(test_module.web.HTTPBadRequest): @@ -200,7 +198,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -216,9 +214,9 @@ async def test_create_rev_reg(self): ) as mock_json_response: mock_find.return_value = True mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.CoroutineMock( + init_issuer_registry=async_mock.AsyncMock( return_value=async_mock.MagicMock( - generate_registry=async_mock.CoroutineMock(), + generate_registry=async_mock.AsyncMock(), serialize=async_mock.MagicMock(return_value="dummy"), ) ) @@ -230,7 +228,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -250,7 +248,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, @@ -266,7 +264,7 @@ async def test_create_rev_reg_no_revo_support(self): ) as mock_json_response: mock_find = True mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.CoroutineMock( + init_issuer_registry=async_mock.AsyncMock( side_effect=test_module.RevocationNotSupportedError( error_code="dummy" ) @@ -286,7 +284,7 @@ async def test_rev_regs_created(self): } with async_mock.patch.object( - test_module.IssuerRevRegRecord, "query", async_mock.CoroutineMock() + test_module.IssuerRevRegRecord, "query", async_mock.AsyncMock() ) as mock_query, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: @@ -308,7 +306,7 @@ async def test_get_rev_reg(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock(return_value="dummy") ) @@ -331,7 +329,7 @@ async def test_get_rev_reg_not_found(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -349,11 +347,11 @@ async def test_get_rev_reg_issued(self): with async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve, async_mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_query, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: @@ -372,7 +370,7 @@ async def test_get_rev_reg_issued_x(self): with async_mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -393,7 +391,7 @@ async def test_get_cred_rev_record(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: @@ -413,7 +411,7 @@ async def test_get_cred_rev_record_by_cred_ex_id(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: @@ -431,7 +429,7 @@ async def test_get_cred_rev_record_not_found(self): ) CRED_REV_ID = "1" - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "rev_reg_id": REV_REG_ID, "cred_rev_id": CRED_REV_ID, @@ -441,7 +439,7 @@ async def test_get_cred_rev_record_not_found(self): with async_mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") with self.assertRaises(test_module.web.HTTPNotFound): @@ -457,7 +455,7 @@ async def test_get_active_rev_reg(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.CoroutineMock( + get_active_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( serialize=async_mock.MagicMock(return_value="dummy") ) @@ -478,7 +476,7 @@ async def test_get_active_rev_reg_not_found(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.CoroutineMock( + get_active_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -499,7 +497,7 @@ async def test_get_tails_file(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_file_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock(tails_local_path="dummy") ) ) @@ -520,7 +518,7 @@ async def test_get_tails_file_not_found(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_file_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -540,9 +538,9 @@ async def test_upload_tails_file_basic(self): ) as mock_indy_revoc, async_mock.patch.object( test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: - mock_upload = async_mock.CoroutineMock() + mock_upload = async_mock.AsyncMock() mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, @@ -565,7 +563,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 = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=False, @@ -585,9 +583,9 @@ async def test_upload_tails_file_fail(self): with async_mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_upload = async_mock.CoroutineMock(side_effect=RevocationError("test")) + mock_upload = async_mock.AsyncMock(side_effect=RevocationError("test")) mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, @@ -611,10 +609,10 @@ async def test_send_rev_reg_def(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - send_def=async_mock.CoroutineMock(), - send_entry=async_mock.CoroutineMock(), + send_def=async_mock.AsyncMock(), + send_entry=async_mock.AsyncMock(), serialize=async_mock.MagicMock(return_value="dummy"), ) ) @@ -636,7 +634,7 @@ async def test_send_rev_reg_def_not_found(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -655,9 +653,9 @@ async def test_send_rev_reg_def_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - send_def=async_mock.CoroutineMock( + send_def=async_mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -679,9 +677,9 @@ async def test_send_rev_reg_entry(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - send_entry=async_mock.CoroutineMock(), + send_entry=async_mock.AsyncMock(), serialize=async_mock.MagicMock(return_value="dummy"), ) ) @@ -703,7 +701,7 @@ async def test_send_rev_reg_entry_not_found(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -722,9 +720,9 @@ async def test_send_rev_reg_entry_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - send_entry=async_mock.CoroutineMock( + send_entry=async_mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -739,7 +737,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -751,10 +749,10 @@ async def test_update_rev_reg(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + set_tails_file_public_uri=async_mock.AsyncMock(), + save=async_mock.AsyncMock(), serialize=async_mock.MagicMock(return_value="dummy"), ) ) @@ -769,7 +767,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -781,7 +779,7 @@ async def test_update_rev_reg_not_found(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -795,7 +793,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 = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } @@ -805,9 +803,9 @@ async def test_update_rev_reg_x(self): test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.CoroutineMock( + set_tails_file_public_uri=async_mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -822,7 +820,7 @@ async def test_set_rev_reg_state(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -837,10 +835,10 @@ async def test_set_rev_reg_state(self): test_module.web, "json_response", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( return_value=async_mock.MagicMock( - set_state=async_mock.CoroutineMock(), - save=async_mock.CoroutineMock(), + set_state=async_mock.AsyncMock(), + save=async_mock.AsyncMock(), serialize=async_mock.MagicMock(return_value="dummy"), ) ) @@ -855,7 +853,7 @@ async def test_set_rev_reg_state_not_found(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.CoroutineMock( + self.request.json = async_mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -870,7 +868,7 @@ async def test_set_rev_reg_state_not_found(self): test_module.web, "FileResponse", async_mock.Mock() ) as mock_json_response: mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.CoroutineMock( + get_issuer_rev_reg_record=async_mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) diff --git a/aries_cloudagent/settings/tests/test_routes.py b/aries_cloudagent/settings/tests/test_routes.py index b17774c050..0cd27a58eb 100644 --- a/aries_cloudagent/settings/tests/test_routes.py +++ b/aries_cloudagent/settings/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from asynctest import mock as async_mock +from unittest import mock as async_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 = async_mock.MagicMock( query={}, - json=async_mock.CoroutineMock(return_value={}), + json=async_mock.AsyncMock(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 = async_mock.MagicMock( query={}, - json=async_mock.CoroutineMock(return_value={}), + json=async_mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) with async_mock.patch.object( @@ -122,7 +122,7 @@ async def test_update_profile_settings(mock_response): } request = async_mock.MagicMock( query={}, - json=async_mock.CoroutineMock( + json=async_mock.AsyncMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -163,7 +163,7 @@ async def test_update_profile_settings(mock_response): } request = async_mock.MagicMock( query={}, - json=async_mock.CoroutineMock( + json=async_mock.AsyncMock( 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 b1a146a45d..c8ae18dbf4 100644 --- a/aries_cloudagent/storage/tests/test_askar_storage.py +++ b/aries_cloudagent/storage/tests/test_askar_storage.py @@ -2,9 +2,9 @@ import pytest import os -from asynctest import mock as async_mock +from unittest import mock as async_mock -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...askar.profile import AskarProfileManager from ...config.injection_context import InjectionContext @@ -50,15 +50,15 @@ class TestAskarStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.asyncio async def test_record(self): with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -149,7 +149,7 @@ async def test_record(self): await storage.get_record("connection", None) with async_mock.patch.object( - test_module.non_secrets, "get_wallet_record", async_mock.CoroutineMock() + test_module.non_secrets, "get_wallet_record", async_mock.AsyncMock() ) 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 async_mock.patch.object( test_module.non_secrets, "update_wallet_record_value", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_update_value, async_mock.patch.object( test_module.non_secrets, "update_wallet_record_tags", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_update_tags, async_mock.patch.object( test_module.non_secrets, "delete_wallet_record", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) 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 async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -250,9 +250,9 @@ async def test_storage_search_x(self): await search.fetch(10) with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -357,7 +357,7 @@ async def test_postgres_wallet_storage_works(self): await postgres_wallet.remove() -class TestAskarStorageSearchSession(AsyncTestCase): +class TestAskarStorageSearchSession(IsolatedAsyncioTestCase): @pytest.mark.asyncio async def test_askar_storage_search_session(self): profile = "profileId" diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index db0366c830..8cc6ebf557 100644 --- a/aries_cloudagent/storage/tests/test_in_memory_storage.py +++ b/aries_cloudagent/storage/tests/test_in_memory_storage.py @@ -1,6 +1,6 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ...core.in_memory import InMemoryProfile from ...storage.error import ( @@ -183,7 +183,7 @@ async def test_search(self, store_search): # search again with with iterator mystery error search = store_search.search_records(record.type, {}, None) with async_mock.patch.object( - search, "fetch", async_mock.CoroutineMock() + search, "fetch", async_mock.AsyncMock() ) as mock_fetch: mock_fetch.return_value = async_mock.MagicMock( pop=async_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 ff1092cf61..96606b9c87 100644 --- a/aries_cloudagent/storage/tests/test_indy_storage.py +++ b/aries_cloudagent/storage/tests/test_indy_storage.py @@ -9,7 +9,7 @@ import indy.wallet from indy.error import ErrorCode -from asynctest import mock as async_mock +from unittest import mock as async_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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete, async_mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -172,7 +172,7 @@ async def test_record(self): await storage.get_record("connection", None) with async_mock.patch.object( - indy.non_secrets, "get_wallet_record", async_mock.CoroutineMock() + indy.non_secrets, "get_wallet_record", async_mock.AsyncMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -183,15 +183,15 @@ async def test_record(self): with async_mock.patch.object( indy.non_secrets, "update_wallet_record_value", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_update_value, async_mock.patch.object( indy.non_secrets, "update_wallet_record_tags", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_update_tags, async_mock.patch.object( indy.non_secrets, "delete_wallet_record", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete, async_mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -280,9 +280,9 @@ async def test_storage_search_x(self): await search.fetch(10) with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.CoroutineMock(), + async_mock.AsyncMock(), ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete, async_mock.patch.object( IndySdkProfile, "_make_finalizer" ): @@ -346,9 +346,9 @@ async def test_storage_del_close(self): storage = session.inject(BaseStorage) with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) 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 async_mock.patch.object( # error on close - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") mock_indy_open_search.return_value = 1 @@ -376,9 +376,9 @@ async def test_storage_del_close(self): await search.close() with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) as mock_indy_close_search, async_mock.patch.object( asyncio, "get_event_loop", async_mock.MagicMock() ) as mock_get_event_loop: @@ -402,9 +402,9 @@ async def test_storage_del_close(self): await coro with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.CoroutineMock() + indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() ) as mock_indy_close_search, async_mock.patch.object( asyncio, "get_event_loop", async_mock.MagicMock() ) as mock_get_event_loop: diff --git a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py index fa092511b4..f4d08d9a28 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py @@ -1,5 +1,5 @@ import pytest -from asynctest import mock as async_mock +from unittest import mock as async_mock from ....config.injection_context import InjectionContext diff --git a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py index f3d8456f83..75fcccc155 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....messaging.models.base import BaseModelError @@ -134,7 +134,7 @@ def test_record() -> VCRecord: ) -class TestVCRecord(AsyncTestCase): +class TestVCRecord(IsolatedAsyncioTestCase): def test_create(self): record = test_record() diff --git a/aries_cloudagent/tails/tests/test_indy.py b/aries_cloudagent/tails/tests/test_indy.py index 082d772955..eb961e0bfb 100644 --- a/aries_cloudagent/tails/tests/test_indy.py +++ b/aries_cloudagent/tails/tests/test_indy.py @@ -1,4 +1,5 @@ -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -12,7 +13,7 @@ REV_REG_ID = f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:0" -class TestIndyTailsServer(AsyncTestCase): +class TestIndyTailsServer(IsolatedAsyncioTestCase): async def test_upload_no_tails_upload_url_x(self): context = InjectionContext(settings={"ledger.genesis_transactions": "dummy"}) indy_tails = test_module.IndyTailsServer() @@ -30,7 +31,7 @@ async def test_upload(self): indy_tails = test_module.IndyTailsServer() with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + test_module, "put_file", async_mock.AsyncMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -49,7 +50,7 @@ async def test_upload_indy_sdk(self): profile.context.injector.bind_instance( BaseMultipleLedgerManager, async_mock.MagicMock( - get_write_ledgers=async_mock.CoroutineMock( + get_write_ledgers=async_mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -61,7 +62,7 @@ async def test_upload_indy_sdk(self): indy_tails = test_module.IndyTailsServer() with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + test_module, "put_file", async_mock.AsyncMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -80,7 +81,7 @@ async def test_upload_indy_vdr(self): profile.context.injector.bind_instance( BaseMultipleLedgerManager, async_mock.MagicMock( - get_write_ledgers=async_mock.CoroutineMock( + get_write_ledgers=async_mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -92,7 +93,7 @@ async def test_upload_indy_vdr(self): indy_tails = test_module.IndyTailsServer() with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + test_module, "put_file", async_mock.AsyncMock() ) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( @@ -115,7 +116,7 @@ async def test_upload_x(self): indy_tails = test_module.IndyTailsServer() with async_mock.patch.object( - test_module, "put_file", async_mock.CoroutineMock() + test_module, "put_file", async_mock.AsyncMock() ) as mock_put: mock_put.side_effect = test_module.PutError("Server down for maintenance") diff --git a/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py b/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py index c5f8f19a1e..e60ddcfcea 100644 --- a/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py +++ b/aries_cloudagent/transport/inbound/tests/test_delivery_queue.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ....connections.models.connection_target import ConnectionTarget from ....transport.outbound.message import OutboundMessage @@ -6,7 +6,7 @@ from ..delivery_queue import DeliveryQueue -class TestDeliveryQueue(AsyncTestCase): +class TestDeliveryQueue(IsolatedAsyncioTestCase): async def test_message_add_and_check(self): queue = DeliveryQueue() diff --git a/aries_cloudagent/transport/inbound/tests/test_http_transport.py b/aries_cloudagent/transport/inbound/tests/test_http_transport.py index aea3f2e740..2e3c793bed 100644 --- a/aries_cloudagent/transport/inbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ import json from aiohttp.test_utils import AioHTTPTestCase, unused_port -from asynctest import mock as async_mock +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -61,7 +61,7 @@ def receive_message( message: InboundMessage, can_respond: bool = False, ): - message.wait_processing_complete = async_mock.CoroutineMock() + message.wait_processing_complete = async_mock.AsyncMock() 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", async_mock.MagicMock() ) as mock_site: mock_site.return_value = async_mock.MagicMock( - start=async_mock.CoroutineMock(side_effect=OSError()) + start=async_mock.AsyncMock(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 async_mock.patch.object( - test_module.HttpTransport, "create_session", async_mock.CoroutineMock() + test_module.HttpTransport, "create_session", async_mock.AsyncMock() ) as mock_session: mock_session.return_value = async_mock.MagicMock( - receive=async_mock.CoroutineMock( + receive=async_mock.AsyncMock( return_value=async_mock.MagicMock( receipt=async_mock.MagicMock(direct_response_requested=True), - wait_processing_complete=async_mock.CoroutineMock(), + wait_processing_complete=async_mock.AsyncMock(), ) ), can_respond=True, profile=InMemoryProfile.test_profile(), clear_response=async_mock.MagicMock(), - wait_response=async_mock.CoroutineMock(return_value=b"Hello world"), + wait_response=async_mock.AsyncMock(return_value=b"Hello world"), response_buffer="something", ) async with self.client.post("/", data=test_message) as resp: @@ -134,7 +134,7 @@ async def test_send_message_outliers(self): assert result == "Hello world" mock_session.return_value = async_mock.MagicMock( - receive=async_mock.CoroutineMock( + receive=async_mock.AsyncMock( side_effect=test_module.WireFormatParseError() ), profile=InMemoryProfile.test_profile(), diff --git a/aries_cloudagent/transport/inbound/tests/test_manager.py b/aries_cloudagent/transport/inbound/tests/test_manager.py index 7b0e2f4424..8a27c3fa41 100644 --- a/aries_cloudagent/transport/inbound/tests/test_manager.py +++ b/aries_cloudagent/transport/inbound/tests/test_manager.py @@ -1,4 +1,5 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -9,7 +10,7 @@ from ..manager import InboundTransportManager -class TestInboundTransportManager(AsyncTestCase): +class TestInboundTransportManager(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() @@ -58,8 +59,8 @@ async def test_setup(self): async def test_start_stop(self): transport = async_mock.MagicMock() - transport.start = async_mock.CoroutineMock() - transport.stop = async_mock.CoroutineMock() + transport.start = async_mock.AsyncMock() + transport.stop = async_mock.AsyncMock() mgr = InboundTransportManager(self.profile, None) mgr.register_transport(transport, "transport_cls") @@ -75,7 +76,7 @@ async def test_create_session(self): test_wire_format = async_mock.MagicMock() self.profile.context.injector.bind_instance(BaseWireFormat, test_wire_format) - test_inbound_handler = async_mock.CoroutineMock() + test_inbound_handler = async_mock.AsyncMock() mgr = InboundTransportManager(self.profile, test_inbound_handler) test_transport = "http" test_accept = True @@ -147,7 +148,7 @@ async def test_close_return(self): async def test_dispatch_complete_undelivered(self): mgr = InboundTransportManager(self.profile, None) test_wire_format = async_mock.MagicMock( - parse_message=async_mock.CoroutineMock(return_value=("payload", "receipt")) + parse_message=async_mock.AsyncMock(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_message.py b/aries_cloudagent/transport/inbound/tests/test_message.py index 71a8defee8..8fd67d368a 100644 --- a/aries_cloudagent/transport/inbound/tests/test_message.py +++ b/aries_cloudagent/transport/inbound/tests/test_message.py @@ -1,6 +1,6 @@ import asyncio -from asynctest import TestCase +from unittest import TestCase from ..message import InboundMessage from ..receipt import MessageReceipt diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index e1e5fcd9cd..3dac5fb85f 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -1,7 +1,8 @@ import asyncio import pytest -from asynctest import TestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import TestCase from ....admin.server import AdminResponder from ....core.in_memory import InMemoryProfile @@ -89,7 +90,7 @@ async def test_parse_inbound(self): test_session_id = "session-id" test_transport_type = "transport-type" test_wire_format = async_mock.MagicMock() - test_wire_format.parse_message = async_mock.CoroutineMock() + test_wire_format.parse_message = async_mock.AsyncMock() test_parsed = "parsed-payload" test_receipt = async_mock.MagicMock() test_wire_format.parse_message.return_value = (test_parsed, test_receipt) @@ -114,10 +115,10 @@ async def test_parse_inbound(self): async def test_receive(self): self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallets_by_message = async_mock.AsyncMock( return_value=[async_mock.MagicMock(is_managed=True)] ) - self.multitenant_mgr.get_wallet_profile = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -136,7 +137,7 @@ async def test_receive(self): test_msg = async_mock.MagicMock() with async_mock.patch.object( - sess, "parse_inbound", async_mock.CoroutineMock() + sess, "parse_inbound", async_mock.AsyncMock() ) as encode, async_mock.patch.object( sess, "receive_inbound", async_mock.MagicMock() ) as receive: @@ -147,10 +148,10 @@ async def test_receive(self): async def test_receive_no_wallet_found(self): self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallets_by_message = async_mock.AsyncMock( side_effect=ValueError("no such wallet") ) - self.multitenant_mgr.get_wallet_profile = async_mock.CoroutineMock( + self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -167,7 +168,7 @@ async def test_receive_no_wallet_found(self): test_msg = async_mock.MagicMock() with async_mock.patch.object( - sess, "parse_inbound", async_mock.CoroutineMock() + sess, "parse_inbound", async_mock.AsyncMock() ) as encode, async_mock.patch.object( sess, "receive_inbound", async_mock.MagicMock() ) as receive: @@ -267,7 +268,7 @@ async def test_wait_response(self): assert sess.response_buffered with async_mock.patch.object( - sess, "encode_outbound", async_mock.CoroutineMock() + sess, "encode_outbound", async_mock.AsyncMock() ) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) assert encode.awaited_once_with(test_msg) @@ -292,7 +293,7 @@ async def test_wait_response_x(self): assert sess.response_buffered with async_mock.patch.object( - sess, "encode_outbound", async_mock.CoroutineMock() + sess, "encode_outbound", async_mock.AsyncMock() ) as encode: encode.side_effect = WireFormatError() with pytest.raises(asyncio.TimeoutError): @@ -305,7 +306,7 @@ async def test_wait_response_x(self): async def test_encode_response(self): test_wire_format = async_mock.MagicMock() - test_wire_format.encode_message = async_mock.CoroutineMock() + test_wire_format.encode_message = async_mock.AsyncMock() 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 03250fe7f9..dc049db5c0 100644 --- a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py @@ -3,7 +3,7 @@ import pytest from aiohttp.test_utils import AioHTTPTestCase, unused_port -from asynctest import mock as async_mock +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile @@ -72,7 +72,7 @@ async def test_start_x(self): test_module.web, "TCPSite", async_mock.MagicMock() ) as mock_site: mock_site.return_value = async_mock.MagicMock( - start=async_mock.CoroutineMock(side_effect=OSError()) + start=async_mock.AsyncMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() diff --git a/aries_cloudagent/transport/outbound/tests/test_http_transport.py b/aries_cloudagent/transport/outbound/tests/test_http_transport.py index 3dc96d35bc..b8826afb5f 100644 --- a/aries_cloudagent/transport/outbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ from aiohttp.test_utils import AioHTTPTestCase from aiohttp import web -from asynctest import mock as async_mock +from unittest import mock as async_mock from ....core.in_memory import InMemoryProfile from ....utils.stats import Collector @@ -15,7 +15,7 @@ class TestHttpTransport(AioHTTPTestCase): - async def setUpAsync(self): + async def asyncSetUpAsync(self): self.profile = InMemoryProfile.test_profile() self.message_results = [] self.headers = {} @@ -135,7 +135,7 @@ async def test_transport_coverage(self): mock_response = async_mock.MagicMock(status=404) mock_session.post = async_mock.MagicMock( return_value=async_mock.MagicMock( - __aenter__=async_mock.CoroutineMock(return_value=mock_response) + __aenter__=async_mock.AsyncMock(return_value=mock_response) ) ) with pytest.raises(OutboundTransportError): diff --git a/aries_cloudagent/transport/outbound/tests/test_manager.py b/aries_cloudagent/transport/outbound/tests/test_manager.py index 7521173734..28095cc4e7 100644 --- a/aries_cloudagent/transport/outbound/tests/test_manager.py +++ b/aries_cloudagent/transport/outbound/tests/test_manager.py @@ -1,6 +1,7 @@ import json -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile from ....connections.models.connection_target import ConnectionTarget @@ -16,7 +17,7 @@ from ..message import OutboundMessage -class TestOutboundTransportManager(AsyncTestCase): +class TestOutboundTransportManager(IsolatedAsyncioTestCase): def test_register_path(self): mgr = OutboundTransportManager(InMemoryProfile.test_profile()) mgr.register("http") @@ -53,10 +54,10 @@ async def test_send_message(self): mgr.register_class(transport_cls, "transport_cls") transport = async_mock.MagicMock() - transport.handle_message = async_mock.CoroutineMock() - transport.wire_format.encode_message = async_mock.CoroutineMock() - transport.start = async_mock.CoroutineMock() - transport.stop = async_mock.CoroutineMock() + transport.handle_message = async_mock.AsyncMock() + transport.wire_format.encode_message = async_mock.AsyncMock() + transport.start = async_mock.AsyncMock() + transport.stop = async_mock.AsyncMock() transport.schemes = ["http"] transport.is_external = False @@ -149,7 +150,7 @@ async def test_enqueue_webhook(self): transport_cls.schemes = ["http"] transport_cls.return_value = async_mock.MagicMock() transport_cls.return_value.schemes = ["http"] - transport_cls.return_value.start = async_mock.CoroutineMock() + transport_cls.return_value.start = async_mock.AsyncMock() tid = mgr.register_class(transport_cls, "transport_cls") await mgr.start_transport(tid) @@ -225,7 +226,7 @@ async def test_process_loop_retry_later(self): mgr.outbound_buffer.append(mock_queued) with async_mock.patch.object( - test_module.asyncio, "sleep", async_mock.CoroutineMock() + test_module.asyncio, "sleep", async_mock.AsyncMock() ) as mock_sleep_x: mock_sleep_x.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -246,7 +247,7 @@ async def test_process_loop_new(self): with async_mock.patch.object( mgr, "deliver_queued_message", async_mock.MagicMock() ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.CoroutineMock() + mgr.outbound_event, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( test_module, "trace_event", async_mock.MagicMock() ) as mock_trace: @@ -269,7 +270,7 @@ async def test_process_loop_new_deliver(self): with async_mock.patch.object( mgr, "deliver_queued_message", async_mock.MagicMock() ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.CoroutineMock() + mgr.outbound_event, "wait", async_mock.AsyncMock() ) as mock_wait, async_mock.patch.object( test_module, "trace_event", async_mock.MagicMock() ) as mock_trace: @@ -318,11 +319,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 = async_mock.CoroutineMock( - return_value=encoded_msg - ) + base_wire_format.encode_message = async_mock.AsyncMock(return_value=encoded_msg) profile = InMemoryProfile.test_profile(bind={BaseWireFormat: base_wire_format}) - profile.session = async_mock.CoroutineMock(return_value=async_mock.MagicMock()) + profile.session = async_mock.AsyncMock(return_value=async_mock.MagicMock()) outbound = async_mock.MagicMock(payload="payload", enc_payload=None) target = async_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 48697cf399..2840790aa8 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 setUpAsync(self): + async def asyncSetUpAsync(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 53bcf7353b..3772cfed3c 100644 --- a/aries_cloudagent/transport/queue/tests/test_basic_queue.py +++ b/aries_cloudagent/transport/queue/tests/test_basic_queue.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import basic as test_module from ..basic import BasicMessageQueue @@ -15,7 +16,7 @@ async def collect(queue, count=1): return found -class TestBasicQueue(AsyncTestCase): +class TestBasicQueue(IsolatedAsyncioTestCase): async def test_enqueue_dequeue(self): queue = BasicMessageQueue() @@ -39,7 +40,7 @@ async def test_dequeue_x(self): with async_mock.patch.object( test_module.asyncio, "get_event_loop", async_mock.MagicMock() ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_wait.return_value = ( async_mock.MagicMock(), @@ -71,7 +72,7 @@ async def test_dequeue_none(self): with async_mock.patch.object( test_module.asyncio, "get_event_loop", async_mock.MagicMock() ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.CoroutineMock() + test_module.asyncio, "wait", async_mock.AsyncMock() ) as mock_wait: mock_wait.return_value = ( async_mock.MagicMock(), diff --git a/aries_cloudagent/transport/tests/test_pack_format.py b/aries_cloudagent/transport/tests/test_pack_format.py index 764e4a54bf..4bbaaf7ea4 100644 --- a/aries_cloudagent/transport/tests/test_pack_format.py +++ b/aries_cloudagent/transport/tests/test_pack_format.py @@ -1,8 +1,8 @@ import json from base64 import b64encode -from asynctest import TestCase as AsyncTestCase -from asynctest import mock as async_mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock as async_mock from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix @@ -16,7 +16,7 @@ from ..pack_format import PackWireFormat -class TestPackWireFormat(AsyncTestCase): +class TestPackWireFormat(IsolatedAsyncioTestCase): test_message_type = DIDCommPrefix.qualify_current("PROTOCOL/MESSAGE") test_message_id = "MESSAGE_ID" test_content = "CONTENT" @@ -55,7 +55,7 @@ async def test_errors(self): serializer.task_queue = None with async_mock.patch.object( - serializer, "unpack", async_mock.CoroutineMock() + serializer, "unpack", async_mock.AsyncMock() ) as mock_unpack: mock_unpack.return_value = "{missing-brace" with self.assertRaises(WireFormatParseError) as context: @@ -65,7 +65,7 @@ async def test_errors(self): serializer = PackWireFormat() serializer.task_queue = None with async_mock.patch.object( - serializer, "unpack", async_mock.CoroutineMock() + serializer, "unpack", async_mock.AsyncMock() ) as mock_unpack: mock_unpack.return_value = json.dumps([1, 2, 3]) with self.assertRaises(WireFormatParseError) as context: @@ -93,14 +93,14 @@ async def test_pack_x(self): ) mock_wallet = async_mock.MagicMock( - pack_message=async_mock.CoroutineMock(side_effect=WalletError()) + pack_message=async_mock.AsyncMock(side_effect=WalletError()) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], None, ["key"]) mock_wallet = async_mock.MagicMock( - pack_message=async_mock.CoroutineMock( + pack_message=async_mock.AsyncMock( side_effect=[json.dumps("message").encode("utf-8"), WalletError()] ) ) diff --git a/aries_cloudagent/transport/tests/test_stats.py b/aries_cloudagent/transport/tests/test_stats.py index f2cc267d0c..3b0784e779 100644 --- a/aries_cloudagent/transport/tests/test_stats.py +++ b/aries_cloudagent/transport/tests/test_stats.py @@ -1,10 +1,11 @@ -from asynctest import TestCase as AsyncTestCase, mock as async_mock +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from .. import stats as test_module -class TestStatsTracer(AsyncTestCase): +class TestStatsTracer(IsolatedAsyncioTestCase): def setUp(self): self.context = async_mock.MagicMock( socket_timer=async_mock.MagicMock( diff --git a/aries_cloudagent/transport/tests/test_wire_format.py b/aries_cloudagent/transport/tests/test_wire_format.py index 48471402a1..c22e403dae 100644 --- a/aries_cloudagent/transport/tests/test_wire_format.py +++ b/aries_cloudagent/transport/tests/test_wire_format.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..wire_format import JsonWireFormat -class TestWireFormat(AsyncTestCase): +class TestWireFormat(IsolatedAsyncioTestCase): async def test_get_recipient_keys(self): serializer = JsonWireFormat() recipient_keys = serializer.get_recipient_keys("message_body") diff --git a/aries_cloudagent/utils/tests/test_http.py b/aries_cloudagent/utils/tests/test_http.py index 6e2ff84adb..b35a49ac25 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 setUpAsync(self): + async def asyncSetUpAsync(self): self.fail_calls = 0 self.succeed_calls = 0 self.redirects = 0 diff --git a/aries_cloudagent/utils/tests/test_outofband.py b/aries_cloudagent/utils/tests/test_outofband.py index 6e3821ff57..81d5763ca7 100644 --- a/aries_cloudagent/utils/tests/test_outofband.py +++ b/aries_cloudagent/utils/tests/test_outofband.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ...protocols.out_of_band.v1_0.messages.invitation import InvitationMessage from ...wallet.did_info import DIDInfo diff --git a/aries_cloudagent/utils/tests/test_repeat.py b/aries_cloudagent/utils/tests/test_repeat.py index 0056334a8a..bb86e345be 100644 --- a/aries_cloudagent/utils/tests/test_repeat.py +++ b/aries_cloudagent/utils/tests/test_repeat.py @@ -1,9 +1,9 @@ -from asynctest import mock, TestCase +from unittest import IsolatedAsyncioTestCase, mock from .. import repeat as test_module -class TestRepeat(TestCase): +class TestRepeat(IsolatedAsyncioTestCase): async def test_iter(self): expect = [5, 7, 11, 17, 25] seq = test_module.RepeatSequence(5, interval=5.0, backoff=0.25) diff --git a/aries_cloudagent/utils/tests/test_stats.py b/aries_cloudagent/utils/tests/test_stats.py index e055192a49..d984b93785 100644 --- a/aries_cloudagent/utils/tests/test_stats.py +++ b/aries_cloudagent/utils/tests/test_stats.py @@ -1,11 +1,11 @@ from tempfile import NamedTemporaryFile -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..stats import Collector -class TestStats(AsyncTestCase): +class TestStats(IsolatedAsyncioTestCase): async def test_fn_decorator(self): stats = Collector() diff --git a/aries_cloudagent/utils/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py index dc0cc559a0..2b8f20c624 100644 --- a/aries_cloudagent/utils/tests/test_task_queue.py +++ b/aries_cloudagent/utils/tests/test_task_queue.py @@ -1,6 +1,7 @@ import asyncio -from asynctest import mock as async_mock, TestCase as AsyncTestCase +from unittest import mock as async_mock +from unittest import IsolatedAsyncioTestCase from ..task_queue import CompletedTask, PendingTask, TaskQueue, task_exc_info @@ -11,7 +12,7 @@ async def retval(val, *, delay=0): return val -class TestTaskQueue(AsyncTestCase): +class TestTaskQueue(IsolatedAsyncioTestCase): async def test_run(self): queue = TaskQueue() task = None @@ -108,7 +109,7 @@ async def noop(): with async_mock.patch.object( queue, "drain", async_mock.MagicMock() ) as mock_drain, async_mock.patch.object( - queue, "wait_for", async_mock.CoroutineMock() + queue, "wait_for", async_mock.AsyncMock() ) as mock_wait_for: mock_drain.side_effect = [queue.loop.create_task(noop()), None] await queue.complete(cleanup=True) diff --git a/aries_cloudagent/utils/tests/test_tracing.py b/aries_cloudagent/utils/tests/test_tracing.py index c27d461dc4..b9c7278383 100644 --- a/aries_cloudagent/utils/tests/test_tracing.py +++ b/aries_cloudagent/utils/tests/test_tracing.py @@ -1,7 +1,7 @@ import json import requests -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ...protocols.out_of_band.v1_0.messages.invitation import InvitationMessage from ...protocols.issue_credential.v1_0.models.credential_exchange import ( @@ -16,7 +16,7 @@ from .. import tracing as test_module -class TestTracing(AsyncTestCase): +class TestTracing(IsolatedAsyncioTestCase): test_did = "55GkHamhTU1ZbTbV2ab9DE" def test_get_timer(self): diff --git a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py index d1842d9ac2..d2e9353d96 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -1,4 +1,4 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from aries_cloudagent.wallet.key_type import ED25519 @@ -9,8 +9,8 @@ from ..wallet_key_pair import WalletKeyPair -class TestWalletKeyPair(TestCase): - async def setUp(self): +class TestWalletKeyPair(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() async def test_sign_x_no_public_key(self): @@ -32,7 +32,7 @@ async def test_sign(self): with async_mock.patch.object( InMemoryWallet, "sign_message", - async_mock.CoroutineMock(return_value=signed), + async_mock.AsyncMock(return_value=signed), ) as sign_message: singed_ret = await key_pair.sign(b"Message") @@ -59,7 +59,7 @@ async def test_verify(self): with async_mock.patch.object( InMemoryWallet, "verify_message", - async_mock.CoroutineMock(return_value=True), + async_mock.AsyncMock(return_value=True), ) as verify_message: verified = await key_pair.verify(b"Message", b"signature") diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py index 957c5d56c1..f8858b8a92 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py @@ -1,12 +1,12 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from ...validation_result import PurposeResult from ..controller_proof_purpose import ControllerProofPurpose from ..authentication_proof_purpose import AuthenticationProofPurpose -class TestAuthenticationProofPurpose(TestCase): +class TestAuthenticationProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): date = datetime.now() delta = timedelta(1) diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py index 8ae1dc33c6..b11641e071 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from ....tests.data import TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519 from ....tests.document_loader import custom_document_loader @@ -7,7 +7,7 @@ from ..controller_proof_purpose import ControllerProofPurpose -class TestControllerProofPurpose(TestCase): +class TestControllerProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): term = "TestTerm" date = datetime.now() diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py index 60442b73da..97c061b6bf 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from ...validation_result import PurposeResult from ..assertion_proof_purpose import AssertionProofPurpose @@ -8,7 +8,7 @@ from ....tests.document_loader import custom_document_loader -class TestCredentialIssuancePurpose(TestCase): +class TestCredentialIssuancePurpose(IsolatedAsyncioTestCase): async def test_properties(self): date = datetime.now() delta = timedelta(1) diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py index ffde15d366..13e3d76c7c 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py @@ -1,11 +1,11 @@ from datetime import datetime, timedelta -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from .....messaging.util import datetime_to_str from ..proof_purpose import ProofPurpose -class TestProofPurpose(TestCase): +class TestProofPurpose(IsolatedAsyncioTestCase): async def test_properties(self): term = "TestTerm" date = datetime.now() diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py index a5a141c174..ca4ccc453a 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py @@ -1,4 +1,4 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -24,10 +24,10 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsBlsSignature2020(TestCase): +class TestBbsBlsSignature2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py index ae217d4b63..6f408e1729 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py @@ -1,4 +1,4 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -33,10 +33,10 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsBlsSignatureProof2020(TestCase): +class TestBbsBlsSignatureProof2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py index fdae59d396..e9dfba0d33 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2018.py @@ -1,9 +1,7 @@ -from asynctest import TestCase - -from aries_cloudagent.wallet.key_type import ED25519 - +from unittest import IsolatedAsyncioTestCase from .....did.did_key import DIDKey +from .....wallet.key_type import ED25519 from .....wallet.in_memory import InMemoryWallet from .....core.in_memory import InMemoryProfile @@ -23,10 +21,10 @@ from ..ed25519_signature_2018 import Ed25519Signature2018 -class TestEd25519Signature2018(TestCase): +class TestEd25519Signature2018(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py index c527e3aa48..68950bf3d3 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_ed25519_signature_2020.py @@ -1,6 +1,5 @@ -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.wallet.key_type import ED25519 from ..ed25519_signature_2020 import Ed25519Signature2020 from ...crypto.wallet_key_pair import WalletKeyPair from ...ld_proofs import sign, verify @@ -16,12 +15,13 @@ from .....core.in_memory import InMemoryProfile from .....did.did_key import DIDKey from .....wallet.in_memory import InMemoryWallet +from .....wallet.key_type import ED25519 -class TestEd25519Signature2020(TestCase): +class TestEd25519Signature2020(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) self.key = await self.wallet.create_signing_key( diff --git a/aries_cloudagent/vc/ld_proofs/tests/test_check.py b/aries_cloudagent/vc/ld_proofs/tests/test_check.py index 56573fbde5..ca6ee1668b 100644 --- a/aries_cloudagent/vc/ld_proofs/tests/test_check.py +++ b/aries_cloudagent/vc/ld_proofs/tests/test_check.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ..check import get_properties_without_context from ...tests.document_loader import custom_document_loader diff --git a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py index 26f170793e..9141e48c98 100644 --- a/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py +++ b/aries_cloudagent/vc/ld_proofs/tests/test_ld_proofs.py @@ -1,8 +1,8 @@ +from unittest import IsolatedAsyncioTestCase import pytest from datetime import datetime, timezone -from asynctest import TestCase from ....wallet.key_type import BLS12381G2, ED25519 from ....did.did_key import DIDKey @@ -36,10 +36,10 @@ ) -class TestLDProofs(TestCase): +class TestLDProofs(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) diff --git a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py index 0fd50ccbc1..d22d432b93 100644 --- a/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py +++ b/aries_cloudagent/vc/tests/test_bbs_mattr_interop.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import IsolatedAsyncioTestCase import pytest from ...wallet.key_type import BLS12381G2 @@ -31,8 +31,8 @@ @pytest.mark.ursa_bbs_signatures -class TestBbsMattrInterop(TestCase): - async def setUp(self): +class TestBbsMattrInterop(IsolatedAsyncioTestCase): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) diff --git a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py index 26f027d4a6..05c7b19fa4 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py @@ -1,4 +1,4 @@ -from asynctest import TestCase +from unittest import TestCase from ..validation_result import PresentationVerificationResult diff --git a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index d169a1907a..6866237672 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py @@ -1,4 +1,4 @@ -from asynctest import TestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock as async_mock from datetime import datetime import pytest @@ -37,10 +37,10 @@ ) -class TestLinkedDataVerifiableCredential(TestCase): +class TestLinkedDataVerifiableCredential(IsolatedAsyncioTestCase): test_seed = "testseed000000000000000000000001" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.wallet = InMemoryWallet(self.profile) diff --git a/aries_cloudagent/wallet/models/tests/test_wallet_record.py b/aries_cloudagent/wallet/models/tests/test_wallet_record.py index 39ea44b224..bc1b51bdb1 100644 --- a/aries_cloudagent/wallet/models/tests/test_wallet_record.py +++ b/aries_cloudagent/wallet/models/tests/test_wallet_record.py @@ -1,10 +1,10 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..wallet_record import WalletRecord from ...error import WalletSettingsError -class TestWalletRecord(AsyncTestCase): +class TestWalletRecord(IsolatedAsyncioTestCase): async def test_serde(self): rec = WalletRecord( wallet_id="my-wallet-id", diff --git a/aries_cloudagent/wallet/tests/test_did_posture.py b/aries_cloudagent/wallet/tests/test_did_posture.py index 85aa498d15..d4000ae8db 100644 --- a/aries_cloudagent/wallet/tests/test_did_posture.py +++ b/aries_cloudagent/wallet/tests/test_did_posture.py @@ -1,9 +1,9 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase from ..did_posture import DIDPosture -class TestDIDPosture(AsyncTestCase): +class TestDIDPosture(IsolatedAsyncioTestCase): async def test_did_posture(self): assert DIDPosture.PUBLIC is DIDPosture.get("PUBLIC") assert DIDPosture.POSTED is DIDPosture.get("POSTED") diff --git a/aries_cloudagent/wallet/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index 47ae72cdec..a2953d2f48 100644 --- a/aries_cloudagent/wallet/tests/test_indy_wallet.py +++ b/aries_cloudagent/wallet/tests/test_indy_wallet.py @@ -7,7 +7,7 @@ import indy.did import indy.wallet import pytest -from asynctest import mock as async_mock +from unittest import mock as async_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 async_mock.patch.object( - indy.did, "replace_keys_start", async_mock.CoroutineMock() + indy.did, "replace_keys_start", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.did, "replace_keys_apply", async_mock.CoroutineMock() + indy.did, "replace_keys_apply", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.crypto, "create_key", async_mock.CoroutineMock() + indy.crypto, "create_key", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.did, "create_and_store_my_did", async_mock.CoroutineMock() + indy.did, "create_and_store_my_did", async_mock.AsyncMock() ) 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 = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() + read_only=False, update_endpoint_for_did=async_mock.AsyncMock() ) 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 = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.CoroutineMock() + read_only=False, update_endpoint_for_did=async_mock.AsyncMock() ) 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 = async_mock.MagicMock( - read_only=True, update_endpoint_for_did=async_mock.CoroutineMock() + read_only=True, update_endpoint_for_did=async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.crypto, "get_key_metadata", async_mock.CoroutineMock() + indy.crypto, "get_key_metadata", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.did, "get_my_did_with_meta", async_mock.CoroutineMock() + indy.did, "get_my_did_with_meta", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.did, "set_did_metadata", async_mock.CoroutineMock() + indy.did, "set_did_metadata", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.crypto, "crypto_verify", async_mock.CoroutineMock() + indy.crypto, "crypto_verify", async_mock.AsyncMock() ) 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 async_mock.patch.object( - indy.crypto, "pack_message", async_mock.CoroutineMock() + indy.crypto, "pack_message", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete: fake_wallet = IndyWalletConfig( { @@ -364,15 +364,15 @@ async def test_mock_coverage_wallet_exists_x(self): "load_postgres_plugin", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) 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", async_mock.MagicMock(), ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.CoroutineMock() + indy.wallet, "create_wallet", async_mock.AsyncMock() ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.CoroutineMock() + indy.wallet, "open_wallet", async_mock.AsyncMock() ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.CoroutineMock() + indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.CoroutineMock() + indy.wallet, "close_wallet", async_mock.AsyncMock() ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.CoroutineMock() + indy.wallet, "delete_wallet", async_mock.AsyncMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.AnoncredsMasterSecretDuplicateNameError diff --git a/aries_cloudagent/wallet/tests/test_key_pair.py b/aries_cloudagent/wallet/tests/test_key_pair.py index 6d0ddccb67..9126f15d6e 100644 --- a/aries_cloudagent/wallet/tests/test_key_pair.py +++ b/aries_cloudagent/wallet/tests/test_key_pair.py @@ -1,4 +1,4 @@ -from asynctest import TestCase as AsyncTestCase +from unittest import IsolatedAsyncioTestCase import json @@ -10,11 +10,11 @@ from ..key_pair import KeyPairStorageManager, KEY_PAIR_STORAGE_TYPE -class TestKeyPairStorageManager(AsyncTestCase): +class TestKeyPairStorageManager(IsolatedAsyncioTestCase): test_public_key = b"somepublickeybytes" test_secret = b"verysecretkey" - async def setUp(self): + async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.store = InMemoryStorage(self.profile) self.key_pair_mgr = KeyPairStorageManager(self.store) From fd41c62eeb632f66c6a33c2346c9e6387b17c4a3 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 25 Oct 2023 18:22:22 -0400 Subject: [PATCH 02/33] fix: mt admin test routes mock issues Signed-off-by: Daniel Bluhm --- .../multitenant/admin/tests/test_routes.py | 252 +++++++++--------- 1 file changed, 124 insertions(+), 128 deletions(-) diff --git a/aries_cloudagent/multitenant/admin/tests/test_routes.py b/aries_cloudagent/multitenant/admin/tests/test_routes.py index e64e6a32bf..7a5dc7ceeb 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 as async_mock +from unittest import mock from marshmallow.exceptions import ValidationError from ...base import BaseMultitenantManager, MultitenantManagerError @@ -13,10 +13,10 @@ class TestMultitenantRoutes(IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.mock_multitenant_mgr = async_mock.MagicMock( - __aexit__=async_mock.AsyncMock(), autospec=True + self.mock_multitenant_mgr = mock.MagicMock( + __aexit__=mock.AsyncMock(), autospec=True ) - self.mock_multitenant_mgr.__aenter__ = async_mock.AsyncMock( + self.mock_multitenant_mgr.__aenter__ = mock.AsyncMock( return_value=self.mock_multitenant_mgr ) @@ -27,9 +27,9 @@ async def asyncSetUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -48,14 +48,14 @@ async def test_format_wallet_record_removes_wallet_key(self): assert "wallet.key" not in formatted["settings"] async def test_wallets_list(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True - ) as mock_wallet_record, async_mock.patch.object( + ) as mock_wallet_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: wallets = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567890", @@ -63,8 +63,8 @@ async def test_wallets_list(self): } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567891", @@ -72,8 +72,8 @@ async def test_wallets_list(self): } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567892", @@ -82,7 +82,7 @@ async def test_wallets_list(self): ) ), ] - mock_wallet_record.query = async_mock.AsyncMock() + mock_wallet_record.query = mock.AsyncMock() mock_wallet_record.query.return_value = [wallets[2], wallets[0], wallets[1]] await test_module.wallets_list(self.request) @@ -91,10 +91,10 @@ async def test_wallets_list(self): ) async def test_wallets_list_x(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True ) as mock_wallet_record: - mock_wallet_record.query = async_mock.AsyncMock() + mock_wallet_record.query = mock.AsyncMock() mock_wallet_record.query.side_effect = StorageError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -107,14 +107,14 @@ async def test_wallets_list_x(self): async def test_wallets_list_query(self): self.request.query = {"wallet_name": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module, "WalletRecord", autospec=True - ) as mock_wallet_record, async_mock.patch.object( + ) as mock_wallet_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: wallets = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "wallet_id", "created_at": "1234567890", @@ -123,7 +123,7 @@ async def test_wallets_list_query(self): ) ), ] - mock_wallet_record.query = async_mock.AsyncMock() + mock_wallet_record.query = mock.AsyncMock() mock_wallet_record.query.return_value = wallets await test_module.wallets_list(self.request) @@ -154,11 +154,11 @@ async def test_wallet_create_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test", "settings": {}, @@ -166,11 +166,11 @@ async def test_wallet_create_tenant_settings(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( return_value="test_token" ) print(self.request["context"]) @@ -206,11 +206,11 @@ async def test_wallet_create(self): "wallet_webhook_urls": [], "wallet_dispatch_type": "base", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test", "settings": {}, @@ -218,11 +218,11 @@ async def test_wallet_create(self): } ) ) # wallet_record - self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( return_value=wallet_mock ) - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( return_value="test_token" ) print(self.request["context"]) @@ -247,7 +247,7 @@ async def test_wallet_create(self): async def test_wallet_create_x(self): body = {} - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) self.mock_multitenant_mgr.create_wallet.side_effect = MultitenantManagerError() with self.assertRaises(test_module.web.HTTPBadRequest): @@ -270,11 +270,13 @@ async def test_wallet_create_optional_default_fields(self): "label": "my_test_label", "image_url": "https://image.com", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock() + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + return_value=mock.MagicMock() + ) + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -297,11 +299,13 @@ async def test_wallet_create_raw_key_derivation(self): "wallet_key": "test", "wallet_key_derivation": "RAW", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.create_wallet = async_mock.AsyncMock() - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock() + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.create_wallet = mock.AsyncMock( + return_value=mock.MagicMock() + ) + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock() await test_module.wallet_create(self.request) self.mock_multitenant_mgr.create_wallet.assert_called_once_with( @@ -329,9 +333,9 @@ async def test_wallet_update_tenant_settings(self): "ACAPY_PUBLIC_INVITES": True, }, } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": body["wallet_webhook_urls"], "wallet.dispatch_type": body["wallet_dispatch_type"], @@ -341,15 +345,15 @@ async def test_wallet_update_tenant_settings(self): "debug.invite_public": True, "public_invites": True, } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( return_value=wallet_mock ) @@ -371,24 +375,24 @@ async def test_wallet_update(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": body["wallet_webhook_urls"], "wallet.dispatch_type": body["wallet_dispatch_type"], "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( return_value=wallet_mock ) @@ -408,22 +412,22 @@ async def test_wallet_update_no_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( return_value=wallet_mock ) @@ -444,24 +448,24 @@ async def test_wallet_update_empty_wallet_webhook_urls(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: settings = { "wallet.webhook_urls": [], "wallet.dispatch_type": "base", "default_label": body["label"], "image_url": body["image_url"], } - wallet_mock = async_mock.MagicMock( - serialize=async_mock.MagicMock( + wallet_mock = mock.MagicMock( + serialize=mock.MagicMock( return_value={ "wallet_id": "test-wallet-id", "settings": settings, } ) ) - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( return_value=wallet_mock ) @@ -482,10 +486,10 @@ async def test_wallet_update_wallet_settings_x(self): "label": "test-label", "image_url": "test-image-url", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + with mock.patch.object(test_module.web, "json_response") as mock_response: + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( side_effect=test_module.WalletSettingsError("bad settings") ) @@ -496,7 +500,7 @@ async def test_wallet_update_wallet_settings_x(self): async def test_wallet_update_no_params(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {} - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_update(self.request) @@ -504,8 +508,8 @@ async def test_wallet_update_no_params(self): async def test_wallet_update_not_found(self): self.request.match_info = {"wallet_id": "test-wallet-id"} body = {"label": "test-label"} - self.request.json = async_mock.AsyncMock(return_value=body) - self.mock_multitenant_mgr.update_wallet = async_mock.AsyncMock( + self.request.json = mock.AsyncMock(return_value=body) + self.mock_multitenant_mgr.update_wallet = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -514,14 +518,14 @@ async def test_wallet_update_not_found(self): async def test_wallet_get(self): self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -534,8 +538,8 @@ async def test_wallet_get(self): async def test_wallet_get_not_found(self): self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.side_effect = StorageNotFoundError() @@ -544,13 +548,13 @@ async def test_wallet_get_not_found(self): async def test_wallet_get_x(self): self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -560,19 +564,19 @@ async def test_wallet_get_x(self): async def test_wallet_create_token_managed(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( return_value="test_token" ) @@ -585,22 +589,20 @@ async def test_wallet_create_token_managed(self): async def test_wallet_create_token_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.AsyncMock( - return_value={"wallet_key": "dummy_key"} - ) - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_wallet_record_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_wallet_record_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record - self.mock_multitenant_mgr.create_auth_token = async_mock.AsyncMock( + self.mock_multitenant_mgr.create_auth_token = mock.AsyncMock( return_value="test_token" ) @@ -613,17 +615,15 @@ async def test_wallet_create_token_unmanaged(self): async def test_wallet_create_token_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.AsyncMock( - return_value={"wallet_key": "dummy_key"} - ) - mock_wallet_record = async_mock.MagicMock() - mock_wallet_record.serialize = async_mock.MagicMock( + self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) + mock_wallet_record = mock.MagicMock() + mock_wallet_record.serialize = mock.MagicMock( return_value={"settings": {}, "wallet_id": "dummy"} ) mock_wallet_record.requires_external_key = False - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -634,10 +634,10 @@ async def test_wallet_create_token_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: - mock_wallet_record_retrieve_by_id.return_value = async_mock.MagicMock() + mock_wallet_record_retrieve_by_id.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPUnauthorized): mock_wallet_record_retrieve_by_id.side_effect = ( @@ -655,12 +655,12 @@ async def test_wallet_remove_managed(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() await test_module.wallet_remove(self.request) @@ -671,16 +671,14 @@ async def test_wallet_remove_managed(self): async def test_wallet_remove_unmanaged(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.AsyncMock( - return_value={"wallet_key": "dummy_key"} - ) + self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ): - self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() await test_module.wallet_remove(self.request) @@ -691,15 +689,13 @@ async def test_wallet_remove_unmanaged(self): async def test_wallet_remove_managed_wallet_key_provided_throws(self): self.request.match_info = {"wallet_id": "dummy"} - self.request.json = async_mock.AsyncMock( - return_value={"wallet_key": "dummy_key"} - ) + self.request.json = mock.AsyncMock(return_value={"wallet_key": "dummy_key"}) - mock_wallet_record = async_mock.MagicMock() + mock_wallet_record = mock.MagicMock() mock_wallet_record.requires_external_key = False - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_wallet_record_retrieve_by_id: mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record @@ -710,10 +706,10 @@ async def test_wallet_remove_x(self): self.request.has_body = False self.request.match_info = {"wallet_id": "dummy"} - self.mock_multitenant_mgr.remove_wallet = async_mock.AsyncMock() + self.mock_multitenant_mgr.remove_wallet = mock.AsyncMock() - with async_mock.patch.object( - test_module.WalletRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.WalletRecord, "retrieve_by_id", mock.AsyncMock() ): with self.assertRaises(test_module.web.HTTPUnauthorized): self.mock_multitenant_mgr.remove_wallet.side_effect = ( @@ -728,13 +724,13 @@ async def test_wallet_remove_x(self): await test_module.wallet_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] From 8b77dfa2408824993765b0afe1bd97bd24be0700 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Wed, 25 Oct 2023 18:25:15 -0400 Subject: [PATCH 03/33] fix: conn v1 manager mock issues Signed-off-by: Daniel Bluhm --- .../protocols/connections/v1_0/tests/test_manager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 134a0b0170..8623ac015f 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -130,8 +130,8 @@ async def test_create_invitation_non_multi_use_invitation_fails_on_reuse(self): ) # requestB fails because the invitation was not set to multi-use - rr_awaitable = self.manager.receive_request(requestB, receipt) - await self.assertAsyncRaises(ConnectionManagerError, rr_awaitable) + with self.assertRaises(ConnectionManagerError): + await self.manager.receive_request(requestB, receipt) async def test_create_invitation_public(self): self.context.update_settings({"public_invites": True}) From 6d102c0773340459c4f4d32440edd65e342a6391 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 20:48:35 -0400 Subject: [PATCH 04/33] chore: normalize references to mock, replace async_mock Signed-off-by: Daniel Bluhm --- .../admin/tests/test_admin_server.py | 104 +- .../askar/didcomm/tests/test_v2.py | 18 +- aries_cloudagent/commands/tests/test_help.py | 14 +- aries_cloudagent/commands/tests/test_init.py | 10 +- .../commands/tests/test_provision.py | 26 +- aries_cloudagent/commands/tests/test_start.py | 54 +- .../commands/tests/test_upgrade.py | 182 +-- .../config/tests/test_argparse.py | 14 +- aries_cloudagent/config/tests/test_ledger.py | 208 ++- aries_cloudagent/config/tests/test_logging.py | 38 +- .../config/tests/test_provider.py | 4 +- aries_cloudagent/config/tests/test_wallet.py | 172 +-- .../connections/tests/test_base_manager.py | 328 ++-- aries_cloudagent/core/tests/test_conductor.py | 648 ++++---- .../core/tests/test_dispatcher.py | 134 +- aries_cloudagent/core/tests/test_event_bus.py | 8 +- .../core/tests/test_oob_processor.py | 174 ++- .../core/tests/test_plugin_registry.py | 226 +-- .../core/tests/test_protocol_registry.py | 40 +- aries_cloudagent/holder/tests/test_routes.py | 150 +- .../indy/credx/tests/test_cred_issuance.py | 14 +- .../indy/models/tests/test_pres_preview.py | 16 +- .../indy/sdk/tests/test_holder.py | 102 +- .../indy/sdk/tests/test_issuer.py | 46 +- .../indy/sdk/tests/test_profile.py | 18 +- aries_cloudagent/indy/sdk/tests/test_util.py | 6 +- .../indy/sdk/tests/test_verifier.py | 58 +- .../indy/sdk/tests/test_wallet_plugin.py | 68 +- aries_cloudagent/indy/tests/test_verifier.py | 28 +- .../tests/test_indy_ledger_requests.py | 16 +- .../tests/test_indy_manager.py | 194 +-- .../tests/test_indy_vdr_manager.py | 220 ++- .../tests/test_manager_provider.py | 4 +- aries_cloudagent/ledger/tests/test_indy.py | 1356 ++++++++--------- .../ledger/tests/test_indy_vdr.py | 74 +- aries_cloudagent/ledger/tests/test_routes.py | 278 ++-- .../tests/test_routes.py | 138 +- .../messaging/jsonld/tests/test_credential.py | 4 +- .../messaging/jsonld/tests/test_routes.py | 106 +- .../messaging/models/tests/test_base.py | 12 +- .../models/tests/test_base_record.py | 48 +- .../messaging/schemas/tests/test_routes.py | 152 +- .../tests/test_askar_profile_manager.py | 18 +- .../multitenant/tests/test_base.py | 86 +- .../multitenant/tests/test_manager.py | 20 +- .../v1_0/handlers/tests/test_menu_handler.py | 6 +- .../tests/test_menu_request_handler.py | 14 +- .../handlers/tests/test_perform_handler.py | 16 +- .../actionmenu/v1_0/tests/test_controller.py | 6 +- .../actionmenu/v1_0/tests/test_routes.py | 130 +- .../actionmenu/v1_0/tests/test_service.py | 6 +- .../basicmessage/v1_0/tests/test_routes.py | 38 +- .../handlers/tests/test_request_handler.py | 54 +- .../handlers/tests/test_response_handler.py | 30 +- .../connections/v1_0/tests/test_manager.py | 458 +++--- .../connections/v1_0/tests/test_routes.py | 364 +++-- .../test_keylist_update_response_handler.py | 8 +- .../tests/test_mediation_grant_handler.py | 26 +- .../v1_0/tests/test_mediation_invite_store.py | 4 +- .../v1_0/tests/test_mediation_manager.py | 24 +- .../v1_0/tests/test_routes.py | 340 ++--- .../handlers/tests/test_complete_handler.py | 14 +- .../tests/test_problem_report_handler.py | 18 +- .../handlers/tests/test_request_handler.py | 46 +- .../handlers/tests/test_response_handler.py | 30 +- .../didexchange/v1_0/tests/test_manager.py | 1218 +++++++-------- .../didexchange/v1_0/tests/test_routes.py | 158 +- .../handlers/tests/test_disclose_handler.py | 8 +- .../v1_0/handlers/tests/test_query_handler.py | 10 +- .../v1_0/models/tests/test_record.py | 10 +- .../discovery/v1_0/tests/test_manager.py | 86 +- .../discovery/v1_0/tests/test_routes.py | 48 +- .../tests/test_disclosures_handler.py | 24 +- .../handlers/tests/test_queries_handler.py | 10 +- .../v2_0/models/tests/test_record.py | 10 +- .../discovery/v2_0/tests/test_manager.py | 98 +- .../discovery/v2_0/tests/test_routes.py | 48 +- ...t_endorsed_transaction_response_handler.py | 20 +- ...st_refused_transaction_response_handler.py | 20 +- ...est_transaction_acknowledgement_handler.py | 16 +- .../tests/test_transaction_cancel_handler.py | 22 +- .../test_transaction_job_to_send_handler.py | 16 +- .../tests/test_transaction_request_handler.py | 16 +- .../tests/test_transaction_resend_handler.py | 22 +- .../v1_0/tests/test_manager.py | 116 +- .../v1_0/tests/test_routes.py | 1004 ++++++------ .../tests/test_forward_invitation_handler.py | 10 +- .../handlers/tests/test_invitation_handler.py | 14 +- .../tests/test_invitation_request_handler.py | 10 +- .../introduction/v0_1/tests/test_routes.py | 46 +- .../tests/test_credential_ack_handler.py | 28 +- .../tests/test_credential_issue_handler.py | 84 +- .../tests/test_credential_offer_handler.py | 68 +- .../test_credential_problem_report_handler.py | 16 +- .../tests/test_credential_proposal_handler.py | 46 +- .../tests/test_credential_request_handler.py | 92 +- .../models/tests/test_credential_exchange.py | 10 +- .../v1_0/tests/test_manager.py | 344 ++--- .../v1_0/tests/test_routes.py | 774 +++++----- .../v2_0/formats/indy/tests/test_handler.py | 214 ++- .../formats/ld_proof/tests/test_handler.py | 124 +- .../handlers/tests/test_cred_ack_handler.py | 24 +- .../handlers/tests/test_cred_issue_handler.py | 64 +- .../handlers/tests/test_cred_offer_handler.py | 64 +- .../tests/test_cred_problem_report_handler.py | 16 +- .../tests/test_cred_proposal_handler.py | 46 +- .../tests/test_cred_request_handler.py | 72 +- .../v2_0/messages/tests/test_cred_ack.py | 10 +- .../v2_0/messages/tests/test_cred_issue.py | 6 +- .../v2_0/models/tests/test_cred_ex_record.py | 10 +- .../v2_0/tests/test_manager.py | 220 ++- .../v2_0/tests/test_routes.py | 890 ++++++----- .../v1_0/handlers/tests/test_ack_handler.py | 4 +- .../tests/test_problem_report_handler.py | 14 +- .../tests/test_reuse_accept_handler.py | 14 +- .../v1_0/handlers/tests/test_reuse_handler.py | 14 +- .../out_of_band/v1_0/tests/test_manager.py | 316 ++-- .../out_of_band/v1_0/tests/test_routes.py | 84 +- .../dif/tests/test_pres_exch_handler.py | 164 +- .../tests/test_presentation_ack_handler.py | 24 +- .../tests/test_presentation_handler.py | 58 +- ...est_presentation_problem_report_handler.py | 14 +- .../test_presentation_proposal_handler.py | 46 +- .../test_presentation_request_handler.py | 256 ++-- .../v1_0/models/tests/test_record.py | 10 +- .../present_proof/v1_0/tests/test_manager.py | 242 ++- .../present_proof/v1_0/tests/test_routes.py | 654 ++++---- .../v2_0/formats/dif/tests/test_handler.py | 152 +- .../handlers/tests/test_pres_ack_handler.py | 24 +- .../v2_0/handlers/tests/test_pres_handler.py | 58 +- .../tests/test_pres_problem_report_handler.py | 14 +- .../tests/test_pres_proposal_handler.py | 46 +- .../tests/test_pres_request_handler.py | 274 ++-- .../v2_0/models/tests/test_record.py | 10 +- .../present_proof/v2_0/tests/test_manager.py | 358 +++-- .../present_proof/v2_0/tests/test_routes.py | 954 ++++++------ .../handlers/tests/test_forward_handler.py | 28 +- .../v1_0/tests/test_routing_manager.py | 10 +- .../trustping/v1_0/tests/test_routes.py | 58 +- .../resolver/default/tests/test_indy.py | 28 +- .../default/tests/test_legacy_peer.py | 46 +- .../resolver/default/tests/test_universal.py | 30 +- aries_cloudagent/resolver/tests/test_base.py | 4 +- .../resolver/tests/test_routes.py | 44 +- .../tests/test_issuer_rev_reg_record.py | 52 +- .../models/tests/test_revocation_registry.py | 54 +- .../revocation/tests/test_indy.py | 44 +- .../revocation/tests/test_manager.py | 182 ++- .../revocation/tests/test_routes.py | 418 +++-- .../settings/tests/test_routes.py | 32 +- .../storage/tests/test_askar_storage.py | 92 +- .../storage/tests/test_in_memory_storage.py | 10 +- .../storage/tests/test_indy_storage.py | 174 +-- .../vc_holder/tests/test_indy_vc_holder.py | 4 +- aries_cloudagent/tails/tests/test_indy.py | 30 +- .../inbound/tests/test_http_transport.py | 40 +- .../transport/inbound/tests/test_manager.py | 38 +- .../transport/inbound/tests/test_session.py | 72 +- .../inbound/tests/test_ws_transport.py | 10 +- .../outbound/tests/test_http_transport.py | 14 +- .../transport/outbound/tests/test_manager.py | 146 +- .../transport/queue/tests/test_basic_queue.py | 58 +- .../transport/tests/test_pack_format.py | 26 +- .../transport/tests/test_stats.py | 8 +- .../utils/tests/test_task_queue.py | 14 +- .../crypto/tests/test_wallet_key_pair.py | 12 +- .../test_authentication_proof_purpose.py | 36 +- .../tests/test_controller_proof_purpose.py | 22 +- .../tests/test_credential_issuance_purpose.py | 36 +- .../purposes/tests/test_proof_purpose.py | 28 +- .../tests/test_bbs_bls_signature_2020.py | 10 +- .../test_bbs_bls_signature_proof_2020.py | 8 +- aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py | 18 +- .../wallet/tests/test_indy_wallet.py | 292 ++-- aries_cloudagent/wallet/tests/test_routes.py | 292 ++-- 175 files changed, 9582 insertions(+), 10290 deletions(-) diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index c3887ad61c..4202005c0c 100644 --- a/aries_cloudagent/admin/tests/test_admin_server.py +++ b/aries_cloudagent/admin/tests/test_admin_server.py @@ -1,7 +1,7 @@ import json import pytest -import mock as async_mock +import mock from unittest import IsolatedAsyncioTestCase from aiohttp import ClientSession, DummyCookieJar, TCPConnector, web from aiohttp.test_utils import unused_port @@ -36,37 +36,33 @@ async def asyncTearDown(self): self.client_session = None async def test_debug_middleware(self): - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger: - mock_logger.isEnabledFor = async_mock.MagicMock(return_value=True) - mock_logger.debug = async_mock.MagicMock() + with mock.patch.object(test_module, "LOGGER", mock.MagicMock()) as mock_logger: + mock_logger.isEnabledFor = mock.MagicMock(return_value=True) + mock_logger.debug = mock.MagicMock() - request = async_mock.MagicMock( + request = mock.MagicMock( method="GET", path_qs="/hello/world?a=1&b=2", match_info={"match": "info"}, - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) - handler = async_mock.AsyncMock() + handler = mock.AsyncMock() await test_module.debug_middleware(request, handler) mock_logger.isEnabledFor.assert_called_once() assert mock_logger.debug.call_count == 3 async def test_ready_middleware(self): - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger: - mock_logger.isEnabledFor = async_mock.MagicMock(return_value=True) - mock_logger.debug = async_mock.MagicMock() - mock_logger.info = async_mock.MagicMock() - mock_logger.error = async_mock.MagicMock() - - request = async_mock.MagicMock( - rel_url="/", app=async_mock.MagicMock(_state={"ready": False}) + with mock.patch.object(test_module, "LOGGER", mock.MagicMock()) as mock_logger: + mock_logger.isEnabledFor = mock.MagicMock(return_value=True) + mock_logger.debug = mock.MagicMock() + mock_logger.info = mock.MagicMock() + mock_logger.error = mock.MagicMock() + + request = mock.MagicMock( + rel_url="/", app=mock.MagicMock(_state={"ready": False}) ) - handler = async_mock.AsyncMock(return_value="OK") + handler = mock.AsyncMock(return_value="OK") with self.assertRaises(test_module.web.HTTPServiceUnavailable): await test_module.ready_middleware(request, handler) @@ -74,28 +70,28 @@ async def test_ready_middleware(self): assert await test_module.ready_middleware(request, handler) == "OK" request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.AsyncMock( side_effect=test_module.LedgerConfigError("Bad config") ) with self.assertRaises(test_module.LedgerConfigError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.AsyncMock( side_effect=test_module.web.HTTPFound(location="/api/doc") ) with self.assertRaises(test_module.web.HTTPFound): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock( + handler = mock.AsyncMock( side_effect=test_module.asyncio.CancelledError("Cancelled") ) with self.assertRaises(test_module.asyncio.CancelledError): await test_module.ready_middleware(request, handler) request.app._state["ready"] = True - handler = async_mock.AsyncMock(side_effect=KeyError("No such thing")) + handler = mock.AsyncMock(side_effect=KeyError("No such thing")) with self.assertRaises(KeyError): await test_module.ready_middleware(request, handler) @@ -110,10 +106,8 @@ def get_admin_server( # middleware is task queue xor collector: cover both over test suite task_queue = (settings or {}).pop("task_queue", None) - plugin_registry = async_mock.MagicMock( - test_module.PluginRegistry, autospec=True - ) - plugin_registry.post_process_routes = async_mock.MagicMock() + plugin_registry = mock.MagicMock(test_module.PluginRegistry, autospec=True) + plugin_registry.post_process_routes = mock.MagicMock() context.injector.bind_instance(test_module.PluginRegistry, plugin_registry) collector = Collector() @@ -129,10 +123,10 @@ def get_admin_server( profile, self.outbound_message_router, self.webhook_router, - conductor_stop=async_mock.AsyncMock(), + conductor_stop=mock.AsyncMock(), task_queue=TaskQueue(max_active=4) if task_queue else None, conductor_stats=( - None if task_queue else async_mock.AsyncMock(return_value={"a": 1}) + None if task_queue else mock.AsyncMock(return_value={"a": 1}) ), ) @@ -165,17 +159,15 @@ async def test_start_stop(self): server = self.get_admin_server(settings) await server.start() assert server.app._client_max_size == 4 * 1024 * 1024 - with async_mock.patch.object( - server, "websocket_queues", async_mock.MagicMock() + with mock.patch.object( + server, "websocket_queues", mock.MagicMock() ) as mock_wsq: - mock_wsq.values = async_mock.MagicMock( - return_value=[async_mock.MagicMock(stop=async_mock.MagicMock())] + mock_wsq.values = mock.MagicMock( + return_value=[mock.MagicMock(stop=mock.MagicMock())] ) await server.stop() - with async_mock.patch.object( - web.TCPSite, "start", async_mock.AsyncMock() - ) as mock_start: + with mock.patch.object(web.TCPSite, "start", mock.AsyncMock()) as mock_start: mock_start.side_effect = OSError("Failure to launch") with self.assertRaises(AdminSetupError): await self.get_admin_server(settings).start() @@ -199,7 +191,7 @@ async def test_import_routes_multitenant_middleware(self): context.injector.bind_instance(GoalCodeRegistry, GoalCodeRegistry()) context.injector.bind_instance( test_module.BaseMultitenantManager, - async_mock.MagicMock(spec=test_module.BaseMultitenantManager), + mock.MagicMock(spec=test_module.BaseMultitenantManager), ) await DefaultContextBuilder().load_plugins(context) server = self.get_admin_server( @@ -220,66 +212,66 @@ async def test_import_routes_multitenant_middleware(self): m for m in app.middlewares if ".check_multitenant_authorization" in str(m) ] - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/multitenancy/etc", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await mt_authz_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.AsyncMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.called_once_with(mock_request) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Non-bearer ..."}, path="/test", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) - mock_handler = async_mock.AsyncMock() + mock_handler = mock.AsyncMock() await mt_authz_middle(mock_request, mock_handler) assert mock_handler.called_once_with(mock_request) # multitenant setup context exception paths [setup_ctx_middle] = [m for m in app.middlewares if ".setup_context" in str(m)] - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Non-bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) with self.assertRaises(test_module.web.HTTPUnauthorized): await setup_ctx_middle(mock_request, None) - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( method="GET", headers={"Authorization": "Bearer ..."}, path="/protected/non-multitenancy/non-server", - text=async_mock.AsyncMock(return_value="abc123"), + text=mock.AsyncMock(return_value="abc123"), ) - with async_mock.patch.object( + with mock.patch.object( server.multitenant_manager, "get_profile_for_token", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_get_profile: mock_get_profile.side_effect = [ test_module.MultitenantManagerError("corrupt token"), @@ -493,8 +485,8 @@ async def server(): ) async def test_on_record_event(server, event_topic, webhook_topic): profile = InMemoryProfile.test_profile() - with async_mock.patch.object( - server, "send_webhook", async_mock.AsyncMock() + with mock.patch.object( + server, "send_webhook", mock.AsyncMock() ) as mock_send_webhook: await server._on_record_event(profile, Event(event_topic, None)) mock_send_webhook.assert_called_once_with(profile, webhook_topic, None) diff --git a/aries_cloudagent/askar/didcomm/tests/test_v2.py b/aries_cloudagent/askar/didcomm/tests/test_v2.py index 90706aad9c..ec3fa53dba 100644 --- a/aries_cloudagent/askar/didcomm/tests/test_v2.py +++ b/aries_cloudagent/askar/didcomm/tests/test_v2.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock import pytest from aries_askar import AskarError, Key, KeyAlg, Session @@ -70,9 +70,9 @@ async def test_es_encrypt_x(self, session: Session): ): _ = test_module.ecdh_es_encrypt({}, MESSAGE) - with async_mock.patch( + with mock.patch( "aries_askar.Key.generate", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -80,9 +80,9 @@ async def test_es_encrypt_x(self, session: Session): ): _ = test_module.ecdh_es_encrypt({BOB_KID: bob_pk}, MESSAGE) - with async_mock.patch( + with mock.patch( "aries_askar.Key.aead_encrypt", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -188,9 +188,9 @@ async def test_1pu_encrypt_x(self, session: Session): {BOB_KID: bob_pk, "alt": alt_pk}, ALICE_KID, alice_sk, MESSAGE ) - with async_mock.patch( + with mock.patch( "aries_askar.Key.generate", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, @@ -200,9 +200,9 @@ async def test_1pu_encrypt_x(self, session: Session): {BOB_KID: bob_pk}, ALICE_KID, alice_sk, MESSAGE ) - with async_mock.patch( + with mock.patch( "aries_askar.Key.aead_encrypt", - async_mock.MagicMock(side_effect=AskarError(99, "")), + mock.MagicMock(side_effect=AskarError(99, "")), ): with pytest.raises( test_module.DidcommEnvelopeError, diff --git a/aries_cloudagent/commands/tests/test_help.py b/aries_cloudagent/commands/tests/test_help.py index 53a4501fbd..b94906795e 100644 --- a/aries_cloudagent/commands/tests/test_help.py +++ b/aries_cloudagent/commands/tests/test_help.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import help as command @@ -6,10 +6,10 @@ class TestHelp(IsolatedAsyncioTestCase): def test_exec_help(self): - with async_mock.patch.object( + with mock.patch.object( command.ArgumentParser, "print_help" - ) as mock_print_help, async_mock.patch( - "builtins.print", async_mock.MagicMock() + ) as mock_print_help, mock.patch( + "builtins.print", mock.MagicMock() ) as mock_print: command.execute([]) mock_print_help.assert_called_once() @@ -18,10 +18,10 @@ def test_exec_help(self): mock_print.assert_called_once_with(command.__version__) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( command, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - command, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + command, "execute", mock.MagicMock() ) as mock_execute: command.main() mock_execute.assert_called_once diff --git a/aries_cloudagent/commands/tests/test_init.py b/aries_cloudagent/commands/tests/test_init.py index c9d3cde8cc..0944977dff 100644 --- a/aries_cloudagent/commands/tests/test_init.py +++ b/aries_cloudagent/commands/tests/test_init.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ... import commands as test_module @@ -10,11 +10,11 @@ def test_available(self): assert len(avail) == 4 def test_run(self): - with async_mock.patch.object( - test_module, "load_command", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_command", mock.MagicMock() ) as mock_load: - mock_module = async_mock.MagicMock() - mock_module.execute = async_mock.MagicMock() + mock_module = mock.MagicMock() + mock_module.execute = mock.MagicMock() mock_load.return_value = mock_module test_module.run_command("hello", ["world"]) diff --git a/aries_cloudagent/commands/tests/test_provision.py b/aries_cloudagent/commands/tests/test_provision.py index 3664186bd8..aef197dd72 100644 --- a/aries_cloudagent/commands/tests/test_provision.py +++ b/aries_cloudagent/commands/tests/test_provision.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.base import ConfigError @@ -40,34 +40,34 @@ def test_provision_wallet(self): ) async def test_provision_ledger_configured(self): - profile = async_mock.MagicMock(close=async_mock.AsyncMock()) - with async_mock.patch.object( + profile = mock.MagicMock(close=mock.AsyncMock()) + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ) as mock_wallet_config, async_mock.patch.object( - test_module, "ledger_config", async_mock.AsyncMock(return_value=True) + ) as mock_wallet_config, mock.patch.object( + test_module, "ledger_config", mock.AsyncMock(return_value=True) ) as mock_ledger_config: await test_module.provision({}) async def test_provision_config_x(self): - with async_mock.patch.object( - test_module, "wallet_config", async_mock.AsyncMock() + with mock.patch.object( + test_module, "wallet_config", mock.AsyncMock() ) as mock_wallet_config: mock_wallet_config.side_effect = ConfigError("oops") with self.assertRaises(test_module.ProvisionError): await test_module.provision({}) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once @@ -76,7 +76,7 @@ async def test_provision_should_store_provided_mediation_invite(self): # given mediation_invite = "test-invite" - with async_mock.patch.object( + with mock.patch.object( test_module.MediationInviteStore, "store" ) as invite_store: # when diff --git a/aries_cloudagent/commands/tests/test_start.py b/aries_cloudagent/commands/tests/test_start.py index 1d763dd8a7..5e1464225d 100644 --- a/aries_cloudagent/commands/tests/test_start.py +++ b/aries_cloudagent/commands/tests/test_start.py @@ -1,6 +1,6 @@ import sys -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.error import ArgsParseError @@ -17,25 +17,25 @@ def test_bad_args(self): test_module.execute(["bad"]) async def test_start_shutdown_app(self): - mock_conductor = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(), - stop=async_mock.AsyncMock(), + mock_conductor = mock.MagicMock( + setup=mock.AsyncMock(), + start=mock.AsyncMock(), + stop=mock.AsyncMock(), ) await test_module.start_app(mock_conductor) await test_module.shutdown_app(mock_conductor) def test_exec_start(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "start_app", autospec=True - ) as start_app, async_mock.patch.object( + ) as start_app, mock.patch.object( test_module, "run_loop" - ) as run_loop, async_mock.patch.object( + ) as run_loop, mock.patch.object( test_module, "shutdown_app", autospec=True - ) as shutdown_app, async_mock.patch.object( - test_module, "uvloop", async_mock.MagicMock() + ) as shutdown_app, mock.patch.object( + test_module, "uvloop", mock.MagicMock() ) as mock_uvloop: - mock_uvloop.install = async_mock.MagicMock() + mock_uvloop.install = mock.MagicMock() test_module.execute( [ "-it", @@ -57,13 +57,11 @@ def test_exec_start(self): run_loop.assert_called_once() async def test_run_loop(self): - startup = async_mock.AsyncMock() + startup = mock.AsyncMock() startup_call = startup() - shutdown = async_mock.AsyncMock() + shutdown = mock.AsyncMock() shutdown_call = shutdown() - with async_mock.patch.object( - test_module, "asyncio", autospec=True - ) as mock_asyncio: + with mock.patch.object(test_module, "asyncio", autospec=True) as mock_asyncio: test_module.run_loop(startup_call, shutdown_call) mock_add = mock_asyncio.get_event_loop.return_value.add_signal_handler mock_add.assert_called_once() @@ -78,10 +76,10 @@ async def test_run_loop(self): done_calls[0][1]() # exec partial done_coro = mock_asyncio.ensure_future.call_args[0][0] tasks = [ - async_mock.MagicMock(), - async_mock.MagicMock(cancel=async_mock.MagicMock()), + mock.MagicMock(), + mock.MagicMock(cancel=mock.MagicMock()), ] - mock_asyncio.gather = async_mock.AsyncMock() + mock_asyncio.gather = mock.AsyncMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = tasks @@ -94,13 +92,13 @@ async def test_run_loop(self): shutdown.assert_awaited_once() async def test_run_loop_init_x(self): - startup = async_mock.AsyncMock(side_effect=KeyError("the front fell off")) + startup = mock.AsyncMock(side_effect=KeyError("the front fell off")) startup_call = startup() - shutdown = async_mock.AsyncMock() + shutdown = mock.AsyncMock() shutdown_call = shutdown() - with async_mock.patch.object( + with mock.patch.object( test_module, "asyncio", autospec=True - ) as mock_asyncio, async_mock.patch.object( + ) as mock_asyncio, mock.patch.object( test_module, "LOGGER", autospec=True ) as mock_logger: test_module.run_loop(startup_call, shutdown_call) @@ -116,8 +114,8 @@ async def test_run_loop_init_x(self): ) done_calls[0][1]() # exec partial done_coro = mock_asyncio.ensure_future.call_args[0][0] - task = async_mock.MagicMock() - mock_asyncio.gather = async_mock.AsyncMock() + task = mock.MagicMock() + mock_asyncio.gather = mock.AsyncMock() if sys.version_info.major == 3 and sys.version_info.minor > 6: mock_asyncio.all_tasks.return_value = [task] @@ -131,10 +129,10 @@ async def test_run_loop_init_x(self): mock_logger.exception.assert_called_once() def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once diff --git a/aries_cloudagent/commands/tests/test_upgrade.py b/aries_cloudagent/commands/tests/test_upgrade.py index bde77c2c61..45b6b206fa 100644 --- a/aries_cloudagent/commands/tests/test_upgrade.py +++ b/aries_cloudagent/commands/tests/test_upgrade.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -52,21 +52,21 @@ def test_bad_calls(self): test_module.execute(["bad"]) async def test_upgrade_storage_from_version_included(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): await test_module.upgrade( settings={ @@ -76,21 +76,21 @@ async def test_upgrade_storage_from_version_included(self): ) async def test_upgrade_storage_missing_from_version(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): await test_module.upgrade(settings={}) @@ -100,11 +100,11 @@ async def test_upgrade_from_version(self): "upgrade.from_version": "v0.7.2", } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -118,11 +118,11 @@ async def test_upgrade_all_subwallets(self): "upgrade.page_size": 1, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -140,11 +140,11 @@ async def test_upgrade_specified_subwallets(self): "upgrade.force_upgrade": True, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -157,11 +157,11 @@ async def test_upgrade_specified_subwallets(self): "upgrade.page_size": 1, } ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object(ConnRecord, "save", async_mock.AsyncMock()): + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object(ConnRecord, "save", mock.AsyncMock()): await test_module.upgrade( profile=self.profile, ) @@ -171,19 +171,19 @@ async def test_upgrade_callable(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -207,19 +207,19 @@ async def test_upgrade_callable_named_tag(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -245,13 +245,13 @@ async def test_upgrade_x_same_version(self): type_filter="acapy_version", tag_query={} ) await self.storage.update_record(version_storage_record, f"v{__version__}", {}) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), ): @@ -266,21 +266,21 @@ async def test_upgrade_missing_from_version(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade( @@ -297,19 +297,19 @@ async def test_upgrade_x_callable_not_set(self): type_filter="acapy_version", tag_query={} ) await self.storage.delete_record(version_storage_record) - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -332,19 +332,19 @@ async def test_upgrade_x_callable_not_set(self): assert "No function specified for" in str(ctx.exception) async def test_upgrade_x_class_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -365,26 +365,26 @@ async def test_upgrade_x_class_not_found(self): assert "Unknown Record type" in str(ctx.exception) async def test_execute(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "query", - async_mock.AsyncMock(return_value=[ConnRecord()]), - ), async_mock.patch.object( - ConnRecord, "save", async_mock.AsyncMock() - ), async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + mock.AsyncMock(return_value=[ConnRecord()]), + ), mock.patch.object( + ConnRecord, "save", mock.AsyncMock() + ), mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: - mock_get_event_loop.return_value = async_mock.MagicMock( - run_until_complete=async_mock.MagicMock(), + mock_get_event_loop.return_value = mock.MagicMock( + run_until_complete=mock.MagicMock(), ) test_module.execute( [ @@ -397,19 +397,19 @@ async def test_execute(self): ) async def test_upgrade_x_invalid_record_type(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -430,19 +430,19 @@ async def test_upgrade_x_invalid_record_type(self): assert "Only BaseRecord can be resaved" in str(ctx.exception) async def test_upgrade_force(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "wallet_config", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( self.profile, - async_mock.AsyncMock(did="public DID", verkey="verkey"), + mock.AsyncMock(did="public DID", verkey="verkey"), ) ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -487,10 +487,10 @@ async def test_add_version_record(self): assert version_storage_record.value == "v0.7.5" async def test_upgrade_x_invalid_config(self): - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock(return_value={}), + mock.MagicMock(return_value={}), ): with self.assertRaises(UpgradeError) as ctx: await test_module.upgrade(profile=self.profile) @@ -505,10 +505,10 @@ async def test_upgrade_x_params(self): assert "upgrade requires either profile or settings" in str(ctx.exception) def test_main(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "__name__", "__main__" - ) as mock_name, async_mock.patch.object( - test_module, "execute", async_mock.MagicMock() + ) as mock_name, mock.patch.object( + test_module, "execute", mock.MagicMock() ) as mock_execute: test_module.main() mock_execute.assert_called_once @@ -652,10 +652,10 @@ async def test_upgrade_explicit_check(self): "upgrade.from_version": "v0.7.0", } ) - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -681,10 +681,10 @@ async def test_upgrade_explicit_check(self): ctx.exception ) - with async_mock.patch.object( + with mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { @@ -711,12 +711,12 @@ async def test_upgrade_explicit_check(self): ctx.exception ) - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger, async_mock.patch.object( + with mock.patch.object( + test_module, "LOGGER", mock.MagicMock() + ) as mock_logger, mock.patch.object( test_module.yaml, "safe_load", - async_mock.MagicMock( + mock.MagicMock( return_value={ "v0.7.2": { "resave_records": { diff --git a/aries_cloudagent/config/tests/test_argparse.py b/aries_cloudagent/config/tests/test_argparse.py index a6f5b2c7f2..c110666606 100644 --- a/aries_cloudagent/config/tests/test_argparse.py +++ b/aries_cloudagent/config/tests/test_argparse.py @@ -1,6 +1,6 @@ from configargparse import ArgumentTypeError -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import argparse @@ -28,7 +28,7 @@ async def test_transport_settings(self): group = argparse.TransportGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -61,7 +61,7 @@ async def test_get_genesis_transactions_list_with_ledger_selection(self): group = argparse.LedgerGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -129,7 +129,7 @@ async def test_upgrade_config(self): group = argparse.UpgradeGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -250,7 +250,7 @@ async def test_general_settings_file(self): group = argparse.GeneralGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -305,7 +305,7 @@ async def test_transport_settings_file(self): group = argparse.TransportGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() @@ -596,7 +596,7 @@ async def test_discover_features_args(self): group = argparse.DiscoverFeaturesGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() diff --git a/aries_cloudagent/config/tests/test_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index 637044a1e0..515f1db52c 100644 --- a/aries_cloudagent/config/tests/test_ledger.py +++ b/aries_cloudagent/config/tests/test_ledger.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import argparse @@ -16,14 +16,12 @@ class TestLedgerConfig(IsolatedAsyncioTestCase): async def test_fetch_genesis_transactions(self): - with async_mock.patch.object( - test_module, "fetch", async_mock.AsyncMock() - ) as mock_fetch: + with mock.patch.object(test_module, "fetch", mock.AsyncMock()) as mock_fetch: await test_module.fetch_genesis_transactions("http://1.2.3.4:9000/genesis") async def test_fetch_genesis_transactions_x(self): - with async_mock.patch.object( - test_module, "fetch", async_mock.AsyncMock(return_value=TEST_GENESIS) + with mock.patch.object( + test_module, "fetch", mock.AsyncMock(return_value=TEST_GENESIS) ) as mock_fetch: mock_fetch.side_effect = test_module.FetchError("404 Not Found") with self.assertRaises(test_module.ConfigError): @@ -35,10 +33,10 @@ async def test_get_genesis_url(self): settings = { "ledger.genesis_url": "00000000000000000000000000000000", } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS), + mock.AsyncMock(return_value=TEST_GENESIS), ) as mock_fetch: await test_module.get_genesis_transactions(settings) self.assertEqual(settings["ledger.genesis_transactions"], TEST_GENESIS) @@ -47,11 +45,11 @@ async def test_get_genesis_file(self): settings = { "ledger.genesis_file": "/tmp/genesis/path", } - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS) + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS) ) ) ) @@ -63,7 +61,7 @@ async def test_get_genesis_file_io_x(self): "ledger.genesis_file": "/tmp/genesis/path", } - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.side_effect = IOError("no read permission") with self.assertRaises(test_module.ConfigError): await test_module.get_genesis_transactions(settings) @@ -73,8 +71,8 @@ async def test_ledger_config_no_taa_accept(self): "ledger.genesis_transactions": TEST_GENESIS, "default_endpoint": "http://1.2.3.4:8051", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -82,7 +80,7 @@ async def test_ledger_config_no_taa_accept(self): }, } ), - get_latest_txn_author_acceptance=async_mock.AsyncMock( + get_latest_txn_author_acceptance=mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), read_only=False, @@ -97,8 +95,8 @@ async def _get_session(): setattr(profile, "session", _get_session) session.context.injector.bind_instance(BaseLedger, mock_ledger) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = False assert not await test_module.ledger_config( @@ -109,8 +107,8 @@ async def test_accept_taa(self): settings = { "ledger.genesis_transactions": TEST_GENESIS, } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={ "taa_required": True, "taa_record": { @@ -118,13 +116,13 @@ async def test_accept_taa(self): }, } ), - get_latest_txn_author_acceptance=async_mock.AsyncMock( + get_latest_txn_author_acceptance=mock.AsyncMock( return_value={"digest": b"1234567890123456789012345678901234567890"} ), - update_endpoint_for_did=async_mock.AsyncMock(), + update_endpoint_for_did=mock.AsyncMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock(set_did_endpoint=async_mock.AsyncMock()) + mock_wallet = mock.MagicMock(set_did_endpoint=mock.AsyncMock()) session = InMemoryProfile.test_session(settings=settings) profile = session.profile @@ -136,8 +134,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: mock_accept_taa.return_value = True await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -147,13 +145,13 @@ async def test_ledger_config_read_only_skip_taa_accept(self): settings = { "ledger.genesis_transactions": TEST_GENESIS, } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock(), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock( + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock( side_effect=LedgerError( "Error cannot update endpoint when ledger is in read only mode" ) @@ -170,8 +168,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: with self.assertRaises(test_module.ConfigError) as x_context: await test_module.ledger_config(profile, TEST_DID, provision=True) @@ -184,13 +182,13 @@ async def test_ledger_config_read_only_skip_profile_endpoint_publish(self): "ledger.genesis_url": "00000000000000000000000000000000", "profile_endpoint": "http://agent.ca", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock(), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), read_only=True, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -203,8 +201,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config(profile, TEST_DID, provision=True) mock_ledger.get_txn_author_agreement.assert_not_called() @@ -217,16 +215,16 @@ async def test_ledger_config_read_write_skip_taa_endpoint_publish(self): "default_endpoint": "http://agent-default.ca", "profile_endpoint": "http://agent-profile.ca", } - mock_ledger = async_mock.MagicMock( - get_txn_author_agreement=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_txn_author_agreement=mock.AsyncMock( return_value={"taa_required": False} ), - get_latest_txn_author_acceptance=async_mock.AsyncMock(), - update_endpoint_for_did=async_mock.AsyncMock(), + get_latest_txn_author_acceptance=mock.AsyncMock(), + update_endpoint_for_did=mock.AsyncMock(), read_only=False, ) - mock_wallet = async_mock.MagicMock( - set_did_endpoint=async_mock.AsyncMock(), + mock_wallet = mock.MagicMock( + set_did_endpoint=mock.AsyncMock(), ) session = InMemoryProfile.test_session(settings=settings) @@ -239,8 +237,8 @@ async def _get_session(): session.context.injector.bind_instance(BaseLedger, mock_ledger) session.context.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "accept_taa", async_mock.AsyncMock() + with mock.patch.object( + test_module, "accept_taa", mock.AsyncMock() ) as mock_accept_taa: await test_module.ledger_config( profile, @@ -337,17 +335,15 @@ async def test_load_multiple_genesis_transactions_from_config_a(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -434,17 +430,15 @@ async def test_load_multiple_genesis_transactions_from_config_b(self): ], "ledger.genesis_url": "http://localhost:9000/genesis", } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -498,17 +492,15 @@ async def test_load_multiple_genesis_transactions_config_error_a(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -565,17 +557,15 @@ async def test_load_multiple_genesis_transactions_multiple_write(self): }, ] } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: - mock_open.return_value = async_mock.MagicMock( - __enter__=async_mock.MagicMock( - return_value=async_mock.MagicMock( - read=async_mock.MagicMock(return_value=TEST_GENESIS_TXNS) + mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: + mock_open.return_value = mock.MagicMock( + __enter__=mock.MagicMock( + return_value=mock.MagicMock( + read=mock.MagicMock(return_value=TEST_GENESIS_TXNS) ) ) ) @@ -626,22 +616,20 @@ async def test_load_multiple_genesis_transactions_from_config_io_x(self): }, ], } - with async_mock.patch.object( + with mock.patch.object( test_module, "fetch_genesis_transactions", - async_mock.AsyncMock(return_value=TEST_GENESIS_TXNS), - ) as mock_fetch, async_mock.patch( - "builtins.open", async_mock.MagicMock() - ) as mock_open: + mock.AsyncMock(return_value=TEST_GENESIS_TXNS), + ) as mock_fetch, mock.patch("builtins.open", mock.MagicMock()) as mock_open: mock_open.side_effect = IOError("no read permission") with self.assertRaises(test_module.ConfigError): await test_module.load_multiple_genesis_transactions_from_config( settings ) - @async_mock.patch("sys.stdout") + @mock.patch("sys.stdout") async def test_ledger_accept_taa_not_tty_not_accept_config(self, mock_stdout): - mock_stdout.isatty = async_mock.MagicMock(return_value=False) + mock_stdout.isatty = mock.MagicMock(return_value=False) mock_profile = InMemoryProfile.test_profile() taa_info = { @@ -653,9 +641,9 @@ async def test_ledger_accept_taa_not_tty_not_accept_config(self, mock_stdout): None, mock_profile, taa_info, provision=False ) - @async_mock.patch("sys.stdout") + @mock.patch("sys.stdout") async def test_ledger_accept_taa_tty(self, mock_stdout): - mock_stdout.isatty = async_mock.MagicMock(return_value=True) + mock_stdout.isatty = mock.MagicMock(return_value=True) mock_profile = InMemoryProfile.test_profile() taa_info = { @@ -663,34 +651,32 @@ async def test_ledger_accept_taa_tty(self, mock_stdout): "aml_record": {"aml": ["wallet_agreement", "on_file"]}, } - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.AsyncMock() ) as mock_prompt: mock_prompt.side_effect = EOFError() assert not await test_module.accept_taa( None, mock_profile, taa_info, provision=False ) - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.AsyncMock() ) as mock_prompt: mock_prompt.return_value = "x" assert not await test_module.accept_taa( None, mock_profile, taa_info, provision=False ) - with async_mock.patch.object( - test_module, "use_asyncio_event_loop", async_mock.MagicMock() - ) as mock_use_aio_loop, async_mock.patch.object( - test_module.prompt_toolkit, "prompt", async_mock.AsyncMock() + with mock.patch.object( + test_module, "use_asyncio_event_loop", mock.MagicMock() + ) as mock_use_aio_loop, mock.patch.object( + test_module.prompt_toolkit, "prompt", mock.AsyncMock() ) as mock_prompt: - mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.AsyncMock() - ) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) mock_prompt.return_value = "" assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False @@ -733,9 +719,7 @@ async def test_ledger_accept_taa(self): "ledger.taa_acceptance_version": "1.0", } ) - mock_ledger = async_mock.MagicMock( - accept_txn_author_agreement=async_mock.AsyncMock() - ) + mock_ledger = mock.MagicMock(accept_txn_author_agreement=mock.AsyncMock()) assert await test_module.accept_taa( mock_ledger, mock_profile, taa_info, provision=False ) @@ -747,7 +731,7 @@ async def test_ledger_config(self): group = argparse.LedgerGroup() group.add_arguments(parser) - with async_mock.patch.object(parser, "exit") as exit_parser: + with mock.patch.object(parser, "exit") as exit_parser: parser.parse_args(["-h"]) exit_parser.assert_called_once() diff --git a/aries_cloudagent/config/tests/test_logging.py b/aries_cloudagent/config/tests/test_logging.py index 88bc315e31..13ceff1f8d 100644 --- a/aries_cloudagent/config/tests/test_logging.py +++ b/aries_cloudagent/config/tests/test_logging.py @@ -3,7 +3,7 @@ from io import StringIO -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from tempfile import NamedTemporaryFile @@ -21,8 +21,8 @@ class TestLoggingConfigurator(IsolatedAsyncioTestCase): host_arg_value = "host" port_arg_value = "port" - @async_mock.patch.object(test_module, "load_resource", autospec=True) - @async_mock.patch.object(test_module, "fileConfig", autospec=True) + @mock.patch.object(test_module, "load_resource", autospec=True) + @mock.patch.object(test_module, "fileConfig", autospec=True) def test_configure_default(self, mock_file_config, mock_load_resource): test_module.LoggingConfigurator.configure() @@ -34,24 +34,24 @@ def test_configure_default(self, mock_file_config, mock_load_resource): ) def test_configure_default_no_resource(self): - with async_mock.patch.object( - test_module, "load_resource", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_resource", mock.MagicMock() ) as mock_load: mock_load.return_value = None test_module.LoggingConfigurator.configure() def test_configure_default_file(self): log_file = NamedTemporaryFile() - with async_mock.patch.object( - test_module, "load_resource", async_mock.MagicMock() + with mock.patch.object( + test_module, "load_resource", mock.MagicMock() ) as mock_load: mock_load.return_value = None test_module.LoggingConfigurator.configure( log_level="ERROR", log_file=log_file.name ) - @async_mock.patch.object(test_module, "load_resource", autospec=True) - @async_mock.patch.object(test_module, "fileConfig", autospec=True) + @mock.patch.object(test_module, "load_resource", autospec=True) + @mock.patch.object(test_module, "fileConfig", autospec=True) def test_configure_path(self, mock_file_config, mock_load_resource): path = "a path" test_module.LoggingConfigurator.configure(path) @@ -63,9 +63,9 @@ def test_configure_path(self, mock_file_config, mock_load_resource): def test_banner_did(self): stdout = StringIO() - mock_http = async_mock.MagicMock(scheme="http", host="1.2.3.4", port=8081) - mock_https = async_mock.MagicMock(schemes=["https", "archie"]) - mock_admin_server = async_mock.MagicMock(host="1.2.3.4", port=8091) + mock_http = mock.MagicMock(scheme="http", host="1.2.3.4", port=8081) + mock_https = mock.MagicMock(schemes=["https", "archie"]) + mock_admin_server = mock.MagicMock(host="1.2.3.4", port=8091) with contextlib.redirect_stdout(stdout): test_label = "Aries Cloud Agent" test_did = "55GkHamhTU1ZbTbV2ab9DE" @@ -83,20 +83,20 @@ def test_banner_did(self): assert test_did in output def test_load_resource(self): - with async_mock.patch("builtins.open", async_mock.MagicMock()) as mock_open: + with mock.patch("builtins.open", mock.MagicMock()) as mock_open: test_module.load_resource("abc", encoding="utf-8") mock_open.side_effect = IOError("insufficient privilege") test_module.load_resource("abc", encoding="utf-8") - with async_mock.patch.object( - test_module.pkg_resources, "resource_stream", async_mock.MagicMock() - ) as mock_res_stream, async_mock.patch.object( - test_module, "TextIOWrapper", async_mock.MagicMock() + with mock.patch.object( + test_module.pkg_resources, "resource_stream", mock.MagicMock() + ) as mock_res_stream, mock.patch.object( + test_module, "TextIOWrapper", mock.MagicMock() ) as mock_text_io_wrapper: test_module.load_resource("abc:def", encoding="utf-8") - with async_mock.patch.object( - test_module.pkg_resources, "resource_stream", async_mock.MagicMock() + with mock.patch.object( + test_module.pkg_resources, "resource_stream", mock.MagicMock() ) as mock_res_stream: test_module.load_resource("abc:def", encoding=None) diff --git a/aries_cloudagent/config/tests/test_provider.py b/aries_cloudagent/config/tests/test_provider.py index 2b8d874f5d..944b4a7b86 100644 --- a/aries_cloudagent/config/tests/test_provider.py +++ b/aries_cloudagent/config/tests/test_provider.py @@ -1,7 +1,7 @@ from tempfile import NamedTemporaryFile from weakref import ref -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...utils.stats import Collector @@ -34,7 +34,7 @@ async def test_stats_provider_provide_collector(self): timing_log = NamedTemporaryFile().name settings = {"timing.enabled": True, "timing.log.file": timing_log} - mock_provider = async_mock.MagicMock(BaseProvider, autospec=True) + mock_provider = mock.MagicMock(BaseProvider, autospec=True) mock_provider.provide.return_value.mock_method = lambda: () stats_provider = StatsProvider(mock_provider, ("mock_method",)) collector = Collector(log_path=timing_log) diff --git a/aries_cloudagent/config/tests/test_wallet.py b/aries_cloudagent/config/tests/test_wallet.py index 72f7d8d554..f7e1f848e2 100644 --- a/aries_cloudagent/config/tests/test_wallet.py +++ b/aries_cloudagent/config/tests/test_wallet.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -33,13 +33,13 @@ async def open(self, context, config): class TestWalletConfig(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.injector = Injector(enforce_typing=False) - self.session = async_mock.MagicMock(ProfileSession)() - self.session.commit = async_mock.AsyncMock() - self.profile = async_mock.MagicMock( + self.session = mock.MagicMock(ProfileSession)() + self.session.commit = mock.AsyncMock() + self.profile = mock.MagicMock( backend="indy", created=True, name="Test Wallet", - transaction=async_mock.AsyncMock(return_value=self.session), + transaction=mock.AsyncMock(return_value=self.session), ) def _inject(cls): @@ -57,32 +57,32 @@ async def test_wallet_config_existing_replace(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_existing_open(self): - self.profile = async_mock.MagicMock( + self.profile = mock.MagicMock( backend="indy", created=False, name="Test Wallet", - transaction=async_mock.AsyncMock(return_value=self.session), + transaction=mock.AsyncMock(return_value=self.session), ) self.context.injector.clear_binding(ProfileManager) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) @@ -94,23 +94,23 @@ async def test_wallet_config_existing_open(self): "debug.enabled": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) self.context.injector.bind_instance(ProfileManager, MockManager(self.profile)) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -125,21 +125,21 @@ async def test_wallet_config_auto_provision(self): "auto_provision": False, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - MockManager, "open", async_mock.AsyncMock() - ) as mock_mgr_open, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + MockManager, "open", mock.AsyncMock() + ) as mock_mgr_open, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_mgr_open.side_effect = test_module.ProfileNotFoundError() @@ -156,14 +156,14 @@ async def test_wallet_config_non_indy_x(self): } ) self.profile.backend = "not-indy" - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -174,19 +174,19 @@ async def test_wallet_config_bad_seed_x(self): "wallet.seed": "00000000000000000000000000000000", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( test_module, "seed_to_did", - async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): with self.assertRaises(test_module.ConfigError): await test_module.wallet_config(self.context, provision=True) @@ -198,19 +198,19 @@ async def test_wallet_config_seed_local(self): "wallet.local_did": True, } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -222,38 +222,38 @@ async def test_wallet_config_seed_public(self): "wallet.seed": "00000000000000000000000000000000", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( test_module, "seed_to_did", - async_mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + mock.MagicMock(return_value="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"), + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): await test_module.wallet_config(self.context, provision=True) async def test_wallet_config_seed_no_public_did(self): - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None), - set_public_did=async_mock.AsyncMock(), - create_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), + set_public_did=mock.AsyncMock(), + create_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - test_module, "seed_to_did", async_mock.MagicMock() - ) as mock_seed_to_did, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + test_module, "seed_to_did", mock.MagicMock() + ) as mock_seed_to_did, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_seed_to_did.return_value = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" @@ -265,21 +265,21 @@ async def test_wallet_config_for_key_derivation_method(self): "wallet.key_derivation_method": "derivation_method", } ) - mock_wallet = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + mock_wallet = mock.MagicMock( + get_public_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), - set_public_did=async_mock.AsyncMock(), - create_local_did=async_mock.AsyncMock( - return_value=async_mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) + set_public_did=mock.AsyncMock(), + create_local_did=mock.AsyncMock( + return_value=mock.MagicMock(did=TEST_DID, verkey=TEST_VERKEY) ), ) self.injector.bind_instance(BaseWallet, mock_wallet) - with async_mock.patch.object( - MockManager, "provision", async_mock.AsyncMock() - ) as mock_mgr_provision, async_mock.patch.object( - test_module, "add_or_update_version_to_storage", async_mock.AsyncMock() + with mock.patch.object( + MockManager, "provision", mock.AsyncMock() + ) as mock_mgr_provision, mock.patch.object( + test_module, "add_or_update_version_to_storage", mock.AsyncMock() ): mock_mgr_provision.return_value = self.profile diff --git a/aries_cloudagent/connections/tests/test_base_manager.py b/aries_cloudagent/connections/tests/test_base_manager.py index 256bc5f6ab..0fd7407614 100644 --- a/aries_cloudagent/connections/tests/test_base_manager.py +++ b/aries_cloudagent/connections/tests/test_base_manager.py @@ -2,7 +2,7 @@ from unittest.mock import call -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from pydid import DID, DIDDocument, DIDDocumentBuilder from pydid.doc.builder import ServiceBuilder @@ -83,8 +83,8 @@ async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) self.route_manager = CoordinateMediationV1RouteManager() self.resolver = DIDResolver() @@ -110,7 +110,7 @@ async def asyncSetUp(self): ) self.context = self.profile.context - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) @@ -215,7 +215,7 @@ async def test_create_did_document_mediation_svc_endpoints_overwritten(self): routing_keys=self.test_mediator_routing_keys, endpoint=self.test_mediator_endpoint, ) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(mediation_record.routing_keys, mediation_record.endpoint) ) doc = await self.manager.create_did_document( @@ -308,7 +308,7 @@ async def test_store_did_document_with_routing_keys(self): assert context.output and "Key already associated with DID" in context.output[0] async def test_fetch_connection_targets_no_my_did(self): - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.my_did = None assert await self.manager.fetch_connection_targets(mock_conn) == [] @@ -330,13 +330,13 @@ async def test_fetch_connection_targets_conn_invitation_did_no_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): @@ -354,11 +354,11 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -378,13 +378,13 @@ async def test_fetch_connection_targets_conn_invitation_did_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -425,11 +425,11 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -448,13 +448,13 @@ async def test_fetch_connection_targets_conn_invitation_btcr_resolver(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -491,10 +491,10 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se ], } did_doc = DIDDocument.deserialize(did_doc_json) - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) local_did = await session.wallet.create_local_did( @@ -512,13 +512,13 @@ async def test_fetch_connection_targets_conn_invitation_btcr_without_services(se routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -531,10 +531,10 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self ) builder.service.add(type_="LinkedData", service_endpoint=self.test_endpoint) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) self.context.injector.bind_instance(DIDResolver, self.resolver) await session.wallet.create_local_did( method=SOV, @@ -551,13 +551,13 @@ async def test_fetch_connection_targets_conn_invitation_no_didcomm_services(self routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -579,11 +579,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -602,13 +602,13 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -641,11 +641,11 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -664,13 +664,13 @@ async def test_fetch_connection_targets_conn_invitation_supports_Ed25519Verifica routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -703,11 +703,11 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -726,13 +726,13 @@ async def test_fetch_connection_targets_conn_invitation_supported_JsonWebKey2020 routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -764,11 +764,11 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel recipient_keys=[vmethod], ) did_doc = builder.build() - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -787,13 +787,13 @@ async def test_fetch_connection_targets_conn_invitation_unsupported_key_type(sel routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=did_doc.id, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) with self.assertRaises(BaseConnectionManagerError): await self.manager.fetch_connection_targets(mock_conn) @@ -809,11 +809,11 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_no_resolver(self) metadata=None, ) - mock_oob_invite = async_mock.MagicMock(services=[self.test_did]) + mock_oob_invite = mock.MagicMock(services=[self.test_did]) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, - retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER.rfc23, ) @@ -836,8 +836,8 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): ) did_doc = builder.build() - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - self.resolver.dereference = async_mock.AsyncMock( + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) + self.resolver.dereference = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -850,18 +850,18 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): metadata=None, ) - mock_oob_invite = async_mock.MagicMock( + mock_oob_invite = mock.MagicMock( label="a label", their_did=self.test_target_did, services=["dummy"], ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -876,10 +876,10 @@ async def test_fetch_connection_targets_oob_invitation_svc_did_resolver(self): async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): async with self.profile.session() as session: - self.resolver.get_endpoint_for_did = async_mock.AsyncMock( + self.resolver.get_endpoint_for_did = mock.AsyncMock( return_value=self.test_endpoint ) - self.resolver.get_key_for_did = async_mock.AsyncMock( + self.resolver.get_key_for_did = mock.AsyncMock( return_value=self.test_target_verkey ) self.context.injector.bind_instance(DIDResolver, self.resolver) @@ -892,11 +892,11 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): metadata=None, ) - mock_oob_invite = async_mock.MagicMock( + mock_oob_invite = mock.MagicMock( label="a label", their_did=self.test_target_did, services=[ - async_mock.MagicMock( + mock.MagicMock( service_endpoint=self.test_endpoint, recipient_keys=[ DIDKey.from_public_key_b58( @@ -907,13 +907,13 @@ async def test_fetch_connection_targets_oob_invitation_svc_block_resolver(self): ) ], ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=mock_oob_invite), + retrieve_invitation=mock.AsyncMock(return_value=mock_oob_invite), ) targets = await self.manager.fetch_connection_targets(mock_conn) @@ -936,7 +936,7 @@ async def test_fetch_connection_targets_conn_initiator_completed_no_their_did(se metadata=None, ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=None, state=ConnRecord.State.COMPLETED.rfc23, @@ -956,7 +956,7 @@ async def test_fetch_connection_targets_conn_completed_their_did(self): did_doc = self.make_did_doc(did=self.test_did, verkey=self.test_verkey) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_did, their_label="label", @@ -985,7 +985,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): metadata=None, ) - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( self.test_endpoint, [self.test_verkey], @@ -995,7 +995,7 @@ async def test_fetch_connection_targets_conn_no_invi_with_their_did(self): did_doc = self.make_did_doc(did=self.test_did, verkey=self.test_verkey) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_did, their_label="label", @@ -1030,7 +1030,7 @@ async def test_verification_methods_for_service(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) recip, routing = await self.manager.verification_methods_for_service( @@ -1042,7 +1042,7 @@ async def test_verification_methods_for_service(self): async def test_resolve_connection_targets_empty(self): """Test resolve connection targets.""" did = "did:sov:" + self.test_did - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), []) ) targets = await self.manager.resolve_connection_targets(did) @@ -1064,7 +1064,7 @@ async def test_resolve_connection_targets(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) targets = await self.manager.resolve_connection_targets(did) @@ -1086,7 +1086,7 @@ async def test_resolve_connection_targets_x_bad_reference(self): routing_keys=["did:example:123#some-random-id"], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertLogs() as cm: @@ -1111,7 +1111,7 @@ async def test_resolve_connection_targets_x_bad_key_material(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1133,7 +1133,7 @@ async def test_resolve_connection_targets_x_unsupported_key(self): routing_keys=[route_key.key_id], ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) with self.assertRaises(BaseConnectionManagerError) as cm: @@ -1146,7 +1146,7 @@ async def test_record_did_empty(self): service_builder.add_didcomm( self.test_endpoint, recipient_keys=[], routing_keys=[] ) - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(DIDDocument(id=DID(did)), service_builder.services) ) await self.manager.record_did(did) @@ -1162,7 +1162,7 @@ async def test_record_did(self): self.test_endpoint, recipient_keys=[vm], routing_keys=[] ) doc = doc_builder.build() - self.manager.resolve_didcomm_services = async_mock.AsyncMock( + self.manager.resolve_didcomm_services = mock.AsyncMock( return_value=(doc, doc.service) ) await self.manager.record_did(did) @@ -1189,14 +1189,14 @@ async def test_find_inbound_connection(self): recipient_did_public=False, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" # First pass: not yet in cache - with async_mock.patch.object( + with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1204,8 +1204,8 @@ async def test_find_inbound_connection(self): assert conn_rec # Second pass: in cache - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1219,13 +1219,13 @@ async def test_find_inbound_connection_no_cache(self): recipient_did_public=False, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( + with mock.patch.object( BaseConnectionManager, "resolve_inbound_connection", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_conn_mgr_resolve_conn: self.context.injector.clear_binding(BaseCache) mock_conn_mgr_resolve_conn.return_value = mock_conn @@ -1240,13 +1240,13 @@ async def test_resolve_inbound_connection(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -1266,13 +1266,13 @@ async def test_resolve_inbound_connection_injector_error(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = InjectionError() mock_mgr_find_conn.return_value = mock_conn @@ -1286,13 +1286,13 @@ async def test_resolve_inbound_connection_wallet_not_found_error(self): recipient_did_public=True, ) - mock_conn = async_mock.MagicMock() + mock_conn = mock.MagicMock() mock_conn.connection_id = "dummy" - with async_mock.patch.object( - InMemoryWallet, "get_local_did_for_verkey", async_mock.AsyncMock() - ) as mock_wallet_get_local_did_for_verkey, async_mock.patch.object( - self.manager, "find_connection", async_mock.AsyncMock() + with mock.patch.object( + InMemoryWallet, "get_local_did_for_verkey", mock.AsyncMock() + ) as mock_wallet_get_local_did_for_verkey, mock.patch.object( + self.manager, "find_connection", mock.AsyncMock() ) as mock_mgr_find_conn: mock_wallet_get_local_did_for_verkey.side_effect = WalletNotFoundError() mock_mgr_find_conn.return_value = mock_conn @@ -1322,13 +1322,13 @@ async def test_get_connection_targets_conn_invitation_no_did(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1381,19 +1381,19 @@ async def test_get_connection_targets_retrieve_connection(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn mock_conn_target_ser.return_value = {"serialized": "value"} @@ -1425,7 +1425,7 @@ async def test_get_connection_targets_from_cache(self): ) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", @@ -1433,12 +1433,12 @@ async def test_get_connection_targets_from_cache(self): state=ConnRecord.State.COMPLETED.rfc160, ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1469,7 +1469,7 @@ async def test_get_connection_targets_no_cache(self): ) await self.manager.store_did_document(did_doc) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", @@ -1477,12 +1477,12 @@ async def test_get_connection_targets_no_cache(self): state=ConnRecord.State.COMPLETED.rfc160, ) - with async_mock.patch.object( + with mock.patch.object( ConnectionTarget, "serialize", autospec=True - ) as mock_conn_target_ser, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - self.manager, "fetch_connection_targets", async_mock.AsyncMock() + ) as mock_conn_target_ser, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + self.manager, "fetch_connection_targets", mock.AsyncMock() ) as mock_fetch_connection_targets: mock_fetch_connection_targets.return_value = [ConnectionTarget()] mock_conn_rec_retrieve_by_id.return_value = mock_conn @@ -1526,13 +1526,13 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): routing_keys=[self.test_verkey], label="label", ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=self.test_did, their_did=self.test_target_did, connection_id="dummy", their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.INVITATION.rfc23, - retrieve_invitation=async_mock.AsyncMock(return_value=conn_invite), + retrieve_invitation=mock.AsyncMock(return_value=conn_invite), ) targets = await self.manager.get_connection_targets( @@ -1549,9 +1549,7 @@ async def test_get_conn_targets_conn_invitation_no_cache(self): assert target.sender_key == local_did.verkey async def test_create_static_connection(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: _my, _their, conn_rec = await self.manager.create_static_connection( my_did=self.test_did, their_did=self.test_target_did, @@ -1567,11 +1565,9 @@ async def test_create_static_connection_multitenant(self): ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.AsyncMock() + self.route_manager.route_static = mock.AsyncMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1600,13 +1596,11 @@ async def test_create_static_connection_multitenant_auto_disclose_features(self) } ) self.multitenant_mgr.get_default_mediator.return_value = None - self.route_manager.route_static = async_mock.AsyncMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + self.route_manager.route_static = mock.AsyncMock() + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + ) as mock_wallet_create_local_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -1629,16 +1623,14 @@ async def test_create_static_connection_multitenant_mediator(self): {"wallet.id": "test_wallet", "multitenant.enabled": True} ) - default_mediator = async_mock.MagicMock() - self.route_manager.route_static = async_mock.AsyncMock() + default_mediator = mock.MagicMock() + self.route_manager.route_static = mock.AsyncMock() - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( + with mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( BaseConnectionManager, "create_did_document" - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( BaseConnectionManager, "store_did_document" ) as store_did_document: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1688,9 +1680,7 @@ async def test_create_static_connection_multitenant_mediator(self): ) async def test_create_static_connection_no_their(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: with self.assertRaises(BaseConnectionManagerError): await self.manager.create_static_connection( my_did=self.test_did, @@ -1700,9 +1690,7 @@ async def test_create_static_connection_no_their(self): ) async def test_create_static_connection_their_seed_only(self): - with async_mock.patch.object( - ConnRecord, "save", autospec=True - ) as mock_conn_rec_save: + with mock.patch.object(ConnRecord, "save", autospec=True) as mock_conn_rec_save: _my, _their, conn_rec = await self.manager.create_static_connection( my_did=self.test_did, their_seed=self.test_seed, @@ -1712,12 +1700,12 @@ async def test_create_static_connection_their_seed_only(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_find_connection_retrieve_by_did(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_conn_retrieve_by_did: - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1730,14 +1718,14 @@ async def test_find_connection_retrieve_by_did(self): async def test_find_connection_retrieve_by_did_auto_disclose_features(self): self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1750,15 +1738,15 @@ async def test_find_connection_retrieve_by_did_auto_disclose_features(self): mock_proactive_disclose_features.assert_called_once() async def test_find_connection_retrieve_by_invitation_key(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_invitation_key.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_invitation_key.return_value = mock.MagicMock( state=ConnRecord.State.RESPONSE, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.find_connection( @@ -1769,10 +1757,10 @@ async def test_find_connection_retrieve_by_invitation_key(self): assert conn_rec async def test_find_connection_retrieve_none_by_invitation_key(self): - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_key", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + ConnRecord, "retrieve_by_invitation_key", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_key: mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() mock_conn_retrieve_by_invitation_key.side_effect = StorageNotFoundError() @@ -1787,19 +1775,19 @@ async def test_find_connection_retrieve_none_by_invitation_key(self): async def test_get_endpoints(self): conn_id = "dummy" - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( InMemoryWallet, "get_local_did", autospec=True - ) as mock_wallet_get_local_did, async_mock.patch.object( - self.manager, "get_connection_targets", async_mock.AsyncMock() + ) as mock_wallet_get_local_did, mock.patch.object( + self.manager, "get_connection_targets", mock.AsyncMock() ) as mock_get_conn_targets: - mock_retrieve.return_value = async_mock.MagicMock() - mock_wallet_get_local_did.return_value = async_mock.MagicMock( + mock_retrieve.return_value = mock.MagicMock() + mock_wallet_get_local_did.return_value = mock.MagicMock( metadata={"endpoint": "localhost:8020"} ) mock_get_conn_targets.return_value = [ - async_mock.MagicMock(endpoint="10.20.30.40:5060") + mock.MagicMock(endpoint="10.20.30.40:5060") ] assert await self.manager.get_endpoints(conn_id) == ( "localhost:8020", diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index 7da2c37c34..698f355df2 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -1,6 +1,6 @@ from io import StringIO -import mock as async_mock +import mock from unittest import IsolatedAsyncioTestCase from ...admin.base_server import BaseAdminServer @@ -80,7 +80,7 @@ def make_did_doc(self, did, verkey): class StubContextBuilder(ContextBuilder): def __init__(self, settings): super().__init__(settings) - self.wire_format = async_mock.create_autospec(PackWireFormat()) + self.wire_format = mock.create_autospec(PackWireFormat()) async def build_context(self) -> InjectionContext: context = InjectionContext(settings=self.settings, enforce_typing=False) @@ -105,29 +105,29 @@ async def test_startup_version_record_exists(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.7.3")), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value="v0.7.3")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock( + mock.MagicMock( return_value=["v0.7.4", "0.7.5", "v0.8.0-rc1", "v8.0.0", "v0.8.1-rc2"] ), - ), async_mock.patch.object( + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -161,25 +161,25 @@ async def test_startup_version_no_upgrade_add_record(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.8.1")), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value="v0.8.1")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=[]), - ), async_mock.patch.object( + mock.MagicMock(return_value=[]), + ), mock.patch.object( test_module, "add_version_record", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -193,23 +193,21 @@ async def test_startup_version_no_upgrade_add_record(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=[]), + mock.MagicMock(return_value=[]), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -231,27 +229,27 @@ async def test_startup_version_force_upgrade(self): } builder: ContextBuilder = StubContextBuilder(test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.8.0")), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value="v0.8.0")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -265,27 +263,27 @@ async def test_startup_version_force_upgrade(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(return_value=async_mock.MagicMock(value="v0.7.0")), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value="v0.7.0")), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.7.2", "v0.7.3", "v0.7.4"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.7.2", "v0.7.3", "v0.7.4"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() session = await conductor.root_profile.session() @@ -299,24 +297,24 @@ async def test_startup_version_force_upgrade(self): await conductor.start() await conductor.stop() - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): await conductor.setup() session = await conductor.root_profile.session() @@ -335,27 +333,27 @@ async def test_startup_version_record_not_exists(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "get_upgrade_version_list", - async_mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), - ), async_mock.patch.object( + mock.MagicMock(return_value=["v0.8.0-rc1", "v8.0.0", "v0.8.1-rc1"]), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -389,17 +387,17 @@ async def test_startup_admin_server_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( - test_module, "AdminServer", async_mock.MagicMock() + ) as mock_logger, mock.patch.object( + test_module, "AdminServer", mock.MagicMock() ) as mock_admin_server: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } mock_admin_server.side_effect = ValueError() with self.assertRaises(ValueError): @@ -409,23 +407,21 @@ async def test_startup_no_public_did(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): mock_outbound_mgr.return_value.registered_transports = {} - mock_outbound_mgr.return_value.enqueue_message = async_mock.AsyncMock() - mock_outbound_mgr.return_value.start = async_mock.AsyncMock() - mock_outbound_mgr.return_value.stop = async_mock.AsyncMock() + mock_outbound_mgr.return_value.enqueue_message = mock.AsyncMock() + mock_outbound_mgr.return_value.start = mock.AsyncMock() + mock_outbound_mgr.return_value.stop = mock.AsyncMock() await conductor.setup() mock_inbound_mgr.return_value.setup.assert_awaited_once() @@ -451,20 +447,20 @@ async def test_stats(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_inbound_mgr.return_value.sessions = ["dummy"] mock_outbound_mgr.return_value.outbound_buffer = [ - async_mock.MagicMock(state=QueuedOutboundMessage.STATE_ENCODE), - async_mock.MagicMock(state=QueuedOutboundMessage.STATE_DELIVER), + mock.MagicMock(state=QueuedOutboundMessage.STATE_ENCODE), + mock.MagicMock(state=QueuedOutboundMessage.STATE_DELIVER), ] mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -487,15 +483,15 @@ async def test_inbound_message_handler(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.dispatcher, "queue_message", autospec=True ) as mock_dispatch_q: message_body = "{}" @@ -516,18 +512,18 @@ async def test_inbound_message_handler_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.dispatcher, "queue_message", autospec=True - ) as mock_dispatch_q, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + ) as mock_dispatch_q, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: mock_dispatch_q.side_effect = test_module.LedgerConfigError("ledger down") @@ -559,7 +555,7 @@ async def test_outbound_message_handler_return_route(self): receipt.recipient_verkey = test_from_verkey inbound = InboundMessage("[]", receipt) - with async_mock.patch.object( + with mock.patch.object( conductor.inbound_transport_manager, "return_to_session" ) as mock_return: mock_return.return_value = True @@ -577,11 +573,11 @@ async def test_outbound_message_handler_with_target(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -609,13 +605,13 @@ async def test_outbound_message_handler_with_connection(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as conn_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -651,11 +647,11 @@ async def test_outbound_message_handler_with_verkey_no_target(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -669,8 +665,8 @@ async def test_outbound_message_handler_with_verkey_no_target(self): status = await conductor.outbound_message_router( conductor.root_profile, message, - inbound=async_mock.MagicMock( - receipt=async_mock.MagicMock(recipient_verkey=TestDIDs.test_verkey) + inbound=mock.MagicMock( + receipt=mock.MagicMock(recipient_verkey=TestDIDs.test_verkey) ), ) @@ -688,12 +684,12 @@ async def test_handle_nots(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( - test_module, "OutboundTransportManager", async_mock.MagicMock() + with mock.patch.object( + test_module, "OutboundTransportManager", mock.MagicMock() ) as mock_outbound_mgr: - mock_outbound_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - enqueue_message=async_mock.AsyncMock(), + mock_outbound_mgr.return_value = mock.MagicMock( + setup=mock.AsyncMock(), + enqueue_message=mock.AsyncMock(), ) payload = "{}" @@ -707,14 +703,12 @@ async def test_handle_nots(self): conductor.handle_not_returned(conductor.root_profile, message) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_conn_mgr, async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() + ) as mock_conn_mgr, mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() ) as mock_run_task: - mock_conn_mgr.return_value.get_connection_targets = ( - async_mock.AsyncMock() - ) + mock_conn_mgr.return_value.get_connection_targets = mock.AsyncMock() mock_run_task.side_effect = test_module.ConnectionManagerError() await conductor.queue_outbound(conductor.root_profile, message) mock_outbound_mgr.return_value.enqueue_message.assert_not_called() @@ -729,13 +723,13 @@ async def test_handle_nots(self): async def test_handle_outbound_queue(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - encoded_outbound_message_mock = async_mock.MagicMock(payload="message_payload") + encoded_outbound_message_mock = mock.MagicMock(payload="message_payload") payload = "{}" message = OutboundMessage( payload=payload, connection_id="dummy-conn-id", - target=async_mock.MagicMock(endpoint="endpoint"), + target=mock.MagicMock(endpoint="endpoint"), reply_to_verkey=TestDIDs.test_verkey, ) await conductor.setup() @@ -745,19 +739,19 @@ async def test_handle_not_returned_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() - ) as mock_dispatch_run, async_mock.patch.object( - conductor, "queue_outbound", async_mock.AsyncMock() - ) as mock_queue, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() + ) as mock_dispatch_run, mock.patch.object( + conductor, "queue_outbound", mock.AsyncMock() + ) as mock_queue, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" @@ -780,22 +774,22 @@ async def test_queue_outbound_ledger_x(self): builder: ContextBuilder = StubContextBuilder(self.test_settings_admin) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as conn_mgr, async_mock.patch.object( - conductor.dispatcher, "run_task", async_mock.MagicMock() - ) as mock_dispatch_run, async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + ) as conn_mgr, mock.patch.object( + conductor.dispatcher, "run_task", mock.MagicMock() + ) as mock_dispatch_run, mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: - conn_mgr.return_value.get_connection_targets = async_mock.AsyncMock() + conn_mgr.return_value.get_connection_targets = mock.AsyncMock() mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" ) @@ -817,11 +811,11 @@ async def test_admin(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) builder.update_settings({"admin.enabled": "1"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() admin = conductor.context.inject(BaseAdminServer) @@ -834,16 +828,14 @@ async def test_admin(self): ED25519, ) - with async_mock.patch.object( + with mock.patch.object( admin, "start", autospec=True - ) as admin_start, async_mock.patch.object( + ) as admin_start, mock.patch.object( admin, "stop", autospec=True - ) as admin_stop, async_mock.patch.object( + ) as admin_stop, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() admin_start.assert_awaited_once_with() @@ -861,11 +853,11 @@ async def test_admin_startx(self): } ) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() admin = conductor.context.inject(BaseAdminServer) @@ -878,26 +870,24 @@ async def test_admin_startx(self): ED25519, ) - with async_mock.patch.object( + with mock.patch.object( admin, "start", autospec=True - ) as admin_start, async_mock.patch.object( + ) as admin_start, mock.patch.object( admin, "stop", autospec=True - ) as admin_stop, async_mock.patch.object( + ) as admin_stop, mock.patch.object( test_module, "OutOfBandManager" - ) as oob_mgr, async_mock.patch.object( + ) as oob_mgr, mock.patch.object( test_module, "ConnectionManager" - ) as conn_mgr, async_mock.patch.object( + ) as conn_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): admin_start.side_effect = KeyError("trouble") - oob_mgr.return_value.create_invitation = async_mock.AsyncMock( + oob_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=KeyError("double trouble") ) - conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=KeyError("triple trouble") ) await conductor.start() @@ -910,15 +900,15 @@ async def test_setup_collector(self): builder: ContextBuilder = StubCollectorContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -927,19 +917,17 @@ async def test_start_static(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -950,7 +938,7 @@ async def test_start_static(self): ED25519, ) - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.AsyncMock() await conductor.start() mock_mgr.return_value.create_static_connection.assert_awaited_once() @@ -959,22 +947,22 @@ async def test_start_x_in(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "InboundTransportManager" - ) as mock_intx_mgr, async_mock.patch.object( + ) as mock_intx_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: - mock_intx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), + mock_intx_mgr.return_value = mock.MagicMock( + setup=mock.AsyncMock(), + start=mock.AsyncMock(side_effect=KeyError("trouble")), ) mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -983,18 +971,18 @@ async def test_start_x_out_a(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "OutboundTransportManager" ) as mock_outx_mgr: - mock_outx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), - registered_transports={"test": async_mock.MagicMock(schemes=["http"])}, + mock_outx_mgr.return_value = mock.MagicMock( + setup=mock.AsyncMock(), + start=mock.AsyncMock(side_effect=KeyError("trouble")), + registered_transports={"test": mock.MagicMock(schemes=["http"])}, ) await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -1003,20 +991,20 @@ async def test_start_x_out_b(self): builder.update_settings({"debug.test_suite_endpoint": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "OutboundTransportManager" ) as mock_outx_mgr: - mock_outx_mgr.return_value = async_mock.MagicMock( - setup=async_mock.AsyncMock(), - start=async_mock.AsyncMock(side_effect=KeyError("trouble")), - stop=async_mock.AsyncMock(), + mock_outx_mgr.return_value = mock.MagicMock( + setup=mock.AsyncMock(), + start=mock.AsyncMock(side_effect=KeyError("trouble")), + stop=mock.AsyncMock(), registered_transports={}, - enqueue_message=async_mock.AsyncMock(), + enqueue_message=mock.AsyncMock(), ) await conductor.setup() - mock_mgr.return_value.create_static_connection = async_mock.AsyncMock() + mock_mgr.return_value.create_static_connection = mock.AsyncMock() with self.assertRaises(KeyError): await conductor.start() @@ -1028,7 +1016,7 @@ async def test_dispatch_complete_non_fatal_x(self): receipt = MessageReceipt(direct_response_mode="snail mail") message = InboundMessage(message_body, receipt) exc = KeyError("sample exception") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -1039,16 +1027,16 @@ async def test_dispatch_complete_non_fatal_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: conductor.dispatch_complete(message, mock_task) mock_notify.assert_not_called() @@ -1061,7 +1049,7 @@ async def test_dispatch_complete_fatal_x(self): receipt = MessageReceipt(direct_response_mode="snail mail") message = InboundMessage(message_body, receipt) exc = test_module.LedgerTransactionError("Ledger is wobbly") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -1072,16 +1060,16 @@ async def test_dispatch_complete_fatal_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( - conductor.admin_server, "notify_fatal_error", async_mock.MagicMock() + with mock.patch.object( + conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: conductor.dispatch_complete(message, mock_task) mock_notify.assert_called_once_with() @@ -1097,19 +1085,15 @@ async def test_print_invite_connection(self): ) conductor = test_module.Conductor(builder) - with async_mock.patch( - "sys.stdout", new=StringIO() - ) as captured, async_mock.patch.object( + with mock.patch("sys.stdout", new=StringIO()) as captured, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), + ), mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() @@ -1131,26 +1115,22 @@ async def test_clear_default_mediator(self): builder.update_settings({"mediation.clear": True}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", - return_value=async_mock.MagicMock( - clear_default_mediator=async_mock.AsyncMock() - ), - ) as mock_mgr, async_mock.patch.object( + return_value=mock.MagicMock(clear_default_mediator=mock.AsyncMock()), + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1161,36 +1141,32 @@ async def test_set_default_mediator(self): builder.update_settings({"mediation.default_id": "test-id"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", - return_value=async_mock.MagicMock( - set_default_mediator_by_id=async_mock.AsyncMock() - ), - ) as mock_mgr, async_mock.patch.object( - MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ), async_mock.patch.object( + return_value=mock.MagicMock(set_default_mediator_by_id=mock.AsyncMock()), + ) as mock_mgr, mock.patch.object( + MediationRecord, "retrieve_by_id", mock.AsyncMock() + ), mock.patch.object( test_module, "LOGGER", - async_mock.MagicMock( - exception=async_mock.MagicMock( + mock.MagicMock( + exception=mock.MagicMock( side_effect=Exception("This method should not have been called") ) ), - ), async_mock.patch.object( + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1201,26 +1177,22 @@ async def test_set_default_mediator_x(self): builder.update_settings({"mediation.default_id": "test-id"}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=Exception()), - ), async_mock.patch.object( - test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + mock.AsyncMock(side_effect=Exception()), + ), mock.patch.object(test_module, "LOGGER") as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1238,14 +1210,14 @@ async def test_webhook_router(self): test_endpoint = "http://example" test_attempts = 2 - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( conductor.outbound_transport_manager, "enqueue_webhook" ) as mock_enqueue: conductor.webhook_router( @@ -1256,7 +1228,7 @@ async def test_webhook_router(self): ) # swallow error - with async_mock.patch.object( + with mock.patch.object( conductor.outbound_transport_manager, "enqueue_webhook", side_effect=OutboundDeliveryError, @@ -1274,15 +1246,15 @@ async def test_shutdown_multitenant_profiles(self): ) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LoggingConfigurator", autospec=True ) as mock_logger: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() multitenant_mgr = conductor.context.inject(BaseMultitenantManager) @@ -1290,11 +1262,11 @@ async def test_shutdown_multitenant_profiles(self): multitenant_mgr._profiles.put( "test1", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.AsyncMock()), ) multitenant_mgr._profiles.put( "test2", - async_mock.MagicMock(close=async_mock.AsyncMock()), + mock.MagicMock(close=mock.AsyncMock()), ) await conductor.stop() @@ -1305,13 +1277,13 @@ async def test_shutdown_multitenant_profiles(self): def get_invite_store_mock( invite_string: str, invite_already_used: bool = False -) -> async_mock.MagicMock: +) -> mock.MagicMock: unused_invite = MediationInviteRecord(invite_string, invite_already_used) used_invite = MediationInviteRecord(invite_string, used=True) - return async_mock.MagicMock( - get_mediation_invite_record=async_mock.AsyncMock(return_value=unused_invite), - mark_default_invite_as_used=async_mock.AsyncMock(return_value=used_invite), + return mock.MagicMock( + get_mediation_invite_record=mock.AsyncMock(return_value=unused_invite), + mark_default_invite_as_used=mock.AsyncMock(return_value=used_invite), ) @@ -1330,65 +1302,61 @@ def __get_mediator_config( return builder - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), ) - @async_mock.patch.object(test_module.ConnectionInvitation, "from_url") + @mock.patch.object(test_module.ConnectionInvitation, "from_url") async def test_mediator_invitation_0160(self, mock_from_url, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_conn_record = async_mock.MagicMock() + mock_conn_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", - async_mock.MagicMock( - return_value=async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock( - return_value=mock_conn_record - ) + mock.MagicMock( + return_value=mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn_record) ) ), - ) as mock_mgr, async_mock.patch.object( - mock_conn_record, "metadata_set", async_mock.AsyncMock() - ), async_mock.patch.object( + ) as mock_mgr, mock.patch.object( + mock_conn_record, "metadata_set", mock.AsyncMock() + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() mock_from_url.assert_called_once_with("test-invite") mock_mgr.return_value.receive_invitation.assert_called_once() - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), ) - @async_mock.patch.object(test_module.InvitationMessage, "from_url") + @mock.patch.object(test_module.InvitationMessage, "from_url") async def test_mediator_invitation_0434(self, mock_from_url, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", False) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() conductor.root_profile.context.update_settings( @@ -1410,20 +1378,18 @@ async def test_mediator_invitation_0434(self, mock_from_url, _): connection_id=conn_record.connection_id, state=OobRecord.STATE_INITIAL, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", - async_mock.MagicMock( - return_value=async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=oob_record) + mock.MagicMock( + return_value=mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=oob_record) ) ), - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): assert not conductor.root_profile.settings["mediation.connections_invite"] await conductor.start() @@ -1431,8 +1397,8 @@ async def test_mediator_invitation_0434(self, mock_from_url, _): mock_from_url.assert_called_once_with("test-invite") mock_mgr.return_value.receive_invitation.assert_called_once() - @async_mock.patch.object(test_module, "MediationInviteStore") - @async_mock.patch.object(test_module.ConnectionInvitation, "from_url") + @mock.patch.object(test_module, "MediationInviteStore") + @mock.patch.object(test_module.ConnectionInvitation, "from_url") async def test_mediation_invitation_should_use_stored_invitation( self, patched_from_url, patched_invite_store ): @@ -1448,37 +1414,33 @@ async def test_mediation_invitation_should_use_stored_invitation( conductor = test_module.Conductor( self.__get_mediator_config(invite_string, True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - mock_conn_record = async_mock.MagicMock() + mock_conn_record = mock.MagicMock() mocked_store = get_invite_store_mock(invite_string) patched_invite_store.return_value = mocked_store - connection_manager_mock = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn_record) - ) - mock_mediation_manager = async_mock.MagicMock( - clear_default_mediator=async_mock.AsyncMock() + connection_manager_mock = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn_record) ) + mock_mediation_manager = mock.MagicMock(clear_default_mediator=mock.AsyncMock()) # when - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", return_value=connection_manager_mock - ), async_mock.patch.object( - mock_conn_record, "metadata_set", async_mock.AsyncMock() - ), async_mock.patch.object( + ), mock.patch.object( + mock_conn_record, "metadata_set", mock.AsyncMock() + ), mock.patch.object( test_module, "MediationManager", return_value=mock_mediation_manager - ), async_mock.patch.object( + ), mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1490,8 +1452,8 @@ async def test_mediation_invitation_should_use_stored_invitation( patched_from_url.assert_called_with(invite_string) mock_mediation_manager.clear_default_mediator.assert_called_once() - @async_mock.patch.object(test_module, "MediationInviteStore") - @async_mock.patch.object(test_module, "ConnectionManager") + @mock.patch.object(test_module, "MediationInviteStore") + @mock.patch.object(test_module, "ConnectionManager") async def test_mediation_invitation_should_not_create_connection_for_old_invitation( self, patched_connection_manager, patched_invite_store ): @@ -1501,27 +1463,23 @@ async def test_mediation_invitation_should_not_create_connection_for_old_invitat conductor = test_module.Conductor( self.__get_mediator_config(invite_string, True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() invite_store_mock = get_invite_store_mock(invite_string, True) patched_invite_store.return_value = invite_store_mock - connection_manager_mock = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock() - ) + connection_manager_mock = mock.MagicMock(receive_invitation=mock.AsyncMock()) patched_connection_manager.return_value = connection_manager_mock - with async_mock.patch.object( + with mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): # when await conductor.start() @@ -1533,7 +1491,7 @@ async def test_mediation_invitation_should_not_create_connection_for_old_invitat ) connection_manager_mock.receive_invitation.assert_not_called() - @async_mock.patch.object( + @mock.patch.object( test_module, "MediationInviteStore", return_value=get_invite_store_mock("test-invite"), @@ -1542,26 +1500,24 @@ async def test_mediator_invitation_x(self, _): conductor = test_module.Conductor( self.__get_mediator_config("test-invite", True) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "from_url", - async_mock.MagicMock(side_effect=Exception()), - ) as mock_from_url, async_mock.patch.object( + mock.MagicMock(side_effect=Exception()), + ) as mock_from_url, mock.patch.object( test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(value=f"v{__version__}") - ), + mock.AsyncMock(return_value=mock.MagicMock(value=f"v{__version__}")), ): await conductor.start() await conductor.stop() @@ -1574,17 +1530,17 @@ async def test_setup_ledger_both_multiple_and_base(self): builder.update_settings({"ledger.ledger_config_list": [{"...": "..."}]}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "load_multiple_genesis_transactions_from_config", - async_mock.AsyncMock(), - ) as mock_multiple_genesis_load, async_mock.patch.object( - test_module, "get_genesis_transactions", async_mock.AsyncMock() - ) as mock_genesis_load, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_multiple_genesis_load, mock.patch.object( + test_module, "get_genesis_transactions", mock.AsyncMock() + ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() mock_multiple_genesis_load.assert_called_once() @@ -1595,13 +1551,13 @@ async def test_setup_ledger_only_base(self): builder.update_settings({"ledger.genesis_transactions": "..."}) conductor = test_module.Conductor(builder) - with async_mock.patch.object( - test_module, "get_genesis_transactions", async_mock.AsyncMock() - ) as mock_genesis_load, async_mock.patch.object( + with mock.patch.object( + test_module, "get_genesis_transactions", mock.AsyncMock() + ) as mock_genesis_load, mock.patch.object( test_module, "OutboundTransportManager", autospec=True ) as mock_outbound_mgr: mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() mock_genesis_load.assert_called_once() @@ -1610,23 +1566,23 @@ async def test_startup_x_no_storage_version(self): builder: ContextBuilder = StubContextBuilder(self.test_settings) conductor = test_module.Conductor(builder) - with async_mock.patch.object( + with mock.patch.object( test_module, "InboundTransportManager", autospec=True - ) as mock_inbound_mgr, async_mock.patch.object( + ) as mock_inbound_mgr, mock.patch.object( test_module, "OutboundTransportManager", autospec=True - ) as mock_outbound_mgr, async_mock.patch.object( + ) as mock_outbound_mgr, mock.patch.object( test_module, "LOGGER" - ) as mock_logger, async_mock.patch.object( + ) as mock_logger, mock.patch.object( BaseStorage, "find_record", - async_mock.AsyncMock(side_effect=StorageNotFoundError()), - ), async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError()), + ), mock.patch.object( test_module, "upgrade", - async_mock.AsyncMock(), + mock.AsyncMock(), ): mock_outbound_mgr.return_value.registered_transports = { - "test": async_mock.MagicMock(schemes=["http"]) + "test": mock.MagicMock(schemes=["http"]) } await conductor.setup() diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index 8c793c327d..43df17e272 100644 --- a/aries_cloudagent/core/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -1,7 +1,7 @@ import json from unittest import IsolatedAsyncioTestCase -import mock as async_mock +import mock import pytest from marshmallow import EXCLUDE @@ -35,7 +35,7 @@ def make_profile() -> Profile: profile.context.injector.bind_instance(ProtocolRegistry, ProtocolRegistry()) profile.context.injector.bind_instance(Collector, Collector()) profile.context.injector.bind_instance(EventBus, EventBus()) - profile.context.injector.bind_instance(RouteManager, async_mock.MagicMock()) + profile.context.injector.bind_instance(RouteManager, mock.MagicMock()) return profile @@ -109,22 +109,22 @@ async def test_dispatch(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "BaseConnectionManager", autospec=True - ) as conn_mgr_mock, async_mock.patch.object( + ) as conn_mgr_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(return_value=("1.1", None)), ): - conn_mgr_mock.return_value = async_mock.MagicMock( - find_inbound_connection=async_mock.AsyncMock( - return_value=async_mock.MagicMock(connection_id="dummy") + conn_mgr_mock.return_value = mock.MagicMock( + find_inbound_connection=mock.AsyncMock( + return_value=mock.MagicMock(connection_id="dummy") ) ) await dispatcher.queue_message( @@ -160,16 +160,16 @@ async def test_dispatch_versioned_message(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -202,7 +202,7 @@ async def test_dispatch_versioned_message_no_message_class(self): rcv = Receiver() message = {"@type": "proto-name/1.1/no-such-message-type"} - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True ) as handler_mock: await dispatcher.queue_message( @@ -236,15 +236,13 @@ async def test_dispatch_versioned_message_message_class_deserialize_x(self): rcv = Receiver() message = {"@type": "proto-name/1.1/no-such-message-type"} - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( - registry, "resolve_message_class", async_mock.MagicMock() + ) as handler_mock, mock.patch.object( + registry, "resolve_message_class", mock.MagicMock() ) as mock_resolve: - mock_resolve.return_value = async_mock.MagicMock( - deserialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ) + mock_resolve.return_value = mock.MagicMock( + deserialize=mock.MagicMock(side_effect=test_module.BaseModelError()) ) await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -281,16 +279,16 @@ async def test_dispatch_versioned_message_handle_greater_succeeds(self): ) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True - ) as handler_mock, async_mock.patch.object( + ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - async_mock.AsyncMock(return_value="1.1"), - ), async_mock.patch.object( + mock.AsyncMock(return_value="1.1"), + ), mock.patch.object( test_module, "validate_get_response_version", - async_mock.AsyncMock(return_value=("1.1", None)), + mock.AsyncMock(return_value=("1.1", None)), ): await dispatcher.queue_message( dispatcher.profile, make_inbound(message), rcv.send @@ -325,7 +323,7 @@ async def test_dispatch_versioned_message_fail(self): "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) } - with async_mock.patch.object( + with mock.patch.object( StubAgentMessageHandler, "handle", autospec=True ) as handler_mock: await dispatcher.queue_message( @@ -343,10 +341,10 @@ async def test_bad_message_dispatch_parse_x(self): await dispatcher.setup() rcv = Receiver() bad_messages = ["not even a dict", {"bad": "message"}] - with async_mock.patch.object( - test_module, "get_version_from_message_type", async_mock.AsyncMock() - ), async_mock.patch.object( - test_module, "validate_get_response_version", async_mock.AsyncMock() + with mock.patch.object( + test_module, "get_version_from_message_type", mock.AsyncMock() + ), mock.patch.object( + test_module, "validate_get_response_version", mock.AsyncMock() ): for bad in bad_messages: await dispatcher.queue_message( @@ -397,7 +395,7 @@ async def test_dispatch_log(self): await dispatcher.setup() exc = KeyError("sample exception") - mock_task = async_mock.MagicMock( + mock_task = mock.MagicMock( exc_info=(type(exc), exc, exc.__traceback__), ident="abc", timing={ @@ -427,12 +425,10 @@ async def test_create_send_outbound(self): outbound_message = await responder.create_outbound( json.dumps(message.serialize()) ) - with async_mock.patch.object( - responder, "_send", async_mock.AsyncMock() - ), async_mock.patch.object( + with mock.patch.object(responder, "_send", mock.AsyncMock()), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ): await responder.send_outbound(outbound_message) @@ -452,12 +448,10 @@ async def test_create_send_outbound_with_msg_attrs(self): message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) outbound_message = await responder.create_outbound(message) - with async_mock.patch.object( - responder, "_send", async_mock.AsyncMock() - ), async_mock.patch.object( + with mock.patch.object(responder, "_send", mock.AsyncMock()), mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ): await responder.send_outbound( message=outbound_message, @@ -482,10 +476,10 @@ async def test_create_send_outbound_with_msg_attrs_x(self): responder = test_module.DispatcherResponder(context, message, None) outbound_message = await responder.create_outbound(message) outbound_message.connection_id = "123" - with async_mock.patch.object( + with mock.patch.object( test_module.BaseResponder, "conn_rec_active_state_check", - async_mock.AsyncMock(return_value=False), + mock.AsyncMock(return_value=False), ): with self.assertRaises(RuntimeError): await responder.send_outbound( @@ -508,8 +502,8 @@ async def test_conn_rec_active_state_check_a(self): context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_ret_by_id: conn_rec = test_module.ConnRecord() conn_rec.state = test_module.ConnRecord.State.COMPLETED @@ -529,13 +523,13 @@ async def test_conn_rec_active_state_check_b(self): profile = make_profile() profile.context.injector.bind_instance(BaseCache, InMemoryCache()) profile.context.injector.bind_instance( - EventBus, async_mock.MagicMock(notify=async_mock.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.AsyncMock()) ) context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_ret_by_id: conn_rec_a = test_module.ConnRecord() conn_rec_a.state = test_module.ConnRecord.State.REQUEST @@ -553,28 +547,28 @@ async def test_create_enc_outbound(self): context = RequestContext(profile) message = StubAgentMessage() responder = test_module.DispatcherResponder(context, message, None) - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.AsyncMock() ) as mock_send_outbound: await responder.send(message) assert mock_send_outbound.called_once() msg_json = json.dumps(StubAgentMessage().serialize()) message = msg_json.encode("utf-8") - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.AsyncMock() ) as mock_send_outbound: await responder.send(message) message = StubAgentMessage() - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.AsyncMock() ) as mock_send_outbound: await responder.send_reply(message) assert mock_send_outbound.called_once() message = json.dumps(StubAgentMessage().serialize()) - with async_mock.patch.object( - responder, "send_outbound", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_outbound", mock.AsyncMock() ) as mock_send_outbound: await responder.send_reply(message) @@ -611,14 +605,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.AsyncMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), + # mock.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -640,14 +634,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.AsyncMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "version-with-degraded-features")), + # mock.AsyncMock(return_value=("1.1", "version-with-degraded-features")), # ): # await dispatcher.queue_message( # dispatcher.profile, make_inbound(message), rcv.send @@ -669,14 +663,14 @@ def _smaller_scope(): # "@type": DIDCommPrefix.qualify_current(StubAgentMessage.Meta.message_type) # } - # with async_mock.patch.object( + # with mock.patch.object( # test_module, # "get_version_from_message_type", - # async_mock.AsyncMock(return_value="1.1"), - # ), async_mock.patch.object( + # mock.AsyncMock(return_value="1.1"), + # ), mock.patch.object( # test_module, # "validate_get_response_version", - # async_mock.AsyncMock(return_value=("1.1", "version-not-supported")), + # mock.AsyncMock(return_value=("1.1", "version-not-supported")), # ): # with self.assertRaises(test_module.MessageParseError): # await dispatcher.queue_message( diff --git a/aries_cloudagent/core/tests/test_event_bus.py b/aries_cloudagent/core/tests/test_event_bus.py index c201f94b24..cf36790488 100644 --- a/aries_cloudagent/core/tests/test_event_bus.py +++ b/aries_cloudagent/core/tests/test_event_bus.py @@ -3,7 +3,7 @@ import pytest import re -from unittest import mock as async_mock +from unittest import mock from .. import event_bus as test_module from ..event_bus import EventBus, Event @@ -18,7 +18,7 @@ def event_bus(): @pytest.fixture def profile(): - yield async_mock.MagicMock() + yield mock.MagicMock() @pytest.fixture @@ -105,8 +105,8 @@ def _raise_exception(profile, event): bad_processor = _raise_exception event_bus.subscribe(re.compile(".*"), bad_processor) event_bus.subscribe(re.compile(".*"), processor) - with async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: await event_bus.notify(profile, event) diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index eebdaa6931..7bc1175b4f 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -1,7 +1,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from unittest.mock import ANY from ...connections.models.conn_record import ConnRecord @@ -23,12 +23,12 @@ class TestOobProcessor(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = async_mock.AsyncMock() + self.inbound_message_router = mock.AsyncMock() self.oob_processor = OobMessageProcessor( inbound_message_router=self.inbound_message_router ) - self.oob_record = async_mock.MagicMock( + self.oob_record = mock.MagicMock( connection_id="a-connection-id", attach_thread_id="the-thid", their_service={ @@ -36,9 +36,9 @@ async def asyncSetUp(self): "routingKeys": ["6QSduYdf8Bi6t8PfNm5vNomGWDtXhmMmTRzaciudBXYJ"], "serviceEndpoint": "http://their-service-endpoint.com", }, - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), + save=mock.AsyncMock(), ) self.context = RequestContext.test_context() self.context.message = ConnectionInvitation() @@ -47,17 +47,17 @@ async def test_clean_finished_oob_record_no_multi_use_no_request_attach(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - mock_oob = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=False, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=mock_oob), + mock.AsyncMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -75,17 +75,17 @@ async def test_clean_finished_oob_record_multi_use(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - mock_oob = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=mock_oob), + mock.AsyncMock(return_value=mock_oob), ) as mock_retrieve_oob: await self.oob_processor.clean_finished_oob_record( self.profile, test_message @@ -102,10 +102,10 @@ async def test_clean_finished_oob_record_x(self): test_message = InvitationMessage() test_message.assign_thread_id("the-thid", "the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError(),) @@ -114,11 +114,11 @@ async def test_clean_finished_oob_record_x(self): ) async def test_find_oob_target_for_outbound_message(self): - mock_oob = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", their_service={ @@ -136,10 +136,10 @@ async def test_find_oob_target_for_outbound_message(self): message = json.dumps({"~thread": {"thid": "the-thid"}}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=mock_oob), + mock.AsyncMock(return_value=mock_oob), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -174,10 +174,10 @@ async def test_find_oob_target_for_outbound_message_oob_not_found(self): message = json.dumps({}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve_oob: target = await self.oob_processor.find_oob_target_for_outbound_message( self.profile, outbound @@ -189,11 +189,11 @@ async def test_find_oob_target_for_outbound_message_oob_not_found(self): ) async def test_find_oob_target_for_outbound_message_update_service_thread(self): - mock_oob = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=True, - invitation=async_mock.MagicMock(requests_attach=[]), + invitation=mock.MagicMock(requests_attach=[]), invi_msg_id="the-pthid", our_recipient_key="3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx", their_service={ @@ -208,10 +208,10 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): }, ) - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=mock_oob), + mock.AsyncMock(return_value=mock_oob), ): message = json.dumps({}) outbound = OutboundMessage(reply_thread_id="the-thid", payload=message) @@ -247,10 +247,10 @@ async def test_find_oob_target_for_outbound_message_update_service_thread(self): async def test_find_oob_record_for_inbound_message_parent_thread_id(self): # With pthid - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -263,10 +263,10 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # With pthid, throws error - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -279,10 +279,10 @@ async def test_find_oob_record_for_inbound_message_parent_thread_id(self): mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Without pthid - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -295,10 +295,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( self, ): # With thread_id and recipient_verkey - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -319,10 +319,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( ) # With thread_id and recipient_verkey, throws error - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(side_effect=(StorageNotFoundError(),)), + mock.AsyncMock(side_effect=(StorageNotFoundError(),)), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" @@ -341,15 +341,15 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( ) # With connection - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=None), + mock.AsyncMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", recipient_verkey="our-recipient-key" ) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() assert not await self.oob_processor.find_oob_record_for_inbound_message( self.context @@ -357,10 +357,10 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( mock_retrieve.assert_not_called() # Without thread_id and recipient_verkey - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=None), + mock.AsyncMock(return_value=None), ) as mock_retrieve: self.context.message_receipt = MessageReceipt() @@ -372,14 +372,14 @@ async def test_find_oob_record_for_inbound_message_connectionless_retrieve_oob( async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="a-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -393,14 +393,14 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is different - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -414,14 +414,14 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is not the same, state is not await response - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_ACCEPTED - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -435,20 +435,18 @@ async def test_find_oob_record_for_inbound_message_sender_connection_id_no_match mock_retrieve.assert_called_once_with(ANY, {"invi_msg_id": "the-pthid"}) # Connection id is not the same, state is AWAIT_RESPONSE. oob has connection_id - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(return_value=self.oob_record), + ) as mock_retrieve, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock( - return_value=async_mock.MagicMock(delete_record=async_mock.AsyncMock()) - ), + mock.AsyncMock(return_value=mock.MagicMock(delete_record=mock.AsyncMock())), ) as mock_retrieve_conn: self.oob_record.role = OobRecord.ROLE_SENDER self.oob_record.state = OobRecord.STATE_AWAIT_RESPONSE - self.context.connection_record = async_mock.MagicMock( + self.context.connection_record = mock.MagicMock( connection_id="another-connection-id" ) self.context.message_receipt = MessageReceipt( @@ -473,10 +471,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_set(self): AttachDecorator.data_json({"@id": "the-thid"}) ] - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -500,10 +498,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( AttachDecorator.data_json({"@id": "another-thid"}) ] - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -518,10 +516,10 @@ async def test_find_oob_record_for_inbound_message_attach_thread_id_not_in_list( async def test_find_oob_record_for_inbound_message_not_attach_thread_id_matching( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -538,10 +536,10 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc ): self.oob_record.attach_thread_id = "another-thid" - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", parent_thread_id="the-pthid" @@ -556,10 +554,10 @@ async def test_find_oob_record_for_inbound_message_not_attach_thread_id_not_matc async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their_service( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -577,10 +575,10 @@ async def test_find_oob_record_for_inbound_message_recipient_verkey_not_in_their async def test_find_oob_record_for_inbound_message_their_service_matching_with_message_receipt( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -606,10 +604,10 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco self.oob_record.their_service = None - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -631,10 +629,10 @@ async def test_find_oob_record_for_inbound_message_their_service_set_on_oob_reco async def test_find_oob_record_for_inbound_message_session_emit_delete( self, ): - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -657,10 +655,10 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( ): self.oob_record.connection_id = None - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(return_value=self.oob_record), + mock.AsyncMock(return_value=self.oob_record), ) as mock_retrieve: self.context.message_receipt = MessageReceipt( thread_id="the-thid", @@ -678,9 +676,9 @@ async def test_find_oob_record_for_inbound_message_session_connectionless_save( self.oob_record.save.assert_called_once() async def test_handle_message_connection(self): - oob_record = async_mock.MagicMock( + oob_record = mock.MagicMock( connection_id="the-conn-id", - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), attach_thread_id=None, their_service=None, ) @@ -709,9 +707,7 @@ async def test_handle_message_connection(self): self.inbound_message_router.assert_called_once_with(self.profile, ANY, False) async def test_handle_message_connectionless(self): - oob_record = async_mock.MagicMock( - save=async_mock.AsyncMock(), connection_id=None - ) + oob_record = mock.MagicMock(save=mock.AsyncMock(), connection_id=None) await self.oob_processor.handle_message( self.profile, @@ -743,7 +739,7 @@ async def test_handle_message_connectionless(self): async def test_handle_message_unsupported_message_type(self): with self.assertRaises(OobMessageProcessorError) as err: await self.oob_processor.handle_message( - self.profile, [{"@type": "unsupported"}], async_mock.MagicMock() + self.profile, [{"@type": "unsupported"}], mock.MagicMock() ) assert ( "None of the oob attached messages supported. Supported message types are issue-credential/1.0/offer-credential, issue-credential/2.0/offer-credential, present-proof/1.0/request-presentation, present-proof/2.0/request-presentation" diff --git a/aries_cloudagent/core/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py index b3d75ada63..b6373d9282 100644 --- a/aries_cloudagent/core/tests/test_plugin_registry.py +++ b/aries_cloudagent/core/tests/test_plugin_registry.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from unittest.mock import call @@ -20,36 +20,36 @@ def setUp(self): self.registry = PluginRegistry(blocklist=[self.blocked_module]) self.context = InjectionContext(enforce_typing=False) - self.proto_registry = async_mock.MagicMock( - register_message_types=async_mock.MagicMock(), - register_controllers=async_mock.MagicMock(), + self.proto_registry = mock.MagicMock( + register_message_types=mock.MagicMock(), + register_controllers=mock.MagicMock(), ) - self.goal_code_registry = async_mock.MagicMock( - register_controllers=async_mock.MagicMock(), + self.goal_code_registry = mock.MagicMock( + register_controllers=mock.MagicMock(), ) self.context.injector.bind_instance(ProtocolRegistry, self.proto_registry) self.context.injector.bind_instance(GoalCodeRegistry, self.goal_code_registry) async def test_setup(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - ctx = async_mock.MagicMock() + ctx = mock.MagicMock() self.registry._plugins[mod_name] = mod assert list(self.registry.plugin_names) == [mod_name] assert list(self.registry.plugins) == [mod] - mod.setup = async_mock.AsyncMock() + mod.setup = mock.AsyncMock() await self.registry.init_context(ctx) mod.setup.assert_awaited_once_with(ctx) async def test_register_routes(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.AsyncMock() - definition = async_mock.MagicMock() + mod.routes.register = mock.AsyncMock() + definition = mock.MagicMock() definition.versions = [ { "major_version": 1, @@ -59,10 +59,10 @@ async def test_register_routes(self): } ] - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, mod.routes]), + mock.MagicMock(side_effect=[definition, mod.routes]), ) as load_module: await self.registry.register_admin_routes(app) @@ -73,10 +73,10 @@ async def test_register_routes(self): load_module.assert_has_calls(calls) assert mod.routes.register.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]), + mock.MagicMock(side_effect=[definition, ModuleLoadError()]), ) as load_module: await self.registry.register_admin_routes(app) @@ -89,16 +89,16 @@ async def test_register_routes(self): async def test_register_routes_mod_no_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.AsyncMock() + mod.routes.register = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, mod.routes]), + mock.MagicMock(side_effect=[None, mod.routes]), ) as load_module: await self.registry.register_admin_routes(app) @@ -106,10 +106,10 @@ async def test_register_routes_mod_no_version(self): load_module.assert_has_calls(calls) assert mod.routes.register.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, ModuleLoadError()]), + mock.MagicMock(side_effect=[None, ModuleLoadError()]), ) as load_module: await self.registry.register_admin_routes(app) @@ -122,12 +122,12 @@ async def test_register_routes_mod_no_version(self): async def test_post_process_routes(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.post_process_routes = async_mock.MagicMock() - definition = async_mock.MagicMock() + mod.routes.post_process_routes = mock.MagicMock() + definition = mock.MagicMock() definition.versions = [ { "major_version": 1, @@ -137,10 +137,10 @@ async def test_post_process_routes(self): } ] - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, mod.routes]), + mock.MagicMock(side_effect=[definition, mod.routes]), ) as load_module: self.registry.post_process_routes(app) @@ -151,10 +151,10 @@ async def test_post_process_routes(self): load_module.assert_has_calls(calls) assert mod.routes.post_process_routes.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[definition, ModuleLoadError()]), + mock.MagicMock(side_effect=[definition, ModuleLoadError()]), ) as load_module: self.registry.post_process_routes(app) @@ -167,16 +167,16 @@ async def test_post_process_routes(self): async def test_post_process_routes_mod_no_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name - app = async_mock.MagicMock() + app = mock.MagicMock() self.registry._plugins[mod_name] = mod - mod.routes.register = async_mock.AsyncMock() + mod.routes.register = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, mod.routes]), + mock.MagicMock(side_effect=[None, mod.routes]), ) as load_module: self.registry.post_process_routes(app) @@ -184,10 +184,10 @@ async def test_post_process_routes_mod_no_version(self): load_module.assert_has_calls(calls) assert mod.routes.post_process_routes.call_count == 1 - with async_mock.patch.object( + with mock.patch.object( ClassLoader, "load_module", - async_mock.MagicMock(side_effect=[None, ModuleLoadError()]), + mock.MagicMock(side_effect=[None, ModuleLoadError()]), ) as load_module: self.registry.post_process_routes(app) @@ -197,46 +197,46 @@ async def test_post_process_routes_mod_no_version(self): async def test_validate_version_not_a_list(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions_not_a_list = {} - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions_not_a_list, mod_name) async def test_validate_version_list_element_not_an_object(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [{}, []] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_element_empty(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_missing_attribute(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -248,15 +248,15 @@ async def test_validate_version_list_missing_attribute(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_negative_version(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -268,15 +268,15 @@ async def test_validate_version_negative_version(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_min_greater_current(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -288,15 +288,15 @@ async def test_validate_version_min_greater_current(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_multiple_major(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -314,15 +314,15 @@ async def test_validate_version_multiple_major(self): }, ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_bad_path(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -334,15 +334,15 @@ async def test_validate_version_bad_path(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock(return_value=None) + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock(return_value=None) ) as load_module: with pytest.raises(ProtocolDefinitionValidationError): self.registry.validate_version(versions, mod_name) async def test_validate_version_list_correct(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -360,8 +360,8 @@ async def test_validate_version_list_correct(self): }, ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions, mod_name) is True @@ -372,7 +372,7 @@ async def test_validate_version_list_correct(self): async def test_validate_version_list_extra_attributes_ok(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -385,14 +385,14 @@ async def test_validate_version_list_extra_attributes_ok(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: assert self.registry.validate_version(versions, mod_name) is True async def test_validate_version_no_such_mod(self): mod_name = "no_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() mod.__name__ = mod_name versions = [ @@ -404,8 +404,8 @@ async def test_validate_version_no_such_mod(self): } ] - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = None @@ -414,20 +414,20 @@ async def test_validate_version_no_such_mod(self): async def test_register_plugin_already_present(self): mod_name = "test_mod" - mod = async_mock.MagicMock() + mod = mock.MagicMock() self.registry._plugins[mod_name] = mod assert mod == self.registry.register_plugin(mod_name) async def test_register_plugin_load_x(self): - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError("failure to load") assert self.registry.register_plugin("dummy") is None async def test_register_plugin_no_mod(self): - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = None assert self.registry.register_plugin("dummy") is None @@ -437,8 +437,8 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -453,8 +453,8 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -469,8 +469,8 @@ class MODULE: setup = "present" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -485,8 +485,8 @@ class MODULE: setup = "present" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module @@ -502,58 +502,58 @@ class MODULE: no_setup = "no setup attr" obj = MODULE() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [ obj, # module None, # routes None, # message types - async_mock.MagicMock(versions="not-a-list"), + mock.MagicMock(versions="not-a-list"), ] assert self.registry.register_plugin("dummy") is None async def test_register_package_x(self): - with async_mock.patch.object( - ClassLoader, "scan_subpackages", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "scan_subpackages", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError() assert not self.registry.register_package("dummy") async def test_load_protocols_load_x(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + mock_plugin = mock.MagicMock(__name__="dummy") + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = ModuleLoadError() await self.registry.load_protocols(None, mock_plugin) assert load_module.call_count == 1 async def test_load_protocols_load_mod(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_mod = async_mock.MagicMock() - mock_mod.MESSAGE_TYPES = async_mock.MagicMock() - mock_mod.CONTROLLERS = async_mock.MagicMock() + mock_plugin = mock.MagicMock(__name__="dummy") + mock_mod = mock.MagicMock() + mock_mod.MESSAGE_TYPES = mock.MagicMock() + mock_mod.CONTROLLERS = mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.return_value = mock_mod await self.registry.load_protocols(self.context, mock_plugin) async def test_load_protocols_no_mod_load_x(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") + mock_plugin = mock.MagicMock(__name__="dummy") - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, ModuleLoadError()] await self.registry.load_protocols(self.context, mock_plugin) assert load_module.call_count == 2 async def test_load_protocols_no_mod_def_no_message_types(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_def = async_mock.MagicMock( + mock_plugin = mock.MagicMock(__name__="dummy") + mock_def = mock.MagicMock( versions=[ { "major_version": 1, @@ -564,16 +564,16 @@ async def test_load_protocols_no_mod_def_no_message_types(self): ] ) - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, mock_def, ModuleLoadError()] await self.registry.load_protocols(self.context, mock_plugin) assert load_module.call_count == 3 async def test_load_protocols_no_mod_def_message_types(self): - mock_plugin = async_mock.MagicMock(__name__="dummy") - mock_def = async_mock.MagicMock( + mock_plugin = mock.MagicMock(__name__="dummy") + mock_def = mock.MagicMock( versions=[ { "major_version": 1, @@ -589,12 +589,12 @@ async def test_load_protocols_no_mod_def_message_types(self): }, ] ) - mock_mod = async_mock.MagicMock() - mock_mod.MESSAGE_TYPES = async_mock.MagicMock() - mock_mod.CONTROLLERS = async_mock.MagicMock() + mock_mod = mock.MagicMock() + mock_mod.MESSAGE_TYPES = mock.MagicMock() + mock_mod.CONTROLLERS = mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_module", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_module", mock.MagicMock() ) as load_module: load_module.side_effect = [None, mock_def, mock_mod, mock_mod] await self.registry.load_protocols(self.context, mock_plugin) diff --git a/aries_cloudagent/core/tests/test_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py index 154e0ac322..1357b9f082 100644 --- a/aries_cloudagent/core/tests/test_protocol_registry.py +++ b/aries_cloudagent/core/tests/test_protocol_registry.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -205,17 +205,17 @@ async def test_disclosed(self): self.registry.register_message_types( {self.test_message_type: self.test_message_handler} ) - mock = async_mock.MagicMock() - mock.return_value.check_access = async_mock.AsyncMock() - mock.return_value.check_access.return_value = True - mock.return_value.determine_roles = async_mock.AsyncMock() - mock.return_value.determine_roles.return_value = ["ROLE"] - self.registry.register_controllers({self.test_protocol: mock}) + mocked = mock.MagicMock() + mocked.return_value.check_access = mock.AsyncMock() + mocked.return_value.check_access.return_value = True + mocked.return_value.determine_roles = mock.AsyncMock() + mocked.return_value.determine_roles.return_value = ["ROLE"] + self.registry.register_controllers({self.test_protocol: mocked}) protocols = [self.test_protocol] ctx = InjectionContext() published = await self.registry.prepare_disclosed(ctx, protocols) - mock.return_value.check_access.assert_called_once_with(ctx) - mock.return_value.determine_roles.assert_called_once_with(ctx) + mocked.return_value.check_access.assert_called_once_with(ctx) + mocked.return_value.determine_roles.assert_called_once_with(ctx) assert len(published) == 1 assert published[0]["pid"] == self.test_protocol assert published[0]["roles"] == ["ROLE"] @@ -235,8 +235,8 @@ def __init__(self, protocol): async def check_access(self, context): return False - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.return_value = Mockery published = await self.registry.prepare_disclosed(ctx, protocols) @@ -246,9 +246,9 @@ def test_resolve_message_class_str(self): self.registry.register_message_types( {self.test_message_type: self.test_message_handler} ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.return_value = mock_class result = self.registry.resolve_message_class(self.test_message_type) @@ -269,9 +269,9 @@ def test_resolve_message_load_class_str(self): "path": "v1_2", }, ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.side_effect = [mock_class, mock_class] result = self.registry.resolve_message_class("proto/1.1/aaa") @@ -288,9 +288,9 @@ def test_resolve_message_load_class_none(self): "path": "v1_2", }, ) - mock_class = async_mock.MagicMock() - with async_mock.patch.object( - ClassLoader, "load_class", async_mock.MagicMock() + mock_class = mock.MagicMock() + with mock.patch.object( + ClassLoader, "load_class", mock.MagicMock() ) as load_class: load_class.side_effect = [mock_class, mock_class] result = self.registry.resolve_message_class("proto/1.2/bbb") diff --git a/aries_cloudagent/holder/tests/test_routes.py b/aries_cloudagent/holder/tests/test_routes.py index e4094fe8e3..6c4d1888fd 100644 --- a/aries_cloudagent/holder/tests/test_routes.py +++ b/aries_cloudagent/holder/tests/test_routes.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -38,7 +38,7 @@ def setUp(self): setattr(self.context, "profile", self.profile) self.request_dict = {"context": self.context} - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -49,15 +49,15 @@ async def test_credentials_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credential=async_mock.AsyncMock( + mock.MagicMock( + get_credential=mock.AsyncMock( return_value=json.dumps({"hello": "world"}) ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_get(self.request) json_response.assert_called_once_with({"hello": "world"}) @@ -67,8 +67,8 @@ async def test_credentials_get_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credential=async_mock.AsyncMock( + mock.MagicMock( + get_credential=mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -80,17 +80,15 @@ async def test_credentials_get_not_found(self): async def test_credentials_revoked(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.AsyncMock(return_value=False) - ), + mock.MagicMock(credential_revoked=mock.AsyncMock(return_value=False)), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_revoked(self.request) json_response.assert_called_once_with({"revoked": False}) @@ -105,12 +103,12 @@ async def test_credentials_revoked_no_ledger(self): async def test_credentials_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.AsyncMock( + mock.MagicMock( + credential_revoked=mock.AsyncMock( side_effect=test_module.WalletNotFoundError("no such cred") ) ), @@ -121,14 +119,14 @@ async def test_credentials_not_found(self): async def test_credentials_x_ledger(self): self.request.match_info = {"credential_id": "dummy"} - ledger = async_mock.create_autospec(BaseLedger) + ledger = mock.create_autospec(BaseLedger) self.profile.context.injector.bind_instance( - BaseLedger, async_mock.create_autospec(BaseLedger) + BaseLedger, mock.create_autospec(BaseLedger) ) self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - credential_revoked=async_mock.AsyncMock( + mock.MagicMock( + credential_revoked=mock.AsyncMock( side_effect=test_module.LedgerError("down for maintenance") ) ), @@ -141,18 +139,18 @@ async def test_attribute_mime_types_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_mime_type=async_mock.AsyncMock( + mock.MagicMock( + get_mime_type=mock.AsyncMock( side_effect=[None, {"a": "application/jpeg"}] ) ), ) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credentials_attr_mime_types_get(self.request) mock_response.assert_called_once_with({"results": None}) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credentials_attr_mime_types_get(self.request) mock_response.assert_called_once_with( {"results": {"a": "application/jpeg"}} @@ -162,13 +160,11 @@ async def test_credentials_remove(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - delete_credential=async_mock.AsyncMock(return_value=None) - ), + mock.MagicMock(delete_credential=mock.AsyncMock(return_value=None)), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_remove(self.request) json_response.assert_called_once_with({}) @@ -178,8 +174,8 @@ async def test_credentials_remove_not_found(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - delete_credential=async_mock.AsyncMock( + mock.MagicMock( + delete_credential=mock.AsyncMock( side_effect=test_module.WalletNotFoundError() ) ), @@ -191,13 +187,13 @@ async def test_credentials_list(self): self.request.query = {"start": "0", "count": "10"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials=async_mock.AsyncMock(return_value=[{"hello": "world"}]) + mock.MagicMock( + get_credentials=mock.AsyncMock(return_value=[{"hello": "world"}]) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.credentials_list(self.request) json_response.assert_called_once_with({"results": [{"hello": "world"}]}) @@ -207,8 +203,8 @@ async def test_credentials_list_x_holder(self): self.request.query = {"start": "0", "count": "10"} self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials=async_mock.AsyncMock( + mock.MagicMock( + get_credentials=mock.AsyncMock( side_effect=test_module.IndyHolderError() ) ), @@ -221,13 +217,13 @@ async def test_w3c_cred_get(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD) + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_cred_get(self.request) json_response.assert_called_once_with(VC_RECORD.serialize()) @@ -236,8 +232,8 @@ async def test_w3c_cred_get_not_found_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -250,8 +246,8 @@ async def test_w3c_cred_get_storage_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageError() ) ), @@ -264,14 +260,14 @@ async def test_w3c_cred_remove(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD), - delete_credential=async_mock.AsyncMock(return_value=None), + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), + delete_credential=mock.AsyncMock(return_value=None), ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_cred_remove(self.request) json_response.assert_called_once_with({}) @@ -281,8 +277,8 @@ async def test_w3c_cred_remove_not_found_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ), @@ -295,9 +291,9 @@ async def test_w3c_cred_remove_storage_x(self): self.request.match_info = {"credential_id": "dummy"} self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - retrieve_credential_by_id=async_mock.AsyncMock(return_value=VC_RECORD), - delete_credential=async_mock.AsyncMock( + mock.MagicMock( + retrieve_credential_by_id=mock.AsyncMock(return_value=VC_RECORD), + delete_credential=mock.AsyncMock( side_effect=test_module.StorageError() ), ), @@ -307,7 +303,7 @@ async def test_w3c_cred_remove_storage_x(self): await test_module.w3c_cred_remove(self.request) async def test_w3c_creds_list(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -320,23 +316,23 @@ async def test_w3c_creds_list(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=[VC_RECORD]) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=[VC_RECORD]) ) ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.w3c_creds_list(self.request) json_response.assert_called_once_with({"results": [VC_RECORD.serialize()]}) async def test_w3c_creds_list_not_found_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -349,10 +345,10 @@ async def test_w3c_creds_list_not_found_x(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -364,7 +360,7 @@ async def test_w3c_creds_list_not_found_x(self): await test_module.w3c_creds_list(self.request) async def test_w3c_creds_list_storage_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "types": [ "VerifiableCredential", @@ -377,12 +373,10 @@ async def test_w3c_creds_list_storage_x(self): ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(side_effect=test_module.StorageError()) ) ) ), @@ -392,13 +386,13 @@ async def test_w3c_creds_list_storage_x(self): await test_module.w3c_creds_list(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py index 331efbf929..3a389914fa 100644 --- a/aries_cloudagent/indy/credx/tests/test_cred_issuance.py +++ b/aries_cloudagent/indy/credx/tests/test_cred_issuance.py @@ -2,7 +2,7 @@ import tempfile import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager @@ -46,16 +46,16 @@ class TestIndyCredxIssuance(IsolatedAsyncioTestCase): async def asyncSetUp(self): context = InjectionContext(enforce_typing=False) - mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock(return_value={"value": {}}), - get_revoc_reg_delta=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.AsyncMock(return_value=mock_ledger) self.ledger = mock_ledger self.holder_profile = await AskarProfileManager().provision( @@ -77,8 +77,8 @@ async def asyncSetUp(self): self.issuer_profile._context.injector.bind_instance(BaseLedger, mock_ledger) self.issuer_profile._context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, mock_ledger) ) ), diff --git a/aries_cloudagent/indy/models/tests/test_pres_preview.py b/aries_cloudagent/indy/models/tests/test_pres_preview.py index 7601b3fda1..307fd652b9 100644 --- a/aries_cloudagent/indy/models/tests/test_pres_preview.py +++ b/aries_cloudagent/indy/models/tests/test_pres_preview.py @@ -6,7 +6,7 @@ from unittest import TestCase from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile from ....ledger.multiple_ledger.ledger_requests_executor import ( @@ -402,13 +402,13 @@ async def test_to_indy_proof_request_revo_default_interval(self): context.injector.bind_instance( IndyLedgerRequestsExecutor, IndyLedgerRequestsExecutor(mock_profile) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), @@ -447,15 +447,15 @@ async def test_to_indy_proof_request_revo(self): ) context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) ), diff --git a/aries_cloudagent/indy/sdk/tests/test_holder.py b/aries_cloudagent/indy/sdk/tests/test_holder.py index dc4b0e39f3..6784005809 100644 --- a/aries_cloudagent/indy/sdk/tests/test_holder.py +++ b/aries_cloudagent/indy/sdk/tests/test_holder.py @@ -1,7 +1,7 @@ import json import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase import indy.anoncreds @@ -16,23 +16,23 @@ @pytest.mark.indy class TestIndySdkHolder(IsolatedAsyncioTestCase): def setUp(self): - mock_ledger = async_mock.MagicMock( - get_credential_definition=async_mock.MagicMock(return_value={"value": {}}), - get_revoc_reg_delta=async_mock.AsyncMock( + mock_ledger = mock.MagicMock( + get_credential_definition=mock.MagicMock(return_value={"value": {}}), + get_revoc_reg_delta=mock.AsyncMock( return_value=( {"value": {"...": "..."}}, 1234567890, ) ), ) - mock_ledger.__aenter__ = async_mock.AsyncMock(return_value=mock_ledger) + mock_ledger.__aenter__ = mock.AsyncMock(return_value=mock_ledger) self.ledger = mock_ledger - self.wallet = async_mock.MagicMock() + self.wallet = mock.MagicMock() self.holder = test_module.IndySdkHolder(self.wallet) assert "IndySdkHolder" in str(self.holder) - @async_mock.patch("indy.anoncreds.prover_create_credential_req") + @mock.patch("indy.anoncreds.prover_create_credential_req") async def test_create_credential_request(self, mock_create_credential_req): mock_create_credential_req.return_value = ("{}", "[]") @@ -50,7 +50,7 @@ async def test_create_credential_request(self, mock_create_credential_req): assert (json.loads(cred_req_json), json.loads(cred_req_meta_json)) == ({}, []) - @async_mock.patch("indy.anoncreds.prover_store_credential") + @mock.patch("indy.anoncreds.prover_store_credential") async def test_store_credential(self, mock_store_cred): mock_store_cred.return_value = "cred_id" @@ -69,14 +69,12 @@ async def test_store_credential(self, mock_store_cred): assert cred_id == "cred_id" - @async_mock.patch("indy.anoncreds.prover_store_credential") + @mock.patch("indy.anoncreds.prover_store_credential") async def test_store_credential_with_mime_types(self, mock_store_cred): - with async_mock.patch.object( - test_module, "IndySdkStorage", async_mock.MagicMock() + with mock.patch.object( + test_module, "IndySdkStorage", mock.MagicMock() ) as mock_storage: - mock_storage.return_value = async_mock.MagicMock( - add_record=async_mock.AsyncMock() - ) + mock_storage.return_value = mock.MagicMock(add_record=mock.AsyncMock()) mock_store_cred.return_value = "cred_id" @@ -100,7 +98,7 @@ async def test_store_credential_with_mime_types(self, mock_store_cred): assert cred_id == "cred_id" - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attrs_mime_types(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -125,7 +123,7 @@ async def test_get_credential_attrs_mime_types(self, mock_nonsec_get_wallet_reco assert mime_types == dummy_tags - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attr_mime_type(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -150,7 +148,7 @@ async def test_get_credential_attr_mime_type(self, mock_nonsec_get_wallet_record assert a_mime_type == dummy_tags["a"] - @async_mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.get_wallet_record") async def test_get_credential_attr_mime_type_x(self, mock_nonsec_get_wallet_record): cred_id = "credential_id" dummy_tags = {"a": "1", "b": "2"} @@ -164,9 +162,9 @@ async def test_get_credential_attr_mime_type_x(self, mock_nonsec_get_wallet_reco assert await self.holder.get_mime_type(cred_id, "a") is None - @async_mock.patch("indy.anoncreds.prover_search_credentials") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search") + @mock.patch("indy.anoncreds.prover_search_credentials") + @mock.patch("indy.anoncreds.prover_fetch_credentials") + @mock.patch("indy.anoncreds.prover_close_credentials_search") async def test_get_credentials( self, mock_close_cred_search, mock_fetch_credentials, mock_search_credentials ): @@ -194,9 +192,9 @@ async def test_get_credentials( credentials = await self.holder.get_credentials(0, 0, {}) # 0 defaults to all assert len(credentials) == SIZE - @async_mock.patch("indy.anoncreds.prover_search_credentials") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search") + @mock.patch("indy.anoncreds.prover_search_credentials") + @mock.patch("indy.anoncreds.prover_fetch_credentials") + @mock.patch("indy.anoncreds.prover_close_credentials_search") async def test_get_credentials_seek( self, mock_close_cred_search, mock_fetch_credentials, mock_search_credentials ): @@ -209,9 +207,9 @@ async def test_get_credentials_seek( (("search_handle", 3),), ] - @async_mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") + @mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") async def test_get_credentials_for_presentation_request_by_reft( self, mock_prover_close_credentials_search_for_proof_req, @@ -289,9 +287,9 @@ async def test_get_credentials_for_presentation_request_by_reft( for c in credentials[-test_module.IndyHolder.CHUNK // 2 :] ) # revocable last - @async_mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") - @async_mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") + @mock.patch("indy.anoncreds.prover_search_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_fetch_credentials_for_proof_req") + @mock.patch("indy.anoncreds.prover_close_credentials_search_for_proof_req") async def test_get_credentials_for_presentation_request_by_referent_default_refts( self, mock_prover_close_credentials_search_for_proof_req, @@ -324,7 +322,7 @@ async def test_get_credentials_for_presentation_request_by_referent_default_reft self.wallet.handle, json.dumps(PRES_REQ), json.dumps({}) ) - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential(self, mock_get_cred): mock_get_cred.return_value = "{}" credential_json = await self.holder.get_credential("credential_id") @@ -332,13 +330,13 @@ async def test_get_credential(self, mock_get_cred): assert json.loads(credential_json) == {} - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential_not_found(self, mock_get_cred): mock_get_cred.side_effect = IndyError(error_code=ErrorCode.WalletItemNotFound) with self.assertRaises(test_module.WalletNotFoundError): await self.holder.get_credential("credential_id") - @async_mock.patch("indy.anoncreds.prover_get_credential") + @mock.patch("indy.anoncreds.prover_get_credential") async def test_get_credential_x(self, mock_get_cred): mock_get_cred.side_effect = IndyError("unexpected failure") @@ -346,8 +344,8 @@ async def test_get_credential_x(self, mock_get_cred): await self.holder.get_credential("credential_id") async def test_credential_revoked(self): - with async_mock.patch.object( # no creds revoked - self.holder, "get_credential", async_mock.AsyncMock() + with mock.patch.object( # no creds revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -359,8 +357,8 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - with async_mock.patch.object( # cred not revocable - self.holder, "get_credential", async_mock.AsyncMock() + with mock.patch.object( # cred not revocable + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -372,7 +370,7 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "value": { @@ -383,8 +381,8 @@ async def test_credential_revoked(self): 1234567890, ) ) - with async_mock.patch.object( # cred not revoked - self.holder, "get_credential", async_mock.AsyncMock() + with mock.patch.object( # cred not revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -396,8 +394,8 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert not result - with async_mock.patch.object( # cred revoked - self.holder, "get_credential", async_mock.AsyncMock() + with mock.patch.object( # cred revoked + self.holder, "get_credential", mock.AsyncMock() ) as mock_get_cred: mock_get_cred.return_value = json.dumps( { @@ -409,9 +407,9 @@ async def test_credential_revoked(self): result = await self.holder.credential_revoked(self.ledger, "credential_id") assert result - @async_mock.patch("indy.anoncreds.prover_delete_credential") - @async_mock.patch("indy.non_secrets.get_wallet_record") - @async_mock.patch("indy.non_secrets.delete_wallet_record") + @mock.patch("indy.anoncreds.prover_delete_credential") + @mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.delete_wallet_record") async def test_delete_credential( self, mock_nonsec_del_wallet_record, @@ -433,9 +431,9 @@ async def test_delete_credential( self.wallet.handle, "credential_id" ) - @async_mock.patch("indy.anoncreds.prover_delete_credential") - @async_mock.patch("indy.non_secrets.get_wallet_record") - @async_mock.patch("indy.non_secrets.delete_wallet_record") + @mock.patch("indy.anoncreds.prover_delete_credential") + @mock.patch("indy.non_secrets.get_wallet_record") + @mock.patch("indy.non_secrets.delete_wallet_record") async def test_delete_credential_x( self, mock_nonsec_del_wallet_record, @@ -460,7 +458,7 @@ async def test_delete_credential_x( await self.holder.delete_credential("credential_id") assert mock_prover_del_cred.call_count == 2 - @async_mock.patch("indy.anoncreds.prover_create_proof") + @mock.patch("indy.anoncreds.prover_create_proof") async def test_create_presentation(self, mock_create_proof): mock_create_proof.return_value = "{}" PROOF_REQ = { @@ -578,10 +576,10 @@ async def test_create_revocation_state(self): "timestamp": 1234567890, } - with async_mock.patch.object( - test_module, "create_tails_reader", async_mock.AsyncMock() - ) as mock_create_tails_reader, async_mock.patch.object( - indy.anoncreds, "create_revocation_state", async_mock.AsyncMock() + with mock.patch.object( + test_module, "create_tails_reader", mock.AsyncMock() + ) as mock_create_tails_reader, mock.patch.object( + indy.anoncreds, "create_revocation_state", mock.AsyncMock() ) as mock_create_rr_state: mock_create_rr_state.return_value = json.dumps(rr_state) diff --git a/aries_cloudagent/indy/sdk/tests/test_issuer.py b/aries_cloudagent/indy/sdk/tests/test_issuer.py index 51932914c6..d0946a65d7 100644 --- a/aries_cloudagent/indy/sdk/tests/test_issuer.py +++ b/aries_cloudagent/indy/sdk/tests/test_issuer.py @@ -1,7 +1,7 @@ import json import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from indy.error import ( @@ -52,7 +52,7 @@ async def asyncSetUp(self): "name": "test-wallet", } ).create_wallet() - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile(self.wallet, self.context) self.issuer = test_module.IndySdkIssuer(self.profile) @@ -62,7 +62,7 @@ async def tearDown(self): async def test_repr(self): assert "IndySdkIssuer" in str(self.issuer) # cover __repr__ - @async_mock.patch("indy.anoncreds.issuer_create_and_store_credential_def") + @mock.patch("indy.anoncreds.issuer_create_and_store_credential_def") async def test_schema_cred_def(self, mock_indy_cred_def): assert ( self.issuer.make_schema_id(TEST_DID, SCHEMA_NAME, SCHEMA_VERSION) @@ -94,19 +94,19 @@ async def test_schema_cred_def(self, mock_indy_cred_def): ) ) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet(self, mock_indy_create_offer): mock_indy_create_offer.return_value = {"sample": "offer"} assert await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet_no(self, mock_indy_create_offer): mock_indy_create_offer.side_effect = WalletItemNotFound( error_code=ErrorCode.WalletItemNotFound ) assert not await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_credential_definition_in_wallet_x(self, mock_indy_create_offer): mock_indy_create_offer.side_effect = IndyError( error_code=ErrorCode.WalletInvalidHandle @@ -114,12 +114,12 @@ async def test_credential_definition_in_wallet_x(self, mock_indy_create_offer): with self.assertRaises(test_module.IndyIssuerError): await self.issuer.credential_definition_in_wallet(CRED_DEF_ID) - @async_mock.patch("indy.anoncreds.issuer_create_credential_offer") + @mock.patch("indy.anoncreds.issuer_create_credential_offer") async def test_create_credential_offer(self, mock_create_offer): test_offer = {"test": "offer"} test_cred_def_id = "test-cred-def-id" mock_create_offer.return_value = json.dumps(test_offer) - mock_profile = async_mock.MagicMock() + mock_profile = mock.MagicMock() issuer = test_module.IndySdkIssuer(mock_profile) offer_json = await issuer.create_credential_offer(test_cred_def_id) assert json.loads(offer_json) == test_offer @@ -127,10 +127,10 @@ async def test_create_credential_offer(self, mock_create_offer): mock_profile.wallet.handle, test_cred_def_id ) - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) - @async_mock.patch("indy.anoncreds.issuer_revoke_credential") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_revoke_credential") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_create_revoke_credentials( self, mock_indy_merge_rr_deltas, @@ -212,10 +212,10 @@ async def test_create_revoke_credentials( assert mock_indy_revoke_credential.call_count == 2 mock_indy_merge_rr_deltas.assert_called_once() - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) - @async_mock.patch("indy.anoncreds.issuer_revoke_credential") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_revoke_credential") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_create_revoke_credentials_x( self, mock_indy_merge_rr_deltas, @@ -310,8 +310,8 @@ def mock_revoke(_h, _t, _r, cred_rev_id): assert mock_indy_revoke_credential.call_count == 3 mock_indy_merge_rr_deltas.assert_not_called() - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) async def test_create_credential_rr_full( self, mock_tails_reader, @@ -341,8 +341,8 @@ async def test_create_credential_rr_full( test_values, ) - @async_mock.patch("indy.anoncreds.issuer_create_credential") - @async_mock.patch.object(test_module, "create_tails_reader", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_credential") + @mock.patch.object(test_module, "create_tails_reader", autospec=True) async def test_create_credential_x_indy( self, mock_tails_reader, @@ -373,8 +373,8 @@ async def test_create_credential_x_indy( test_values, ) - @async_mock.patch("indy.anoncreds.issuer_create_and_store_revoc_reg") - @async_mock.patch.object(test_module, "create_tails_writer", autospec=True) + @mock.patch("indy.anoncreds.issuer_create_and_store_revoc_reg") + @mock.patch.object(test_module, "create_tails_writer", autospec=True) async def test_create_and_store_revocation_registry( self, mock_indy_tails_writer, mock_indy_rr ): @@ -388,7 +388,7 @@ async def test_create_and_store_revocation_registry( ) assert (rr_id, rrdef_json, rre_json) == ("a", "b", "c") - @async_mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") + @mock.patch("indy.anoncreds.issuer_merge_revocation_registry_deltas") async def test_merge_revocation_registry_deltas(self, mock_indy_merge): mock_indy_merge.return_value = json.dumps({"net": "delta"}) assert {"net": "delta"} == json.loads( diff --git a/aries_cloudagent/indy/sdk/tests/test_profile.py b/aries_cloudagent/indy/sdk/tests/test_profile.py index cf0675cd95..669656ced2 100644 --- a/aries_cloudagent/indy/sdk/tests/test_profile.py +++ b/aries_cloudagent/indy/sdk/tests/test_profile.py @@ -1,6 +1,6 @@ import logging -from unittest import mock as async_mock +from unittest import mock import pytest from ....config.injection_context import InjectionContext @@ -20,7 +20,7 @@ async def open_wallet(): handle=1, master_secret_id="master-secret", ) - with async_mock.patch.object(opened, "close", async_mock.AsyncMock()): + with mock.patch.object(opened, "close", mock.AsyncMock()): yield opened @@ -47,12 +47,12 @@ async def test_init_multi_ledger(open_wallet): "is_write": True, "endorser_did": "9QPa6tHvBHttLg6U4xvviv", "endorser_alias": "endorser_dev", - "genesis_transactions": async_mock.MagicMock(), + "genesis_transactions": mock.MagicMock(), }, { "id": "SovrinStagingNet", "is_production": False, - "genesis_transactions": async_mock.MagicMock(), + "genesis_transactions": mock.MagicMock(), }, ] } @@ -82,18 +82,18 @@ async def test_properties(profile: IndySdkProfile): assert profile.wallet.created assert profile.wallet.master_secret_id == "master-secret" - with async_mock.patch.object(profile, "opened", False): + with mock.patch.object(profile, "opened", False): with pytest.raises(ProfileError): await profile.remove() - with async_mock.patch.object(profile.opened, "close", async_mock.AsyncMock()): + with mock.patch.object(profile.opened, "close", mock.AsyncMock()): await profile.remove() assert profile.opened is None def test_settings_genesis_transactions(open_wallet): context = InjectionContext( - settings={"ledger.genesis_transactions": async_mock.MagicMock()} + settings={"ledger.genesis_transactions": mock.MagicMock()} ) context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) profile = IndySdkProfile(open_wallet, context) @@ -103,8 +103,8 @@ def test_settings_ledger_config(open_wallet): context = InjectionContext( settings={ "ledger.ledger_config_list": [ - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ] } ) diff --git a/aries_cloudagent/indy/sdk/tests/test_util.py b/aries_cloudagent/indy/sdk/tests/test_util.py index 0e7a35a7d2..cd1a3a5349 100644 --- a/aries_cloudagent/indy/sdk/tests/test_util.py +++ b/aries_cloudagent/indy/sdk/tests/test_util.py @@ -4,7 +4,7 @@ import indy.blob_storage -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...util import indy_client_dir, generate_pr_nonce @@ -27,8 +27,8 @@ async def test_tails_reader(self): with open(tails_local, "a") as f: print("1234123412431234", file=f) - with async_mock.patch.object( - indy.blob_storage, "open_reader", async_mock.AsyncMock() + with mock.patch.object( + indy.blob_storage, "open_reader", mock.AsyncMock() ) as mock_blob_open_reader: result = await create_tails_reader(tails_local) assert result == mock_blob_open_reader.return_value diff --git a/aries_cloudagent/indy/sdk/tests/test_verifier.py b/aries_cloudagent/indy/sdk/tests/test_verifier.py index a5b6cfcab2..d5e9f37088 100644 --- a/aries_cloudagent/indy/sdk/tests/test_verifier.py +++ b/aries_cloudagent/indy/sdk/tests/test_verifier.py @@ -3,7 +3,7 @@ from copy import deepcopy -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from indy.error import IndyError @@ -294,8 +294,8 @@ @pytest.mark.indy class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={ "...": "...", "value": { @@ -324,15 +324,15 @@ def setUp(self): self.verifier = IndySdkVerifier(mock_profile) assert repr(self.verifier) == "" - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_verify_presentation(self, mock_verify): mock_verify.return_value = "val" - with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.AsyncMock() - ) as mock_pre_verify, async_mock.patch.object( - self.verifier, "non_revoc_intervals", async_mock.MagicMock() - ) as mock_non_revox, async_mock.patch.object( + with mock.patch.object( + self.verifier, "pre_verify", mock.AsyncMock() + ) as mock_pre_verify, mock.patch.object( + self.verifier, "non_revoc_intervals", mock.MagicMock() + ) as mock_non_revox, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -359,15 +359,15 @@ async def test_verify_presentation(self, mock_verify): assert verified == "val" - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_verify_presentation_x_indy(self, mock_verify): mock_verify.side_effect = IndyError(error_code=1) - with async_mock.patch.object( - self.verifier, "pre_verify", async_mock.AsyncMock() - ) as mock_pre_verify, async_mock.patch.object( - self.verifier, "non_revoc_intervals", async_mock.MagicMock() - ) as mock_non_revox, async_mock.patch.object( + with mock.patch.object( + self.verifier, "pre_verify", mock.AsyncMock() + ) as mock_pre_verify, mock.patch.object( + self.verifier, "non_revoc_intervals", mock.MagicMock() + ) as mock_non_revox, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -391,9 +391,9 @@ async def test_verify_presentation_x_indy(self, mock_verify): assert not verified - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr(self, mock_verify): - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -419,13 +419,13 @@ async def test_check_encoding_attr(self, mock_verify): assert len(msgs) == 1 assert "TS_OUT_NRI::19_uuid" in msgs - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr_tamper_raw(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_NAME) INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][ "raw" ] = "Mock chicken" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -447,13 +447,13 @@ async def test_check_encoding_attr_tamper_raw(self, mock_verify): "VALUE_ERROR::Encoded representation mismatch for 'Preferred Name'" in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_encoding_attr_tamper_encoded(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_NAME) INDY_PROOF_X["requested_proof"]["revealed_attrs"]["19_uuid"][ "encoded" ] = "1234567890" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -475,9 +475,9 @@ async def test_check_encoding_attr_tamper_encoded(self, mock_verify): "VALUE_ERROR::Encoded representation mismatch for 'Preferred Name'" in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names(self, mock_verify): - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) @@ -509,13 +509,13 @@ async def test_check_pred_names(self, mock_verify): assert "TS_OUT_NRI::18_id_GE_uuid" in msgs assert "TS_OUT_NRI::18_busid_GE_uuid" in msgs - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_pred_value(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES) INDY_PROOF_X["proof"]["proofs"][0]["primary_proof"]["ge_proofs"][0][ "predicate" ]["value"] = 0 - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -540,11 +540,11 @@ async def test_check_pred_names_tamper_pred_value(self, mock_verify): in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify): INDY_PROOF_REQ_X = deepcopy(INDY_PROOF_REQ_PRED_NAMES) INDY_PROOF_REQ_X["requested_predicates"]["18_busid_GE_uuid"]["name"] = "dummy" - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -569,13 +569,13 @@ async def test_check_pred_names_tamper_pred_req_attr(self, mock_verify): in msgs ) - @async_mock.patch("indy.anoncreds.verifier_verify_proof") + @mock.patch("indy.anoncreds.verifier_verify_proof") async def test_check_pred_names_tamper_attr_groups(self, mock_verify): INDY_PROOF_X = deepcopy(INDY_PROOF_PRED_NAMES) INDY_PROOF_X["requested_proof"]["revealed_attr_groups"][ "x_uuid" ] = INDY_PROOF_X["requested_proof"]["revealed_attr_groups"].pop("18_uuid") - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ("test", self.ledger) diff --git a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py index b90c6d0a59..1ca4f752f5 100644 --- a/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py +++ b/aries_cloudagent/indy/sdk/tests/test_wallet_plugin.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -15,12 +15,12 @@ async def test_file_ext(self): def test_load_postgres_plugin(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=0), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=0), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib test_module.load_postgres_plugin(storage_config, storage_creds) @@ -30,11 +30,11 @@ def test_load_postgres_plugin(self): def test_load_postgres_plugin_init_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=2) + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=2) ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -46,11 +46,11 @@ def test_load_postgres_plugin_init_x_raise(self): def test_load_postgres_plugin_init_x_exit(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=2) + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=2) ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): @@ -61,12 +61,12 @@ def test_load_postgres_plugin_init_x_exit(self): def test_load_postgres_plugin_config_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -78,12 +78,12 @@ def test_load_postgres_plugin_config_x_raise(self): def test_load_postgres_plugin_config_x_exit(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): @@ -94,12 +94,12 @@ def test_load_postgres_plugin_config_x_exit(self): def test_load_postgres_plugin_bad_json_x_raise(self): storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}' storage_creds = '"account":"test"' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(OSError) as context: @@ -111,12 +111,12 @@ def test_load_postgres_plugin_bad_json_x_raise(self): def test_load_postgres_plugin_bad_json_x_exit(self): storage_config = '"wallet_scheme":"MultiWalletSingleTable"' storage_creds = '{"account":"test"}' - mock_stg_lib = async_mock.MagicMock( - postgresstorage_init=async_mock.MagicMock(return_value=0), - init_storagetype=async_mock.MagicMock(return_value=2), + mock_stg_lib = mock.MagicMock( + postgresstorage_init=mock.MagicMock(return_value=0), + init_storagetype=mock.MagicMock(return_value=2), ) - with async_mock.patch.object( - test_module.cdll, "LoadLibrary", async_mock.Mock() + with mock.patch.object( + test_module.cdll, "LoadLibrary", mock.Mock() ) as mock_load: mock_load.return_value = mock_stg_lib with self.assertRaises(SystemExit): diff --git a/aries_cloudagent/indy/tests/test_verifier.py b/aries_cloudagent/indy/tests/test_verifier.py index e31ecefdf2..910f110c71 100644 --- a/aries_cloudagent/indy/tests/test_verifier.py +++ b/aries_cloudagent/indy/tests/test_verifier.py @@ -4,7 +4,7 @@ from time import time from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...ledger.multiple_ledger.ledger_requests_executor import ( @@ -309,8 +309,8 @@ async def verify_presentation( @pytest.mark.indy class TestIndySdkVerifier(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + self.ledger = mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={ "...": "...", "value": { @@ -343,9 +343,9 @@ async def test_check_timestamps(self): ) context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -362,7 +362,7 @@ async def test_check_timestamps(self): context.injector.bind_instance( IndyLedgerRequestsExecutor, IndyLedgerRequestsExecutor(mock_profile) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -374,13 +374,13 @@ async def test_check_timestamps(self): ) # timestamp for irrevocable credential - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = ( None, - async_mock.MagicMock( - get_credential_definition=async_mock.AsyncMock( + mock.MagicMock( + get_credential_definition=mock.AsyncMock( return_value={ "...": "...", "value": {"no": "revocation"}, @@ -398,7 +398,7 @@ async def test_check_timestamps(self): assert "Timestamp in presentation identifier #" in str(context.exception) # all clear, no timestamps - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -442,9 +442,9 @@ async def test_check_timestamps(self): proof_req_x = deepcopy(INDY_PROOF_REQ_NAME) proof_req_x["non_revoked"] = {"from": 1600000000, "to": 1600001000} proof_x["identifiers"][0]["timestamp"] = 1579890000 - with async_mock.patch.object( - test_module, "LOGGER", async_mock.MagicMock() - ) as mock_logger, async_mock.patch.object( + with mock.patch.object( + test_module, "LOGGER", mock.MagicMock() + ) as mock_logger, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) @@ -461,7 +461,7 @@ async def test_check_timestamps(self): proof_req_x = deepcopy(INDY_PROOF_REQ_NAME) proof_x = deepcopy(INDY_PROOF_NAME) proof_req_x.pop("non_revoked") - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier" ) as mock_get_ledger: mock_get_ledger.return_value = (None, self.ledger) diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py index 4199f395d1..58c4d475e1 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile @@ -31,14 +31,14 @@ async def asyncSetUp(self): ) self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - extract_did_from_identifier=async_mock.AsyncMock( + mock.MagicMock( + extract_did_from_identifier=mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.AsyncMock( return_value=("test_prod_1", self.ledger) ), - get_ledger_inst_by_id=async_mock.AsyncMock(return_value=self.ledger), + get_ledger_inst_by_id=mock.AsyncMock(return_value=self.ledger), ), ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -68,11 +68,11 @@ async def test_get_ledger_for_identifier_is_digit(self): async def test_get_ledger_for_identifier_x(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - extract_did_from_identifier=async_mock.AsyncMock( + mock.MagicMock( + extract_did_from_identifier=mock.AsyncMock( return_value="WgWxqztrNooG92RXvxSTWv" ), - lookup_did_in_configured_ledgers=async_mock.AsyncMock( + lookup_did_in_configured_ledgers=mock.AsyncMock( side_effect=MultipleLedgerManagerError ), ), diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py index a239c69f95..14a144959e 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_manager.py @@ -4,7 +4,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from collections import OrderedDict @@ -29,7 +29,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -136,17 +136,17 @@ async def test_get_ledger_inst_by_id(self): ledger_inst = await self.manager.get_ledger_inst_by_id("test_invalid") assert not ledger_inst - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -160,10 +160,10 @@ async def test_get_ledger_by_did_self_cert_a( assert ledger_inst.pool.name == "test_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_self_cert_b( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -178,10 +178,10 @@ async def test_get_ledger_by_did_self_cert_b( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -195,10 +195,10 @@ async def test_get_ledger_by_did_self_cert_b( assert ledger_inst.pool.name == "test_non_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -213,12 +213,12 @@ async def test_get_ledger_by_did_not_self_cert( "verkey": "ABUF7uxYTxZ6qYdZ4G9e1Gi", } ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -233,81 +233,81 @@ async def test_get_ledger_by_did_not_self_cert( assert ledger_inst.pool.name == "test_prod_1" assert not is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_state_proof_not_valid( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_no_data( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply.get("result").pop("data") - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_timeout( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = asyncio.TimeoutError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_ledger_error( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = LedgerError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -319,21 +319,21 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -346,10 +346,10 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -364,10 +364,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -379,10 +379,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -399,12 +399,12 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( ) get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -417,19 +417,19 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = False @@ -439,17 +439,17 @@ async def test_lookup_did_in_configured_ledgers_x( ) assert "not found in any of the ledgers total: (production: " in cm - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_REPLY) mock_wait.return_value = mock_submit.return_value ( diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py index a7635b215f..6cc0d0200b 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_vdr_manager.py @@ -3,7 +3,7 @@ import pytest from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from copy import deepcopy from collections import OrderedDict @@ -61,7 +61,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile(bind={BaseCache: InMemoryCache()}) self.context = self.profile.context setattr(self.context, "profile", self.profile) - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.production_ledger = OrderedDict() self.non_production_ledger = OrderedDict() @@ -165,19 +165,17 @@ async def test_get_ledger_inst_by_id(self): ledger_inst = await self.manager.get_ledger_inst_by_id("test_invalid") assert not ledger_inst - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_self_cert_a( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -191,12 +189,10 @@ async def test_get_ledger_by_did_self_cert_a( assert ledger_inst.pool.name == "test_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_self_cert_b( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -211,10 +207,10 @@ async def test_get_ledger_by_did_self_cert_b( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -228,12 +224,10 @@ async def test_get_ledger_by_did_self_cert_b( assert ledger_inst.pool.name == "test_non_prod_1" assert is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -248,12 +242,12 @@ async def test_get_ledger_by_did_not_self_cert( "verkey": "ABUF7uxYTxZ6qYdZ4G9e1Gi", } ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -268,91 +262,81 @@ async def test_get_ledger_by_did_not_self_cert( assert ledger_inst.pool.name == "test_prod_1" assert not is_self_certified - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_state_proof_not_valid( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(get_nym_reply) mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_no_data( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply.pop("data") - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_timeout( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = asyncio.TimeoutError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_ledger_error( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.side_effect = LedgerError assert not await self.manager._get_ledger_by_did( "test_prod_1", "Av63wJYM7xYR4AiygYq4c3" ) - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY) mock_wait.return_value = mock_submit.return_value ( @@ -364,23 +348,21 @@ async def test_lookup_did_in_configured_ledgers_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): get_nym_reply = deepcopy(GET_NYM_INDY_VDR_REPLY) get_nym_reply["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -393,12 +375,10 @@ async def test_get_ledger_by_did_not_self_cert_not_self_cert_prod( assert ledger_id == "test_prod_1" assert ledger_inst.pool.name == "test_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -413,10 +393,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( self.profile, non_production_ledgers=self.non_production_ledger, ) - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value ( @@ -428,12 +408,10 @@ async def test_lookup_did_in_configured_ledgers_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_get_ledger_by_did_not_self_cert_non_prod( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): @@ -450,12 +428,12 @@ async def test_get_ledger_by_did_not_self_cert_non_prod( ) get_nym_reply = deepcopy(GET_NYM_REPLY) get_nym_reply["result"]["data"]["verkey"] = "ABUF7uxYTxZ6qYdZ4G9e1Gi" - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = get_nym_reply mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = True @@ -468,21 +446,19 @@ async def test_get_ledger_by_did_not_self_cert_non_prod( assert ledger_id == "test_non_prod_1" assert ledger_inst.pool.name == "test_non_prod_1" - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module.SubTrie, "verify_spv_proof", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module.SubTrie, "verify_spv_proof", mock.AsyncMock() ) as mock_verify_spv_proof: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value mock_verify_spv_proof.return_value = False @@ -492,19 +468,17 @@ async def test_lookup_did_in_configured_ledgers_x( ) assert "not found in any of the ledgers total: (production: " in cm - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") - @async_mock.patch( - "aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close" - ) - @async_mock.patch("indy_vdr.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_close") + @mock.patch("indy_vdr.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedger._submit") async def test_lookup_did_in_configured_ledgers_prod_not_cached( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - with async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: - mock_build_get_nym_req.return_value = async_mock.MagicMock() + mock_build_get_nym_req.return_value = mock.MagicMock() mock_submit.return_value = GET_NYM_INDY_VDR_REPLY mock_wait.return_value = mock_submit.return_value ( diff --git a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py index e0b25fd860..d6b8b70706 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_manager_provider.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....askar.profile import AskarProfileManager @@ -69,7 +69,7 @@ async def test_provide_invalid_manager(self): @pytest.mark.indy async def test_provide_indy_manager(self): context = InjectionContext() - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): profile = IndySdkProfile( IndyOpenWallet( config=IndyWalletConfig({"name": "test-profile"}), diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index 037c0d957f..5bbfc05dd9 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -5,7 +5,7 @@ from os import path -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -49,9 +49,7 @@ class TestIndySdkLedgerPoolProvider(IsolatedAsyncioTestCase): async def test_provide(self): provider = IndySdkLedgerPoolProvider() - mock_injector = async_mock.MagicMock( - inject=async_mock.MagicMock(return_value=None) - ) + mock_injector = mock.MagicMock(inject=mock.MagicMock(return_value=None)) provider.provide( settings={ "ledger.read_only": True, @@ -75,24 +73,24 @@ async def asyncSetUp(self): self.test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): self.profile = IndySdkProfile( - async_mock.AsyncMock(), + mock.AsyncMock(), context, ) self.session = await self.profile.session() - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("builtins.open") async def test_init( self, mock_open, mock_open_ledger, mock_list_pools, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", genesis_transactions="genesis_transactions"), @@ -115,17 +113,17 @@ async def test_init( ) assert ledger.did_to_nym(ledger.nym_to_did(self.test_did)) == self.test_did - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("builtins.open") async def test_init_not_checked( self, mock_open, mock_open_ledger, mock_list_pools, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name"), self.profile) @@ -139,10 +137,10 @@ async def test_init_not_checked( mock_list_pools.return_value = [{"pool": ledger.pool_name}] await ledger.__aenter__() - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.list_pools") + @mock.patch("builtins.open") async def test_init_do_not_recreate(self, mock_open, mock_list_pools): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [{"pool": "name"}, {"pool": "another"}] pool = IndySdkLedgerPool("name") @@ -153,14 +151,14 @@ async def test_init_do_not_recreate(self, mock_open, mock_list_pools): mock_open.assert_called_once_with(GENESIS_TRANSACTION_PATH, "w") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.delete_pool_ledger_config") - @async_mock.patch("indy.pool.list_pools") - @async_mock.patch("builtins.open") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.delete_pool_ledger_config") + @mock.patch("indy.pool.list_pools") + @mock.patch("builtins.open") async def test_init_recreate( self, mock_open, mock_list_pools, mock_delete_config, mock_create_config ): - mock_open.return_value = async_mock.MagicMock() + mock_open.return_value = mock.MagicMock() mock_list_pools.return_value = [{"pool": "name"}, {"pool": "another"}] mock_delete_config.return_value = None @@ -175,16 +173,16 @@ async def test_init_recreate( "name", json.dumps({"genesis_txn": GENESIS_TRANSACTION_PATH}) ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -198,18 +196,18 @@ async def test_aenter_aexit( mock_close_pool.assert_called_once() assert ledger.pool_handle is None - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit_nested_keepalive( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, keepalive=1), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -230,17 +228,17 @@ async def test_aenter_aexit_nested_keepalive( mock_close_pool.assert_called_once() assert ledger.pool_handle is None - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_aenter_aexit_close_x( self, mock_close_pool, mock_open_ledger, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_close_pool.side_effect = IndyError(ErrorCode.PoolLedgerTimeout) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -251,17 +249,17 @@ async def test_aenter_aexit_close_x( assert ledger.pool_handle == mock_open_ledger.return_value assert ledger.pool.ref_count == 1 - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_submit_pool_closed( self, mock_close_pool, mock_open_ledger, mock_create_config, mock_set_proto ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -269,12 +267,12 @@ async def test_submit_pool_closed( await ledger._submit("{}") assert "sign and submit request to closed pool" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.sign_and_submit_request") - @async_mock.patch("indy.ledger.multi_sign_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.sign_and_submit_request") + @mock.patch("indy.ledger.multi_sign_request") async def test_submit_signed( self, mock_indy_multi_sign, @@ -287,10 +285,10 @@ async def test_submit_signed( mock_indy_multi_sign.return_value = json.dumps({"endorsed": "content"}) mock_sign_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: async with ledger: @@ -299,7 +297,7 @@ async def test_submit_signed( with self.assertRaises(BadLedgerRequestError): await ledger._submit("{}", True) - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -323,12 +321,12 @@ async def test_submit_signed( taa_accept=False, ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.sign_and_submit_request") - @async_mock.patch("indy.ledger.append_txn_author_agreement_acceptance_to_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.sign_and_submit_request") + @mock.patch("indy.ledger.append_txn_author_agreement_acceptance_to_request") async def test_submit_signed_taa_accept( self, mock_append_taa, @@ -341,16 +339,16 @@ async def test_submit_signed_taa_accept( mock_append_taa.return_value = "{}" mock_sign_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True), self.profile ) - ledger.get_latest_txn_author_acceptance = async_mock.AsyncMock( + ledger.get_latest_txn_author_acceptance = mock.AsyncMock( return_value={ "text": "sample", "version": "0.0", @@ -374,11 +372,11 @@ async def test_submit_signed_taa_accept( "{}", "sample", "0.0", "digest", "dummy", "now" ) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_unsigned( self, mock_submit, @@ -387,17 +385,17 @@ async def test_submit_unsigned( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "REPLY"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -405,11 +403,11 @@ async def test_submit_unsigned( await ledger._submit("{}", False) mock_submit.assert_called_once_with(ledger.pool_handle, "{}") - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_unsigned_ledger_transaction_error( self, mock_submit, @@ -418,16 +416,16 @@ async def test_submit_unsigned_ledger_transaction_error( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "NO-SUCH-OP"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -439,11 +437,11 @@ async def test_submit_unsigned_ledger_transaction_error( await ledger._submit("{}", False) mock_submit.assert_called_once_with(ledger.pool_handle, "{}") - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.submit_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.submit_request") async def test_submit_rejected( self, mock_submit, @@ -452,17 +450,17 @@ async def test_submit_rejected( mock_create_config, mock_set_proto, ): - mock_did = async_mock.MagicMock() + mock_did = mock.MagicMock() future = asyncio.Future() future.set_result(mock_did) mock_submit.return_value = '{"op": "REQNACK", "reason": "a reason"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -473,10 +471,10 @@ async def test_submit_rejected( mock_submit.return_value = '{"op": "REJECT", "reason": "another reason"}' - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = future @@ -485,11 +483,11 @@ async def test_submit_rejected( await ledger._submit("{}", False) assert "Ledger rejected transaction request" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch("indy.ledger.multi_sign_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.ledger.multi_sign_request") async def test_txn_endorse( self, mock_indy_multi_sign, @@ -501,10 +499,10 @@ async def test_txn_endorse( mock_indy_multi_sign.return_value = json.dumps({"endorsed": "content"}) mock_indy_open.return_value = 1 - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -522,17 +520,15 @@ async def test_txn_endorse( ) assert json.loads(endorsed_json) == {"endorsed": "content"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("indy.ledger.append_request_endorser") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.ledger.append_request_endorser") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema( self, mock_is_ledger_read_only, @@ -545,11 +541,11 @@ async def test_send_schema( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) issuer.create_schema.return_value = ("schema_issuer_did:name:1.0", "{}") mock_fetch_schema_by_id.return_value = None @@ -559,11 +555,11 @@ async def test_send_schema( r'{"op":"REPLY","result":{"txnMetadata":{"seqNo": 1}}}' ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future async with ledger: @@ -574,7 +570,7 @@ async def test_send_schema( issuer, "schema_name", "schema_version", [1, 2, 3] ) - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -610,15 +606,13 @@ async def test_send_schema( assert schema_id == issuer.create_schema.return_value[0] assert "signed_txn" in signed_txn - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") async def test_send_schema_already_exists( self, mock_build_schema_req, @@ -629,25 +623,23 @@ async def test_send_schema_already_exists( mock_create_config, mock_set_proto, ): - # mock_did = async_mock.AsyncMock() + # mock_did = mock.AsyncMock() - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - mock_add_record = async_mock.AsyncMock() + mock_add_record = mock.AsyncMock() future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=mock_add_record) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock_add_record)) ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = self.test_did_info @@ -666,16 +658,14 @@ async def test_send_schema_already_exists( mock_add_record.assert_not_called() - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_ledger_transaction_error_already_exists( self, mock_is_ledger_read_only, @@ -687,22 +677,22 @@ async def test_send_schema_ledger_transaction_error_already_exists( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.AsyncMock( + ledger._submit = mock.AsyncMock( side_effect=LedgerTransactionError("UnauthorizedClientRequest") ) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = self.test_did_info @@ -717,13 +707,11 @@ async def test_send_schema_ledger_transaction_error_already_exists( ) assert schema_id == fetch_schema_id - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") async def test_send_schema_ledger_read_only( self, mock_check_existing, @@ -732,15 +720,15 @@ async def test_send_schema_ledger_read_only( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -756,14 +744,12 @@ async def test_send_schema_ledger_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_issuer_error( self, mock_is_ledger_read_only, @@ -773,16 +759,16 @@ async def test_send_schema_issuer_error( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - issuer = async_mock.MagicMock(IndyIssuer) - issuer.create_schema = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.create_schema = mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -798,15 +784,13 @@ async def test_send_schema_issuer_error( ) assert "dummy error" in str(context.exception) - @async_mock.patch("indy.pool.set_protocol_version") - @async_mock.patch("indy.pool.create_pool_ledger_config") - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") + @mock.patch("indy.pool.set_protocol_version") + @mock.patch("indy.pool.create_pool_ledger_config") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.check_existing_schema") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") async def test_send_schema_ledger_transaction_error( self, mock_build_schema_req, @@ -817,16 +801,16 @@ async def test_send_schema_ledger_transaction_error( mock_create_config, mock_set_proto, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ("1", "{}") ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - ledger._submit = async_mock.AsyncMock( + ledger._submit = mock.AsyncMock( side_effect=LedgerTransactionError("Some other error message") ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -841,16 +825,14 @@ async def test_send_schema_ledger_transaction_error( issuer, "schema_name", "schema_version", [1, 2, 3] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") - @async_mock.patch( - "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no" - ) - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_schema_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_seq_no") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_schema_no_seq_no( self, mock_is_ledger_read_only, @@ -862,9 +844,9 @@ async def test_send_schema_no_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) issuer.create_schema.return_value = ("schema_issuer_did:name:1.0", "{}") @@ -874,12 +856,12 @@ async def test_send_schema_no_seq_no( mock_submit.return_value = ( r'{"op":"REPLY","result":{"txnMetadata":{"no": "seqNo"}}}' ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: - mock_wallet.get_public_did = async_mock.AsyncMock() + mock_wallet.get_public_did = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did @@ -889,24 +871,24 @@ async def test_send_schema_no_seq_no( ) assert "schema sequence number" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.fetch_schema_by_id") async def test_check_existing_schema( self, mock_fetch_schema_by_id, mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_fetch_schema_by_id.return_value = {"attrNames": ["a", "b", "c"]} ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: @@ -926,11 +908,11 @@ async def test_check_existing_schema( attribute_names=["a", "b", "c", "d"], ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema( self, mock_parse_get_schema_resp, @@ -939,17 +921,17 @@ async def test_get_schema( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') mock_submit.return_value = '{"result":{"seqNo":1}}' - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -978,10 +960,10 @@ async def test_get_schema( mock_parse_get_schema_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_schema_request") async def test_get_schema_not_found( self, mock_build_get_schema_req, @@ -989,15 +971,15 @@ async def test_get_schema_not_found( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"seqNo": None}}) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1017,12 +999,12 @@ async def test_get_schema_not_found( assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema_by_seq_no( self, mock_parse_get_schema_resp, @@ -1032,7 +1014,7 @@ async def test_get_schema_by_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') @@ -1058,10 +1040,10 @@ async def test_get_schema_by_seq_no( mock_submit.side_effect = list( submissions ) # becomes list iterator, unsubscriptable, in mock object - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did ledger = IndySdkLedger( @@ -1076,8 +1058,8 @@ async def test_get_schema_by_seq_no( ) mock_submit.assert_has_calls( [ - async_mock.call(mock_build_get_txn_req.return_value), - async_mock.call( + mock.call(mock_build_get_txn_req.return_value), + mock.call( mock_build_get_schema_req.return_value, sign_did=mock_did ), ] @@ -1088,12 +1070,12 @@ async def test_get_schema_by_seq_no( mock_parse_get_schema_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("indy.ledger.build_get_schema_request") - @async_mock.patch("indy.ledger.parse_get_schema_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("indy.ledger.build_get_schema_request") + @mock.patch("indy.ledger.parse_get_schema_response") async def test_get_schema_by_wrong_seq_no( self, mock_parse_get_schema_resp, @@ -1103,7 +1085,7 @@ async def test_get_schema_by_wrong_seq_no( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_schema_resp.return_value = (None, '{"attrNames": ["a", "b"]}') @@ -1126,27 +1108,27 @@ async def test_get_schema_by_wrong_seq_no( submissions ) # becomes list iterator, unsubscriptable, in mock object ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value mock_did.did = self.test_did async with ledger: with self.assertRaises(LedgerTransactionError): await ledger.get_schema("999") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_credential_definition( self, mock_is_ledger_read_only, @@ -1159,7 +1141,7 @@ async def test_send_credential_definition( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_is_ledger_read_only.return_value = False @@ -1181,7 +1163,7 @@ async def test_send_credential_definition( mock_fetch_cred_def.side_effect = [None, cred_def] - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1193,11 +1175,11 @@ async def test_send_credential_definition( tag = "default" ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future async with ledger: @@ -1226,18 +1208,18 @@ async def test_send_credential_definition( mock_get_schema.assert_called_once_with(schema_id) mock_build_cred_def.assert_called_once_with(mock_did.did, cred_def_json) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") - @async_mock.patch("indy.ledger.append_request_endorser") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("indy.ledger.append_request_endorser") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_send_credential_definition_endorse_only( self, mock_is_ledger_read_only, @@ -1251,7 +1233,7 @@ async def test_send_credential_definition_endorse_only( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_is_ledger_read_only.return_value = False @@ -1273,7 +1255,7 @@ async def test_send_credential_definition_endorse_only( mock_fetch_cred_def.side_effect = [None, cred_def] - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1283,7 +1265,7 @@ async def test_send_credential_definition_endorse_only( ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -1309,16 +1291,16 @@ async def test_send_credential_definition_endorse_only( ) assert "signed_txn" in signed_txn - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_exists_in_ledger_and_wallet( self, mock_build_cred_def, @@ -1330,7 +1312,7 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1351,7 +1333,7 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_fetch_cred_def.return_value = {"mock": "cred-def"} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1362,11 +1344,11 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( schema_id = "schema_issuer_did:name:1.0" tag = "default" future = asyncio.Future() - future.set_result(async_mock.MagicMock(add_record=async_mock.AsyncMock())) - with async_mock.patch.object( + future.set_result(mock.MagicMock(add_record=mock.AsyncMock())) + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( - ledger, "get_indy_storage", async_mock.MagicMock() + ) as mock_wallet_get_public_did, mock.patch.object( + ledger, "get_indy_storage", mock.MagicMock() ) as mock_get_storage: mock_get_storage.return_value = future mock_wallet_get_public_did.return_value = DIDInfo( @@ -1396,43 +1378,43 @@ async def test_send_credential_definition_exists_in_ledger_and_wallet( mock_build_cred_def.assert_not_called() mock_get_storage.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") async def test_send_credential_definition_no_such_schema( self, mock_close, mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_offer_exception( self, mock_build_cred_def, @@ -1444,33 +1426,33 @@ async def test_send_credential_definition_offer_exception( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] mock_get_schema.return_value = {"seqNo": 999} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.credential_definition_in_wallet.side_effect = IndyIssuerError( "common IO error" ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_in_wallet_not_ledger( @@ -1480,7 +1462,7 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1499,24 +1481,24 @@ async def test_send_credential_definition_cred_def_in_wallet_not_ledger( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( @@ -1526,7 +1508,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1545,17 +1527,17 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1563,10 +1545,10 @@ async def test_send_credential_definition_cred_def_not_on_ledger_wallet_check_x( ) assert "dummy error" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send_x( @@ -1576,7 +1558,7 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1595,20 +1577,18 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.AsyncMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) + issuer.create_and_store_credential_definition = mock.AsyncMock( side_effect=IndyIssuerError("dummy error") ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1616,10 +1596,10 @@ async def test_send_credential_definition_cred_def_not_on_ledger_nor_wallet_send ) assert "dummy error" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_read_only( @@ -1629,7 +1609,7 @@ async def test_send_credential_definition_read_only( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1648,11 +1628,9 @@ async def test_send_credential_definition_read_only( mock_fetch_cred_def.return_value = {} - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.AsyncMock( - return_value=False - ) - issuer.create_and_store_credential_definition = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) + issuer.create_and_store_credential_definition = mock.AsyncMock( return_value=("cred-def-id", "cred-def-json") ) ledger = IndySdkLedger( @@ -1660,10 +1638,10 @@ async def test_send_credential_definition_read_only( ) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError) as context: await ledger.create_and_send_credential_definition( @@ -1671,10 +1649,10 @@ async def test_send_credential_definition_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( @@ -1684,7 +1662,7 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_get_schema.return_value = {"seqNo": 999} cred_def_id = f"{self.test_did}:3:CL:999:default" @@ -1703,33 +1681,31 @@ async def test_send_credential_definition_cred_def_on_ledger_not_in_wallet( mock_fetch_cred_def.return_value = cred_def - issuer = async_mock.MagicMock(IndyIssuer) - issuer.credential_definition_in_wallet = async_mock.AsyncMock( - return_value=False - ) + issuer = mock.MagicMock(IndyIssuer) + issuer.credential_definition_in_wallet = mock.AsyncMock(return_value=False) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() async with ledger: with self.assertRaises(LedgerError): await ledger.create_and_send_credential_definition( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_on_ledger_in_wallet( self, mock_build_cred_def, @@ -1741,7 +1717,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1762,7 +1738,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_fetch_cred_def.return_value = cred_def - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.create_and_store_credential_definition.return_value = ( cred_def_id, @@ -1771,7 +1747,7 @@ async def test_send_credential_definition_on_ledger_in_wallet( ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: async with ledger: @@ -1803,16 +1779,16 @@ async def test_send_credential_definition_on_ledger_in_wallet( mock_build_cred_def.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch( + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch( "aries_cloudagent.ledger.indy.IndySdkLedger.fetch_credential_definition" ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("indy.ledger.build_cred_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("indy.ledger.build_cred_def_request") async def test_send_credential_definition_create_cred_def_exception( self, mock_build_cred_def, @@ -1824,7 +1800,7 @@ async def test_send_credential_definition_create_cred_def_exception( mock_open, mock_get_schema, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_find_all_records.return_value = [] @@ -1845,14 +1821,14 @@ async def test_send_credential_definition_create_cred_def_exception( mock_fetch_cred_def.return_value = None - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_and_store_credential_definition.side_effect = IndyIssuerError( "invalid structure" ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) schema_id = "schema_issuer_did:name:1.0" tag = "default" - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -1868,11 +1844,11 @@ async def test_send_credential_definition_create_cred_def_exception( issuer, schema_id, None, tag ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_get_credential_definition( self, mock_parse_get_cred_def_resp, @@ -1881,16 +1857,16 @@ async def test_get_credential_definition( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_cred_def_resp.return_value = ( None, json.dumps({"result": {"seqNo": 1}}), ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: - mock_wallet_get_public_did.return_value = async_mock.AsyncMock() + mock_wallet_get_public_did.return_value = mock.AsyncMock() mock_did = mock_wallet_get_public_did.return_value ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), @@ -1919,11 +1895,11 @@ async def test_get_credential_definition( mock_parse_get_cred_def_resp.return_value[1] ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_get_credential_definition_ledger_not_found( self, mock_parse_get_cred_def_resp, @@ -1932,13 +1908,13 @@ async def test_get_credential_definition_ledger_not_found( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_parse_get_cred_def_resp.side_effect = IndyError( error_code=ErrorCode.LedgerNotFound, error_details={"message": "not today"} ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -1961,11 +1937,11 @@ async def test_get_credential_definition_ledger_not_found( assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_cred_def_request") - @async_mock.patch("indy.ledger.parse_get_cred_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_cred_def_request") + @mock.patch("indy.ledger.parse_get_cred_def_response") async def test_fetch_credential_definition_ledger_x( self, mock_parse_get_cred_def_resp, @@ -1974,7 +1950,7 @@ async def test_fetch_credential_definition_ledger_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_parse_get_cred_def_resp.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, @@ -1983,7 +1959,7 @@ async def test_fetch_credential_definition_ledger_x( self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -1992,20 +1968,20 @@ async def test_fetch_credential_definition_ledger_x( await ledger.fetch_credential_definition("cred_def_id") assert "not today" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_key_for_did( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"verkey": self.test_verkey})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2022,21 +1998,21 @@ async def test_get_key_for_did( ) assert response == self.test_verkey - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": {"endpoint": endpoint}})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2056,14 +2032,14 @@ async def test_get_endpoint_for_did( ) assert response == endpoint - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_of_type_profile_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://company.com/masterdata" endpoint_type = EndpointType.PROFILE @@ -2077,7 +2053,7 @@ async def test_get_endpoint_of_type_profile_for_did( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2100,14 +2076,14 @@ async def test_get_endpoint_of_type_profile_for_did( ) assert response == endpoint - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_all_endpoints_for_did( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) profile_endpoint = "http://company.com/masterdata" default_endpoint = "http://agent.company.com" @@ -2116,7 +2092,7 @@ async def test_get_all_endpoints_for_did( ) mock_submit.return_value = json.dumps({"result": {"data": data_json}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2136,20 +2112,20 @@ async def test_get_all_endpoints_for_did( ) assert response == json.loads(data_json).get("endpoint") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_all_endpoints_for_did_none( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) profile_endpoint = "http://company.com/masterdata" default_endpoint = "http://agent.company.com" mock_submit.return_value = json.dumps({"result": {"data": None}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2169,20 +2145,20 @@ async def test_get_all_endpoints_for_did_none( ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did_address_none( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": None})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2202,18 +2178,18 @@ async def test_get_endpoint_for_did_address_none( ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_endpoint_for_did_no_endpoint( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"data": None}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2233,12 +2209,12 @@ async def test_get_endpoint_for_did_no_endpoint( ) assert response is None - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_for_did( self, mock_is_ledger_read_only, @@ -2248,7 +2224,7 @@ async def test_update_endpoint_for_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = ["http://old.aries.ca", "http://new.aries.ca"] mock_is_ledger_read_only.return_value = False @@ -2263,7 +2239,7 @@ async def test_update_endpoint_for_did( for i in range(len(endpoint)) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2281,17 +2257,17 @@ async def test_update_endpoint_for_did( ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call(mock_build_attrib_req.return_value, True, True), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") @pytest.mark.asyncio async def test_construct_attr_json_with_routing_keys(self, mock_close, mock_open): ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) @@ -2310,8 +2286,8 @@ async def test_construct_attr_json_with_routing_keys(self, mock_close, mock_open } ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") @pytest.mark.asyncio async def test_construct_attr_json_with_routing_keys_all_exist_endpoints( self, mock_close, mock_open @@ -2334,12 +2310,12 @@ async def test_construct_attr_json_with_routing_keys_all_exist_endpoints( } ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") @pytest.mark.asyncio async def test_update_endpoint_for_did_calls_attr_json( self, @@ -2351,17 +2327,17 @@ async def test_update_endpoint_for_did_calls_attr_json( mock_open, ): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) mock_is_ledger_read_only.return_value = False async with ledger: - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( ledger, "_construct_attr_json", - async_mock.AsyncMock( + mock.AsyncMock( return_value=json.dumps( { "endpoint": { @@ -2373,11 +2349,11 @@ async def test_update_endpoint_for_did_calls_attr_json( } ) ), - ) as mock_construct_attr_json, async_mock.patch.object( + ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.AsyncMock(return_value={}), - ), async_mock.patch.object( + mock.AsyncMock(return_value={}), + ), mock.patch.object( ledger, "did_to_nym" ): mock_wallet_get_public_did.return_value = self.test_did_info @@ -2391,12 +2367,12 @@ async def test_update_endpoint_for_did_calls_attr_json( "https://url", EndpointType.ENDPOINT, {}, routing_keys ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_for_did_no_prior_endpoints( self, mock_is_ledger_read_only, @@ -2406,18 +2382,18 @@ async def test_update_endpoint_for_did_no_prior_endpoints( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://new.aries.ca" mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: - with async_mock.patch.object( - ledger, "get_all_endpoints_for_did", async_mock.AsyncMock() + with mock.patch.object( + ledger, "get_all_endpoints_for_did", mock.AsyncMock() ) as mock_get_all: mock_get_all.return_value = None response = await ledger.update_endpoint_for_did( @@ -2433,19 +2409,17 @@ async def test_update_endpoint_for_did_no_prior_endpoints( ) mock_submit.assert_has_calls( [ - async_mock.call( - mock_build_attrib_req.return_value, True, True - ), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("indy.ledger.build_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("indy.ledger.build_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_update_endpoint_of_type_profile_for_did( self, mock_is_ledger_read_only, @@ -2455,7 +2429,7 @@ async def test_update_endpoint_of_type_profile_for_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = ["http://company.com/oldProfile", "http://company.com/newProfile"] endpoint_type = EndpointType.PROFILE @@ -2473,12 +2447,12 @@ async def test_update_endpoint_of_type_profile_for_did( for i in range(len(endpoint)) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - # ledger = async_mock.patch.object( + # ledger = mock.patch.object( # ledger, # "is_ledger_read_only", - # async_mock.AsyncMock(return_value=False), + # mock.AsyncMock(return_value=False), # ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2496,30 +2470,30 @@ async def test_update_endpoint_of_type_profile_for_did( ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call(mock_build_attrib_req.return_value, True, True), + mock.call(mock_build_attrib_req.return_value, True, True), ] ) assert response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_update_endpoint_for_did_duplicate( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( {"result": {"data": json.dumps({"endpoint": {"endpoint": endpoint}})}} ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2539,14 +2513,14 @@ async def test_update_endpoint_for_did_duplicate( ) assert not response - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_attrib_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_attrib_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_update_endpoint_for_did_read_only( self, mock_submit, mock_build_get_attrib_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) endpoint = "http://aries.ca" mock_submit.return_value = json.dumps( @@ -2555,7 +2529,7 @@ async def test_update_endpoint_for_did_read_only( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2566,11 +2540,11 @@ async def test_update_endpoint_for_did_read_only( ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym( self, mock_is_ledger_read_only, @@ -2579,14 +2553,14 @@ async def test_register_nym( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" - ) as mock_wallet_get_local_did, async_mock.patch.object( + ) as mock_wallet_get_local_did, mock.patch.object( IndySdkWallet, "replace_local_did_metadata" ) as mock_wallet_replace_local_did_metadata: ledger = IndySdkLedger( @@ -2594,7 +2568,7 @@ async def test_register_nym( ) mock_wallet_get_public_did.return_value = self.test_did_info mock_wallet_get_local_did.return_value = self.test_did_info - mock_wallet_replace_local_did_metadata.return_value = async_mock.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.AsyncMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2623,15 +2597,15 @@ async def test_register_nym( }, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") async def test_register_nym_read_only(self, mock_close, mock_open): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2645,24 +2619,24 @@ async def test_register_nym_read_only(self, mock_close, mock_open): ) assert "read only" in str(context.exception) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_no_public_did( self, mock_is_ledger_read_only, mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock( + mock_wallet = mock.MagicMock( type="indy", - get_local_did=async_mock.AsyncMock(), - replace_local_did_metadata=async_mock.AsyncMock(), + get_local_did=mock.AsyncMock(), + replace_local_did_metadata=mock.AsyncMock(), ) mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -2675,11 +2649,11 @@ async def test_register_nym_no_public_did( None, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_ledger_x( self, mock_is_ledger_read_only, @@ -2688,7 +2662,7 @@ async def test_register_nym_ledger_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_build_nym_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, @@ -2696,7 +2670,7 @@ async def test_register_nym_ledger_x( mock_is_ledger_read_only.return_value = False self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2709,11 +2683,11 @@ async def test_register_nym_ledger_x( None, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.is_ledger_read_only") async def test_register_nym_steward_register_others_did( self, mock_is_ledger_read_only, @@ -2722,20 +2696,20 @@ async def test_register_nym_steward_register_others_did( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_is_ledger_read_only.return_value = False ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" - ) as mock_wallet_get_local_did, async_mock.patch.object( + ) as mock_wallet_get_local_did, mock.patch.object( IndySdkWallet, "replace_local_did_metadata" ) as mock_wallet_replace_local_did_metadata: mock_wallet_get_public_did.return_value = self.test_did_info mock_wallet_get_local_did.side_effect = WalletNotFoundError() - mock_wallet_replace_local_did_metadata.return_value = async_mock.AsyncMock() + mock_wallet_replace_local_did_metadata.return_value = mock.AsyncMock() async with ledger: await ledger.register_nym( self.test_did, @@ -2758,14 +2732,14 @@ async def test_register_nym_steward_register_others_did( ) mock_wallet_replace_local_did_metadata.assert_not_called() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_nym_role( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( { @@ -2806,7 +2780,7 @@ async def test_get_nym_role( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2818,20 +2792,20 @@ async def test_get_nym_role( ) assert mock_submit.called_once_with(mock_build_get_nym_req.return_value) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") async def test_get_nym_role_indy_x( self, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_build_get_nym_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2840,14 +2814,14 @@ async def test_get_nym_role_indy_x( await ledger.get_nym_role(self.test_did) assert "not today" in context.exception.message - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_nym_role_did_not_public_x( self, mock_submit, mock_build_get_nym_req, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps( { @@ -2879,7 +2853,7 @@ async def test_get_nym_role_did_not_public_x( } ) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2887,12 +2861,12 @@ async def test_get_nym_role_did_not_public_x( with self.assertRaises(BadLedgerRequestError): await ledger.get_nym_role(self.test_did) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair( self, mock_submit, @@ -2902,7 +2876,7 @@ async def test_rotate_public_did_keypair( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.side_effect = [ json.dumps({"result": {"data": json.dumps({"seqNo": 1234})}}), @@ -2915,11 +2889,11 @@ async def test_rotate_public_did_keypair( ), ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2928,23 +2902,23 @@ async def test_rotate_public_did_keypair( async with ledger: await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair_no_nym( self, mock_submit, mock_build_get_nym_request, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.return_value = json.dumps({"result": {"data": json.dumps(None)}}) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2954,12 +2928,12 @@ async def test_rotate_public_did_keypair_no_nym( with self.assertRaises(BadLedgerRequestError): await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_nym_request") - @async_mock.patch("indy.ledger.build_get_txn_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_nym_request") + @mock.patch("indy.ledger.build_get_txn_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.register_nym") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_rotate_public_did_keypair_corrupt_nym_txn( self, mock_submit, @@ -2969,18 +2943,18 @@ async def test_rotate_public_did_keypair_corrupt_nym_txn( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_submit.side_effect = [ json.dumps({"result": {"data": json.dumps({"seqNo": 1234})}}), json.dumps({"result": {"data": None}}), ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "rotate_did_keypair_start", autospec=True - ) as mock_wallet_rotate_did_keypair_start, async_mock.patch.object( + ) as mock_wallet_rotate_did_keypair_start, mock.patch.object( IndySdkWallet, "rotate_did_keypair_apply", autospec=True ) as mock_wallet_rotate_did_keypair_apply: mock_wallet_get_public_did.return_value = self.test_did_info @@ -2990,11 +2964,11 @@ async def test_rotate_public_did_keypair_corrupt_nym_txn( with self.assertRaises(BadLedgerRequestError): await ledger.rotate_public_did_keypair() - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_def_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_def_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_def_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_def_response") async def test_get_revoc_reg_def( self, mock_indy_parse_get_rrdef_resp, @@ -3003,7 +2977,7 @@ async def test_get_revoc_reg_def( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rrdef_resp.return_value = ( "rr-id", @@ -3014,7 +2988,7 @@ async def test_get_revoc_reg_def( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3022,14 +2996,14 @@ async def test_get_revoc_reg_def( result = await ledger.get_revoc_reg_def("rr-id") assert result == {"...": "...", "txnTime": 1234567890} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_def_request") async def test_get_revoc_reg_def_indy_x( self, mock_indy_build_get_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_indy_build_get_rrdef_req.side_effect = IndyError( error_code=ErrorCode.CommonInvalidParam1, error_details={"message": "not today"}, @@ -3038,7 +3012,7 @@ async def test_get_revoc_reg_def_indy_x( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3047,11 +3021,11 @@ async def test_get_revoc_reg_def_indy_x( await ledger.get_revoc_reg_def("rr-id") assert "not today" in context.exception.message - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_response") async def test_get_revoc_reg_entry( self, mock_indy_parse_get_rr_resp, @@ -3060,7 +3034,7 @@ async def test_get_revoc_reg_entry( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rr_resp.return_value = ( "rr-id", @@ -3071,7 +3045,7 @@ async def test_get_revoc_reg_entry( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3079,11 +3053,11 @@ async def test_get_revoc_reg_entry( (result, _) = await ledger.get_revoc_reg_entry("rr-id", 1234567890) assert result == {"hello": "world"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_response") async def test_get_revoc_reg_entry_x( self, mock_indy_parse_get_rr_resp, @@ -3092,7 +3066,7 @@ async def test_get_revoc_reg_entry_x( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rr_resp.side_effect = IndyError( error_code=ErrorCode.PoolLedgerTimeout, @@ -3101,7 +3075,7 @@ async def test_get_revoc_reg_entry_x( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3109,11 +3083,11 @@ async def test_get_revoc_reg_entry_x( async with ledger: await ledger.get_revoc_reg_entry("rr-id", 1234567890) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_get_revoc_reg_delta_request") - @async_mock.patch("indy.ledger.parse_get_revoc_reg_delta_response") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_get_revoc_reg_delta_request") + @mock.patch("indy.ledger.parse_get_revoc_reg_delta_response") async def test_get_revoc_reg_delta( self, mock_indy_parse_get_rrd_resp, @@ -3122,7 +3096,7 @@ async def test_get_revoc_reg_delta( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_parse_get_rrd_resp.return_value = ( "rr-id", @@ -3133,7 +3107,7 @@ async def test_get_revoc_reg_delta( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3141,23 +3115,23 @@ async def test_get_revoc_reg_delta( (result, _) = await ledger.get_revoc_reg_delta("rr-id") assert result == {"hello": "world"} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_public_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3172,21 +3146,21 @@ async def test_send_revoc_reg_def_public_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_local_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = self.test_did_info @@ -3203,21 +3177,21 @@ async def test_send_revoc_reg_def_local_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_def_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_def_request") async def test_send_revoc_reg_def_x_no_did( self, mock_indy_build_rrdef_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rrdef_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = None @@ -3231,23 +3205,23 @@ async def test_send_revoc_reg_def_x_no_did( context.exception ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_public_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3264,21 +3238,21 @@ async def test_send_revoc_reg_entry_public_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_local_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = self.test_did_info @@ -3297,21 +3271,21 @@ async def test_send_revoc_reg_entry_local_did( write_ledger=True, ) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") - @async_mock.patch("indy.ledger.build_revoc_reg_entry_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("indy.ledger.build_revoc_reg_entry_request") async def test_send_revoc_reg_entry_x_no_did( self, mock_indy_build_rre_req, mock_submit, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) mock_indy_build_rre_req.return_value = '{"hello": "world"}' ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, read_only=True), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_local_did" ) as mock_wallet_get_local_did: mock_wallet_get_local_did.return_value = None @@ -3327,17 +3301,17 @@ async def test_send_revoc_reg_entry_x_no_did( context.exception ) - @async_mock.patch("indy.pool.open_pool_ledger") - @async_mock.patch("indy.pool.close_pool_ledger") + @mock.patch("indy.pool.open_pool_ledger") + @mock.patch("indy.pool.close_pool_ledger") async def test_taa_digest_bad_value( self, mock_close_pool, mock_open_ledger, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3345,11 +3319,11 @@ async def test_taa_digest_bad_value( with self.assertRaises(ValueError): await ledger.taa_digest(None, None) - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("indy.ledger.build_get_acceptance_mechanisms_request") - @async_mock.patch("indy.ledger.build_get_txn_author_agreement_request") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("indy.ledger.build_get_acceptance_mechanisms_request") + @mock.patch("indy.ledger.build_get_txn_author_agreement_request") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger._submit") async def test_get_txn_author_agreement( self, mock_submit, @@ -3358,14 +3332,14 @@ async def test_get_txn_author_agreement( mock_close, mock_open, ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) txn_result_data = {"text": "text", "version": "1.0"} mock_submit.side_effect = [ json.dumps({"result": {"data": txn_result_data}}) for i in range(2) ] ledger = IndySdkLedger(IndySdkLedgerPool("name", checked=True), self.profile) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3381,11 +3355,11 @@ async def test_get_txn_author_agreement( ) mock_submit.assert_has_calls( [ - async_mock.call( + mock.call( mock_build_get_acc_mech_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), - async_mock.call( + mock.call( mock_build_get_taa_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ), @@ -3402,14 +3376,14 @@ async def test_get_txn_author_agreement( "taa_required": True, } - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.add_record") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") async def test_accept_and_get_latest_txn_author_agreement( self, mock_find_all_records, mock_add_record, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile @@ -3436,7 +3410,7 @@ async def test_accept_and_get_latest_txn_author_agreement( {"pool_name": ledger.pool_name}, ) ] - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3452,20 +3426,20 @@ async def test_accept_and_get_latest_txn_author_agreement( response = await ledger.get_latest_txn_author_acceptance() assert response == acceptance - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.storage.indy.IndySdkStorage.find_all_records") async def test_get_latest_txn_author_agreement_none( self, mock_find_all_records, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile ) mock_find_all_records.return_value = [] - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info @@ -3476,13 +3450,13 @@ async def test_get_latest_txn_author_agreement_none( response = await ledger.get_latest_txn_author_acceptance() assert response == {} - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") - @async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") + @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedger.get_schema") async def test_credential_definition_id2schema_id( self, mock_get_schema, mock_close, mock_open ): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() self.session.context.injector.bind_provider(BaseWallet, mock_wallet) S_ID = f"{self.test_did}:2:favourite_drink:1.0" SEQ_NO = "9999" @@ -3491,7 +3465,7 @@ async def test_credential_definition_id2schema_id( ledger = IndySdkLedger( IndySdkLedgerPool("name", checked=True, cache=InMemoryCache()), self.profile ) - with async_mock.patch.object( + with mock.patch.object( IndySdkWallet, "get_public_did" ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = self.test_did_info diff --git a/aries_cloudagent/ledger/tests/test_indy_vdr.py b/aries_cloudagent/ledger/tests/test_indy_vdr.py index a820d5f8c2..4d6d31860e 100644 --- a/aries_cloudagent/ledger/tests/test_indy_vdr.py +++ b/aries_cloudagent/ledger/tests/test_indy_vdr.py @@ -2,7 +2,7 @@ import indy_vdr import pytest -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile @@ -40,15 +40,15 @@ def ledger(): ledger = IndyVdrLedger(IndyVdrLedgerPool("test-ledger"), profile) async def open(): - ledger.pool.handle = async_mock.MagicMock(indy_vdr.Pool) + ledger.pool.handle = mock.MagicMock(indy_vdr.Pool) async def close(): ledger.pool.handle = None - with async_mock.patch.object(ledger.pool, "open", open), async_mock.patch.object( + with mock.patch.object(ledger.pool, "open", open), mock.patch.object( ledger.pool, "close", close - ), async_mock.patch.object( - ledger, "is_ledger_read_only", async_mock.AsyncMock(return_value=False) + ), mock.patch.object( + ledger, "is_ledger_read_only", mock.AsyncMock(return_value=False) ): yield ledger @@ -101,10 +101,10 @@ async def test_fetch_txn_author_agreement( ledger: IndyVdrLedger, ): async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.AsyncMock( + mock.AsyncMock( side_effect=[ {"data": {"aml": ".."}}, {"data": {"text": "text", "version": "1.0"}}, @@ -210,7 +210,7 @@ async def test_send_schema( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -224,10 +224,10 @@ async def test_send_schema( "txnMetadata": {"seqNo": 1} } - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.AsyncMock(return_value=None), + mock.AsyncMock(return_value=None), ): schema_id, schema_def = await ledger.create_and_send_schema( issuer, "schema_name", "9.1", ["a", "b"] @@ -260,7 +260,7 @@ async def test_send_schema_no_public_did( self, ledger: IndyVdrLedger, ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -274,7 +274,7 @@ async def test_send_schema_already_exists( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -284,10 +284,10 @@ async def test_send_schema_already_exists( ) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.AsyncMock( + mock.AsyncMock( return_value=( issuer.create_schema.return_value[0], {"schema": "result"}, @@ -307,7 +307,7 @@ async def test_send_schema_ledger_read_only( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -318,14 +318,14 @@ async def test_send_schema_ledger_read_only( async with ledger: ledger.pool.read_only = True - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.AsyncMock(return_value=False), - ), async_mock.patch.object( + mock.AsyncMock(return_value=False), + ), mock.patch.object( ledger, "is_ledger_read_only", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ): with pytest.raises(LedgerError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -339,7 +339,7 @@ async def test_send_schema_ledger_transaction_error( ): wallet = (await ledger.profile.session()).wallet test_did = await wallet.create_public_did(SOV, ED25519) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.create_schema.return_value = ( "schema_issuer_did:schema_name:9.1", ( @@ -351,10 +351,10 @@ async def test_send_schema_ledger_transaction_error( async with ledger: ledger.pool_handle.submit_request.side_effect = VdrError(99, "message") - with async_mock.patch.object( + with mock.patch.object( ledger, "check_existing_schema", - async_mock.AsyncMock(return_value=False), + mock.AsyncMock(return_value=False), ): with pytest.raises(LedgerTransactionError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -366,7 +366,7 @@ async def test_send_schema_no_indy_did( self, ledger: IndyVdrLedger, ): - wallet = async_mock.MagicMock((await ledger.profile.session()).wallet) + wallet = mock.MagicMock((await ledger.profile.session()).wallet) wallet.create_public_did.return_value = { "result": { "did": "did:web:doma.in", @@ -376,7 +376,7 @@ async def test_send_schema_no_indy_did( "method": WEB.method_name, } } - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): schema_id, schema_def = await ledger.create_and_send_schema( @@ -443,7 +443,7 @@ async def test_send_credential_definition( } }, } - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) issuer.make_credential_definition_id.return_value = cred_def_id issuer.credential_definition_in_wallet.return_value = False issuer.create_and_store_credential_definition.return_value = ( @@ -480,7 +480,7 @@ async def test_send_credential_definition_no_public_did( self, ledger: IndyVdrLedger, ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: with pytest.raises(BadLedgerRequestError): await ledger.create_and_send_credential_definition( @@ -491,7 +491,7 @@ async def test_send_credential_definition_no_public_did( async def test_send_credential_definition_no_such_schema( self, ledger: IndyVdrLedger ): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: ledger.pool_handle.submit_request.return_value = {} with pytest.raises(BadLedgerRequestError): @@ -501,7 +501,7 @@ async def test_send_credential_definition_no_such_schema( @pytest.mark.asyncio async def test_send_credential_definition_read_only(self, ledger: IndyVdrLedger): - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) async with ledger: ledger.pool.read_only = True with pytest.raises(LedgerError): @@ -574,7 +574,7 @@ async def test_get_key_for_did_non_sov_public_did( ledger: IndyVdrLedger, ): async with ledger: - wallet = async_mock.MagicMock((await ledger.profile.session()).wallet) + wallet = mock.MagicMock((await ledger.profile.session()).wallet) wallet.get_public_did.return_value = DIDInfo( "did:web:doma.in", "verkey", @@ -740,10 +740,10 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg test_did = await wallet.create_public_did(SOV, ED25519) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "_construct_attr_json", - async_mock.AsyncMock( + mock.AsyncMock( return_value=json.dumps( { "endpoint": { @@ -755,10 +755,10 @@ async def test_update_endpoint_for_did_calls_attr_json(self, ledger: IndyVdrLedg } ) ), - ) as mock_construct_attr_json, async_mock.patch.object( + ) as mock_construct_attr_json, mock.patch.object( ledger, "get_all_endpoints_for_did", - async_mock.AsyncMock(return_value={}), + mock.AsyncMock(return_value={}), ): await ledger.update_endpoint_for_did( test_did.did, @@ -1008,10 +1008,10 @@ async def test_credential_definition_id2schema_id(self, ledger: IndyVdrLedger): SEQ_NO = "9999" async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger, "get_schema", - async_mock.AsyncMock(return_value={"id": S_ID}), + mock.AsyncMock(return_value={"id": S_ID}), ) as mock_get_schema: s_id_short = await ledger.credential_definition_id2schema_id( f"55GkHamhTU1ZbTbV2ab9DE:3:CL:{SEQ_NO}:tag" @@ -1031,10 +1031,10 @@ async def test_rotate_did_keypair(self, ledger: IndyVdrLedger): public_did = await wallet.create_public_did(SOV, ED25519) async with ledger: - with async_mock.patch.object( + with mock.patch.object( ledger.pool_handle, "submit_request", - async_mock.AsyncMock( + mock.AsyncMock( side_effect=[ {"data": json.dumps({"seqNo": 1234})}, {"data": {"txn": {"data": {"role": "101", "alias": "Billy"}}}}, diff --git a/aries_cloudagent/ledger/tests/test_routes.py b/aries_cloudagent/ledger/tests/test_routes.py index a04add9e3a..c6ca6f2e57 100644 --- a/aries_cloudagent/ledger/tests/test_routes.py +++ b/aries_cloudagent/ledger/tests/test_routes.py @@ -1,7 +1,7 @@ from typing import Tuple from unittest import IsolatedAsyncioTestCase -import mock as async_mock +import mock from ...core.in_memory import InMemoryProfile from ...ledger.base import BaseLedger @@ -22,7 +22,7 @@ class TestLedgerRoutes(IsolatedAsyncioTestCase): def setUp(self): - self.ledger = async_mock.create_autospec(BaseLedger) + self.ledger = mock.create_autospec(BaseLedger) self.ledger.pool_name = "pool.0" self.profile = InMemoryProfile.test_profile() self.context = self.profile.context @@ -30,9 +30,9 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -48,10 +48,8 @@ def setUp(self): async def test_missing_ledger(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) self.profile.context.injector.clear_binding(BaseLedger) @@ -83,15 +81,15 @@ async def test_missing_ledger(self): async def test_get_verkey_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -103,15 +101,15 @@ async def test_get_verkey_a(self): async def test_get_verkey_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -126,15 +124,15 @@ async def test_get_verkey_b(self): async def test_get_verkey_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_key_for_did.return_value = self.test_verkey result = await test_module.get_did_verkey(self.request) @@ -154,8 +152,8 @@ async def test_get_verkey_no_did(self): async def test_get_verkey_did_not_public(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -168,8 +166,8 @@ async def test_get_verkey_did_not_public(self): async def test_get_verkey_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -182,15 +180,15 @@ async def test_get_verkey_x(self): async def test_get_endpoint(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = self.test_endpoint result = await test_module.get_did_endpoint(self.request) @@ -202,15 +200,15 @@ async def test_get_endpoint(self): async def test_get_endpoint_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = self.test_endpoint result = await test_module.get_did_endpoint(self.request) @@ -225,8 +223,8 @@ async def test_get_endpoint_multitenant(self): async def test_get_endpoint_of_type_profile(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -235,8 +233,8 @@ async def test_get_endpoint_of_type_profile(self): "did": self.test_did, "endpoint_type": self.test_endpoint_type.w3c, } - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_endpoint_for_did.return_value = ( self.test_endpoint_type_profile @@ -258,8 +256,8 @@ async def test_get_endpoint_no_did(self): async def test_get_endpoint_x(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -275,8 +273,8 @@ async def test_register_nym(self): "verkey": self.test_verkey, "role": "reset", } - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: success: bool = True txn: dict = None @@ -326,22 +324,22 @@ async def test_register_nym_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -370,22 +368,22 @@ async def test_register_nym_create_transaction_for_endorser_no_public_did(self): } self.profile.context.settings["endorser.author"] = True - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -413,18 +411,16 @@ async def test_register_nym_create_transaction_for_endorser_storage_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -449,8 +445,8 @@ async def test_register_nym_create_transaction_for_endorser_not_found_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -471,8 +467,8 @@ async def test_register_nym_create_transaction_for_endorser_base_model_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() self.ledger.register_nym.return_value: Tuple[bool, dict] = ( @@ -495,11 +491,11 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_info_x( "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) self.ledger.register_nym.return_value: Tuple[bool, dict] = ( True, @@ -519,11 +515,11 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_did_x(se "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_name": ("name"), } @@ -540,16 +536,16 @@ async def test_register_nym_create_transaction_for_endorser_no_endorser_did_x(se async def test_get_nym_role_a(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -559,16 +555,16 @@ async def test_get_nym_role_a(self): async def test_get_nym_role_b(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -580,16 +576,16 @@ async def test_get_nym_role_b(self): async def test_get_nym_role_multitenant(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.query = {"did": self.test_did} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_nym_role.return_value = Role.USER result = await test_module.get_nym_role(self.request) @@ -606,8 +602,8 @@ async def test_get_nym_role_bad_request(self): async def test_get_nym_role_ledger_txn_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -622,8 +618,8 @@ async def test_get_nym_role_ledger_txn_error(self): async def test_get_nym_role_bad_ledger_req(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -638,8 +634,8 @@ async def test_get_nym_role_bad_ledger_req(self): async def test_get_nym_role_ledger_error(self): self.profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -650,19 +646,19 @@ async def test_get_nym_role_ledger_error(self): await test_module.get_nym_role(self.request) async def test_rotate_public_did_keypair(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = async_mock.AsyncMock() + self.ledger.rotate_public_did_keypair = mock.AsyncMock() await test_module.rotate_public_did_keypair(self.request) json_response.assert_called_once_with({}) async def test_rotate_public_did_keypair_public_wallet_x(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.ledger.rotate_public_did_keypair = async_mock.AsyncMock( + self.ledger.rotate_public_did_keypair = mock.AsyncMock( side_effect=test_module.WalletError("Exception") ) @@ -670,8 +666,8 @@ async def test_rotate_public_did_keypair_public_wallet_x(self): await test_module.rotate_public_did_keypair(self.request) async def test_get_taa(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = {"taa_required": False} self.ledger.get_latest_txn_author_acceptance.return_value = None @@ -688,8 +684,8 @@ async def test_get_taa_required(self): } taa_info = {"taa_required": True} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = taa_info self.ledger.get_latest_txn_author_acceptance.return_value = accepted @@ -705,7 +701,7 @@ async def test_get_taa_x(self): await test_module.ledger_get_taa(self.request) async def test_taa_accept_not_required(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "version": "version", "text": "text", @@ -718,7 +714,7 @@ async def test_taa_accept_not_required(self): await test_module.ledger_accept_taa(self.request) async def test_accept_taa(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "version": "version", "text": "text", @@ -726,8 +722,8 @@ async def test_accept_taa(self): } ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.ledger.get_txn_author_agreement.return_value = { "taa_record": {"text": "text"}, @@ -746,7 +742,7 @@ async def test_accept_taa(self): assert result is json_response.return_value async def test_accept_taa_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "version": "version", "text": "text", @@ -762,28 +758,28 @@ async def test_accept_taa_x(self): await test_module.ledger_accept_taa(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] async def test_get_write_ledger(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_ledger_id_by_ledger_pool_name=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_id_by_ledger_pool_name=mock.AsyncMock( return_value="test_ledger_id" ) ), ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_write_ledger(self.request) json_response.assert_called_once_with( @@ -794,8 +790,8 @@ async def test_get_write_ledger(self): assert result is json_response.return_value async def test_get_write_ledger_single_ledger(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_write_ledger(self.request) json_response.assert_called_once_with( @@ -808,18 +804,18 @@ async def test_get_write_ledger_single_ledger(self): async def test_get_ledger_config(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_prod_ledgers=async_mock.AsyncMock( + mock.MagicMock( + get_prod_ledgers=mock.AsyncMock( return_value={ - "test_1": async_mock.MagicMock(), - "test_2": async_mock.MagicMock(), - "test_5": async_mock.MagicMock(), + "test_1": mock.MagicMock(), + "test_2": mock.MagicMock(), + "test_5": mock.MagicMock(), } ), - get_nonprod_ledgers=async_mock.AsyncMock( + get_nonprod_ledgers=mock.AsyncMock( return_value={ - "test_3": async_mock.MagicMock(), - "test_4": async_mock.MagicMock(), + "test_3": mock.MagicMock(), + "test_4": mock.MagicMock(), } ), ), @@ -830,8 +826,8 @@ async def test_get_ledger_config(self): {"id": "test_3", "genesis_transactions": "..."}, {"id": "test_4", "genesis_transactions": "..."}, ] - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: result = await test_module.get_ledger_config(self.request) json_response.assert_called_once_with( diff --git a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py index b8cdb22a10..08ceb622a3 100644 --- a/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py +++ b/aries_cloudagent/messaging/credential_definitions/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -26,26 +26,26 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_credential_definition = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_credential_definition = mock.AsyncMock( return_value=( CRED_DEF_ID, {"cred": "def", "signed_txn": "..."}, True, ) ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"cred": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) - self.issuer = async_mock.create_autospec(IndyIssuer) + self.issuer = mock.create_autospec(IndyIssuer) self.profile_injector.bind_instance(IndyIssuer, self.issuer) - self.storage = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.AsyncMock( - return_value=[async_mock.MagicMock(value=CRED_DEF_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.AsyncMock( + return_value=[mock.MagicMock(value=CRED_DEF_ID)] ) self.session_inject[BaseStorage] = self.storage @@ -54,9 +54,9 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -64,7 +64,7 @@ def setUp(self): ) async def test_send_credential_definition(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -74,7 +74,7 @@ async def test_send_credential_definition(self): self.request.query = {"create_transaction_for_endorser": "false"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = ( await test_module.credential_definitions_send_credential_definition( self.request @@ -89,7 +89,7 @@ async def test_send_credential_definition(self): ) async def test_send_credential_definition_create_transaction_for_endorser(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -102,22 +102,22 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -140,7 +140,7 @@ async def test_send_credential_definition_create_transaction_for_endorser(self): async def test_send_credential_definition_create_transaction_for_endorser_storage_x( self, ): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -153,23 +153,21 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), } ) ) - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -180,7 +178,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_storag async def test_send_credential_definition_create_transaction_for_endorser_not_found_x( self, ): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -193,8 +191,8 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,7 +204,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_not_fo async def test_send_credential_definition_create_transaction_for_endorser_base_model_x( self, ): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -219,8 +217,8 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -232,7 +230,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_base_m async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_info_x( self, ): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -245,11 +243,11 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_definitions_send_credential_definition( @@ -259,7 +257,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end async def test_send_credential_definition_create_transaction_for_endorser_no_endorser_did_x( self, ): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -272,11 +270,11 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_name": ("name"), } @@ -288,7 +286,7 @@ async def test_send_credential_definition_create_transaction_for_endorser_no_end ) async def test_send_credential_definition_no_ledger(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -304,7 +302,7 @@ async def test_send_credential_definition_no_ledger(self): ) async def test_send_credential_definition_ledger_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0", "support_revocation": False, @@ -314,7 +312,7 @@ async def test_send_credential_definition_ledger_x(self): self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.__aenter__ = async_mock.AsyncMock( + self.ledger.__aenter__ = mock.AsyncMock( side_effect=test_module.LedgerError("oops") ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -325,7 +323,7 @@ async def test_send_credential_definition_ledger_x(self): async def test_created(self): self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_created(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -335,14 +333,14 @@ async def test_created(self): async def test_get_credential_definition(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request ) @@ -357,14 +355,14 @@ async def test_get_credential_definition(self): async def test_get_credential_definition_multitenant(self): self.profile_injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.credential_definitions_get_credential_definition( self.request ) @@ -379,10 +377,8 @@ async def test_get_credential_definition_multitenant(self): async def test_get_credential_definition_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) self.request.match_info = {"cred_def_id": CRED_DEF_ID} @@ -394,13 +390,13 @@ async def test_get_credential_definition_no_ledger(self): ) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/messaging/jsonld/tests/test_credential.py b/aries_cloudagent/messaging/jsonld/tests/test_credential.py index 3a8cc08917..46ff019838 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_credential.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_credential.py @@ -3,7 +3,7 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -64,7 +64,7 @@ async def asyncSetUp(self): setattr( self.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) self.context.injector.bind_instance(DocumentLoader, custom_document_loader) diff --git a/aries_cloudagent/messaging/jsonld/tests/test_routes.py b/aries_cloudagent/messaging/jsonld/tests/test_routes.py index ed4541fc52..cfe206eec4 100644 --- a/aries_cloudagent/messaging/jsonld/tests/test_routes.py +++ b/aries_cloudagent/messaging/jsonld/tests/test_routes.py @@ -3,7 +3,7 @@ from aiohttp import web from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from pyld import jsonld import pytest @@ -59,15 +59,15 @@ def did_doc(): @pytest.fixture def mock_resolver(did_doc): - did_resolver = DIDResolver(async_mock.MagicMock()) - did_resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + did_resolver = DIDResolver(mock.MagicMock()) + did_resolver.resolve = mock.AsyncMock(return_value=did_doc) yield did_resolver @pytest.fixture def mock_sign_credential(): temp = test_module.sign_credential - sign_credential = async_mock.AsyncMock(return_value="fake_signage") + sign_credential = mock.AsyncMock(return_value="fake_signage") test_module.sign_credential = sign_credential yield test_module.sign_credential test_module.sign_credential = temp @@ -76,7 +76,7 @@ def mock_sign_credential(): @pytest.fixture def mock_verify_credential(): temp = test_module.verify_credential - verify_credential = async_mock.AsyncMock(return_value="fake_verify") + verify_credential = mock.AsyncMock(return_value="fake_verify") test_module.verify_credential = verify_credential yield test_module.verify_credential test_module.verify_credential = temp @@ -85,15 +85,15 @@ def mock_verify_credential(): @pytest.fixture def mock_sign_request(mock_sign_credential): context = AdminRequestContext.test_context() - outbound_message_router = async_mock.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.AsyncMock( + json=mock.AsyncMock( return_value={ "verkey": "fake_verkey", "doc": {}, @@ -138,15 +138,15 @@ def request_body(): def mock_verify_request(mock_verify_credential, mock_resolver, request_body): def _mock_verify_request(request_body=request_body): context = AdminRequestContext.test_context({DIDResolver: mock_resolver}) - outbound_message_router = async_mock.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={}, query={}, - json=async_mock.AsyncMock(return_value=request_body), + json=mock.AsyncMock(return_value=request_body), __getitem__=lambda _, k: request_dict[k], ) return request @@ -156,7 +156,7 @@ def _mock_verify_request(request_body=request_body): @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -175,7 +175,7 @@ async def test_sign(mock_sign_request, mock_response): ) @pytest.mark.asyncio async def test_sign_bad_req_error(mock_sign_request, mock_response, error): - test_module.sign_credential = async_mock.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.AsyncMock(side_effect=error()) await test_module.sign(mock_sign_request) assert "error" in mock_response.call_args[0][0] @@ -183,7 +183,7 @@ async def test_sign_bad_req_error(mock_sign_request, mock_response, error): @pytest.mark.parametrize("error", [WalletError]) @pytest.mark.asyncio async def test_sign_bad_req_http_error(mock_sign_request, mock_response, error): - test_module.sign_credential = async_mock.AsyncMock(side_effect=error()) + test_module.sign_credential = mock.AsyncMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.sign(mock_sign_request) @@ -206,7 +206,7 @@ async def test_verify(mock_verify_request, mock_response): ) @pytest.mark.asyncio async def test_verify_bad_req_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.AsyncMock(side_effect=error()) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -220,7 +220,7 @@ async def test_verify_bad_req_error(mock_verify_request, mock_response, error): ) @pytest.mark.asyncio async def test_verify_bad_req_http_error(mock_verify_request, mock_response, error): - test_module.verify_credential = async_mock.AsyncMock(side_effect=error()) + test_module.verify_credential = mock.AsyncMock(side_effect=error()) with pytest.raises(web.HTTPForbidden): await test_module.verify(mock_verify_request()) @@ -229,7 +229,7 @@ async def test_verify_bad_req_http_error(mock_verify_request, mock_response, err async def test_verify_bad_ver_meth_deref_req_error( mock_resolver, mock_verify_request, mock_response ): - mock_resolver.dereference = async_mock.AsyncMock(side_effect=ResolverError) + mock_resolver.dereference = mock.AsyncMock(side_effect=ResolverError) await test_module.verify(mock_verify_request()) assert "error" in mock_response.call_args[0][0] @@ -256,14 +256,14 @@ async def test_verify_bad_vmethod_unsupported( @pytest.mark.asyncio async def test_register(): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() def test_post_process_routes(): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] @@ -280,9 +280,9 @@ async def asyncSetUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -333,22 +333,22 @@ async def test_verify_credential(self): }, } - self.request.json = async_mock.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.AsyncMock(return_value=POSTED_REQUEST) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.verify(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with({"valid": True}) # expected response # compact, expand take a LONG TIME: do them once above, mock for error cases - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = { "@context": "...", "id": "...", @@ -376,14 +376,14 @@ async def test_verify_credential(self): result = await test_module.verify(self.request) assert "error" in json.loads(result) - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = { "@context": "...", "id": "...", @@ -468,9 +468,9 @@ async def test_sign_credential(self): }, }, } - self.request.json = async_mock.AsyncMock(return_value=POSTED_REQUEST) + self.request.json = mock.AsyncMock(return_value=POSTED_REQUEST) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.sign(self.request) assert result == mock_response.return_value mock_response.assert_called_once() @@ -481,9 +481,9 @@ async def test_sign_credential(self): posted_request_x = deepcopy(POSTED_REQUEST) posted_request_x["doc"]["options"].pop("verificationMethod") posted_request_x["doc"]["options"].pop("creator") - self.request.json = async_mock.AsyncMock(return_value=posted_request_x) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + self.request.json = mock.AsyncMock(return_value=posted_request_x) + with mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_response.side_effect = lambda x: json.dumps(x) result = await test_module.sign(self.request) @@ -491,15 +491,15 @@ async def test_sign_credential(self): # compact, expand take a LONG TIME: do them once above, mock for error cases posted_request = deepcopy(POSTED_REQUEST) - self.request.json = async_mock.AsyncMock(return_value=posted_request) - with async_mock.patch.object( - jsonld, "compact", async_mock.MagicMock() - ) as mock_compact, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() - ) as mock_expand, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + self.request.json = mock.AsyncMock(return_value=posted_request) + with mock.patch.object( + jsonld, "compact", mock.MagicMock() + ) as mock_compact, mock.patch.object( + jsonld, "expand", mock.MagicMock() + ) as mock_expand, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_expand.return_value = [async_mock.MagicMock()] + mock_expand.return_value = [mock.MagicMock()] mock_compact.return_value = {} # drop all attributes mock_response.side_effect = lambda x: json.dumps(x) result = await test_module.sign(self.request) @@ -510,8 +510,8 @@ async def test_sign_credential(self): await test_module.sign(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() diff --git a/aries_cloudagent/messaging/models/tests/test_base.py b/aries_cloudagent/messaging/models/tests/test_base.py index dca01ebf14..b627227a0d 100644 --- a/aries_cloudagent/messaging/models/tests/test_base.py +++ b/aries_cloudagent/messaging/models/tests/test_base.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, INCLUDE, fields, validates_schema, ValidationError @@ -82,12 +82,12 @@ def test_model_validate_succeeds(self): def test_ser_x(self): model = ModelImpl(attr="hello world") - with async_mock.patch.object( - model, "_get_schema_class", async_mock.MagicMock() + with mock.patch.object( + model, "_get_schema_class", mock.MagicMock() ) as mock_get_schema_class: - mock_get_schema_class.return_value = async_mock.MagicMock( - return_value=async_mock.MagicMock( - dump=async_mock.MagicMock(side_effect=ValidationError("error")) + mock_get_schema_class.return_value = mock.MagicMock( + return_value=mock.MagicMock( + dump=mock.MagicMock(side_effect=ValidationError("error")) ) ) with self.assertRaises(BaseModelError): diff --git a/aries_cloudagent/messaging/models/tests/test_base_record.py b/aries_cloudagent/messaging/models/tests/test_base_record.py index ee1c038a6f..dffee831d5 100644 --- a/aries_cloudagent/messaging/models/tests/test_base_record.py +++ b/aries_cloudagent/messaging/models/tests/test_base_record.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import EXCLUDE, fields @@ -85,29 +85,25 @@ def test_from_storage_values(self): async def test_post_save_new(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock() - mock_storage.add_record = async_mock.AsyncMock() + mock_storage = mock.MagicMock() + mock_storage.add_record = mock.AsyncMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() - with async_mock.patch.object( - record, "post_save", async_mock.AsyncMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.AsyncMock()) as post_save: await record.save(session, reason="reason", event=True) post_save.assert_called_once_with(session, True, None, True) mock_storage.add_record.assert_called_once() async def test_post_save_exist(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock() - mock_storage.update_record = async_mock.AsyncMock() + mock_storage = mock.MagicMock() + mock_storage.update_record = mock.AsyncMock() session.context.injector.bind_instance(BaseStorage, mock_storage) record = BaseRecordImpl() last_state = "last_state" record._last_state = last_state record._id = "id" - with async_mock.patch.object( - record, "post_save", async_mock.AsyncMock() - ) as post_save: + with mock.patch.object(record, "post_save", mock.AsyncMock()) as post_save: await record.save(session, reason="reason", event=False) post_save.assert_called_once_with(session, False, last_state, False) mock_storage.update_record.assert_called_once() @@ -117,7 +113,7 @@ async def test_cache(self): await BaseRecordImpl.set_cached_key(None, None, None) await BaseRecordImpl.clear_cached_key(None, None) session = InMemoryProfile.test_session() - mock_cache = async_mock.MagicMock(BaseCache, autospec=True) + mock_cache = mock.MagicMock(BaseCache, autospec=True) session.context.injector.bind_instance(BaseCache, mock_cache) record = BaseRecordImpl() cache_key = "cache_key" @@ -148,11 +144,9 @@ async def test_retrieve_by_tag_filter_multi_x_delete(self): async def test_save_x(self): session = InMemoryProfile.test_session() rec = ARecordImpl(a="1", b="0", code="one") - with async_mock.patch.object( - session, "inject", async_mock.MagicMock() - ) as mock_inject: - mock_inject.return_value = async_mock.MagicMock( - add_record=async_mock.AsyncMock(side_effect=ZeroDivisionError()) + with mock.patch.object(session, "inject", mock.MagicMock()) as mock_inject: + mock_inject.return_value = mock.MagicMock( + add_record=mock.AsyncMock(side_effect=ZeroDivisionError()) ) with self.assertRaises(ZeroDivisionError): await rec.save(session) @@ -164,7 +158,7 @@ async def test_neq(self): async def test_query(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" record_value = {"created_at": time_now(), "updated_at": time_now()} @@ -184,7 +178,7 @@ async def test_query(self): async def test_query_x(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" record_value = {"created_at": time_now(), "updated_at": time_now()} @@ -194,17 +188,17 @@ async def test_query_x(self): ) mock_storage.find_all_records.return_value = [stored] - with async_mock.patch.object( + with mock.patch.object( BaseRecordImpl, "from_storage", - async_mock.MagicMock(side_effect=BaseModelError), + mock.MagicMock(side_effect=BaseModelError), ): with self.assertRaises(BaseModelError): await BaseRecordImpl.query(session, tag_filter) async def test_query_post_filter(self): session = InMemoryProfile.test_session() - mock_storage = async_mock.MagicMock(BaseStorage, autospec=True) + mock_storage = mock.MagicMock(BaseStorage, autospec=True) session.context.injector.bind_instance(BaseStorage, mock_storage) record_id = "record_id" a_record = ARecordImpl(ident=record_id, a="one", b="two", code="red") @@ -260,21 +254,19 @@ async def test_query_post_filter(self): ) assert not result - @async_mock.patch("builtins.print") + @mock.patch("builtins.print") def test_log_state(self, mock_print): test_param = "test.log" - with async_mock.patch.object( - BaseRecordImpl, "LOG_STATE_FLAG", test_param - ) as cls: + with mock.patch.object(BaseRecordImpl, "LOG_STATE_FLAG", test_param) as cls: record = BaseRecordImpl() record.log_state( msg="state", params={"a": "1", "b": "2"}, - settings=async_mock.MagicMock(get={test_param: 1}.get), + settings=mock.MagicMock(get={test_param: 1}.get), ) mock_print.assert_called_once() - @async_mock.patch("builtins.print") + @mock.patch("builtins.print") def test_skip_log(self, mock_print): record = BaseRecordImpl() record.log_state("state", settings=None) diff --git a/aries_cloudagent/messaging/schemas/tests/test_routes.py b/aries_cloudagent/messaging/schemas/tests/test_routes.py index 3482da421f..0d2f4dc50c 100644 --- a/aries_cloudagent/messaging/schemas/tests/test_routes.py +++ b/aries_cloudagent/messaging/schemas/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ....admin.request_context import AdminRequestContext from ....core.in_memory import InMemoryProfile @@ -24,22 +24,22 @@ def setUp(self): self.session_inject = {} self.profile = InMemoryProfile.test_profile() self.profile_injector = self.profile.context.injector - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.create_and_send_schema = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.create_and_send_schema = mock.AsyncMock( return_value=(SCHEMA_ID, {"schema": "def", "signed_txn": "..."}) ) - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( return_value={"schema": "def", "signed_txn": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) - self.issuer = async_mock.create_autospec(IndyIssuer) + self.issuer = mock.create_autospec(IndyIssuer) self.profile_injector.bind_instance(IndyIssuer, self.issuer) - self.storage = async_mock.create_autospec(BaseStorage) - self.storage.find_all_records = async_mock.AsyncMock( - return_value=[async_mock.MagicMock(value=SCHEMA_ID)] + self.storage = mock.create_autospec(BaseStorage) + self.storage.find_all_records = mock.AsyncMock( + return_value=[mock.MagicMock(value=SCHEMA_ID)] ) self.session_inject[BaseStorage] = self.storage self.context = AdminRequestContext.test_context( @@ -47,9 +47,9 @@ def setUp(self): ) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -57,7 +57,7 @@ def setUp(self): ) async def test_send_schema(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -67,7 +67,7 @@ async def test_send_schema(self): self.request.query = {"create_transaction_for_endorser": "false"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_send_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -88,7 +88,7 @@ async def test_send_schema(self): ) async def test_send_schema_create_transaction_for_endorser(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -101,22 +101,22 @@ async def test_send_schema_create_transaction_for_endorser(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -139,7 +139,7 @@ async def test_send_schema_create_transaction_for_endorser(self): ) async def test_send_schema_create_transaction_for_endorser_storage_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -152,18 +152,16 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_record=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_txn_mgr.return_value = mock.MagicMock( + create_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_did": ("did"), "endorser_name": ("name"), @@ -175,7 +173,7 @@ async def test_send_schema_create_transaction_for_endorser_storage_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_not_found_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -188,8 +186,8 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -197,7 +195,7 @@ async def test_send_schema_create_transaction_for_endorser_not_found_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_base_model_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -210,8 +208,8 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -219,7 +217,7 @@ async def test_send_schema_create_transaction_for_endorser_base_model_x(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -232,17 +230,17 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_info_x(se "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.schemas_send_schema(self.request) async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -255,11 +253,11 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel "conn_id": "dummy", } - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "endorser_name": ("name"), } @@ -269,7 +267,7 @@ async def test_send_schema_create_transaction_for_endorser_no_endorser_did_x(sel await test_module.schemas_send_schema(self.request) async def test_send_schema_no_ledger(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -282,7 +280,7 @@ async def test_send_schema_no_ledger(self): await test_module.schemas_send_schema(self.request) async def test_send_schema_x_ledger(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "schema_name": "schema_name", "schema_version": "1.0", @@ -290,7 +288,7 @@ async def test_send_schema_x_ledger(self): } ) self.request.query = {"create_transaction_for_endorser": "false"} - self.ledger.create_and_send_schema = async_mock.AsyncMock( + self.ledger.create_and_send_schema = mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -300,7 +298,7 @@ async def test_send_schema_x_ledger(self): async def test_created(self): self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_created(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with({"schema_ids": [SCHEMA_ID]}) @@ -308,14 +306,14 @@ async def test_created(self): async def test_get_schema(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -328,14 +326,14 @@ async def test_get_schema(self): async def test_get_schema_multitenant(self): self.profile_injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) self.request.match_info = {"schema_id": SCHEMA_ID} - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(test_module.web, "json_response") as mock_response: + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -348,14 +346,14 @@ async def test_get_schema_multitenant(self): async def test_get_schema_on_seq_no(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": "12345"} - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: result = await test_module.schemas_get_schema(self.request) assert result == mock_response.return_value mock_response.assert_called_once_with( @@ -365,14 +363,12 @@ async def test_get_schema_on_seq_no(self): async def test_get_schema_no_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -383,14 +379,14 @@ async def test_get_schema_no_ledger(self): async def test_get_schema_x_ledger(self): self.profile_injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) self.request.match_info = {"schema_id": SCHEMA_ID} - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( side_effect=test_module.LedgerError("Down for routine maintenance") ) @@ -398,13 +394,13 @@ async def test_get_schema_x_ledger(self): await test_module.schemas_get_schema(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py index 4453a9286c..e894fefd75 100644 --- a/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py +++ b/aries_cloudagent/multitenant/tests/test_askar_profile_manager.py @@ -1,7 +1,7 @@ import asyncio from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...config.injection_context import InjectionContext from ...core.in_memory import InMemoryProfile @@ -17,7 +17,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = AskarProfileMultitenantManager(self.profile) @@ -41,9 +41,9 @@ async def test_get_wallet_profile_should_open_store_and_return_profile_with_wall }, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.wallet_config" - ) as wallet_config, async_mock.patch( + ) as wallet_config, mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile", ) as AskarProfile: sub_wallet_profile_context = InjectionContext() @@ -104,7 +104,7 @@ async def test_get_wallet_profile_should_create_profile(self): create_profile_stub = asyncio.Future() create_profile_stub.set_result("") - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) @@ -127,10 +127,10 @@ async def test_get_wallet_profile_should_use_custom_subwallet_name(self): {"multitenant.wallet_name": multitenant_sub_wallet_name} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.wallet_config" ) as wallet_config: - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) @@ -154,7 +154,7 @@ def side_effect(context, provision): async def test_remove_wallet_profile(self): test_profile = InMemoryProfile.test_profile({"wallet.id": "test"}) - with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + with mock.patch.object(InMemoryProfile, "remove") as profile_remove: await self.manager.remove_wallet_profile(test_profile) profile_remove.assert_called_once_with() @@ -163,7 +163,7 @@ async def test_open_profiles(self): create_profile_stub = asyncio.Future() create_profile_stub.set_result("") - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.askar_profile_manager.AskarProfile" ) as AskarProfile: sub_wallet_profile = AskarProfile(None, None) diff --git a/aries_cloudagent/multitenant/tests/test_base.py b/aries_cloudagent/multitenant/tests/test_base.py index b4455d9865..1776457750 100644 --- a/aries_cloudagent/multitenant/tests/test_base.py +++ b/aries_cloudagent/multitenant/tests/test_base.py @@ -1,7 +1,7 @@ from datetime import datetime from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock import jwt from .. import base as test_module @@ -49,7 +49,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MockMultitenantManager(self.profile) @@ -59,7 +59,7 @@ async def test_init_throws_no_profile(self): MockMultitenantManager(None) async def test_get_default_mediator(self): - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator" ) as get_default_mediator: mediaton_record = MediationRecord() @@ -142,7 +142,7 @@ async def test_wallet_exists_false(self): async def test_get_wallet_by_key_routing_record_does_not_exist(self): recipient_key = "test" - with async_mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: + with mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: wallet = await self.manager._get_wallet_by_key(recipient_key) assert wallet is None @@ -178,7 +178,7 @@ async def test_get_wallet_by_key(self): assert isinstance(wallet, WalletRecord) async def test_create_wallet_removes_key_only_unmanaged_mode(self): - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: get_wallet_profile.return_value = InMemoryProfile.test_profile() @@ -194,7 +194,7 @@ async def test_create_wallet_removes_key_only_unmanaged_mode(self): assert managed_wallet_record.settings.get("wallet.key") == "test_key" async def test_create_wallet_fails_if_wallet_name_exists(self): - with async_mock.patch.object( + with mock.patch.object( self.manager, "_wallet_name_exists" ) as _wallet_name_exists: _wallet_name_exists.return_value = True @@ -208,13 +208,13 @@ async def test_create_wallet_fails_if_wallet_name_exists(self): ) async def test_create_wallet_saves_wallet_record_creates_profile(self): - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "save" - ) as wallet_record_save, async_mock.patch.object( + ) as wallet_record_save, mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: get_wallet_profile.return_value = InMemoryProfile.test_profile() @@ -246,14 +246,14 @@ async def test_create_wallet_adds_wallet_route(self): key_type=ED25519, ) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "save" - ) as wallet_record_save, async_mock.patch.object( + ) as wallet_record_save, mock.patch.object( self.manager, "get_wallet_profile" - ) as get_wallet_profile, async_mock.patch.object( + ) as get_wallet_profile, mock.patch.object( InMemoryWallet, "get_public_did" ) as get_public_did: get_wallet_profile.return_value = InMemoryProfile.test_profile( @@ -283,9 +283,9 @@ async def test_create_wallet_adds_wallet_route(self): assert wallet_record.wallet_key == "test_key" async def test_update_wallet(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( WalletRecord, "save" ) as wallet_record_save: wallet_id = "test-wallet-id" @@ -310,7 +310,7 @@ async def test_update_wallet(self): assert wallet_record.wallet_dispatch_type == "default" async def test_remove_wallet_fails_no_wallet_key_but_required(self): - with async_mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: + with mock.patch.object(WalletRecord, "retrieve_by_id") as retrieve_by_id: retrieve_by_id.return_value = WalletRecord( wallet_id="test", key_management_mode=WalletRecord.MODE_UNMANAGED, @@ -321,15 +321,15 @@ async def test_remove_wallet_fails_no_wallet_key_but_required(self): await self.manager.remove_wallet("test") async def test_remove_wallet_removes_profile_wallet_storage_records(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( self.manager, "get_wallet_profile" - ) as get_wallet_profile, async_mock.patch.object( + ) as get_wallet_profile, mock.patch.object( self.manager, "remove_wallet_profile" - ) as remove_wallet_profile, async_mock.patch.object( + ) as remove_wallet_profile, mock.patch.object( WalletRecord, "delete_record" - ) as wallet_delete_record, async_mock.patch.object( + ) as wallet_delete_record, mock.patch.object( InMemoryStorage, "delete_all_records" ) as delete_all_records: wallet_record = WalletRecord( @@ -366,12 +366,12 @@ async def test_create_auth_token_fails_no_wallet_key_but_required(self): async def test_create_auth_token_managed(self): self.profile.settings["multitenant.jwt_secret"] = "very_secret_jwt" - wallet_record = async_mock.MagicMock( + wallet_record = mock.MagicMock( wallet_id="test_wallet", key_management_mode=WalletRecord.MODE_MANAGED, requires_external_key=False, settings={}, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -381,7 +381,7 @@ async def test_create_auth_token_managed(self): {"wallet_id": wallet_record.wallet_id, "iat": iat}, "very_secret_jwt" ) - with async_mock.patch.object(test_module, "datetime") as mock_datetime: + with mock.patch.object(test_module, "datetime") as mock_datetime: mock_datetime.utcnow.return_value = utc_now token = await self.manager.create_auth_token(wallet_record) @@ -390,12 +390,12 @@ async def test_create_auth_token_managed(self): async def test_create_auth_token_unmanaged(self): self.profile.settings["multitenant.jwt_secret"] = "very_secret_jwt" - wallet_record = async_mock.MagicMock( + wallet_record = mock.MagicMock( wallet_id="test_wallet", key_management_mode=WalletRecord.MODE_UNMANAGED, requires_external_key=True, settings={"wallet.type": "indy"}, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) utc_now = datetime(2020, 1, 1, 0, 0, 0) @@ -410,7 +410,7 @@ async def test_create_auth_token_unmanaged(self): "very_secret_jwt", ) - with async_mock.patch.object(test_module, "datetime") as mock_datetime: + with mock.patch.object(test_module, "datetime") as mock_datetime: mock_datetime.utcnow.return_value = utc_now token = await self.manager.create_auth_token(wallet_record, "test_key") @@ -463,7 +463,7 @@ async def test_get_wallet_and_profile(self): session = await self.profile.session() await wallet_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -512,7 +512,7 @@ async def test_get_profile_for_token_managed_wallet_no_iat(self): {"wallet_id": wallet_record.wallet_id}, "very_secret_jwt", algorithm="HS256" ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -549,7 +549,7 @@ async def test_get_profile_for_token_managed_wallet_iat(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -587,7 +587,7 @@ async def test_get_profile_for_token_managed_wallet_x_iat_no_match(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile, self.assertRaises( MultitenantManagerError, msg="Token not valid" @@ -623,7 +623,7 @@ async def test_get_profile_for_token_unmanaged_wallet(self): algorithm="HS256", ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "get_wallet_profile" ) as get_wallet_profile: mock_profile = InMemoryProfile.test_profile() @@ -649,10 +649,10 @@ async def test_get_wallets_by_message_missing_wire_format_raises(self): await self.manager.get_wallets_by_message({}) async def test_get_wallets_by_message(self): - message_body = async_mock.MagicMock() + message_body = mock.MagicMock() recipient_keys = ["1", "2", "3", "4"] - mock_wire_format = async_mock.MagicMock( + mock_wire_format = mock.MagicMock( get_recipient_keys=lambda mesage_body: recipient_keys ) @@ -663,9 +663,7 @@ async def test_get_wallets_by_message(self): WalletRecord(settings={}), ] - with async_mock.patch.object( - self.manager, "_get_wallet_by_key" - ) as get_wallet_by_key: + with mock.patch.object(self.manager, "_get_wallet_by_key") as get_wallet_by_key: get_wallet_by_key.side_effect = return_wallets wallets = await self.manager.get_wallets_by_message( @@ -678,14 +676,14 @@ async def test_get_wallets_by_message(self): assert get_wallet_by_key.call_count == 4 async def test_get_profile_for_key(self): - mock_wallet = async_mock.MagicMock() + mock_wallet = mock.MagicMock() mock_wallet.requires_external_key = False - with async_mock.patch.object( + with mock.patch.object( self.manager, "_get_wallet_by_key", - async_mock.AsyncMock(return_value=mock_wallet), - ), async_mock.patch.object( - self.manager, "get_wallet_profile", async_mock.AsyncMock() + mock.AsyncMock(return_value=mock_wallet), + ), mock.patch.object( + self.manager, "get_wallet_profile", mock.AsyncMock() ) as mock_get_wallet_profile: profile = await self.manager.get_profile_for_key( self.context, "test-verkey" diff --git a/aries_cloudagent/multitenant/tests/test_manager.py b/aries_cloudagent/multitenant/tests/test_manager.py index a0a78d2b66..8268a6713b 100644 --- a/aries_cloudagent/multitenant/tests/test_manager.py +++ b/aries_cloudagent/multitenant/tests/test_manager.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...messaging.responder import BaseResponder @@ -12,7 +12,7 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - self.responder = async_mock.AsyncMock(send=async_mock.AsyncMock()) + self.responder = mock.AsyncMock(send=mock.AsyncMock()) self.context.injector.bind_instance(BaseResponder, self.responder) self.manager = MultitenantManager(self.profile) @@ -21,7 +21,7 @@ async def test_get_wallet_profile_returns_from_cache(self): wallet_record = WalletRecord(wallet_id="test") self.manager._profiles.put("test", InMemoryProfile.test_profile()) - with async_mock.patch( + with mock.patch( "aries_cloudagent.config.wallet.wallet_config" ) as wallet_config: profile = await self.manager.get_wallet_profile( @@ -37,7 +37,7 @@ async def test_get_wallet_profile_not_in_cache(self): {"admin.webhook_urls": ["http://localhost:8020"]} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.config.wallet.wallet_config" ) as wallet_config: profile = await self.manager.get_wallet_profile( @@ -78,7 +78,7 @@ def side_effect(context, provision): settings=wallet_record_settings, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: wallet_config.side_effect = side_effect @@ -98,7 +98,7 @@ async def test_get_wallet_profile_settings_reset(self): settings={}, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: @@ -151,7 +151,7 @@ async def test_get_wallet_profile_settings_reset_overwrite(self): }, ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.multitenant.manager.wallet_config" ) as wallet_config: @@ -175,9 +175,9 @@ def side_effect(context, provision): assert profile.settings.get("mediation.clear") is True async def test_update_wallet_update_wallet_profile(self): - with async_mock.patch.object( + with mock.patch.object( WalletRecord, "retrieve_by_id" - ) as retrieve_by_id, async_mock.patch.object( + ) as retrieve_by_id, mock.patch.object( WalletRecord, "save" ) as wallet_record_save: wallet_id = "test-wallet-id" @@ -213,7 +213,7 @@ async def test_remove_wallet_profile(self): ) self.manager._profiles.put("test", test_profile) - with async_mock.patch.object(InMemoryProfile, "remove") as profile_remove: + with mock.patch.object(InMemoryProfile, "remove") as profile_remove: await self.manager.remove_wallet_profile(test_profile) assert not self.manager._profiles.has("test") profile_remove.assert_called_once_with() diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py index 4fa58a8d18..1031fffaac 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -10,10 +10,10 @@ class TestMenuHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" - handler.save_connection_menu = async_mock.AsyncMock() + handler.save_connection_menu = mock.AsyncMock() responder = MockResponder() request_context.message = handler.Menu() diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py index 4d0a626af5..0d32f3c902 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_menu_request_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,16 +12,16 @@ async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.AsyncMock(return_value="menu") + self.menu_service.get_active_menu = mock.AsyncMock(return_value="menu") handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) @@ -33,16 +33,16 @@ async def test_called(self): assert target == {} async def test_called_no_active_menu(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.MenuRequest() - self.menu_service.get_active_menu = async_mock.AsyncMock(return_value=None) + self.menu_service.get_active_menu = mock.AsyncMock(return_value=None) handler_inst = handler.MenuRequestHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py index 0e56a5d698..d0276ddd30 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/handlers/tests/test_perform_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -12,18 +12,16 @@ async def asyncSetUp(self): self.context = RequestContext.test_context() async def test_called(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.AsyncMock( - return_value="perform" - ) + self.menu_service.perform_menu_action = mock.AsyncMock(return_value="perform") handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) @@ -35,16 +33,16 @@ async def test_called(self): assert target == {} async def test_called_no_active_menu(self): - MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(handler.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service) - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = "dummy" responder = MockResponder() self.context.message = handler.Perform() - self.menu_service.perform_menu_action = async_mock.AsyncMock(return_value=None) + self.menu_service.perform_menu_action = mock.AsyncMock(return_value=None) handler_inst = handler.PerformHandler() await handler_inst.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py index b8f9274222..1407df6ead 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_controller.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....core.in_memory import InMemoryProfile from .....messaging.request_context import RequestContext @@ -12,12 +12,12 @@ async def asyncSetUp(self): self.context = RequestContext(self.session.profile) async def test_controller(self): - MenuService = async_mock.MagicMock(test_module.BaseMenuService, autospec=True) + MenuService = mock.MagicMock(test_module.BaseMenuService, autospec=True) self.menu_service = MenuService() self.context.injector.bind_instance( test_module.BaseMenuService, self.menu_service ) - self.context.inject = async_mock.AsyncMock(return_value=self.menu_service) + self.context.inject = mock.AsyncMock(return_value=self.menu_service) controller = test_module.Controller("protocol") diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py index 0e5be07b1c..54f3cacd5c 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,9 +13,9 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -23,22 +23,22 @@ def setUp(self): ) async def test_actionmenu_close(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock() - test_module.save_connection_menu = async_mock.AsyncMock() + test_module.retrieve_connection_menu = mock.AsyncMock() + test_module.save_connection_menu = mock.AsyncMock() - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_close(self.request) mock_response.assert_called_once_with({}) async def test_actionmenu_close_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock() - test_module.save_connection_menu = async_mock.AsyncMock( + test_module.retrieve_connection_menu = mock.AsyncMock() + test_module.save_connection_menu = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -46,35 +46,35 @@ async def test_actionmenu_close_x(self): await test_module.actionmenu_close(self.request) async def test_actionmenu_close_not_found(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.AsyncMock(return_value=None) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.actionmenu_close(self.request) async def test_actionmenu_fetch(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - test_module.retrieve_connection_menu = async_mock.AsyncMock(return_value=None) + test_module.retrieve_connection_menu = mock.AsyncMock(return_value=None) - with async_mock.patch.object(test_module.web, "json_response") as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: res = await test_module.actionmenu_fetch(self.request) mock_response.assert_called_once_with({"result": None}) async def test_actionmenu_perform(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True - ) as mock_perform, async_mock.patch.object( + ) as mock_perform, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() res = await test_module.actionmenu_perform(self.request) mock_response.assert_called_once_with({}) @@ -84,16 +84,16 @@ async def test_actionmenu_perform(self): ) async def test_actionmenu_perform_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -101,33 +101,33 @@ async def test_actionmenu_perform_no_conn_record(self): await test_module.actionmenu_perform(self.request) async def test_actionmenu_perform_conn_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_perform(self.request) async def test_actionmenu_request(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "MenuRequest", autospec=True - ) as menu_request, async_mock.patch.object( + ) as menu_request, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() res = await test_module.actionmenu_request(self.request) mock_response.assert_called_once_with({}) @@ -137,16 +137,16 @@ async def test_actionmenu_request(self): ) async def test_actionmenu_request_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -154,34 +154,34 @@ async def test_actionmenu_request_no_conn_record(self): await test_module.actionmenu_request(self.request) async def test_actionmenu_request_conn_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Perform", autospec=True ) as mock_perform: # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_request(self.request) async def test_actionmenu_send(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True - ) as mock_menu, async_mock.patch.object( + ) as mock_menu, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() - mock_menu.deserialize = async_mock.MagicMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_menu.deserialize = mock.MagicMock() res = await test_module.actionmenu_send(self.request) mock_response.assert_called_once_with({}) @@ -191,16 +191,16 @@ async def test_actionmenu_send(self): ) async def test_actionmenu_send_deserialize_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() - mock_menu.deserialize = async_mock.MagicMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock() + mock_menu.deserialize = mock.MagicMock( side_effect=test_module.BaseModelError("cannot deserialize") ) @@ -208,18 +208,18 @@ async def test_actionmenu_send_deserialize_x(self): await test_module.actionmenu_send(self.request) async def test_actionmenu_send_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_menu.deserialize = async_mock.MagicMock() + mock_menu.deserialize = mock.MagicMock() # Emulate storage not found (bad connection id) - mock_conn_record.retrieve_by_id = async_mock.AsyncMock( + mock_conn_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -227,31 +227,31 @@ async def test_actionmenu_send_no_conn_record(self): await test_module.actionmenu_send(self.request) async def test_actionmenu_send_conn_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_record, async_mock.patch.object( + ) as mock_conn_record, mock.patch.object( test_module, "Menu", autospec=True ) as mock_menu: - mock_menu.deserialize = async_mock.MagicMock() + mock_menu.deserialize = mock.MagicMock() # Emulate connection not ready - mock_conn_record.retrieve_by_id = async_mock.AsyncMock() + mock_conn_record.retrieve_by_id = mock.AsyncMock() mock_conn_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.actionmenu_send(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py index fe9c1e0a50..af20c24af4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/tests/test_service.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....core.event_bus import EventBus, MockEventBus from .....core.in_memory import InMemoryProfile @@ -21,7 +21,7 @@ async def test_get_active_menu(self): self.context ) - connection = async_mock.MagicMock() + connection = mock.MagicMock() connection.connection_id = "connid" thread_id = "thid" @@ -47,7 +47,7 @@ async def test_perform_menu_action(self): action_name = "action" action_params = {"a": 1, "b": 2} - connection = async_mock.MagicMock() + connection = mock.MagicMock() connection.connection_id = "connid" thread_id = "thid" diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py index 652b1fdffd..c676424c86 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....storage.error import StorageNotFoundError @@ -13,9 +13,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -24,33 +24,33 @@ async def asyncSetUp(self): self.test_conn_id = "connection-id" async def test_connections_send_message(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True - ) as mock_basic_message, async_mock.patch.object( + ) as mock_basic_message, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() res = await test_module.connections_send_message(self.request) mock_response.assert_called_once_with({}) mock_basic_message.assert_called_once() async def test_connections_send_message_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -58,29 +58,29 @@ async def test_connections_send_message_no_conn_record(self): await test_module.connections_send_message(self.request) async def test_connections_send_message_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"conn_id": self.test_conn_id} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "BasicMessage", autospec=True ) as mock_basic_message: # Emulate connection not ready - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False await test_module.connections_send_message(self.request) mock_basic_message.assert_not_called() async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py index 034dd35705..19327c146d 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_request_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......core.profile import ProfileSession from ......connections.models import connection_target @@ -75,9 +75,9 @@ def did_doc(): class TestRequestHandler: @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -88,14 +88,14 @@ async def test_called(self, mock_conn_mgr, request_context): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called_with_auto_response(self, mock_conn_mgr, request_context): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() request_context.message = ConnectionRequest() handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -109,21 +109,21 @@ async def test_called_with_auto_response(self, mock_conn_mgr, request_context): assert responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_connection_record_with_mediation_metadata_auto_response( self, mock_conn_mgr, request_context, connection_record ): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = ConnRecord.ACCEPT_AUTO - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_conn_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() request_context.message = ConnectionRequest() - with async_mock.patch.object( + with mock.patch.object( connection_record, "metadata_get", - async_mock.AsyncMock(return_value={"id": "test-mediation-id"}), + mock.AsyncMock(return_value={"id": "test-mediation-id"}), ): handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -135,17 +135,17 @@ async def test_connection_record_with_mediation_metadata_auto_response( assert responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_connection_record_without_mediation_metadata( self, mock_conn_mgr, request_context, session, connection_record ): - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = ConnectionRequest() storage: BaseStorage = session.inject(BaseStorage) - with async_mock.patch.object( + with mock.patch.object( storage, "find_record", - async_mock.AsyncMock(raises=StorageNotFoundError), + mock.AsyncMock(raises=StorageNotFoundError), ) as mock_storage_find_record: handler_inst = handler.ConnectionRequestHandler() responder = MockResponder() @@ -157,9 +157,9 @@ async def test_connection_record_without_mediation_metadata( assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) @@ -177,16 +177,16 @@ async def test_problem_report(self, mock_conn_mgr, request_context): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) request_context.message = ConnectionRequest( @@ -207,16 +207,16 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.receive_request = mock.AsyncMock() mock_conn_mgr.return_value.receive_request.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=ConnectionManagerError("no targets") ) request_context.message = ConnectionRequest( diff --git a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py index 8c0fe1ecfa..99c489f9f5 100644 --- a/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/connections/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......connections.models import connection_target from ......connections.models.diddoc import ( @@ -67,9 +67,9 @@ def did_doc(): class TestResponseHandler: @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -80,10 +80,10 @@ async def test_called(self, mock_conn_mgr, request_context): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_called_auto_ping(self, mock_conn_mgr, request_context): request_context.update_settings({"auto_ping_connection": True}) - mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() request_context.message = ConnectionResponse() handler_inst = handler.ConnectionResponseHandler() responder = MockResponder() @@ -97,9 +97,9 @@ async def test_called_auto_ping(self, mock_conn_mgr, request_context): assert isinstance(result, Ping) @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(handler, "ConnectionManager") async def test_problem_report(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED ) @@ -117,16 +117,16 @@ async def test_problem_report(self, mock_conn_mgr, request_context): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) request_context.message = ConnectionResponse( @@ -145,16 +145,16 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(handler, "ConnectionManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(handler, "ConnectionManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_conn_mgr, request_context, did_doc ): - mock_conn_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_response = mock.AsyncMock() mock_conn_mgr.return_value.accept_response.side_effect = ConnectionManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED ) - mock_conn_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_conn_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=ConnectionManagerError("no target") ) request_context.message = ConnectionResponse( diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py index 8623ac015f..cef9770402 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_manager.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -58,16 +58,14 @@ async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.AsyncMock( - return_value=None - ) + self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) self.resolver = DIDResolver() self.resolver.register_resolver(LegacyPeerDIDResolver()) @@ -90,7 +88,7 @@ async def asyncSetUp(self): ) self.context = self.profile.context - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) @@ -136,8 +134,8 @@ async def test_create_invitation_non_multi_use_invitation_fails_on_reuse(self): async def test_create_invitation_public(self): self.context.update_settings({"public_invites": True}) - self.route_manager.route_verkey = async_mock.AsyncMock() - with async_mock.patch.object( + self.route_manager.route_verkey = mock.AsyncMock() + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -168,7 +166,7 @@ async def test_create_invitation_public_no_public_invites(self): async def test_create_invitation_public_no_public_did(self): self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -266,7 +264,7 @@ async def test_create_invitation_multi_use_metadata_transfers_to_connection(self assert await new_conn_rec.metadata_get_all(session) == {"test": "value"} async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -278,7 +276,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator", ) as mock_get_default_mediator: @@ -292,7 +290,7 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) mock_get_default_mediator.assert_not_called() async def test_create_invitation_mediation_using_default(self): - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) async with self.profile.session() as session: @@ -304,10 +302,10 @@ async def test_create_invitation_mediation_using_default(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.route_manager, "mediation_record_if_id", - async_mock.AsyncMock(return_value=mediation_record), + mock.AsyncMock(return_value=mediation_record), ): _, invite = await self.manager.create_invitation( routing_keys=[self.test_verkey], @@ -356,9 +354,7 @@ async def test_receive_invitation_with_did(self): assert ConnRecord.State.get(invitee_record.state) is ConnRecord.State.REQUEST async def test_receive_invitation_mediation_passes_id_when_auto_accept(self): - with async_mock.patch.object( - ConnectionManager, "create_request" - ) as create_request: + with mock.patch.object(ConnectionManager, "create_request") as create_request: record, connect_invite = await self.manager.create_invitation( my_endpoint="testendpoint" ) @@ -424,14 +420,14 @@ async def test_create_request_multitenant(self): endpoint=self.test_mediator_endpoint, ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -477,14 +473,14 @@ async def test_create_request_mediation_id(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -528,14 +524,14 @@ async def test_create_request_default_mediator(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): did_info = DIDInfo( did=self.test_did, @@ -559,10 +555,10 @@ async def test_create_request_default_mediator(self): async def test_receive_request_public_did_oob_invite(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -576,18 +572,18 @@ async def test_receive_request_public_did_oob_invite(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -599,10 +595,10 @@ async def test_receive_request_public_did_oob_invite(self): async def test_receive_request_public_did_unsolicited_fails(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -616,28 +612,28 @@ async def test_receive_request_public_did_unsolicited_fails(self): ) self.context.update_settings({"public_invites": True}) - with self.assertRaises(ConnectionManagerError), async_mock.patch.object( + with self.assertRaises(ConnectionManagerError), mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) async def test_receive_request_public_did_conn_invite(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -650,35 +646,35 @@ async def test_receive_request_public_did_conn_invite(self): did=self.test_did, ) - mock_connection_record = async_mock.MagicMock() - mock_connection_record.save = async_mock.AsyncMock() - mock_connection_record.attach_request = async_mock.AsyncMock() + mock_connection_record = mock.MagicMock() + mock_connection_record.save = mock.AsyncMock() + mock_connection_record.attach_request = mock.AsyncMock() self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "retrieve_by_invitation_msg_id", - async_mock.AsyncMock(return_value=mock_connection_record), + mock.AsyncMock(return_value=mock_connection_record), ) as mock_conn_retrieve_by_invitation_msg_id: conn_rec = await self.manager.receive_request(mock_request, receipt) assert conn_rec async def test_receive_request_public_did_unsolicited(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -693,18 +689,18 @@ async def test_receive_request_public_did_unsolicited(self): self.context.update_settings({"public_invites": True}) self.context.update_settings({"requests_through_public_did": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "connection_id", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = None conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -712,8 +708,8 @@ async def test_receive_request_public_did_unsolicited(self): async def test_receive_request_public_did_no_did_doc(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did mock_request.connection.did_doc = None @@ -728,13 +724,13 @@ async def test_receive_request_public_did_no_did_doc(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): @@ -742,10 +738,10 @@ async def test_receive_request_public_did_no_did_doc(self): async def test_receive_request_public_did_wrong_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = "dummy" receipt = MessageReceipt( @@ -759,23 +755,23 @@ async def test_receive_request_public_did_wrong_did(self): ) self.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): await self.manager.receive_request(mock_request, receipt) async def test_receive_request_public_did_no_public_invites(self): - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) @@ -788,13 +784,13 @@ async def test_receive_request_public_did_no_public_invites(self): ) self.context.update_settings({"public_invites": False}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True ): with self.assertRaises(ConnectionManagerError): @@ -802,10 +798,10 @@ async def test_receive_request_public_did_no_public_invites(self): async def test_receive_request_public_did_no_auto_accept(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock() - mock_request.connection = async_mock.MagicMock() + mock_request = mock.MagicMock() + mock_request.connection = mock.MagicMock() mock_request.connection.did = self.test_did - mock_request.connection.did_doc = async_mock.MagicMock() + mock_request.connection.did_doc = mock.MagicMock() mock_request.connection.did_doc.did = self.test_did receipt = MessageReceipt( @@ -821,16 +817,16 @@ async def test_receive_request_public_did_no_auto_accept(self): self.context.update_settings( {"public_invites": True, "debug.auto_accept_requests": False} ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( + ) as mock_conn_rec_save, mock.patch.object( ConnRecord, "attach_request", autospec=True - ) as mock_conn_attach_request, async_mock.patch.object( + ) as mock_conn_attach_request, mock.patch.object( ConnRecord, "retrieve_by_id", autospec=True - ) as mock_conn_retrieve_by_id, async_mock.patch.object( + ) as mock_conn_retrieve_by_id, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( - ConnRecord, "retrieve_by_invitation_msg_id", async_mock.AsyncMock() + ), mock.patch.object( + ConnRecord, "retrieve_by_invitation_msg_id", mock.AsyncMock() ) as mock_conn_retrieve_by_invitation_msg_id: mock_conn_retrieve_by_invitation_msg_id.return_value = ConnRecord() conn_rec = await self.manager.receive_request(mock_request, receipt) @@ -842,16 +838,16 @@ async def test_receive_request_public_did_no_auto_accept(self): async def test_create_response(self): conn_rec = ConnRecord(state=ConnRecord.State.REQUEST.rfc160) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.AsyncMock() + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.AsyncMock() ): await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -869,24 +865,22 @@ async def test_create_response_multitenant(self): endpoint=self.test_mediator_endpoint, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ), async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( - ConnRecord, "metadata_get", async_mock.AsyncMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + ConnRecord, "metadata_get", mock.AsyncMock(return_value=False) + ), mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.AsyncMock(return_value=[mediation_record]), + mock.AsyncMock(return_value=[mediation_record]), ): mock_wallet_create_local_did.return_value = DIDInfo( self.test_did, @@ -943,23 +937,21 @@ async def test_create_response_mediation(self): # Ensure the path with new did creation is hit record.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ), async_mock.patch.object( - ConnRecord, "save", autospec=True - ), async_mock.patch.object( - record, "metadata_get", async_mock.AsyncMock(return_value=False) - ), async_mock.patch.object( + ), mock.patch.object(ConnRecord, "save", autospec=True), mock.patch.object( + record, "metadata_get", mock.AsyncMock(return_value=False) + ), mock.patch.object( ConnectionManager, "create_did_document", autospec=True - ) as create_did_document, async_mock.patch.object( + ) as create_did_document, mock.patch.object( InMemoryWallet, "create_local_did" - ) as create_local_did, async_mock.patch.object( + ) as create_local_did, mock.patch.object( self.route_manager, "mediation_records_for_connection", - async_mock.AsyncMock(return_value=[mediation_record]), - ), async_mock.patch.object( + mock.AsyncMock(return_value=[mediation_record]), + ), mock.patch.object( record, "retrieve_request", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( ConnectionResponse, "sign_field", autospec=True ): did_info = DIDInfo( @@ -990,16 +982,16 @@ async def test_create_response_auto_send_mediation_request(self): ) conn_rec.my_did = None - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( ConnectionResponse, "sign_field", autospec=True - ) as mock_sign, async_mock.patch.object( - conn_rec, "metadata_get", async_mock.AsyncMock(return_value=True) + ) as mock_sign, mock.patch.object( + conn_rec, "metadata_get", mock.AsyncMock(return_value=True) ): await self.manager.create_response(conn_rec) @@ -1009,30 +1001,28 @@ async def test_create_response_auto_send_mediation_request(self): assert target["connection_id"] == conn_rec.connection_id async def test_accept_response_find_by_thread_id(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1041,34 +1031,32 @@ async def test_accept_response_find_by_thread_id(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.RESPONSE async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=False), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(return_value=False), connection_id="test-conn-id", invitation_key="test-invitation-id", ) @@ -1080,21 +1068,21 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel assert not self.responder.messages async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1103,21 +1091,21 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_bad_state(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 ) @@ -1125,22 +1113,22 @@ async def test_accept_response_find_by_thread_id_bad_state(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did mock_response.connection.did_doc = None receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, ) @@ -1148,23 +1136,23 @@ async def test_accept_response_find_by_thread_id_no_connection_did_doc(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_did_mismatch(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_did receipt = MessageReceipt(sender_did=self.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, ) @@ -1172,28 +1160,28 @@ async def test_accept_response_find_by_thread_id_did_mismatch(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_verify_invitation_key_sign_failure(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.AsyncMock(side_effect=ValueError) + mock_response.verify_signed_field = mock.AsyncMock(side_effect=ValueError) receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", invitation_key="test-invitation-key", ) @@ -1201,30 +1189,28 @@ async def test_accept_response_verify_invitation_key_sign_failure(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_auto_send_mediation_request(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() - mock_response.connection = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() + mock_response.connection = mock.MagicMock() mock_response.connection.did = self.test_target_did - mock_response.connection.did_doc = async_mock.MagicMock() + mock_response.connection.did_doc = mock.MagicMock() mock_response.connection.did_doc.did = self.test_target_did - mock_response.verify_signed_field = async_mock.AsyncMock( - return_value="sig_verkey" - ) + mock_response.verify_signed_field = mock.AsyncMock(return_value="sig_verkey") receipt = MessageReceipt(recipient_did=self.test_did, recipient_did_public=True) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - MediationManager, "get_default_mediator", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + MediationManager, "get_default_mediator", mock.AsyncMock() ): - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=self.test_target_did, - did_doc=async_mock.MagicMock(did=self.test_target_did), + did_doc=mock.MagicMock(did=self.test_target_did), state=ConnRecord.State.RESPONSE.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(return_value=True), connection_id="test-conn-id", invitation_key="test-invitation-key", ) diff --git a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py index e0d6c156f8..e092c0a52a 100644 --- a/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/connections/v1_0/tests/test_routes.py @@ -2,7 +2,7 @@ from unittest.mock import ANY from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -19,9 +19,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -42,16 +42,16 @@ async def test_connections_list(self): STATE_INVITATION = ConnRecord.State.INVITATION STATE_ABANDONED = ConnRecord.State.ABANDONED ROLE_REQUESTER = ConnRecord.Role.REQUESTER - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.query = async_mock.AsyncMock() + mock_conn_rec.query = mock.AsyncMock() mock_conn_rec.Role = ConnRecord.Role - mock_conn_rec.State = async_mock.MagicMock( + mock_conn_rec.State = mock.MagicMock( COMPLETED=STATE_COMPLETED, INVITATION=STATE_INVITATION, ABANDONED=STATE_ABANDONED, - get=async_mock.MagicMock( + get=mock.MagicMock( side_effect=[ ConnRecord.State.ABANDONED, ConnRecord.State.COMPLETED, @@ -60,24 +60,24 @@ async def test_connections_list(self): ), ) conns = [ # in ascending order here - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.COMPLETED.rfc23, "created_at": "1234567890", } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.INVITATION.rfc23, "created_at": "1234567890", } ) ), - async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.MagicMock( + serialize=mock.MagicMock( return_value={ "state": ConnRecord.State.ABANDONED.rfc23, "created_at": "1234567890", @@ -87,9 +87,7 @@ async def test_connections_list(self): ] mock_conn_rec.query.return_value = [conns[2], conns[0], conns[1]] # jumbled - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.connections_list(self.request) mock_conn_rec.query.assert_called_once_with( ANY, @@ -126,29 +124,27 @@ async def test_connections_list_x(self): STATE_COMPLETED = ConnRecord.State.COMPLETED ROLE_REQUESTER = ConnRecord.Role.REQUESTER - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.Role = async_mock.MagicMock(return_value=ROLE_REQUESTER) - mock_conn_rec.State = async_mock.MagicMock( + mock_conn_rec.Role = mock.MagicMock(return_value=ROLE_REQUESTER) + mock_conn_rec.State = mock.MagicMock( COMPLETED=STATE_COMPLETED, - get=async_mock.MagicMock(return_value=ConnRecord.State.COMPLETED), - ) - mock_conn_rec.query = async_mock.AsyncMock( - side_effect=test_module.StorageError() + get=mock.MagicMock(return_value=ConnRecord.State.COMPLETED), ) + mock_conn_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_list(self.request) async def test_connections_retrieve(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock(return_value={"hello": "world"}) + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -158,15 +154,15 @@ async def test_connections_retrieve(self): async def test_connections_endpoints(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr_cls, async_mock.patch.object( + ) as mock_conn_mgr_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.AsyncMock( + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock( return_value=("localhost:8080", "1.2.3.4:8081") ) ) @@ -180,24 +176,22 @@ async def test_connections_endpoints(self): async def test_connections_endpoints_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr_cls, async_mock.patch.object( + ) as mock_conn_mgr_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.AsyncMock(side_effect=StorageNotFoundError()) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock(side_effect=StorageNotFoundError()) ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_endpoints(self.request) - mock_conn_mgr_cls.return_value = async_mock.MagicMock( - get_endpoints=async_mock.AsyncMock( - side_effect=test_module.WalletError() - ) + mock_conn_mgr_cls.return_value = mock.MagicMock( + get_endpoints=mock.AsyncMock(side_effect=test_module.WalletError()) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -205,13 +199,13 @@ async def test_connections_endpoints_x(self): async def test_connections_metadata(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -223,16 +217,16 @@ async def test_connections_metadata(self): async def test_connections_metadata_get_single(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() self.request.query = {"key": "test"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_get", async_mock.AsyncMock() - ) as mock_metadata_get, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_get", mock.AsyncMock() + ) as mock_metadata_get, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -244,13 +238,13 @@ async def test_connections_metadata_get_single(self): async def test_connections_metadata_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -265,18 +259,18 @@ async def test_connections_metadata_x(self): async def test_connections_metadata_set(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - self.request.json = async_mock.AsyncMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.AsyncMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() + ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -288,18 +282,18 @@ async def test_connections_metadata_set(self): async def test_connections_metadata_set_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - self.request.json = async_mock.AsyncMock( + mock_conn_rec = mock.MagicMock() + self.request.json = mock.AsyncMock( return_value={"metadata": {"hello": "world"}} ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( - mock_conn_rec, "metadata_get_all", async_mock.AsyncMock() - ) as mock_metadata_get_all, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.AsyncMock() - ) as mock_metadata_set, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( + mock_conn_rec, "metadata_get_all", mock.AsyncMock() + ) as mock_metadata_get_all, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() + ) as mock_metadata_set, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -315,8 +309,8 @@ async def test_connections_metadata_set_x(self): async def test_connections_retrieve_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -325,13 +319,13 @@ async def test_connections_retrieve_not_found(self): async def test_connections_retrieve_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -347,7 +341,7 @@ async def test_connections_create_invitation(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", @@ -355,19 +349,19 @@ async def test_connections_create_invitation(self): "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( return_value=( - async_mock.MagicMock( # connection record + mock.MagicMock( # connection record connection_id="dummy", alias="conn-alias" ), - async_mock.MagicMock( # invitation - serialize=async_mock.MagicMock(return_value={"a": "value"}), - to_url=async_mock.MagicMock(return_value="http://endpoint.ca"), + mock.MagicMock( # invitation + serialize=mock.MagicMock(return_value={"a": "value"}), + to_url=mock.MagicMock(return_value="http://endpoint.ca"), ), ) ) @@ -396,7 +390,7 @@ async def test_connections_create_invitation(self): async def test_connections_create_invitation_x(self): self.context.update_settings({"public_invites": True}) - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -404,10 +398,10 @@ async def test_connections_create_invitation_x(self): "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -423,17 +417,17 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): "metadata": {"hello": "world"}, "mediation_id": "some-id", } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) self.request.query = { "auto_accept": "true", "alias": "alias", "public": "true", "multi_use": "true", } - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_invitation = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -441,7 +435,7 @@ async def test_connections_create_invitation_x_bad_mediation_id(self): async def test_connections_create_invitation_public_forbidden(self): self.context.update_settings({"public_invites": False}) - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", @@ -453,23 +447,23 @@ async def test_connections_create_invitation_public_forbidden(self): await test_module.connections_create_invitation(self.request) async def test_connections_receive_invitation(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( return_value=mock_conn_rec ) @@ -477,18 +471,18 @@ async def test_connections_receive_invitation(self): mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) async def test_connections_receive_invitation_bad(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: mock_inv_deser.side_effect = test_module.BaseModelError() @@ -503,22 +497,22 @@ async def test_connections_receive_invitation_forbidden(self): await test_module.connections_receive_invitation(self.request) async def test_connections_receive_invitation_x_bad_mediation_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "auto_accept": "true", "alias": "alias", "mediation_id": "some-id", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module.ConnectionInvitation, "deserialize", autospec=True - ) as mock_inv_deser, async_mock.patch.object( + ) as mock_inv_deser, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_conn_mgr.return_value.receive_invitation = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -532,18 +526,18 @@ async def test_connections_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_request = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_request = mock.AsyncMock() await test_module.connections_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -551,8 +545,8 @@ async def test_connections_accept_invitation(self): async def test_connections_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -562,12 +556,12 @@ async def test_connections_accept_invitation_not_found(self): async def test_connections_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -578,12 +572,12 @@ async def test_connections_accept_invitation_x_bad_mediation_id(self): self.request.match_info = {"conn_id": "dummy"} self.request.query["mediation_id"] = "some-id" - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_request = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_request = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -596,18 +590,18 @@ async def test_connections_accept_request(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock() + mock_conn_mgr.return_value.create_response = mock.AsyncMock() await test_module.connections_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -615,8 +609,8 @@ async def test_connections_accept_request(self): async def test_connections_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -626,14 +620,14 @@ async def test_connections_accept_request_not_found(self): async def test_connections_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_response = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_response = mock.AsyncMock( side_effect=test_module.ConnectionManagerError() ) @@ -642,12 +636,12 @@ async def test_connections_accept_request_x(self): async def test_connections_remove(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.AsyncMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.AsyncMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -661,12 +655,12 @@ async def test_connections_remove_cache_key(self): await cache.set("conn_rec_state::dummy", "active") profile.context.injector.bind_instance(BaseCache, cache) self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.delete_record = async_mock.AsyncMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.delete_record = mock.AsyncMock() assert (await cache.get("conn_rec_state::dummy")) == "active" - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -678,10 +672,10 @@ async def test_connections_remove_cache_key(self): async def test_connections_remove_not_found(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -690,12 +684,12 @@ async def test_connections_remove_not_found(self): async def test_connections_remove_x(self): self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock( - delete_record=async_mock.AsyncMock(side_effect=test_module.StorageError()) + mock_conn_rec = mock.MagicMock( + delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec @@ -703,7 +697,7 @@ async def test_connections_remove_x(self): await test_module.connections_remove(self.request) async def test_connections_create_static(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -721,21 +715,21 @@ async def test_connections_create_static(self): } self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() - mock_my_info = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() + mock_my_info = mock.MagicMock() mock_my_info.did = "my_did" mock_my_info.verkey = "my_verkey" - mock_their_info = async_mock.MagicMock() + mock_their_info = mock.MagicMock() mock_their_info.did = "their_did" mock_their_info.verkey = "their_verkey" - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_conn_mgr, async_mock.patch.object( + ) as mock_conn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_mgr.return_value.create_static_connection = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( return_value=(mock_my_info, mock_their_info, mock_conn_rec) ) @@ -752,7 +746,7 @@ async def test_connections_create_static(self): ) async def test_connections_create_static_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -770,19 +764,19 @@ async def test_connections_create_static_x(self): } self.request.match_info = {"conn_id": "dummy"} - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() - mock_my_info = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() + mock_my_info = mock.MagicMock() mock_my_info.did = "my_did" mock_my_info.verkey = "my_verkey" - mock_their_info = async_mock.MagicMock() + mock_their_info = mock.MagicMock() mock_their_info.did = "their_did" mock_their_info.verkey = "their_verkey" - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_conn_mgr: - mock_conn_mgr.return_value.create_static_connection = async_mock.AsyncMock( + mock_conn_mgr.return_value.create_static_connection = mock.AsyncMock( side_effect=test_module.WalletError() ) @@ -790,13 +784,13 @@ async def test_connections_create_static_x(self): await test_module.connections_create_static(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py index 7399ce0d3c..2b57a90bb6 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_keylist_update_response_handler.py @@ -4,7 +4,7 @@ from typing import AsyncGenerator import pytest from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord @@ -60,9 +60,9 @@ async def test_handler_no_active_connection(self): async def test_handler(self): handler, responder = KeylistUpdateResponseHandler(), MockResponder() - with async_mock.patch.object( + with mock.patch.object( MediationManager, "store_update_results" - ) as mock_store, async_mock.patch.object( + ) as mock_store, mock.patch.object( handler, "notify_keylist_updated" ) as mock_notify: await handler.handle(self.context, responder) @@ -84,7 +84,7 @@ async def _retrieve_by_invitation_key( ): return await generator.__anext__() - with async_mock.patch.object( + with mock.patch.object( self.route_manager, "connection_from_recipient_key", partial(_retrieve_by_invitation_key, _result_generator()), diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py index 62abea7057..4a3c45a20e 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/handlers/tests/test_mediation_grant_handler.py @@ -1,7 +1,7 @@ """Test mediate grant message handler.""" import pytest -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.core.profile import ProfileSession @@ -81,11 +81,11 @@ async def test_handler_connection_has_set_to_default_meta( handler, responder = MediationGrantHandler(), MockResponder() record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object( + with mock.patch.object( context.connection_record, "metadata_get", - async_mock.AsyncMock(return_value=True), - ), async_mock.patch.object( + mock.AsyncMock(return_value=True), + ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: await handler.handle(context, responder) @@ -96,25 +96,25 @@ async def test_handler_connection_has_set_to_default_meta( async def test_handler_multitenant_base_mediation( self, session: ProfileSession, context: RequestContext ): - handler, responder = MediationGrantHandler(), async_mock.AsyncMock() - responder.send = async_mock.AsyncMock() + handler, responder = MediationGrantHandler(), mock.AsyncMock() + responder.send = mock.AsyncMock() profile = context.profile profile.context.update_settings( {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - multitenant_mgr = async_mock.AsyncMock() + multitenant_mgr = mock.AsyncMock() profile.context.injector.bind_instance(BaseMultitenantManager, multitenant_mgr) default_base_mediator = MediationRecord(routing_keys=["key1", "key2"]) - multitenant_mgr.get_default_mediator = async_mock.AsyncMock() + multitenant_mgr.get_default_mediator = mock.AsyncMock() multitenant_mgr.get_default_mediator.return_value = default_base_mediator record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object(MediationManager, "add_key") as add_key: - keylist_updates = async_mock.MagicMock() + with mock.patch.object(MediationManager, "add_key") as add_key: + keylist_updates = mock.MagicMock() add_key.return_value = keylist_updates await handler.handle(context, responder) @@ -130,11 +130,11 @@ async def test_handler_connection_no_set_to_default( handler, responder = MediationGrantHandler(), MockResponder() record = MediationRecord(connection_id=TEST_CONN_ID) await record.save(session) - with async_mock.patch.object( + with mock.patch.object( context.connection_record, "metadata_get", - async_mock.AsyncMock(return_value=False), - ), async_mock.patch.object( + mock.AsyncMock(return_value=False), + ), mock.patch.object( test_module, "MediationManager", autospec=True ) as mock_mediation_manager: await handler.handle(context, responder) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py index 4bf2015bc7..03b0e1cdda 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_invite_store.py @@ -1,6 +1,6 @@ from unittest import IsolatedAsyncioTestCase from unittest import TestCase -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.protocols.coordinate_mediation.mediation_invite_store import ( MediationInviteStore, @@ -49,7 +49,7 @@ def test_unused_should_create_unused_record(self): class TestMediationInviteStore(IsolatedAsyncioTestCase): def setUp(self): - self.storage = async_mock.MagicMock(spec=BaseStorage) + self.storage = mock.MagicMock(spec=BaseStorage) self.mediation_invite_store = MediationInviteStore(self.storage) async def test_store_create_record_to_store_mediation_invite_when_no_record_exists( diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py index e1ac4abb64..c56799eaf5 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_mediation_manager.py @@ -2,7 +2,7 @@ import logging from typing import AsyncIterable, Iterable -from unittest import mock as async_mock +from unittest import mock import pytest from .. import manager as test_module @@ -251,8 +251,8 @@ async def test_set_set_get_default_mediator_id( assert await manager.get_default_mediator_id() == "updated" async def test_set_default_mediator_by_id(self, manager: MediationManager): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: await manager.set_default_mediator_by_id("test") @@ -404,23 +404,23 @@ async def test_store_update_results( ), ] - with async_mock.patch.object( - RouteRecord, "query", async_mock.AsyncMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.AsyncMock() + ) as mock_route_rec_query, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.side_effect = StorageNotFoundError("no record") await manager.store_update_results(TEST_CONN_ID, results) mock_logger_error.assert_called_once() - with async_mock.patch.object( - RouteRecord, "query", async_mock.AsyncMock() - ) as mock_route_rec_query, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + RouteRecord, "query", mock.AsyncMock() + ) as mock_route_rec_query, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_logger_error: mock_route_rec_query.return_value = [ - async_mock.MagicMock(delete_record=async_mock.AsyncMock()) + mock.MagicMock(delete_record=mock.AsyncMock()) ] * 2 await manager.store_update_results(TEST_CONN_ID, results) diff --git a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py index fb9702eb54..5987124d3d 100644 --- a/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/coordinate_mediation/v1_0/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import routes as test_module @@ -15,18 +15,18 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() self.profile.context.injector.bind_instance(DIDMethods, DIDMethods()) self.context = AdminRequestContext.test_context(profile=self.profile) - self.outbound_message_router = async_mock.AsyncMock() + self.outbound_message_router = mock.AsyncMock() self.request_dict = { "context": self.context, "outbound_message_router": self.outbound_message_router, } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( match_info={ "mediation_id": "test-mediation-id", "conn_id": "test-conn-id", }, query={}, - json=async_mock.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: self.request_dict[k], ) serialized = { @@ -38,10 +38,10 @@ def setUp(self): "endpoint": "http://192.168.1.13:3005", "created_at": "1234567890", } - self.mock_record = async_mock.MagicMock( + self.mock_record = mock.MagicMock( **serialized, - serialize=async_mock.MagicMock(return_value=serialized), - save=async_mock.AsyncMock() + serialize=mock.MagicMock(return_value=serialized), + save=mock.AsyncMock() ) def test_mediation_sort_key(self): @@ -66,16 +66,16 @@ def test_mediation_sort_key(self): async def test_list_mediation_requests(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "query", - async_mock.AsyncMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(return_value=[self.mock_record]), + ) as mock_query, mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=InMemoryProfile.test_session()), + mock.MagicMock(return_value=InMemoryProfile.test_session()), ) as session: await test_module.list_mediation_requests(self.request) json_response.assert_called_once_with( @@ -88,16 +88,16 @@ async def test_list_mediation_requests_filters(self): "state": MediationRecord.STATE_GRANTED, "conn_id": "test-conn-id", } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "query", - async_mock.AsyncMock(return_value=[self.mock_record]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(return_value=[self.mock_record]), + ) as mock_query, mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=InMemoryProfile.test_session()), + mock.MagicMock(return_value=InMemoryProfile.test_session()), ) as session: await test_module.list_mediation_requests(self.request) json_response.assert_called_once_with( @@ -112,31 +112,31 @@ async def test_list_mediation_requests_filters(self): ) async def test_list_mediation_requests_x(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationRecord", - async_mock.MagicMock( - query=async_mock.AsyncMock(side_effect=test_module.StorageError()) + mock.MagicMock( + query=mock.AsyncMock(side_effect=test_module.StorageError()) ), ) as mock_med_rec: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.list_mediation_requests(self.request) async def test_list_mediation_requests_no_records(self): - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationRecord", - async_mock.MagicMock(query=async_mock.AsyncMock(return_value=[])), - ) as mock_med_rec, async_mock.patch.object( + mock.MagicMock(query=mock.AsyncMock(return_value=[])), + ) as mock_med_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.list_mediation_requests(self.request) mock_response.assert_called_once_with({"results": []}) async def test_retrieve_mediation_request(self): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_mediation_record_retrieve.return_value = self.mock_record @@ -147,11 +147,11 @@ async def test_retrieve_mediation_request(self): mock_mediation_record_retrieve.assert_called() async def test_retrieve_mediation_request_x_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPNotFound @@ -159,11 +159,11 @@ async def test_retrieve_mediation_request_x_not_found(self): await test_module.retrieve_mediation_request(self.request) async def test_retrieve_mediation_request_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPBadRequest @@ -171,11 +171,11 @@ async def test_retrieve_mediation_request_x_storage_error(self): await test_module.retrieve_mediation_request(self.request) async def test_delete_mediation_request(self): - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( - self.mock_record, "delete_record", async_mock.AsyncMock() - ) as mock_delete_record, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_mediation_record_retrieve, mock.patch.object( + self.mock_record, "delete_record", mock.AsyncMock() + ) as mock_delete_record, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_mediation_record_retrieve.return_value = self.mock_record @@ -187,11 +187,11 @@ async def test_delete_mediation_request(self): mock_delete_record.assert_called() async def test_delete_mediation_request_x_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPNotFound @@ -199,11 +199,11 @@ async def test_delete_mediation_request_x_not_found(self): await test_module.delete_mediation_request(self.request) async def test_delete_mediation_request_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response, self.assertRaises( test_module.web.HTTPBadRequest @@ -213,22 +213,22 @@ async def test_delete_mediation_request_x_storage_error(self): async def test_request_mediation(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module, "MediationManager", autospec=True - ) as mock_med_mgr, async_mock.patch.object( + ) as mock_med_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.AsyncMock(return_value=False), - ) as mock_mediation_record_exists, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(return_value=False), + ) as mock_mediation_record_exists, mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: - mock_med_mgr.return_value.prepare_request = async_mock.AsyncMock( + mock_med_mgr.return_value.prepare_request = mock.AsyncMock( return_value=( self.mock_record, - async_mock.MagicMock( # mediation request - serialize=async_mock.MagicMock(return_value={"a": "value"}), + mock.MagicMock( # mediation request + serialize=mock.MagicMock(return_value={"a": "value"}), ), ) ) @@ -241,10 +241,10 @@ async def test_request_mediation(self): async def test_request_mediation_x_conn_not_ready(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=async_mock.MagicMock(is_ready=False)), + mock.AsyncMock(return_value=mock.MagicMock(is_ready=False)), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -254,12 +254,12 @@ async def test_request_mediation_x_conn_not_ready(self): async def test_request_mediation_x_already_exists(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.MediationRecord, "exists_for_connection_id", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ) as mock_exists_for_conn, self.assertRaises( test_module.web.HTTPBadRequest ) as exc: @@ -269,10 +269,10 @@ async def test_request_mediation_x_already_exists(self): async def test_request_mediation_x_conn_not_found(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPNotFound ): @@ -281,10 +281,10 @@ async def test_request_mediation_x_conn_not_found(self): async def test_request_mediation_x_storage_error(self): body = {} self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_conn_rec_retrieve_by_id, self.assertRaises( test_module.web.HTTPBadRequest ): @@ -292,11 +292,11 @@ async def test_request_mediation_x_storage_error(self): async def test_mediation_request_grant_role_server(self): self.mock_record.role = MediationRecord.ROLE_SERVER - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.mediation_request_grant(self.request) @@ -307,36 +307,36 @@ async def test_mediation_request_grant_role_server(self): async def test_mediation_request_grant_role_client_x(self): self.mock_record.role = MediationRecord.ROLE_CLIENT - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=self.mock_record), + mock.AsyncMock(return_value=self.mock_record), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) async def test_mediation_request_grant_x_rec_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_grant(self.request) async def test_mediation_request_grant_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_grant(self.request) async def test_mediation_request_deny_role_server(self): self.mock_record.role = MediationRecord.ROLE_SERVER - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=self.mock_record), - ) as mock_mediation_record_retrieve, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.mediation_request_deny(self.request) @@ -347,30 +347,30 @@ async def test_mediation_request_deny_role_server(self): async def test_mediation_request_deny_role_client_x(self): self.mock_record.role = MediationRecord.ROLE_CLIENT - with async_mock.patch.object( - test_module.MediationRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_mediation_record_retrieve, async_mock.patch.object( + with mock.patch.object( + test_module.MediationRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_mediation_record_retrieve, mock.patch.object( test_module.web, "json_response" ): - mock_mediation_record_retrieve.return_value = async_mock.MagicMock( + mock_mediation_record_retrieve.return_value = mock.MagicMock( role=MediationRecord.ROLE_CLIENT ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) async def test_mediation_request_deny_x_rec_not_found(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.mediation_request_deny(self.request) async def test_mediation_request_deny_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.mediation_request_deny(self.request) @@ -380,22 +380,20 @@ async def test_get_keylist(self): self.request.query["conn_id"] = "test-id" query_results = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"serialized": "route record"} - ) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"serialized": "route record"}) ) ] - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.AsyncMock(return_value=query_results), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(return_value=query_results), + ) as mock_query, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=session), - ) as mock_session, async_mock.patch.object( + mock.MagicMock(return_value=session), + ) as mock_session, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.get_keylist(self.request) @@ -409,15 +407,15 @@ async def test_get_keylist(self): async def test_get_keylist_no_matching_records(self): session = await self.profile.session() - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.AsyncMock(return_value=[]), - ) as mock_query, async_mock.patch.object( + mock.AsyncMock(return_value=[]), + ) as mock_query, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=session), - ) as mock_session, async_mock.patch.object( + mock.MagicMock(return_value=session), + ) as mock_session, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.get_keylist(self.request) @@ -425,10 +423,10 @@ async def test_get_keylist_no_matching_records(self): mock_response.assert_called_once_with({"results": []}, status=200) async def test_get_keylist_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.RouteRecord, "query", - async_mock.AsyncMock(side_effect=test_module.StorageError), + mock.AsyncMock(side_effect=test_module.StorageError), ) as mock_query, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_keylist(self.request) @@ -460,18 +458,18 @@ async def test_send_keylist_update(self): self.request.json.return_value = body - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( state=MediationRecord.STATE_GRANTED, connection_id="test-conn-id" ) ), - ) as mock_retrieve_by_id, async_mock.patch.object( + ) as mock_retrieve_by_id, mock.patch.object( test_module.web, "json_response", - async_mock.MagicMock( + mock.MagicMock( side_effect=lambda *args, **kwargs: [*args, *kwargs.values()] ), ) as mock_response: @@ -502,11 +500,11 @@ async def test_send_keylist_update_bad_mediation_state(self): ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( state=MediationRecord.STATE_DENIED, connection_id="test-conn-id" ) ), @@ -527,10 +525,10 @@ async def test_send_keylist_update_x_no_mediation_rec(self): }, ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ), self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_update(self.request) @@ -544,26 +542,26 @@ async def test_send_keylist_update_x_storage_error(self): ] } - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ), self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_update(self.request) - @async_mock.patch.object(test_module, "MediationManager", autospec=True) + @mock.patch.object(test_module, "MediationManager", autospec=True) async def test_send_keylist_query(self, mock_manager): self.request.json.return_value = {"filter": {"test": "filter"}} self.request.query = {"paginate_limit": 10, "paginate_offset": 20} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=self.mock_record), - ) as mock_retrieve_by_id, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_retrieve_by_id, mock.patch.object( mock_manager.return_value, "prepare_keylist_query", - async_mock.AsyncMock(), - ) as mock_prepare_keylist_query, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_prepare_keylist_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: await test_module.send_keylist_query(self.request) @@ -577,29 +575,29 @@ async def test_send_keylist_query(self, mock_manager): ) async def test_send_keylist_query_x_no_mediation_record(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPNotFound): await test_module.send_keylist_query(self.request) async def test_send_keylist_query_x_storage_error(self): - with async_mock.patch.object( + with mock.patch.object( test_module.MediationRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), + mock.AsyncMock(side_effect=test_module.StorageError()), ) as mock_retrieve_by_id, self.assertRaises(test_module.web.HTTPBadRequest): await test_module.send_keylist_query(self.request) async def test_get_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(return_value=self.mock_record), + mock.AsyncMock(return_value=self.mock_record), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -609,12 +607,12 @@ async def test_get_default_mediator(self): async def test_get_empty_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(return_value=None), + mock.AsyncMock(return_value=None), ) as mock_mgr_get_default_record: await test_module.get_default_mediator(self.request) json_response.assert_called_once_with( @@ -624,12 +622,12 @@ async def test_get_empty_default_mediator(self): async def test_get_default_mediator_storage_error(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as json_response, async_mock.patch.object( + ) as json_response, mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), + mock.AsyncMock(side_effect=test_module.StorageNotFoundError()), ) as mock_mgr_get_default_record: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.get_default_mediator(self.request) @@ -639,15 +637,15 @@ async def test_set_default_mediator(self): "mediation_id": "fake_id", } self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.AsyncMock(), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.set_default_mediator(self.request) @@ -661,15 +659,15 @@ async def test_set_default_mediator_storage_error(self): "mediation_id": "bad_id", } self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "set_default_mediator_by_id", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_set_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mgr_set_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -677,15 +675,15 @@ async def test_set_default_mediator_storage_error(self): async def test_clear_default_mediator(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(return_value=self.mock_record), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(return_value=self.mock_record), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.AsyncMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.clear_default_mediator(self.request) @@ -696,15 +694,15 @@ async def test_clear_default_mediator(self): async def test_clear_default_mediator_storage_error(self): self.request.query = {} - with async_mock.patch.object( + with mock.patch.object( test_module.MediationManager, "get_default_mediator", - async_mock.AsyncMock(side_effect=test_module.StorageError()), - ) as mock_mgr_get_default_record, async_mock.patch.object( + mock.AsyncMock(side_effect=test_module.StorageError()), + ) as mock_mgr_get_default_record, mock.patch.object( test_module.MediationManager, "clear_default_mediator", - async_mock.AsyncMock(), - ) as mock_mgr_clear_default_record_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_mgr_clear_default_record_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: with self.assertRaises(test_module.web.HTTPBadRequest): @@ -716,17 +714,17 @@ async def test_update_keylist_for_connection(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module.web, "json_response" ) as json_response: await test_module.update_keylist_for_connection(self.request) @@ -738,18 +736,18 @@ async def test_update_keylist_for_connection_not_found(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPNotFound): await test_module.update_keylist_for_connection(self.request) @@ -760,30 +758,30 @@ async def test_update_keylist_for_connection_storage_error(self): self.request.match_info = { "conn_id": "test-conn-id", } - mock_route_manager = async_mock.MagicMock(RouteManager) - mock_keylist_update = async_mock.MagicMock() + mock_route_manager = mock.MagicMock(RouteManager) + mock_keylist_update = mock.MagicMock() mock_keylist_update.serialize.return_value = {"mock": "serialized"} - mock_route_manager.route_connection = async_mock.AsyncMock( + mock_route_manager.route_connection = mock.AsyncMock( return_value=mock_keylist_update ) - mock_route_manager.mediation_record_for_connection = async_mock.AsyncMock() + mock_route_manager.mediation_record_for_connection = mock.AsyncMock() self.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=StorageError), + mock.AsyncMock(side_effect=StorageError), ) as mock_conn_rec_retrieve_by_id: with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.update_keylist_for_connection(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py index 4cad2ad869..c4a44e6182 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......messaging.request_context import RequestContext from ......messaging.responder import MockResponder @@ -25,9 +25,9 @@ class TestDIDXCompleteHandler: """Class unit testing complete handler.""" @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.AsyncMock() + mock_conn_mgr.return_value.accept_complete = mock.AsyncMock() request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() @@ -38,16 +38,14 @@ async def test_called(self, mock_conn_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_x(self, mock_conn_mgr, request_context): - mock_conn_mgr.return_value.accept_complete = async_mock.AsyncMock( + mock_conn_mgr.return_value.accept_complete = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value ) ) - mock_conn_mgr.return_value._logger = async_mock.MagicMock( - exception=async_mock.MagicMock() - ) + mock_conn_mgr.return_value._logger = mock.MagicMock(exception=mock.MagicMock()) request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py index 38d63d3aea..fdccf610c7 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock import pytest from .. import problem_report_handler as test_module @@ -19,11 +19,11 @@ class TestDIDXProblemReportHandler: """Unit test problem report handler.""" @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.AsyncMock() + manager.return_value.receive_problem_report = mock.AsyncMock() request_context.message = DIDXProblemReport() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() await handler_inst.handle(request_context, responder) @@ -31,9 +31,9 @@ async def test_called(self, manager, request_context): assert manager.return_value.receive_problem_report.called_once() @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_no_conn(self, manager, request_context): - manager.return_value.receive_problem_report = async_mock.AsyncMock() + manager.return_value.receive_problem_report = mock.AsyncMock() request_context.message = DIDXProblemReport() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() @@ -41,15 +41,15 @@ async def test_called_no_conn(self, manager, request_context): await handler_inst.handle(request_context, responder) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_unrecognized_report_exception( self, manager, request_context, caplog ): - manager.return_value.receive_problem_report = async_mock.AsyncMock( + manager.return_value.receive_problem_report = mock.AsyncMock( side_effect=DIDXManagerError() ) request_context.message = DIDXProblemReport() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler_inst = test_module.DIDXProblemReportHandler() responder = MockResponder() await handler_inst.handle(request_context, responder) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py index b822cc5b11..c97fa6ad3a 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import conn_record, connection_target @@ -91,9 +91,9 @@ async def asyncSetUp(self): did_doc_attach=self.did_doc_attach, ) - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -106,15 +106,15 @@ async def test_called(self, mock_didx_mgr): ) assert not responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_with_auto_response(self, mock_didx_mgr): - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mock_conn_rec.accept = conn_record.ConnRecord.ACCEPT_AUTO - mock_conn_rec.save = async_mock.AsyncMock() - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_conn_rec.save = mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() self.ctx.message = DIDXRequest() handler_inst = test_module.DIDXRequestHandler() responder = MockResponder() @@ -130,7 +130,7 @@ async def test_called_with_auto_response(self, mock_didx_mgr): ) assert responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_connection_record_with_mediation_metadata_auto_response( self, mock_didx_mgr ): @@ -141,15 +141,15 @@ async def test_connection_record_with_mediation_metadata_auto_response( invitation_msg_id="12345678-1234-5678-1234-567812345678", their_role=conn_record.ConnRecord.Role.REQUESTER, ) - test_exist_conn.metadata_get = async_mock.AsyncMock( + test_exist_conn.metadata_get = mock.AsyncMock( return_value={"id": "mediation-test-id"} ) test_exist_conn.accept = conn_record.ConnRecord.ACCEPT_AUTO - test_exist_conn.save = async_mock.AsyncMock() - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + test_exist_conn.save = mock.AsyncMock() + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=test_exist_conn ) - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() test_ctx = RequestContext.test_context() test_ctx.message = DIDXRequest() test_ctx.message_receipt = MessageReceipt() @@ -162,9 +162,9 @@ async def test_connection_record_with_mediation_metadata_auto_response( ) assert responder.messages - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) @@ -186,15 +186,15 @@ async def test_problem_report(self, mock_didx_mgr): ) assert target == {"target_list": None} - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc(self, mock_conn_target, mock_didx_mgr): - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) self.ctx.message = DIDXRequest( @@ -218,19 +218,19 @@ async def test_problem_report_did_doc(self, mock_conn_target, mock_didx_mgr): ) assert target == {"target_list": [mock_conn_target]} - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.REQUEST_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=DIDXManagerError("no targets") ) self.ctx.message = DIDXRequest( diff --git a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py index 85136440be..a90adddff5 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_response_handler.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models import connection_target @@ -78,9 +78,9 @@ async def asyncSetUp(self): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.AsyncMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -92,10 +92,10 @@ async def test_called(self, mock_didx_mgr): assert not responder.messages @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_called_auto_ping(self, mock_didx_mgr): self.ctx.update_settings({"auto_ping_connection": True}) - mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.accept_response = mock.AsyncMock() self.ctx.message = DIDXResponse() handler_inst = test_module.DIDXResponseHandler() responder = MockResponder() @@ -110,9 +110,9 @@ async def test_called_auto_ping(self, mock_didx_mgr): assert isinstance(result, Ping) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(test_module, "DIDXManager") async def test_problem_report(self, mock_didx_mgr): - mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) @@ -135,19 +135,19 @@ async def test_problem_report(self, mock_didx_mgr): assert target == {"target_list": None} @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( return_value=[mock_conn_target] ) self.ctx.message = DIDXResponse( @@ -171,19 +171,19 @@ async def test_problem_report_did_doc( assert target == {"target_list": [mock_conn_target]} @pytest.mark.asyncio - @async_mock.patch.object(test_module, "DIDXManager") - @async_mock.patch.object(connection_target, "ConnectionTarget") + @mock.patch.object(test_module, "DIDXManager") + @mock.patch.object(connection_target, "ConnectionTarget") async def test_problem_report_did_doc_no_conn_target( self, mock_conn_target, mock_didx_mgr, ): - mock_didx_mgr.return_value.accept_response = async_mock.AsyncMock( + mock_didx_mgr.return_value.accept_response = mock.AsyncMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.RESPONSE_NOT_ACCEPTED.value ) ) - mock_didx_mgr.return_value.diddoc_connection_targets = async_mock.MagicMock( + mock_didx_mgr.return_value.diddoc_connection_targets = mock.MagicMock( side_effect=DIDXManagerError("no target") ) self.ctx.message = DIDXResponse( diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py index a5098e2beb..9e89d70392 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -1,7 +1,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from pydid import DIDDocument from .. import manager as test_module @@ -72,18 +72,16 @@ class TestDidExchangeManager(IsolatedAsyncioTestCase, TestConfig): async def asyncSetUp(self): self.responder = MockResponder() - self.oob_mock = async_mock.MagicMock( - clean_finished_oob_record=async_mock.AsyncMock(return_value=None) + self.oob_mock = mock.MagicMock( + clean_finished_oob_record=mock.AsyncMock(return_value=None) ) - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=([], self.test_endpoint) ) - self.route_manager.mediation_record_if_id = async_mock.AsyncMock( - return_value=None - ) - self.route_manager.mediation_record_for_connection = async_mock.AsyncMock( + self.route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) + self.route_manager.mediation_record_for_connection = mock.AsyncMock( return_value=None ) @@ -112,28 +110,26 @@ async def asyncSetUp(self): key_type=ED25519, ) - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.get_endpoint_for_did = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.get_endpoint_for_did = mock.AsyncMock( return_value=TestConfig.test_endpoint ) self.context.injector.bind_instance(BaseLedger, self.ledger) - self.resolver = async_mock.MagicMock() + self.resolver = mock.MagicMock() did_doc = DIDDocument.deserialize(DOC) - self.resolver.resolve = async_mock.AsyncMock(return_value=did_doc) + self.resolver.resolve = mock.AsyncMock(return_value=did_doc) assert did_doc.verification_method - self.resolver.dereference_verification_method = async_mock.AsyncMock( + self.resolver.dereference_verification_method = mock.AsyncMock( return_value=did_doc.verification_method[0] ) self.context.injector.bind_instance(DIDResolver, self.resolver) - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) - self.multitenant_mgr.get_default_mediator = async_mock.AsyncMock( - return_value=None - ) + self.multitenant_mgr.get_default_mediator = mock.AsyncMock(return_value=None) self.manager = DIDXManager(self.profile) assert self.manager.profile @@ -176,9 +172,9 @@ async def test_receive_invitation(self): ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -187,9 +183,9 @@ async def test_receive_invitation(self): hs_protos=[HSProto.RFC23], ) invi_msg = invi_rec.invitation - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation(invi_msg) @@ -204,9 +200,9 @@ async def test_receive_invitation_oob_public_did(self): ED25519, ) public_did_info = await session.wallet.get_public_did() - with async_mock.patch.object( + with mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = None @@ -216,9 +212,9 @@ async def test_receive_invitation_oob_public_did(self): ) invi_msg = invi_rec.invitation invi_msg.services = [public_did_info.did] - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) invitee_record = await self.manager.receive_invitation( @@ -236,7 +232,7 @@ async def test_receive_invitation_no_auto_accept(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -279,14 +275,14 @@ async def test_create_request_implicit(self): ) await mediation_record.save(session) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) conn_rec = await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -356,8 +352,8 @@ async def test_create_request_implicit_x_public_already_connected(self): SOV, ED25519, ) - with self.assertRaises(DIDXManagerError) as context, async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + with self.assertRaises(DIDXManagerError) as context, mock.patch.object( + test_module.ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_retrieve_by_did: await self.manager.create_request_implicit( their_public_did=TestConfig.test_target_did, @@ -371,25 +367,25 @@ async def test_create_request_implicit_x_public_already_connected(self): assert "Connection already exists for their_did" in str(context.exception) async def test_create_request(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=self.did_info.did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request(mock_conn_rec) @@ -400,15 +396,15 @@ async def test_create_request_multitenant(self): {"multitenant.enabled": True, "wallet.id": "test_wallet"} ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_local_did", autospec=True - ) as mock_wallet_create_local_did, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_wallet_create_local_did, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_wallet_create_local_did.return_value = DIDInfo( TestConfig.test_did, @@ -417,25 +413,23 @@ async def test_create_request_multitenant(self): method=SOV, key_type=ED25519, ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_request( - async_mock.MagicMock( + mock.MagicMock( invitation_key=TestConfig.test_verkey, their_label="Hello", their_role=ConnRecord.Role.RESPONDER.rfc160, alias="Bob", my_did=None, - retrieve_invitation=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) ) @@ -471,11 +465,11 @@ async def test_create_request_mediation_id(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request( @@ -488,7 +482,7 @@ async def test_create_request_mediation_id(self): self.route_manager.route_connection_as_invitee.assert_called_once() async def test_create_request_my_endpoint(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=None, their_did=TestConfig.test_target_did, @@ -497,19 +491,19 @@ async def test_create_request_my_endpoint(self): invitation_key=TestConfig.test_verkey, state=ConnRecord.State.REQUEST.rfc23, alias="Bob", - retrieve_invitation=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - with async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + with mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) didx_req = await self.manager.create_request( @@ -519,18 +513,18 @@ async def test_create_request_my_endpoint(self): assert didx_req async def test_create_request_public_did(self): - mock_conn_rec = async_mock.MagicMock( + mock_conn_rec = mock.MagicMock( connection_id="dummy", my_did=self.did_info.did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.RESPONDER.rfc23, state=ConnRecord.State.REQUEST.rfc23, - retrieve_invitation=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + retrieve_invitation=mock.AsyncMock( + return_value=mock.MagicMock( services=[TestConfig.test_target_did], ) ), - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) request = await self.manager.create_request(mock_conn_rec, use_public_did=True) @@ -538,16 +532,16 @@ async def test_create_request_public_did(self): async def test_receive_request_explicit_public_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( @@ -569,72 +563,70 @@ async def test_receive_request_explicit_public_did(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_mediation_mgr_prep_req.return_value = ( mediation_record, mock_request, ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST - ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -652,10 +644,10 @@ async def test_receive_request_explicit_public_did(self): async def test_receive_request_invi_not_found(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="explicit-not-a-did"), + _thread=mock.MagicMock(pthid="explicit-not-a-did"), ) await session.wallet.create_local_did( @@ -665,10 +657,10 @@ async def test_receive_request_invi_not_found(self): did=TestConfig.test_did, ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError) as context: @@ -684,10 +676,10 @@ async def test_receive_request_invi_not_found(self): async def test_receive_request_public_did_no_did_doc_attachment(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( @@ -709,74 +701,72 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), - ), async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( - self.manager, "record_did", async_mock.AsyncMock() - ), async_mock.patch.object( + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + ), mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( + self.manager, "record_did", mock.AsyncMock() + ), mock.patch.object( MediationManager, "prepare_request", autospec=True ) as mock_mediation_mgr_prep_req: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={}) + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={}) ) mock_mediation_mgr_prep_req.return_value = ( mediation_record, mock_request, ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) - ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -794,10 +784,10 @@ async def test_receive_request_public_did_no_did_doc_attachment(self): async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=None, did_doc_attach=None, - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -810,36 +800,34 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): STATE_REQUEST = ConnRecord.State.REQUEST self.profile.context.update_settings({"public_invites": True}) ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture: - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) mock_conn_rec_cls.ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO mock_conn_rec_cls.State.REQUEST = STATE_REQUEST - mock_conn_rec_cls.State.get = async_mock.MagicMock( - return_value=STATE_REQUEST - ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(save=async_mock.AsyncMock()) + mock_conn_rec_cls.State.get = mock.MagicMock(return_value=STATE_REQUEST) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save=mock.AsyncMock()) ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) mock_conn_rec_cls.return_value = mock_conn_record - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -856,17 +844,17 @@ async def test_receive_request_public_did_no_did_doc_attachment_no_did(self): async def test_receive_request_public_did_x_not_public(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -878,10 +866,10 @@ async def test_receive_request_public_did_x_not_public(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDPosture", autospec=True ) as mock_did_posture: - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.WALLET_ONLY ) @@ -899,16 +887,16 @@ async def test_receive_request_public_did_x_not_public(self): async def test_receive_request_public_did_x_wrong_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -920,35 +908,33 @@ async def test_receive_request_public_did_x_wrong_did(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( - test_module.DIDDoc, "from_json", async_mock.MagicMock() - ) as mock_did_doc_from_json, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( + test_module.DIDDoc, "from_json", mock.MagicMock() + ) as mock_did_doc_from_json, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), + mock.AsyncMock(return_value=DIDDoc("LjgpST2rjsoxYegQDRm7EL")), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) - mock_did_doc_from_json.return_value = async_mock.MagicMock( - did="wrong-did" - ) + mock_did_doc_from_json.return_value = mock.MagicMock(did="wrong-did") - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -966,16 +952,16 @@ async def test_receive_request_public_did_x_wrong_did(self): async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -987,30 +973,30 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): self.profile.context.update_settings({"public_invites": True}) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(side_effect=DIDXManagerError), + mock.AsyncMock(side_effect=DIDXManagerError), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) @@ -1026,17 +1012,17 @@ async def test_receive_request_public_did_x_did_doc_attach_bad_sig(self): async def test_receive_request_public_did_no_public_invites(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -1047,18 +1033,18 @@ async def test_receive_request_public_did_no_public_invites(self): ) self.profile.context.update_settings({"public_invites": False}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( - test_module.DIDDoc, "from_json", async_mock.MagicMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( + test_module.DIDDoc, "from_json", mock.MagicMock() ) as mock_did_doc_from_json: - mock_did_doc_from_json.return_value = async_mock.MagicMock( + mock_did_doc_from_json.return_value = mock.MagicMock( did=TestConfig.test_did ) with self.assertRaises(DIDXManagerError) as context: @@ -1074,16 +1060,16 @@ async def test_receive_request_public_did_no_public_invites(self): async def test_receive_request_public_did_no_auto_accept(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) await session.wallet.create_local_did( @@ -1097,43 +1083,43 @@ async def test_receive_request_public_did_no_auto_accept(self): {"public_invites": True, "debug.auto_accept_requests": False} ) mock_conn_rec_state_request = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ConnRecord.ACCEPT_MANUAL, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=mock_conn_record ) - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) conn_rec = await self.manager.receive_request( request=mock_request, @@ -1150,17 +1136,17 @@ async def test_receive_request_public_did_no_auto_accept(self): async def test_receive_request_implicit_public_did_not_enabled(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1180,24 +1166,24 @@ async def test_receive_request_implicit_public_did_not_enabled(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=None ) @@ -1213,17 +1199,17 @@ async def test_receive_request_implicit_public_did_not_enabled(self): async def test_receive_request_implicit_public_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="did:sov:publicdid0000000000000"), + _thread=mock.MagicMock(pthid="did:sov:publicdid0000000000000"), ) mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -1246,36 +1232,36 @@ async def test_receive_request_implicit_public_did(self): ACCEPT_AUTO = ConnRecord.ACCEPT_AUTO STATE_REQUEST = ConnRecord.State.REQUEST - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "DIDPosture", autospec=True - ) as mock_did_posture, async_mock.patch.object( + ) as mock_did_posture, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_did_posture.get = async_mock.MagicMock( + mock_did_posture.get = mock.MagicMock( return_value=test_module.DIDPosture.PUBLIC ) - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) - mock_conn_rec_cls.retrieve_by_invitation_msg_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_msg_id = mock.AsyncMock( return_value=None ) - mock_conn_record = async_mock.MagicMock( + mock_conn_record = mock.MagicMock( accept=ACCEPT_AUTO, my_did=None, state=STATE_REQUEST.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - metadata_get_all=async_mock.AsyncMock(return_value={}), - metadata_get=async_mock.AsyncMock(return_value=True), - save=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + metadata_get_all=mock.AsyncMock(return_value={}), + metadata_get=mock.AsyncMock(return_value=True), + save=mock.AsyncMock(), ) mock_conn_rec_cls.return_value = mock_conn_record @@ -1295,19 +1281,19 @@ async def test_receive_request_implicit_public_did(self): async def test_receive_request_peer_did(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="dummy-pthid"), + _thread=mock.MagicMock(pthid="dummy-pthid"), ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( my_did=TestConfig.test_did, their_did=TestConfig.test_target_did, invitation_key=TestConfig.test_verkey, @@ -1315,10 +1301,10 @@ async def test_receive_request_peer_did(self): is_multiuse_invitation=True, state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.REQUESTER.rfc23, - save=async_mock.AsyncMock(), - attach_request=async_mock.AsyncMock(), + save=mock.AsyncMock(), + attach_request=mock.AsyncMock(), accept=ConnRecord.ACCEPT_MANUAL, - metadata_get_all=async_mock.AsyncMock(return_value={"test": "value"}), + metadata_get_all=mock.AsyncMock(return_value={"test": "value"}), ) mock_conn_rec_state_request = ConnRecord.State.REQUEST @@ -1330,42 +1316,42 @@ async def test_receive_request_peer_did(self): ) self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() - ) as mock_conn_rec_cls, async_mock.patch.object( + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() + ) as mock_conn_rec_cls, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.manager, "verify_diddoc", - async_mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), + mock.AsyncMock(return_value=DIDDoc(TestConfig.test_did)), ): - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( return_value=mock_conn ) - mock_conn_rec_cls.return_value = async_mock.MagicMock( + mock_conn_rec_cls.return_value = mock.MagicMock( accept=ConnRecord.ACCEPT_AUTO, my_did=None, state=mock_conn_rec_state_request.rfc23, - attach_request=async_mock.AsyncMock(), - retrieve_request=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - metadata_set=async_mock.AsyncMock(), + attach_request=mock.AsyncMock(), + retrieve_request=mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) - mock_did_doc.from_json = async_mock.MagicMock( - return_value=async_mock.MagicMock(did=TestConfig.test_did) + mock_did_doc.from_json = mock.MagicMock( + return_value=mock.MagicMock(did=TestConfig.test_did) ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) - mock_response.return_value = async_mock.MagicMock( - assign_thread_from=async_mock.MagicMock(), - assign_trace_from=async_mock.MagicMock(), + mock_response.return_value = mock.MagicMock( + assign_thread_from=mock.MagicMock(), + assign_trace_from=mock.MagicMock(), ) conn_rec = await self.manager.receive_request( @@ -1383,17 +1369,17 @@ async def test_receive_request_peer_did(self): async def test_receive_request_peer_did_not_found_x(self): async with self.profile.session() as session: - mock_request = async_mock.MagicMock( + mock_request = mock.MagicMock( did=TestConfig.test_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock(return_value="dummy-did-doc") + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value="dummy-did-doc") ), ) ), - _thread=async_mock.MagicMock(pthid="dummy-pthid"), + _thread=mock.MagicMock(pthid="dummy-pthid"), ) await session.wallet.create_local_did( @@ -1403,10 +1389,10 @@ async def test_receive_request_peer_did_not_found_x(self): did=TestConfig.test_did, ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_invitation_key = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_invitation_key = mock.AsyncMock( side_effect=StorageNotFoundError() ) with self.assertRaises(DIDXManagerError): @@ -1424,26 +1410,24 @@ async def test_create_response(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1479,20 +1463,20 @@ async def test_create_response_mediation_id(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.AsyncMock(return_value=False) - ), async_mock.patch.object( + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.AsyncMock(return_value=False) + ), mock.patch.object( test_module, "AttachDecorator", autospec=True ) as mock_attach_deco: - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock( + data=mock.MagicMock(sign=mock.AsyncMock()) ) ) await self.manager.create_response( @@ -1531,14 +1515,14 @@ async def test_create_response_mediation_id_invalid_conn_state(self): await record.save(session) await record.attach_invitation(session, invi) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "log_state", autospec=True - ) as mock_conn_log_state, async_mock.patch.object( + ) as mock_conn_log_state, mock.patch.object( ConnRecord, "retrieve_request", autospec=True - ) as mock_conn_retrieve_request, async_mock.patch.object( + ) as mock_conn_retrieve_request, mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_save, async_mock.patch.object( - record, "metadata_get", async_mock.AsyncMock(return_value=False) + ) as mock_conn_save, mock.patch.object( + record, "metadata_get", mock.AsyncMock(return_value=False) ): with self.assertRaises(DIDXManagerError) as context: await self.manager.create_response( @@ -1558,15 +1542,13 @@ async def test_create_response_multitenant(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module.ConnRecord, "retrieve_request" - ), async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ), async_mock.patch.object( + ), mock.patch.object(conn_rec, "save", mock.AsyncMock()), mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( InMemoryWallet, "create_local_did", autospec=True ) as mock_wallet_create_local_did: mock_wallet_create_local_did.return_value = DIDInfo( @@ -1576,13 +1558,11 @@ async def test_create_response_multitenant(self): method=SOV, key_type=ED25519, ) - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec) @@ -1595,29 +1575,27 @@ async def test_create_response_conn_rec_my_did(self): state=ConnRecord.State.REQUEST.rfc23, ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() - ) as mock_create_did_doc, async_mock.patch.object( - InMemoryWallet, "get_local_did", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() + ) as mock_create_did_doc, mock.patch.object( + InMemoryWallet, "get_local_did", mock.AsyncMock() ) as mock_get_loc_did: mock_get_loc_did.return_value = self.did_info - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response(conn_rec, "http://10.20.30.40:5060/") @@ -1645,26 +1623,24 @@ async def test_create_response_use_public_did(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) await self.manager.create_response( @@ -1676,26 +1652,24 @@ async def test_create_response_use_public_did_x_no_public_did(self): connection_id="dummy", state=ConnRecord.State.REQUEST.rfc23 ) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_request", async_mock.AsyncMock() - ) as mock_retrieve_req, async_mock.patch.object( - conn_rec, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_request", mock.AsyncMock() + ) as mock_retrieve_req, mock.patch.object( + conn_rec, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( test_module, "DIDDoc", autospec=True - ) as mock_did_doc, async_mock.patch.object( + ) as mock_did_doc, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_deco, async_mock.patch.object( + ) as mock_attach_deco, mock.patch.object( test_module, "DIDXResponse", autospec=True - ) as mock_response, async_mock.patch.object( - self.manager, "create_did_document", async_mock.AsyncMock() + ) as mock_response, mock.patch.object( + self.manager, "create_did_document", mock.AsyncMock() ) as mock_create_did_doc: - mock_create_did_doc.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock() + mock_create_did_doc.return_value = mock.MagicMock( + serialize=mock.MagicMock() ) - mock_attach_deco.data_base64 = async_mock.MagicMock( - return_value=async_mock.MagicMock( - data=async_mock.MagicMock(sign=async_mock.AsyncMock()) - ) + mock_attach_deco.data_base64 = mock.MagicMock( + return_value=mock.MagicMock(data=mock.MagicMock(sign=mock.AsyncMock())) ) with self.assertRaises(DIDXManagerError) as context: @@ -1705,16 +1679,14 @@ async def test_create_response_use_public_did_x_no_public_did(self): assert "No public DID configured" in str(context.exception) async def test_accept_response_find_by_thread_id(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1724,38 +1696,38 @@ async def test_accept_response_find_by_thread_id(self): recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1763,16 +1735,14 @@ async def test_accept_response_find_by_thread_id(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_find_by_thread_id_auto_disclose_features(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) @@ -1783,40 +1753,40 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): ) self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1825,50 +1795,48 @@ async def test_accept_response_find_by_thread_id_auto_disclose_features(self): mock_proactive_disclose_features.assert_called_once() async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_did, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() + ) as mock_conn_retrieve_by_did, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() - mock_conn_retrieve_by_did.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_did.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(return_value=False), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(return_value=False), connection_id="test-conn-id", ) @@ -1877,28 +1845,26 @@ async def test_accept_response_not_found_by_thread_id_receipt_has_sender_did(sel assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_conn_retrieve_by_did: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() mock_conn_retrieve_by_did.side_effect = StorageNotFoundError() @@ -1907,28 +1873,26 @@ async def test_accept_response_not_found_by_thread_id_nor_receipt_sender_did(sel await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_bad_state(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( state=ConnRecord.State.ABANDONED.rfc23 ) @@ -1936,8 +1900,8 @@ async def test_accept_response_find_by_thread_id_bad_state(self): await self.manager.accept_response(mock_response, receipt) async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did mock_response.did_doc_attach = None @@ -1946,30 +1910,30 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + self.manager, "record_did", mock.AsyncMock() ): - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) conn_rec = await self.manager.accept_response(mock_response, receipt) @@ -1977,8 +1941,8 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached(self): assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = None mock_response.did_doc_attach = None @@ -1987,30 +1951,30 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self recipient_did_public=True, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() - ) as mock_did_doc_deser, async_mock.patch.object( - self.manager, "record_did", async_mock.AsyncMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() + ) as mock_did_doc_deser, mock.patch.object( + self.manager, "record_did", mock.AsyncMock() ): - mock_did_doc_deser.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock( did=TestConfig.test_target_did ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), - metadata_get=async_mock.AsyncMock(), + save=mock.AsyncMock(), + metadata_get=mock.AsyncMock(), connection_id="test-conn-id", ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) with self.assertRaises(DIDXManagerError) as context: @@ -2018,88 +1982,84 @@ async def test_accept_response_find_by_thread_id_no_did_doc_attached_no_did(self assert "No DID in response" in str(context.exception) async def test_accept_response_find_by_thread_id_did_mismatch(self): - mock_response = async_mock.MagicMock() - mock_response._thread = async_mock.MagicMock() + mock_response = mock.MagicMock() + mock_response._thread = mock.MagicMock() mock_response.did = TestConfig.test_target_did - mock_response.did_doc_attach = async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( - return_value=json.dumps({"dummy": "did-doc"}) - ) + mock_response.did_doc_attach = mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock(return_value=json.dumps({"dummy": "did-doc"})) ), ) ) receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "save", autospec=True - ) as mock_conn_rec_save, async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_id, async_mock.patch.object( - DIDDoc, "deserialize", async_mock.MagicMock() + ) as mock_conn_rec_save, mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_id, mock.patch.object( + DIDDoc, "deserialize", mock.MagicMock() ) as mock_did_doc_deser: - mock_did_doc_deser.return_value = async_mock.MagicMock( - did=TestConfig.test_did - ) - mock_conn_retrieve_by_req_id.return_value = async_mock.MagicMock( + mock_did_doc_deser.return_value = mock.MagicMock(did=TestConfig.test_did) + mock_conn_retrieve_by_req_id.return_value = mock.MagicMock( did=TestConfig.test_target_did, - did_doc_attach=async_mock.MagicMock( - data=async_mock.MagicMock( - verify=async_mock.AsyncMock(return_value=True), - signed=async_mock.MagicMock( - decode=async_mock.MagicMock( + did_doc_attach=mock.MagicMock( + data=mock.MagicMock( + verify=mock.AsyncMock(return_value=True), + signed=mock.MagicMock( + decode=mock.MagicMock( return_value=json.dumps({"dummy": "did-doc"}) ) ), ) ), state=ConnRecord.State.REQUEST.rfc23, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - mock_conn_retrieve_by_id.return_value = async_mock.MagicMock( + mock_conn_retrieve_by_id.return_value = mock.MagicMock( their_did=TestConfig.test_target_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) with self.assertRaises(DIDXManagerError): await self.manager.accept_response(mock_response, receipt) async def test_accept_complete(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED async def test_accept_complete_with_disclose(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) self.context.update_settings({"auto_disclose_features": True}) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() - ) as mock_conn_retrieve_by_req_id, async_mock.patch.object( - V20DiscoveryMgr, "proactive_disclose_features", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() + ) as mock_conn_retrieve_by_req_id, mock.patch.object( + V20DiscoveryMgr, "proactive_disclose_features", mock.AsyncMock() ) as mock_proactive_disclose_features: - mock_conn_retrieve_by_req_id.return_value.save = async_mock.AsyncMock() + mock_conn_retrieve_by_req_id.return_value.save = mock.AsyncMock() conn_rec = await self.manager.accept_complete(mock_complete, receipt) assert ConnRecord.State.get(conn_rec.state) is ConnRecord.State.COMPLETED mock_proactive_disclose_features.assert_called_once() async def test_accept_complete_x_not_found(self): - mock_complete = async_mock.MagicMock() + mock_complete = mock.MagicMock() receipt = MessageReceipt(sender_did=TestConfig.test_target_did) - with async_mock.patch.object( - ConnRecord, "retrieve_by_request_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_request_id", mock.AsyncMock() ) as mock_conn_retrieve_by_req_id: mock_conn_retrieve_by_req_id.side_effect = StorageNotFoundError() with self.assertRaises(DIDXManagerError): @@ -2113,7 +2073,7 @@ async def test_reject_invited(self): state=ConnRecord.State.INVITATION.rfc23, their_role=ConnRecord.Role.RESPONDER, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() reason = "He doesn't like you!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2126,7 +2086,7 @@ async def test_reject_requested(self): state=ConnRecord.State.REQUEST.rfc23, their_role=ConnRecord.Role.REQUESTER, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() reason = "I don't like you either! You just watch yourself!" report = await self.manager.reject(mock_conn, reason=reason) assert report @@ -2138,20 +2098,20 @@ async def test_reject_invalid(self): their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() reason = "I'll be careful." with self.assertRaises(DIDXManagerError) as context: await self.manager.reject(mock_conn, reason=reason) assert "Cannot reject connection in state" in str(context.exception) async def test_receive_problem_report(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() report = DIDXProblemReport( description={ "code": ProblemReportReason.REQUEST_NOT_ACCEPTED.value, @@ -2162,26 +2122,26 @@ async def test_receive_problem_report(self): assert mock_conn.abandon.called_once() async def test_receive_problem_report_x_missing_description(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() report = DIDXProblemReport() with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) assert "Missing description" in str(context.exception) async def test_receive_problem_report_x_unrecognized_code(self): - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="dummy", inbound_connection_id=None, their_did=TestConfig.test_target_did, state=ConnRecord.State.COMPLETED.rfc23, ) - mock_conn.abandon = async_mock.AsyncMock() + mock_conn.abandon = mock.AsyncMock() report = DIDXProblemReport(description={"code": "something random"}) with self.assertRaises(DIDXManagerError) as context: await self.manager.receive_problem_report(mock_conn, report) @@ -2256,10 +2216,10 @@ async def test_resolve_did_document_error(self): ED25519, ) public_did_info = await session.wallet.get_public_did() - with async_mock.patch.object( + with mock.patch.object( self.resolver, "resolve", - async_mock.AsyncMock(side_effect=ResolverError()), + mock.AsyncMock(side_effect=ResolverError()), ): with self.assertRaises(DIDXManagerError) as ctx: await self.manager.get_resolved_did_document(public_did_info.did) diff --git a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py index c851d9d805..aa0d6ad657 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .. import routes as test_module from .....admin.request_context import AdminRequestContext @@ -14,17 +14,15 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, __getitem__=lambda _, k: self.request_dict[k], ) - self.profile.context.injector.bind_instance( - RouteManager, async_mock.MagicMock() - ) + self.profile.context.injector.bind_instance(RouteManager, mock.MagicMock()) async def test_didx_accept_invitation(self): self.request.match_info = {"conn_id": "dummy"} @@ -33,18 +31,18 @@ async def test_didx_accept_invitation(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock(save=async_mock.AsyncMock()) - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock(save=mock.AsyncMock()) + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_class, async_mock.patch.object( + ) as mock_conn_rec_class, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_class.retrieve_by_id.return_value = mock_conn_rec - mock_didx_mgr.return_value.create_request = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_request = mock.AsyncMock() await test_module.didx_accept_invitation(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -52,8 +50,8 @@ async def test_didx_accept_invitation(self): async def test_didx_accept_invitation_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -63,12 +61,12 @@ async def test_didx_accept_invitation_not_found(self): async def test_didx_accept_invitation_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True ) as mock_didx_mgr: - mock_didx_mgr.return_value.create_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -83,14 +81,14 @@ async def test_didx_create_request_implicit(self): "mediator_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="mock serialization") + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="mock serialization") ) ) @@ -105,12 +103,12 @@ async def test_didx_create_request_implicit_not_found_x(self): "mediator_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( side_effect=StorageNotFoundError("not found") ) @@ -125,12 +123,12 @@ async def test_didx_create_request_implicit_wallet_x(self): "my_endpoint": "http://endpoint.ca", } - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_request_implicit = async_mock.AsyncMock( + mock_didx_mgr.return_value.create_request_implicit = mock.AsyncMock( side_effect=test_module.WalletError("wallet error") ) @@ -144,19 +142,19 @@ async def test_didx_receive_request_implicit(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_conn_rec ) @@ -169,16 +167,16 @@ async def test_didx_receive_request_implicit_not_found_x(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_didx_mgr.return_value.receive_request = mock.AsyncMock( side_effect=StorageNotFoundError("tricorder must be broken") ) @@ -192,13 +190,13 @@ async def test_didx_receive_request_implicit_bad_request_x(self): "my_endpoint": "http://endpoint.ca", } self.request._thread.pthid = "did:sov:0000000000000000000000" - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( - test_module.DIDXRequest, "deserialize", async_mock.MagicMock() - ) as mock_didx_req_deser, async_mock.patch.object( + with mock.patch.object( + test_module.DIDXRequest, "deserialize", mock.MagicMock() + ) as mock_didx_req_deser, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_didx_req_deser.side_effect = test_module.BaseModelError("bad bits") @@ -212,18 +210,18 @@ async def test_didx_accept_request(self): "my_endpoint": "http://endpoint.ca", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock() + mock_didx_mgr.return_value.create_response = mock.AsyncMock() await test_module.didx_accept_request(self.request) mock_response.assert_called_once_with(mock_conn_rec.serialize.return_value) @@ -231,8 +229,8 @@ async def test_didx_accept_request(self): async def test_didx_accept_request_not_found(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -242,14 +240,14 @@ async def test_didx_accept_request_not_found(self): async def test_didx_accept_request_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.create_response = async_mock.AsyncMock( + mock_didx_mgr.return_value.create_response = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -258,25 +256,25 @@ async def test_didx_accept_request_x(self): async def test_didx_reject(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.AsyncMock() + mock_didx_mgr.return_value.reject = mock.AsyncMock() await test_module.didx_reject(self.request) async def test_didx_reject_x_not_found(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve_by_id: mock_conn_rec_retrieve_by_id.side_effect = StorageNotFoundError() @@ -285,16 +283,16 @@ async def test_didx_reject_x_not_found(self): async def test_didx_reject_x_bad_conn_state(self): self.request.match_info = {"conn_id": "dummy"} - self.request.json = async_mock.AsyncMock(return_value={"reason": "asdf"}) + self.request.json = mock.AsyncMock(return_value={"reason": "asdf"}) - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve_by_id, async_mock.patch.object( + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve_by_id, mock.patch.object( test_module, "DIDXManager", autospec=True - ) as mock_didx_mgr, async_mock.patch.object( + ) as mock_didx_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_didx_mgr.return_value.reject = async_mock.AsyncMock( + mock_didx_mgr.return_value.reject = mock.AsyncMock( side_effect=test_module.DIDXManagerError() ) @@ -302,13 +300,13 @@ async def test_didx_reject_x_bad_conn_state(self): await test_module.didx_reject(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py index 721c3c6c82..48067632e0 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_disclose_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.base_handler import HandlerException @@ -22,7 +22,7 @@ def request_context() -> RequestContext: ctx = RequestContext.test_context() ctx.connection_ready = True - ctx.connection_record = async_mock.MagicMock(connection_id="test123") + ctx.connection_record = mock.MagicMock(connection_id="test123") yield ctx @@ -53,10 +53,10 @@ async def test_disclose(self, request_context): handler = DiscloseHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=discovery_record), + mock.AsyncMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py index ee3ca03496..238c2908fe 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......core.protocol_registry import ProtocolRegistry from ......messaging.request_context import RequestContext @@ -67,10 +67,10 @@ async def test_receive_query_process_disclosed(self, request_context): request_context.message = query_msg handler = QueryHandler() responder = MockResponder() - with async_mock.patch.object( - ProtocolRegistry, "protocols_matching_query", async_mock.AsyncMock() - ) as mock_query_match, async_mock.patch.object( - ProtocolRegistry, "prepare_disclosed", async_mock.AsyncMock() + with mock.patch.object( + ProtocolRegistry, "protocols_matching_query", mock.AsyncMock() + ) as mock_query_match, mock.patch.object( + ProtocolRegistry, "prepare_disclosed", mock.AsyncMock() ) as mock_prepare_disclosed: mock_prepare_disclosed.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py index df9ea4c8a8..d543b82865 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v1_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -90,10 +90,10 @@ async def test_exists_for_connection_id(self): async def test_exists_for_connection_id_not_found(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( @@ -103,10 +103,10 @@ async def test_exists_for_connection_id_not_found(self): async def test_exists_for_connection_id_duplicate(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V10DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py index 7ded2bc195..5a73fceb2c 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_manager.py @@ -2,7 +2,7 @@ import logging import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -30,9 +30,7 @@ async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) self.manager = V10DiscoveryMgr(self.profile) self.disclose = Disclose( protocols=[ @@ -53,10 +51,10 @@ async def asyncSetUp(self): async def test_receive_disclosure(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as save_ex, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -72,18 +70,18 @@ async def test_receive_disclosure(self): async def test_receive_disclosure_retreive_by_conn(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = True @@ -101,14 +99,14 @@ async def test_receive_disclosure_retreive_by_conn(self): async def test_receive_disclosure_retreive_by_conn_not_found(self): test_conn_id = "test123" self.disclose.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -124,14 +122,14 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): async def test_receive_disclosure_retreive_new_ex_rec(self): test_conn_id = "test123" - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V10DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V10DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -145,10 +143,10 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) async def test_check_if_disclosure_received(self): - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V10DiscoveryExchangeRecord(), @@ -158,22 +156,22 @@ async def test_check_if_disclosure_received(self): async def test_create_and_send_query_with_connection(self): return_ex_rec = V10DiscoveryExchangeRecord(query_msg=Query(query="*")) - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V10DiscoveryExchangeRecord() @@ -186,16 +184,16 @@ async def test_create_and_send_query_with_connection(self): async def test_create_and_send_query_with_connection_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V10DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V10DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V10DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -207,10 +205,10 @@ async def test_create_and_send_query_with_connection_no_responder(self): assert "Unable to send discover-features v1" in self._caplog.text async def test_create_and_send_query_with_no_connection(self): - with async_mock.patch.object( + with mock.patch.object( V10DiscoveryMgr, "receive_query", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclose() received_ex_rec = await self.manager.create_and_send_query(query="*") diff --git a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py index 7922044c28..bc5043e1ec 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -18,9 +18,9 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"query": "*"} @@ -36,9 +36,9 @@ async def test_query_features(self): discovery_exchange_id="3fa85f64-5717-4562-b3fc-2c963f66afa6", query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V10DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -46,7 +46,7 @@ async def test_query_features(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_features_with_connection(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"query": "*", "connection_id": "test", "comment": "test"} @@ -55,9 +55,9 @@ async def test_query_features_with_connection(self): query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V10DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -65,7 +65,7 @@ async def test_query_features_with_connection(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_records(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"connection_id": "test"} @@ -74,9 +74,9 @@ async def test_query_records(self): query_msg=Query(query="*"), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.return_value = test_rec @@ -84,13 +84,13 @@ async def test_query_records(self): mock_response.assert_called_once_with({"results": [test_rec.serialize()]}) async def test_query_records_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"connection_id": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.side_effect = StorageError @@ -98,7 +98,7 @@ async def test_query_records_x(self): await test_module.query_records(self.request) async def test_query_records_all(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() test_recs = [ V10DiscoveryExchangeRecord( @@ -111,9 +111,9 @@ async def test_query_records_all(self): ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.return_value = test_recs @@ -123,11 +123,11 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V10DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.side_effect = StorageError @@ -135,13 +135,13 @@ async def test_query_records_connection_x(self): await test_module.query_records(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py index b6dc14c5f1..58a166b711 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_disclosures_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.storage.error import StorageNotFoundError @@ -24,7 +24,7 @@ def request_context() -> RequestContext: ctx = RequestContext.test_context() ctx.connection_ready = True - ctx.connection_record = async_mock.MagicMock(connection_id="test123") + ctx.connection_record = mock.MagicMock(connection_id="test123") yield ctx @@ -61,10 +61,10 @@ async def test_disclosures(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=discovery_record), + mock.AsyncMock(return_value=discovery_record), ) as mock_get_rec_thread_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -101,14 +101,14 @@ async def test_disclosures_connection_id_no_thid(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(return_value=discovery_record), + mock.AsyncMock(return_value=discovery_record), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages @@ -139,14 +139,14 @@ async def test_disclosures_no_conn_id_no_thid(self, request_context): handler = DisclosuresHandler() mock_responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(side_effect=StorageNotFoundError), - ) as mock_get_rec_thread_id, async_mock.patch.object( + mock.AsyncMock(side_effect=StorageNotFoundError), + ) as mock_get_rec_thread_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(side_effect=StorageNotFoundError), ) as mock_get_rec_conn_id: await handler.handle(request_context, mock_responder) assert not mock_responder.messages diff --git a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py index ee557182c6..a814506686 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py +++ b/aries_cloudagent/protocols/discovery/v2_0/handlers/tests/test_queries_handler.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ......core.protocol_registry import ProtocolRegistry from ......core.goal_code_registry import GoalCodeRegistry @@ -131,10 +131,10 @@ async def test_receive_query_process_disclosed(self, request_context): request_context.message = queries_msg handler = QueriesHandler() responder = MockResponder() - with async_mock.patch.object( - V20DiscoveryMgr, "execute_protocol_query", async_mock.AsyncMock() - ) as mock_exec_protocol_query, async_mock.patch.object( - V20DiscoveryMgr, "execute_goal_code_query", async_mock.AsyncMock() + with mock.patch.object( + V20DiscoveryMgr, "execute_protocol_query", mock.AsyncMock() + ) as mock_exec_protocol_query, mock.patch.object( + V20DiscoveryMgr, "execute_goal_code_query", mock.AsyncMock() ) as mock_goal_code_protocol_query: mock_exec_protocol_query.return_value = [ {"test": "test"}, diff --git a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py index 8e50df1d19..882897d57d 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/discovery/v2_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -147,10 +147,10 @@ async def test_exists_for_connection_id(self): async def test_exists_for_connection_id_not_found(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageNotFoundError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( @@ -160,10 +160,10 @@ async def test_exists_for_connection_id_not_found(self): async def test_exists_for_connection_id_duplicate(self): session = InMemoryProfile.test_session() - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_tag_filter: mock_retrieve_by_tag_filter.side_effect = StorageDuplicateError check = await V20DiscoveryExchangeRecord.exists_for_connection_id( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py index 10bad1b6d3..4e374940d0 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_manager.py @@ -2,7 +2,7 @@ import logging import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -30,9 +30,7 @@ async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) self.disclosures = Disclosures( disclosures=[ { @@ -59,10 +57,10 @@ async def asyncSetUp(self): async def test_receive_disclosure(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as save_ex, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.return_value = TEST_DISCOVERY_EX_REC ex_rec = await self.manager.receive_disclose( @@ -78,17 +76,17 @@ async def test_receive_disclosure(self): async def test_receive_disclosure_retreive_by_conn(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError @@ -107,13 +105,13 @@ async def test_receive_disclosure_retreive_by_conn(self): async def test_receive_disclosure_retreive_by_conn_not_found(self): test_conn_id = "test123" self.queries.assign_thread_id("test123") - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", autospec=True ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError @@ -130,14 +128,14 @@ async def test_receive_disclosure_retreive_by_conn_not_found(self): async def test_receive_disclosure_retreive_new_ex_rec(self): test_conn_id = "test123" - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( - V20DiscoveryExchangeRecord, "retrieve_by_id", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( + V20DiscoveryExchangeRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = StorageNotFoundError mock_exists_for_connection_id.return_value = False @@ -151,12 +149,12 @@ async def test_receive_disclosure_retreive_new_ex_rec(self): ) async def test_proactive_disclosure(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.AsyncMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_receive_query.return_value = Disclosures() await self.manager.proactive_disclose_features("test123") @@ -164,12 +162,12 @@ async def test_proactive_disclosure(self): async def test_proactive_disclosure_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.AsyncMock(), - ) as mock_receive_query, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_receive_query, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: self._caplog.set_level(logging.WARNING) mock_receive_query.return_value = Disclosures() @@ -179,10 +177,10 @@ async def test_proactive_disclosure_no_responder(self): ) async def test_check_if_disclosure_received(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_by_id: mock_retrieve_by_id.side_effect = [ V20DiscoveryExchangeRecord(), @@ -204,22 +202,22 @@ async def test_create_and_send_query_with_connection(self): ] ) ) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "retrieve_by_connection_id", - async_mock.AsyncMock(), - ) as mock_retrieve_by_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_by_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() - ) as mock_disclosure_received, async_mock.patch.object( - self.responder, "send", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() + ) as mock_disclosure_received, mock.patch.object( + self.responder, "send", mock.AsyncMock() ) as mock_send: mock_exists_for_connection_id.return_value = True mock_retrieve_by_connection_id.return_value = V20DiscoveryExchangeRecord() @@ -232,16 +230,16 @@ async def test_create_and_send_query_with_connection(self): async def test_create_and_send_query_with_connection_no_responder(self): self.profile.context.injector.clear_binding(BaseResponder) - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryExchangeRecord, "exists_for_connection_id", - async_mock.AsyncMock(), - ) as mock_exists_for_connection_id, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_exists_for_connection_id, mock.patch.object( V20DiscoveryExchangeRecord, "save", - async_mock.AsyncMock(), - ) as save_ex, async_mock.patch.object( - V20DiscoveryMgr, "check_if_disclosure_received", async_mock.AsyncMock() + mock.AsyncMock(), + ) as save_ex, mock.patch.object( + V20DiscoveryMgr, "check_if_disclosure_received", mock.AsyncMock() ) as mock_disclosure_received: self._caplog.set_level(logging.WARNING) mock_exists_for_connection_id.return_value = False @@ -264,10 +262,10 @@ async def test_create_and_send_query_with_connection_no_responder(self): ) async def test_create_and_send_query_with_no_connection(self): - with async_mock.patch.object( + with mock.patch.object( V20DiscoveryMgr, "receive_query", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_receive_query: mock_receive_query.return_value = Disclosures() received_ex_rec = await self.manager.create_and_send_query( diff --git a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py index a4a4c83f21..a994cfafa5 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/discovery/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -18,9 +18,9 @@ async def asyncSetUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,7 +28,7 @@ async def asyncSetUp(self): ) async def test_query_features(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"query_protocol": "*"} @@ -42,9 +42,9 @@ async def test_query_features(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -52,7 +52,7 @@ async def test_query_features(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_features_with_connection(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = { "query_protocol": "*", @@ -70,9 +70,9 @@ async def test_query_features_with_connection(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20DiscoveryMgr, "create_and_send_query", autospec=True ) as mock_create_query: mock_create_query.return_value = test_rec @@ -80,7 +80,7 @@ async def test_query_features_with_connection(self): mock_response.assert_called_once_with(test_rec.serialize()) async def test_query_records(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"connection_id": "test"} @@ -94,9 +94,9 @@ async def test_query_records(self): ), ) - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.return_value = test_rec @@ -104,13 +104,13 @@ async def test_query_records(self): mock_response.assert_called_once_with({"results": [test_rec.serialize()]}) async def test_query_records_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.query = {"connection_id": "test"} - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.retrieve_by_connection_id.side_effect = StorageError @@ -118,7 +118,7 @@ async def test_query_records_x(self): await test_module.query_records(self.request) async def test_query_records_all(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() test_recs = [ V20DiscoveryExchangeRecord( @@ -141,9 +141,9 @@ async def test_query_records_all(self): ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.return_value = test_recs @@ -153,11 +153,11 @@ async def test_query_records_all(self): ) async def test_query_records_connection_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( test_module, "V20DiscoveryExchangeRecord", autospec=True ) as mock_ex_rec: mock_ex_rec.query.side_effect = StorageError @@ -165,13 +165,13 @@ async def test_query_records_connection_x(self): await test_module.query_records(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py index d4e9e008d2..5c08c853c8 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_endorsed_transaction_response_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,12 +13,12 @@ class TestEndorsedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = True handler = test_module.EndorsedTransactionResponseHandler() @@ -33,12 +33,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock() request_context.message = EndorsedTransactionResponse() request_context.connection_ready = False handler = test_module.EndorsedTransactionResponseHandler() @@ -51,12 +51,12 @@ async def test_called_not_ready(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_endorse_response = async_mock.AsyncMock( + mock_tran_mgr.return_value.receive_endorse_response = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = EndorsedTransactionResponse() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py index d17d7c9fa0..401a251f75 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_refused_transaction_response_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,12 +13,12 @@ class TestRefusedTransactionResponseHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = True handler = test_module.RefusedTransactionResponseHandler() @@ -33,12 +33,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock() request_context.message = RefusedTransactionResponse() request_context.connection_ready = False handler = test_module.RefusedTransactionResponseHandler() @@ -51,12 +51,12 @@ async def test_called_not_ready(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_refuse_response = async_mock.AsyncMock( + mock_tran_mgr.return_value.receive_refuse_response = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = RefusedTransactionResponse() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py index e3203af42b..e934131a67 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_acknowledgement_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......connections.models.conn_record import ConnRecord @@ -15,11 +15,11 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.AsyncMock() + mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( @@ -38,13 +38,13 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.AsyncMock() + mock.AsyncMock() ) request_context.message = TransactionAcknowledgement() request_context.connection_ready = False @@ -59,11 +59,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: mock_tran_mgr.return_value.receive_transaction_acknowledgement = ( - async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock.AsyncMock(side_effect=test_module.TransactionManagerError()) ) request_context.message = TransactionAcknowledgement() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py index ee445b31df..12423880e7 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_cancel_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,12 +15,10 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.AsyncMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -38,14 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.AsyncMock() - ) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock() request_context.message = CancelTransaction() request_context.connection_ready = False handler = test_module.TransactionCancelHandler() @@ -59,11 +55,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_cancel_transaction = ( - async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock_tran_mgr.return_value.receive_cancel_transaction = mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = CancelTransaction() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py index 53658c7f75..b488aaaca3 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_job_to_send_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,14 +13,12 @@ class TestTransactionJobToSendHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = ( - async_mock.AsyncMock() - ) + mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock() request_context.message = TransactionJobToSend() request_context.connection_ready = True handler = test_module.TransactionJobToSendHandler() @@ -35,12 +33,12 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.set_transaction_their_job = async_mock.AsyncMock( + mock_tran_mgr.return_value.set_transaction_their_job = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionJobToSend() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py index 36fa24cb8b..33fb0e11c9 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,10 +15,10 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -36,12 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_tran_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = TransactionRequest() request_context.connection_ready = False handler = test_module.TransactionRequestHandler() @@ -55,10 +55,10 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_tran_mgr.return_value.receive_request = mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionRequest() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py index af949ca173..bc17c2a418 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/handlers/tests/test_transaction_resend_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,12 +15,10 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.AsyncMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() request_context.message = TransactionResend() request_context.connection_record = ConnRecord( connection_id="b5dc1636-a19a-4209-819f-e8f9984d9897" @@ -38,14 +36,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.AsyncMock() - ) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock() request_context.message = TransactionResend() request_context.connection_ready = False handler = test_module.TransactionResendHandler() @@ -59,11 +55,11 @@ async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - with async_mock.patch.object( + with mock.patch.object( test_module, "TransactionManager", autospec=True ) as mock_tran_mgr: - mock_tran_mgr.return_value.receive_transaction_resend = ( - async_mock.AsyncMock(side_effect=test_module.TransactionManagerError()) + mock_tran_mgr.return_value.receive_transaction_resend = mock.AsyncMock( + side_effect=test_module.TransactionManagerError() ) request_context.message = TransactionResend() request_context.connection_record = ConnRecord( diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py index e7c5059d39..a158437844 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_manager.py @@ -3,7 +3,7 @@ import uuid from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....cache.base import BaseCache @@ -102,11 +102,11 @@ async def asyncSetUp(self): self.test_endorser_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx" self.test_refuser_did = "AGDEjaMunDtFtBVrn1qPKQ" - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.txn_endorse = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.txn_endorse = mock.AsyncMock( return_value=self.test_endorsed_message ) - self.ledger.register_nym = async_mock.AsyncMock(return_value=(True, {})) + self.ledger.register_nym = mock.AsyncMock(return_value=(True, {})) self.context = AdminRequestContext.test_context() self.profile = self.context.profile @@ -134,9 +134,7 @@ async def test_transaction_jobs(self): assert author != endorser async def test_create_record(self): - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.create_record( messages_attach=self.test_messages_attach, connection_id=self.test_connection_id, @@ -194,9 +192,7 @@ async def test_create_request(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -234,9 +230,7 @@ async def test_create_request_author_did(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -271,7 +265,7 @@ async def test_create_request_author_did(self): ) async def test_recieve_request(self): - mock_request = async_mock.MagicMock() + mock_request = mock.MagicMock() mock_request.transaction_id = self.test_author_transaction_id mock_request.signature_request = { "context": TransactionRecord.SIGNATURE_CONTEXT, @@ -287,9 +281,7 @@ async def test_recieve_request(self): } mock_request.timing = {"expires_time": self.test_expires_time} - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_request( mock_request, self.test_receivers_connection_id ) @@ -328,9 +320,7 @@ async def test_create_endorse_response(self): transaction_record.state = TransactionRecord.STATE_REQUEST_RECEIVED transaction_record.thread_id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, endorsed_transaction_response, @@ -381,9 +371,7 @@ async def test_create_endorse_response_author_did(self): connection_id=self.test_connection_id, ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, transaction_request, @@ -406,9 +394,7 @@ async def test_create_endorse_response_author_did(self): } ) - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, endorsed_transaction_response, @@ -431,7 +417,7 @@ async def test_receive_endorse_response(self): ) self.test_author_transaction_id = transaction_record._id - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.transaction_id = self.test_author_transaction_id mock_response.thread_id = self.test_endorser_transaction_id mock_response.signature_response = { @@ -445,9 +431,7 @@ async def test_receive_endorse_response(self): mock_response.state = TransactionRecord.STATE_TRANSACTION_ENDORSED mock_response.endorser_did = self.test_endorser_did - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_endorse_response( mock_response ) @@ -475,12 +459,10 @@ async def test_complete_transaction(self): ) future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.AsyncMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) ) self.ledger.get_indy_storage = future - self.ledger.txn_submit = async_mock.AsyncMock( + self.ledger.txn_submit = mock.AsyncMock( return_value=json.dumps( { "result": { @@ -491,13 +473,13 @@ async def test_complete_transaction(self): ) ) - with async_mock.patch.object( + with mock.patch.object( TransactionRecord, "save", autospec=True - ) as save_record, async_mock.patch.object( + ) as save_record, mock.patch.object( ConnRecord, "retrieve_by_id" ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( TransactionJob.TRANSACTION_ENDORSER.name @@ -537,9 +519,7 @@ async def test_create_refuse_response(self): transaction_record.state = TransactionRecord.STATE_REQUEST_RECEIVED transaction_record.thread_id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, refused_transaction_response, @@ -584,7 +564,7 @@ async def test_receive_refuse_response(self): ) self.test_author_transaction_id = transaction_record._id - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.transaction_id = self.test_author_transaction_id mock_response.thread_id = self.test_endorser_transaction_id mock_response.signature_response = { @@ -596,9 +576,7 @@ async def test_receive_refuse_response(self): mock_response.state = TransactionRecord.STATE_TRANSACTION_REFUSED mock_response.endorser_did = self.test_refuser_did - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: transaction_record = await self.manager.receive_refuse_response( mock_response ) @@ -636,9 +614,7 @@ async def test_cancel_transaction(self): transaction_record.thread_id = self.test_endorser_transaction_id transaction_record._id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, cancelled_transaction_response, @@ -671,13 +647,11 @@ async def test_receive_cancel_transaction(self): author_transaction_request, self.test_receivers_connection_id ) - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.state = TransactionRecord.STATE_TRANSACTION_CANCELLED mock_response.thread_id = author_transaction_record._id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: endorser_transaction_record = await self.manager.receive_cancel_transaction( mock_response, self.test_receivers_connection_id ) @@ -710,9 +684,7 @@ async def test_transaction_resend(self): transaction_record.thread_id = self.test_endorser_transaction_id transaction_record._id = self.test_author_transaction_id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: ( transaction_record, resend_transaction_response, @@ -743,13 +715,11 @@ async def test_receive_transaction_resend(self): author_transaction_request, self.test_receivers_connection_id ) - mock_response = async_mock.MagicMock() + mock_response = mock.MagicMock() mock_response.state = TransactionRecord.STATE_TRANSACTION_RESENT_RECEIEVED mock_response.thread_id = author_transaction_record._id - with async_mock.patch.object( - TransactionRecord, "save", autospec=True - ) as save_record: + with mock.patch.object(TransactionRecord, "save", autospec=True) as save_record: endorser_transaction_record = await self.manager.receive_transaction_resend( mock_response, self.test_receivers_connection_id ) @@ -761,45 +731,45 @@ async def test_receive_transaction_resend(self): ) async def test_set_transaction_my_job(self): - conn_record = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + conn_record = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) for i in range(2): await self.manager.set_transaction_my_job(conn_record, "Hello") async def test_set_transaction_their_job(self): - mock_job = async_mock.MagicMock() - mock_receipt = async_mock.MagicMock() + mock_job = mock.MagicMock() + mock_receipt = mock.MagicMock() - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_retrieve: - mock_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ None, {"meta": "data"}, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) for i in range(2): await self.manager.set_transaction_their_job(mock_job, mock_receipt) async def test_set_transaction_their_job_conn_not_found(self): - mock_job = async_mock.MagicMock() - mock_receipt = async_mock.MagicMock() + mock_job = mock.MagicMock() + mock_receipt = mock.MagicMock() - with async_mock.patch.object( - ConnRecord, "retrieve_by_did", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_did", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py index 791ba0aa1c..0aee212ad4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/tests/test_routes.py @@ -2,7 +2,7 @@ import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....connections.models.conn_record import ConnRecord from .....core.in_memory import InMemoryProfile @@ -32,15 +32,13 @@ async def asyncSetUp(self): setattr( self.profile, "session", - async_mock.MagicMock(return_value=self.profile_session), + mock.MagicMock(return_value=self.profile_session), ) - self.ledger = async_mock.create_autospec(BaseLedger) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.txn_endorse = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.txn_submit = async_mock.AsyncMock( + self.ledger = mock.create_autospec(BaseLedger) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.txn_endorse = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.txn_submit = mock.AsyncMock( return_value=json.dumps( { "result": { @@ -52,21 +50,19 @@ async def asyncSetUp(self): ) future = asyncio.Future() future.set_result( - async_mock.MagicMock( - return_value=async_mock.MagicMock(add_record=async_mock.AsyncMock()) - ) + mock.MagicMock(return_value=mock.MagicMock(add_record=mock.AsyncMock())) ) self.ledger.get_indy_storage = future - self.ledger.get_schema = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock( return_value={"id": SCHEMA_ID, "...": "..."} ) self.profile_injector.bind_instance(BaseLedger, self.ledger) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -76,24 +72,22 @@ async def asyncSetUp(self): self.test_did = "sample-did" async def test_transactions_list(self): - with async_mock.patch.object( - TransactionRecord, "query", async_mock.AsyncMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.AsyncMock() + ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_query.return_value = [ - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) - ) + mock.MagicMock(serialize=mock.MagicMock(return_value={"...": "..."})) ] await test_module.transactions_list(self.request) mock_response.assert_called_once_with({"results": [{"...": "..."}]}) async def test_transactions_list_x(self): - with async_mock.patch.object( - TransactionRecord, "query", async_mock.AsyncMock() - ) as mock_query, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "query", mock.AsyncMock() + ) as mock_query, mock.patch.object( test_module.web, "json_response" ) as mock_response: mock_query.side_effect = test_module.StorageError() @@ -104,13 +98,13 @@ async def test_transactions_list_x(self): async def test_transactions_retrieve(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transactions_retrieve(self.request) @@ -119,8 +113,8 @@ async def test_transactions_retrieve(self): async def test_transactions_retrieve_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError() @@ -130,8 +124,8 @@ async def test_transactions_retrieve_not_found_x(self): async def test_transactions_retrieve_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = test_module.BaseModelError() @@ -142,32 +136,32 @@ async def test_transaction_create_request(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -178,8 +172,8 @@ async def test_transaction_create_request(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transaction_create_request(self.request) @@ -189,13 +183,13 @@ async def test_transaction_create_request_not_found_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -206,18 +200,18 @@ async def test_transaction_create_request_base_model_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -237,33 +231,33 @@ async def test_transaction_create_request_no_jobs_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -273,30 +267,30 @@ async def test_transaction_create_request_no_my_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -304,8 +298,8 @@ async def test_transaction_create_request_no_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -315,30 +309,30 @@ async def test_transaction_create_request_no_their_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -346,8 +340,8 @@ async def test_transaction_create_request_no_their_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -357,18 +351,18 @@ async def test_transaction_create_request_my_wrong_job_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -377,8 +371,8 @@ async def test_transaction_create_request_my_wrong_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -388,25 +382,25 @@ async def test_transaction_create_request_mgr_create_request_x(self): self.request.query = { "tran_id": "dummy", } - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "expires_time": "2021-03-29T05:22:19Z", } ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_request=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_request=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -417,8 +411,8 @@ async def test_transaction_create_request_mgr_create_request_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -428,8 +422,8 @@ async def test_endorse_transaction_response(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -441,31 +435,31 @@ async def test_endorse_transaction_response(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -473,8 +467,8 @@ async def test_endorse_transaction_response(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.endorse_transaction_response(self.request) @@ -490,14 +484,12 @@ async def skip_test_endorse_transaction_response_no_endorser_did_info_x(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None) - ), + mock.MagicMock(get_public_did=mock.AsyncMock(return_value=None)), ) - with async_mock.patch.object( + with mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: with self.assertRaises(test_module.web.HTTPForbidden): await test_module.endorse_transaction_response(self.request) @@ -507,8 +499,8 @@ async def test_endorse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -520,12 +512,12 @@ async def test_endorse_transaction_response_not_found_x(self): ), ) - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -536,8 +528,8 @@ async def test_endorse_transaction_response_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -549,18 +541,18 @@ async def test_endorse_transaction_response_base_model_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -571,8 +563,8 @@ async def test_endorse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -584,20 +576,20 @@ async def test_endorse_transaction_response_no_jobs_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -608,8 +600,8 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): self.context.injector.clear_binding(BaseLedger) self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -621,29 +613,29 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -651,8 +643,8 @@ async def skip_test_endorse_transaction_response_no_ledger_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -663,8 +655,8 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -676,17 +668,17 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -694,8 +686,8 @@ async def test_endorse_transaction_response_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -706,8 +698,8 @@ async def skip_test_endorse_transaction_response_ledger_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -718,33 +710,31 @@ async def skip_test_endorse_transaction_response_ledger_x(self): ) ), ) - self.ledger.txn_endorse = async_mock.AsyncMock( - side_effect=test_module.LedgerError() - ) - - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + self.ledger.txn_endorse = mock.AsyncMock(side_effect=test_module.LedgerError()) + + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( return_value=( - async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ), - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -752,8 +742,8 @@ async def skip_test_endorse_transaction_response_ledger_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -764,8 +754,8 @@ async def test_endorse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -777,26 +767,26 @@ async def test_endorse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_endorse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_endorse_response=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -804,8 +794,8 @@ async def test_endorse_transaction_response_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -816,8 +806,8 @@ async def test_refuse_transaction_response(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -829,32 +819,32 @@ async def test_refuse_transaction_response(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.AsyncMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -862,8 +852,8 @@ async def test_refuse_transaction_response(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.refuse_transaction_response(self.request) @@ -874,8 +864,8 @@ async def test_refuse_transaction_response_not_found_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -887,12 +877,12 @@ async def test_refuse_transaction_response_not_found_x(self): ), ) - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -904,8 +894,8 @@ async def test_refuse_transaction_response_conn_base_model_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -917,18 +907,18 @@ async def test_refuse_transaction_response_conn_base_model_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -939,8 +929,8 @@ async def test_refuse_transaction_response_no_jobs_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -952,20 +942,20 @@ async def test_refuse_transaction_response_no_jobs_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -976,8 +966,8 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -989,17 +979,17 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1007,8 +997,8 @@ async def test_refuse_transaction_response_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1019,8 +1009,8 @@ async def test_refuse_transaction_response_txn_mgr_x(self): self.session.context.injector.bind_instance( BaseWallet, - async_mock.MagicMock( - get_public_did=async_mock.AsyncMock( + mock.MagicMock( + get_public_did=mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -1032,26 +1022,26 @@ async def test_refuse_transaction_response_txn_mgr_x(self): ), ) - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( self.context.profile, "session", - async_mock.MagicMock(return_value=self.session), + mock.MagicMock(return_value=self.session), ) as mock_session: - mock_txn_mgr.return_value = async_mock.MagicMock( - create_refuse_response=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + create_refuse_response=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1059,8 +1049,8 @@ async def test_refuse_transaction_response_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1069,28 +1059,28 @@ async def test_refuse_transaction_response_txn_mgr_x(self): async def test_cancel_transaction(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.AsyncMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1098,8 +1088,8 @@ async def test_cancel_transaction(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.cancel_transaction(self.request) @@ -1108,8 +1098,8 @@ async def test_cancel_transaction(self): async def test_cancel_transaction_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1119,14 +1109,14 @@ async def test_cancel_transaction_not_found_x(self): async def test_cancel_transaction_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1135,16 +1125,16 @@ async def test_cancel_transaction_conn_rec_base_model_x(self): async def test_cancel_transaction_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1153,13 +1143,13 @@ async def test_cancel_transaction_no_jobs_x(self): async def test_cancel_transaction_wrong_my_job_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1167,8 +1157,8 @@ async def test_cancel_transaction_wrong_my_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1177,22 +1167,22 @@ async def test_cancel_transaction_wrong_my_job_x(self): async def test_cancel_transaction_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - cancel_transaction=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + cancel_transaction=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1200,8 +1190,8 @@ async def test_cancel_transaction_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1210,28 +1200,28 @@ async def test_cancel_transaction_txn_mgr_x(self): async def test_transaction_resend(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.AsyncMock( return_value=( - async_mock.MagicMock( # transaction + mock.MagicMock( # transaction connection_id="dummy", - serialize=async_mock.MagicMock(return_value={"...": "..."}), + serialize=mock.MagicMock(return_value={"...": "..."}), ), - async_mock.MagicMock(), # refused_transaction_response + mock.MagicMock(), # refused_transaction_response ) ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1239,8 +1229,8 @@ async def test_transaction_resend(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) await test_module.transaction_resend(self.request) @@ -1249,8 +1239,8 @@ async def test_transaction_resend(self): async def test_transaction_resend_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1260,14 +1250,14 @@ async def test_transaction_resend_not_found_x(self): async def test_transaction_resend_conn_rec_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1276,16 +1266,16 @@ async def test_transaction_resend_conn_rec_base_model_x(self): async def test_transaction_resend_no_jobs_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1294,13 +1284,13 @@ async def test_transaction_resend_no_jobs_x(self): async def test_transaction_resend_my_wrong_job_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1309,8 +1299,8 @@ async def test_transaction_resend_my_wrong_job_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -1319,22 +1309,22 @@ async def test_transaction_resend_my_wrong_job_x(self): async def test_transaction_resend_txn_mgr_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - transaction_resend=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + transaction_resend=mock.AsyncMock( side_effect=test_module.TransactionManagerError() ) ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1342,8 +1332,8 @@ async def test_transaction_resend_txn_mgr_x(self): } ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}) ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1352,18 +1342,18 @@ async def test_transaction_resend_txn_mgr_x(self): async def test_set_endorser_role(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value = async_mock.MagicMock( - set_transaction_my_job=async_mock.AsyncMock() + mock_txn_mgr.return_value = mock.MagicMock( + set_transaction_my_job=mock.AsyncMock() ) - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1380,8 +1370,8 @@ async def test_set_endorser_role(self): async def test_set_endorser_role_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1391,8 +1381,8 @@ async def test_set_endorser_role_not_found_x(self): async def test_set_endorser_role_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1402,13 +1392,13 @@ async def test_set_endorser_role_base_model_x(self): async def test_set_endorser_info(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_my_job": ( test_module.TransactionJob.TRANSACTION_AUTHOR.name @@ -1418,7 +1408,7 @@ async def test_set_endorser_info(self): ), } ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1434,13 +1424,13 @@ async def test_set_endorser_info(self): async def test_set_endorser_info_no_prior_value(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_conn_rec_retrieve, async_mock.patch.object( + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_conn_rec_retrieve, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( side_effect=[ { "transaction_my_job": ( @@ -1457,7 +1447,7 @@ async def test_set_endorser_info_no_prior_value(self): }, ] ), - metadata_set=async_mock.AsyncMock(), + metadata_set=mock.AsyncMock(), ) await test_module.set_endorser_info(self.request) @@ -1472,8 +1462,8 @@ async def test_set_endorser_info_not_found_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1484,8 +1474,8 @@ async def test_set_endorser_info_base_model_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: mock_conn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1496,11 +1486,11 @@ async def test_set_endorser_info_no_transaction_jobs_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock(return_value=None) + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock(return_value=None) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.set_endorser_info(self.request) @@ -1509,11 +1499,11 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1527,11 +1517,11 @@ async def test_set_endorser_info_no_transaction_my_job_x(self): async def test_set_endorser_info_my_wrong_job_x(self): self.request.match_info = {"conn_id": "dummy"} self.request.query = {"endorser_did": "did", "endorser_name": "name"} - with async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_rec_retrieve: - mock_conn_rec_retrieve.return_value = async_mock.MagicMock( - metadata_get=async_mock.AsyncMock( + mock_conn_rec_retrieve.return_value = mock.MagicMock( + metadata_get=mock.AsyncMock( return_value={ "transaction_their_job": ( test_module.TransactionJob.TRANSACTION_ENDORSER.name @@ -1546,24 +1536,22 @@ async def test_set_endorser_info_my_wrong_job_x(self): async def test_transaction_write_schema_txn(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() - ) as mock_txn_mgr, async_mock.patch.object( + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() + ) as mock_txn_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_txn_mgr.return_value.complete_transaction = async_mock.AsyncMock() + mock_txn_mgr.return_value.complete_transaction = mock.AsyncMock() mock_txn_mgr.return_value.complete_transaction.return_value = ( - async_mock.AsyncMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}) - ), - async_mock.AsyncMock(), + mock.AsyncMock(serialize=mock.MagicMock(return_value={"...": "..."})), + mock.AsyncMock(), ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(), state=TransactionRecord.STATE_TRANSACTION_ENDORSED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1575,8 +1563,8 @@ async def test_transaction_write_schema_txn(self): async def test_transaction_write_not_found_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.StorageNotFoundError() @@ -1586,8 +1574,8 @@ async def test_transaction_write_not_found_x(self): async def test_transaction_write_base_model_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: mock_txn_rec_retrieve.side_effect = test_module.BaseModelError() @@ -1596,11 +1584,11 @@ async def test_transaction_write_base_model_x(self): async def test_transaction_write_wrong_state_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_txn_rec_retrieve: - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}), state=TransactionRecord.STATE_TRANSACTION_CREATED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1612,19 +1600,19 @@ async def test_transaction_write_wrong_state_x(self): async def test_transaction_write_schema_txn_complete_x(self): self.request.match_info = {"tran_id": "dummy"} - with async_mock.patch.object( - TransactionRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_txn_rec_retrieve, async_mock.patch.object( - test_module, "TransactionManager", async_mock.MagicMock() + with mock.patch.object( + TransactionRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_txn_rec_retrieve, mock.patch.object( + test_module, "TransactionManager", mock.MagicMock() ) as mock_txn_mgr: - mock_txn_mgr.return_value = async_mock.MagicMock( - complete_transaction=async_mock.AsyncMock( + mock_txn_mgr.return_value = mock.MagicMock( + complete_transaction=mock.AsyncMock( side_effect=test_module.StorageError() ) ) - mock_txn_rec_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"...": "..."}), + mock_txn_rec_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value={"...": "..."}), state=TransactionRecord.STATE_TRANSACTION_ENDORSED, messages_attach=[ {"data": {"json": json.dumps({"message": "attached"})}} @@ -1635,14 +1623,14 @@ async def test_transaction_write_schema_txn_complete_x(self): await test_module.transaction_write(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {"paths": {}}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {"paths": {}}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py index 3b3f0ceadd..45049f43e3 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_forward_invitation_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord from ......messaging.base_handler import HandlerException @@ -42,10 +42,10 @@ async def test_handle(self): handler = test_module.ForwardInvitationHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.AsyncMock( return_value=ConnRecord(connection_id="dummy") ) @@ -56,10 +56,10 @@ async def test_handle_x(self): handler = test_module.ForwardInvitationHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_mgr.return_value.receive_invitation = mock.AsyncMock( side_effect=test_module.ConnectionManagerError("oops") ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py index 5ddd695a72..d66afc900b 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -35,19 +35,19 @@ async def asyncSetUp(self): ), message="Hello World", ) - self.context.connection_record = async_mock.MagicMock(connection_id="dummy") + self.context.connection_record = mock.MagicMock(connection_id="dummy") async def test_handle(self): handler = test_module.InvitationHandler() - mock_conn_rec = async_mock.MagicMock(connection_id="dummy") + mock_conn_rec = mock.MagicMock(connection_id="dummy") responder = MockResponder() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: - mock_ctx_inject.return_value = async_mock.MagicMock( - return_invitation=async_mock.AsyncMock() + mock_ctx_inject.return_value = mock.MagicMock( + return_invitation=mock.AsyncMock() ) await handler.handle(self.context, responder) diff --git a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py index 186c86b50b..833090611d 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ......messaging.base_handler import HandlerException from ......messaging.request_context import RequestContext @@ -37,7 +37,7 @@ async def test_handle(self): responder = MockResponder() inv_req = InvitationRequest(responder=responder, message="Hello") - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: await handler.handle(self.context, responder) @@ -54,13 +54,13 @@ async def test_handle_auto_accept(self): routing_keys=[TEST_ROUTE_VERKEY], image_url=TEST_IMAGE_URL, ) - mock_conn_rec = async_mock.MagicMock(connection_id="dummy") + mock_conn_rec = mock.MagicMock(connection_id="dummy") responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.create_invitation = async_mock.AsyncMock( + mock_mgr.return_value.create_invitation = mock.AsyncMock( return_value=(mock_conn_rec, conn_invitation) ) diff --git a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py index 1787ffa28d..af46ee1343 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py +++ b/aries_cloudagent/protocols/introduction/v0_1/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -12,9 +12,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -22,7 +22,7 @@ async def asyncSetUp(self): ) async def test_introduction_start_no_service(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -44,7 +44,7 @@ async def test_introduction_start_no_service(self): await test_module.introduction_start(self.request) async def test_introduction_start(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -61,16 +61,16 @@ async def test_introduction_start(self): "target_connection_id": "dummy", "message": "Hello", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() - ) as mock_ctx_inject, async_mock.patch.object( + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() + ) as mock_ctx_inject, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.AsyncMock() + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.AsyncMock() ) await test_module.introduction_start(self.request) @@ -78,13 +78,13 @@ async def test_introduction_start(self): self.request.match_info["conn_id"], self.request.query["target_connection_id"], self.request.query["message"], - async_mock.ANY, + mock.ANY, self.request["outbound_message_router"], ) mock_response.assert_called_once_with({}) async def test_introduction_start_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "my_seed": "my_seed", "my_did": "my_did", @@ -101,14 +101,14 @@ async def test_introduction_start_x(self): "target_connection_id": "dummy", "message": "Hello", } - mock_conn_rec = async_mock.MagicMock() - mock_conn_rec.serialize = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() + mock_conn_rec.serialize = mock.MagicMock() - with async_mock.patch.object( - self.context, "inject_or", async_mock.MagicMock() + with mock.patch.object( + self.context, "inject_or", mock.MagicMock() ) as mock_ctx_inject: - mock_ctx_inject.return_value = async_mock.MagicMock( - start_introduction=async_mock.AsyncMock( + mock_ctx_inject.return_value = mock.MagicMock( + start_introduction=mock.AsyncMock( side_effect=test_module.IntroductionError() ) ) @@ -117,13 +117,13 @@ async def test_introduction_start_x(self): await test_module.introduction_start(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py index 85b0f31510..ce38c2cbbd 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -16,20 +16,20 @@ class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = True handler = test_module.CredentialAckHandler() @@ -48,12 +48,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() @@ -68,18 +68,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = CredentialAck() request_context.connection_ready = False handler = test_module.CredentialAckHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py index d96a7f2688..67697fbd79 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_issue_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = True handler = test_module.CredentialIssueHandler() @@ -48,25 +48,25 @@ async def test_called_auto_store(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.AsyncMock(), - store_credential=async_mock.AsyncMock(), - send_credential_ack=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock(), + store_credential=mock.AsyncMock(), + send_credential_ack=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), ) @@ -89,31 +89,29 @@ async def test_called_auto_store_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - store_credential=async_mock.AsyncMock( + store_credential=mock.AsyncMock( side_effect=test_module.IndyHolderError() ), - send_credential_ack=async_mock.AsyncMock( + send_credential_ack=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), ) @@ -123,10 +121,10 @@ async def test_called_auto_store_x(self): handler = test_module.CredentialIssueHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -134,12 +132,12 @@ async def test_called_auto_store_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = CredentialIssue() request_context.connection_ready = False handler = test_module.CredentialIssueHandler() @@ -154,18 +152,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = CredentialIssue() handler = test_module.CredentialIssueHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py index 4e0697663c..94613b174f 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_offer_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = True handler = test_module.CredentialOfferHandler() @@ -48,21 +48,21 @@ async def test_called_auto_request(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock( return_value=(None, "credential_request_message") ) request_context.message = CredentialOffer() @@ -88,25 +88,23 @@ async def test_called_auto_request_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,10 +113,10 @@ async def test_called_auto_request_x(self): handler = test_module.CredentialOfferHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -126,12 +124,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() @@ -149,18 +147,18 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = CredentialOffer() request_context.connection_ready = False handler = test_module.CredentialOfferHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py index bd5bcb64d3..103b975ffc 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -17,13 +17,13 @@ class TestCredentialProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = CredentialProblemReport( description={ "en": "Change of plans", @@ -43,13 +43,13 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = CredentialProblemReport( @@ -71,7 +71,7 @@ async def test_called_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_ready = False request_context.message = CredentialProblemReport( diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py index 51cb64533e..f723bf16e8 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,13 +14,13 @@ class TestCredentialProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = CredentialProposal() @@ -38,16 +38,16 @@ async def test_called(self): async def test_called_auto_offer(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( return_value=(None, "credential_offer_message") ) request_context.message = CredentialProposal() @@ -69,18 +69,16 @@ async def test_called_auto_offer(self): async def test_called_auto_offer_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,10 +87,10 @@ async def test_called_auto_offer_x(self): handler = test_module.CredentialProposalHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -100,12 +98,12 @@ async def test_called_auto_offer_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() request_context.message = CredentialProposal() request_context.connection_ready = False handler = test_module.CredentialProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py index 0ed5e7f66d..b89fff1b98 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/handlers/tests/test_credential_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -19,21 +19,19 @@ class TestCredentialRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = CredentialRequest() @@ -54,13 +52,11 @@ async def test_called(self): async def test_called_auto_issue(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -74,14 +70,14 @@ async def test_called_auto_issue(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "credential_issue_message") ) request_context.message = CredentialRequest() @@ -109,13 +105,11 @@ async def test_called_auto_issue(self): async def test_called_auto_issue_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -129,16 +123,16 @@ async def test_called_auto_issue_x(self): }, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.AsyncMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -147,10 +141,10 @@ async def test_called_auto_issue_x(self): handler = test_module.CredentialRequestHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -158,13 +152,11 @@ async def test_called_auto_issue_x(self): async def test_called_auto_issue_no_preview(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -172,14 +164,14 @@ async def test_called_auto_issue_no_preview(self): credential_proposal_dict={"cred_def_id": CD_ID} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "credential_issue_message") ) @@ -202,12 +194,12 @@ async def test_called_auto_issue_no_preview(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = CredentialRequest() request_context.connection_ready = False handler = test_module.CredentialRequestHandler() @@ -225,18 +217,18 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = CredentialRequest() handler = test_module.CredentialRequestHandler() responder = MockResponder() diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py index ac20adde83..ec5dea7a8d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/models/tests/test_credential_exchange.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -78,10 +78,10 @@ async def test_save_error_state(self): record.state = V10CredentialExchange.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="test") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py index 0396176a9d..16977f34a2 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -3,7 +3,7 @@ from copy import deepcopy from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -55,29 +55,23 @@ async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) - setattr( - self.profile, "transaction", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) + setattr(self.profile, "transaction", mock.MagicMock(return_value=self.session)) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -134,10 +128,10 @@ async def test_prepare_send(self): proposal = CredentialProposal( credential_proposal=preview, cred_def_id=CRED_DEF_ID, schema_id=SCHEMA_ID ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "create_offer", autospec=True ) as create_offer: - create_offer.return_value = (async_mock.MagicMock(), async_mock.MagicMock()) + create_offer.return_value = (mock.MagicMock(), mock.MagicMock()) ret_exchange, ret_cred_offer = await self.manager.prepare_send( connection_id, proposal ) @@ -162,13 +156,11 @@ async def test_create_proposal(self): ) ) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: exchange: V10CredentialExchange = await self.manager.create_proposal( connection_id, auto_offer=True, @@ -200,13 +192,11 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: exchange: V10CredentialExchange = await self.manager.create_proposal( connection_id, auto_offer=True, @@ -238,9 +228,7 @@ async def test_receive_proposal(self): ) ) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: proposal = CredentialProposal( credential_proposal=preview, cred_def_id=CRED_DEF_ID, schema_id=None ) @@ -291,14 +279,12 @@ async def test_create_free_offer(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -369,18 +355,16 @@ async def test_create_free_offer_attr_mismatch(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -429,16 +413,16 @@ async def test_create_bound_offer(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "get_cached_key", autospec=True - ) as get_cached_key, async_mock.patch.object( + ) as get_cached_key, mock.patch.object( V10CredentialExchange, "set_cached_key", autospec=True ) as set_cached_key: get_cached_key.return_value = None - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.create_credential_offer = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) self.context.injector.bind_instance(IndyIssuer, issuer) @@ -500,18 +484,16 @@ async def test_create_bound_offer_no_cred_def(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "get_cached_key", autospec=True - ) as get_cached_key, async_mock.patch.object( + ) as get_cached_key, mock.patch.object( V10CredentialExchange, "set_cached_key", autospec=True ) as set_cached_key: get_cached_key.return_value = None - issuer = async_mock.MagicMock() - issuer.create_credential_offer = async_mock.AsyncMock( - return_value=INDY_OFFER - ) + issuer = mock.MagicMock() + issuer.create_credential_offer = mock.AsyncMock(return_value=INDY_OFFER) self.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(CredentialManagerError): @@ -554,12 +536,12 @@ async def test_receive_offer_proposed(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -590,15 +572,15 @@ async def test_receive_free_offer(self): offers_attach=[CredentialOffer.wrap_indy_offer(INDY_OFFER)], ) self.context.message = offer - self.context.connection_record = async_mock.MagicMock() + self.context.connection_record = mock.MagicMock() self.context.connection_record.connection_id = connection_id - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(side_effect=StorageNotFoundError), + mock.AsyncMock(side_effect=StorageNotFoundError), ) as retrieve_ex: exchange = await self.manager.receive_offer(offer, connection_id) @@ -640,17 +622,15 @@ async def test_create_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -707,21 +687,19 @@ async def test_create_request_no_cache(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) await stored_exchange.save(self.session) - with async_mock.patch.object( - V10CredentialExchange, "save", autospec=True - ) as save_ex: + with mock.patch.object(V10CredentialExchange, "save", autospec=True) as save_ex: cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value=cred_def ) cred_req_meta = {} - holder = async_mock.MagicMock() - holder.create_credential_request = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) self.context.injector.bind_instance(IndyHolder, holder) @@ -763,7 +741,7 @@ async def test_create_request_bad_state(self): await self.manager.create_request(stored_exchange, holder_did) async def test_receive_request(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_exchange = V10CredentialExchange( credential_exchange_id="dummy-cxid", @@ -779,12 +757,12 @@ async def test_receive_request(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_request(request, mock_conn, None) @@ -814,17 +792,17 @@ async def test_receive_request_no_connection_cred_request(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="test_conn_id", ) - mock_oob = async_mock.MagicMock() + mock_oob = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_exchange cx_rec = await self.manager.receive_request(request, mock_conn, mock_oob) @@ -855,16 +833,16 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): requests_attach=[CredentialRequest.wrap_indy_cred_req(INDY_CRED_REQ)] ) - mock_conn = async_mock.MagicMock( + mock_conn = mock.MagicMock( connection_id="test_conn_id", ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = (StorageNotFoundError(),) with self.assertRaises(CredentialManagerError): @@ -905,28 +883,28 @@ async def test_issue_credential_revocable(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1000" - issuer.create_credential = async_mock.AsyncMock( + issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", - get_or_fetch_local_tails_path=async_mock.AsyncMock(), + get_or_fetch_local_tails_path=mock.AsyncMock(), max_creds=10, ), ) @@ -970,7 +948,7 @@ async def test_issue_credential_non_revocable(self): thread_id = "thread-id" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) stored_exchange = V10CredentialExchange( credential_exchange_id="dummy-cxid", @@ -993,28 +971,24 @@ async def test_issue_credential_non_revocable(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.AsyncMock( - return_value=(json.dumps(cred), None) - ) + issuer.create_credential = mock.AsyncMock(return_value=(json.dumps(cred), None)) self.context.injector.bind_instance(IndyIssuer, issuer) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF_NR - ) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF_NR) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) self.context.injector.clear_binding(BaseLedger) self.context.injector.bind_instance(BaseLedger, self.ledger) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1064,36 +1038,36 @@ async def test_issue_credential_fills_rr(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} - issuer.create_credential = async_mock.AsyncMock( + issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(cred), stored_exchange.revocation_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( V10CredentialExchange, "save", autospec=True ) as save_ex: - revoc.return_value = async_mock.MagicMock( + revoc.return_value = mock.MagicMock( get_or_create_active_registry=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg registry_id=REV_REG_ID, tails_local_path="dummy-path", max_creds=1000, - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ) ) ), - handle_full_registry=async_mock.AsyncMock(), + handle_full_registry=mock.AsyncMock(), ) (ret_exchange, ret_cred_issue) = await self.manager.issue_credential( stored_exchange, comment=comment, retries=0 @@ -1165,35 +1139,33 @@ async def test_issue_credential_no_active_rr_no_retries(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.AsyncMock( + issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( side_effect=[ None, ( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ), ] @@ -1231,25 +1203,23 @@ async def test_issue_credential_no_active_rr_retry(self): ) await stored_exchange.save(self.session) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred = {"indy": "credential"} cred_rev_id = "1" - issuer.create_credential = async_mock.AsyncMock( + issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(cred), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=None ) with self.assertRaises(CredentialManagerError) as context: @@ -1275,12 +1245,12 @@ async def test_receive_credential(self): credentials_attach=[CredentialIssue.wrap_indy_credential(INDY_CRED)] ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(return_value=stored_exchange), + mock.AsyncMock(return_value=stored_exchange), ) as retrieve_ex: exchange = await self.manager.receive_credential(issue, connection_id) @@ -1331,30 +1301,28 @@ async def test_store_credential(self): await stored_exchange.save(self.session) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.AsyncMock(return_value=cred_id) - holder.get_credential = async_mock.AsyncMock( - return_value=json.dumps(INDY_CRED_INFO) - ) + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock(return_value=cred_id) + holder.get_credential = mock.AsyncMock(return_value=json.dumps(INDY_CRED_INFO)) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationRegistry", autospec=True - ) as mock_rev_reg, async_mock.patch.object( + ) as mock_rev_reg, mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True ) as delete_ex: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) ret_exchange = await self.manager.store_credential( @@ -1410,7 +1378,7 @@ async def test_store_credential_no_preview(self): thread_id = "thread-id" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) cred_no_rev = {**INDY_CRED} cred_no_rev["rev_reg_id"] = None @@ -1434,29 +1402,27 @@ async def test_store_credential_no_preview(self): ) await stored_exchange.save(self.session) - cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=cred_def - ) + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.AsyncMock(return_value=cred_id) - holder.get_credential = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock(return_value=cred_id) + holder.get_credential = mock.AsyncMock( return_value=json.dumps(cred_info_no_rev) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True ) as delete_ex: ret_exchange = await self.manager.store_credential(stored_exchange) @@ -1504,21 +1470,19 @@ async def test_store_credential_holder_store_indy_error(self): ) await stored_exchange.save(self.session) - cred_def = async_mock.MagicMock() - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=cred_def - ) + cred_def = mock.MagicMock() + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_id = "cred-id" - holder = async_mock.MagicMock() - holder.store_credential = async_mock.AsyncMock( + holder = mock.MagicMock() + holder.store_credential = mock.AsyncMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) self.context.injector.bind_instance(IndyHolder, holder) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=("test_ledger_id", self.ledger) ) ), @@ -1544,14 +1508,14 @@ async def test_send_credential_ack(self): ) await stored_exchange.save(self.session) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as mock_save_ex, async_mock.patch.object( + ) as mock_save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True - ) as mock_delete_ex, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_log_exception, async_mock.patch.object( - test_module.LOGGER, "warning", async_mock.MagicMock() + ) as mock_delete_ex, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_log_exception, mock.patch.object( + test_module.LOGGER, "warning", mock.MagicMock() ) as mock_log_warning: mock_delete_ex.side_effect = test_module.StorageError() (exch, ack) = await self.manager.send_credential_ack(stored_exchange) @@ -1579,14 +1543,14 @@ async def test_receive_credential_ack(self): ack = CredentialAck() - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "delete_record", autospec=True - ) as delete_ex, async_mock.patch.object( + ) as delete_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange ret_exchange = await self.manager.receive_credential_ack(ack, connection_id) @@ -1620,12 +1584,12 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1648,10 +1612,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10CredentialExchange, "retrieve_by_connection_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py index 2224c2031a..c45f34b287 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_routes.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -15,9 +15,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -32,17 +32,15 @@ async def test_credential_exchange_list(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.query = async_mock.AsyncMock() + mock_cred_ex.query = mock.AsyncMock() mock_cred_ex.query.return_value = [mock_cred_ex] - mock_cred_ex.serialize = async_mock.MagicMock() + mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_list(self.request) mock_response.assert_called_once_with( {"results": [mock_cred_ex.serialize.return_value]} @@ -56,33 +54,29 @@ async def test_credential_exchange_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.query = async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_cred_ex.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) async def test_credential_exchange_retrieve(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.serialize = async_mock.MagicMock() + mock_cred_ex.serialize = mock.MagicMock() mock_cred_ex.serialize.return_value = {"hello": "world"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( mock_cred_ex.serialize.return_value @@ -91,12 +85,12 @@ async def test_credential_exchange_retrieve(self): async def test_credential_exchange_retrieve_not_found(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -105,40 +99,40 @@ async def test_credential_exchange_retrieve_not_found(self): async def test_credential_exchange_retrieve_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.serialize = async_mock.MagicMock( + mock_cred_ex.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_retrieve(self.request) async def test_credential_exchange_create(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.return_value = ( mock_cred_ex_record, @@ -152,26 +146,26 @@ async def test_credential_exchange_create(self): ) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.side_effect = ( test_module.StorageError() @@ -183,35 +177,33 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.AsyncMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.AsyncMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_create(self.request) assert "credential_proposal" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True - ), async_mock.patch.object( + ), mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - mock_cred_ex_record = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_credential_manager.return_value.prepare_send.return_value = ( mock_cred_ex_record, @@ -227,9 +219,7 @@ async def test_credential_exchange_send(self): async def test_credential_exchange_send_no_proposal(self): conn_id = "connection-id" - self.request.json = async_mock.AsyncMock( - return_value={"connection_id": conn_id} - ) + self.request.json = mock.AsyncMock(return_value={"connection_id": conn_id}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send(self.request) @@ -239,23 +229,23 @@ async def test_credential_exchange_send_no_conn_record(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -265,52 +255,50 @@ async def test_credential_exchange_send_not_ready(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate connection not ready mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ): - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_offer = async_mock.MagicMock() + mock_cred_offer = mock.MagicMock() - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), - prepare_send=async_mock.AsyncMock( + prepare_send=mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -325,18 +313,18 @@ async def test_credential_exchange_send_proposal(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record ) @@ -350,22 +338,22 @@ async def test_credential_exchange_send_proposal(self): ) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) mock_credential_manager.return_value.create_proposal.return_value = ( - async_mock.MagicMock() + mock.MagicMock() ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -375,11 +363,11 @@ async def test_credential_exchange_send_proposal_deser_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deser: mock_preview_deser.side_effect = test_module.BaseModelError() @@ -387,21 +375,21 @@ async def test_credential_exchange_send_proposal_deser_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.CredentialPreview, "deserialize", autospec=True ) as mock_preview_deserialize: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_credential_manager.return_value.create_proposal.return_value = ( - async_mock.MagicMock() + mock.MagicMock() ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -411,20 +399,18 @@ async def test_credential_exchange_send_proposal_x(self): conn_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": conn_id, "credential_proposal": preview_spec} ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) mock_credential_manager.return_value.create_proposal.return_value = ( mock_cred_ex_record @@ -434,7 +420,7 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -446,18 +432,18 @@ async def test_credential_exchange_create_free_offer(self): self.context.update_settings({"debug.auto_respond_credential_offer": True}) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_create_free_offer(self.request) @@ -467,7 +453,7 @@ async def test_credential_exchange_create_free_offer(self): ) async def test_credential_exchange_create_free_offer_no_cred_def_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -480,14 +466,14 @@ async def test_credential_exchange_create_free_offer_no_cred_def_id(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_preview(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value = {"comment": "comment", "cred_def_id": "dummy"} with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -498,15 +484,15 @@ async def test_credential_exchange_create_free_offer_no_conn_id_no_public_did(se ) self.context.update_settings({"default_endpoint": "http://1.2.3.4:8081"}) - self.session_inject[BaseWallet] = async_mock.MagicMock( - get_public_did=async_mock.AsyncMock(return_value=None), + self.session_inject[BaseWallet] = mock.MagicMock( + get_public_did=mock.AsyncMock(return_value=None), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_deser_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -516,13 +502,13 @@ async def test_credential_exchange_create_free_offer_deser_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.side_effect = ( test_module.BaseModelError() ) @@ -531,7 +517,7 @@ async def test_credential_exchange_create_free_offer_deser_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -541,22 +527,22 @@ async def test_credential_exchange_create_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -564,7 +550,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -574,20 +560,20 @@ async def test_credential_exchange_send_free_offer(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_offer(self.request) @@ -597,7 +583,7 @@ async def test_credential_exchange_send_free_offer(self): ) async def test_credential_exchange_send_free_offer_no_cred_def_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "credential_preview": "dummy", @@ -607,7 +593,7 @@ async def test_credential_exchange_send_free_offer_no_cred_def_id(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_preview(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value = { "comment": "comment", "cred_def_id": CRED_DEF_ID, @@ -617,7 +603,7 @@ async def test_credential_exchange_send_free_offer_no_preview(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -625,49 +611,49 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.json.return_value["auto_issue"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True ) as mock_credential_manager: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "cred_def_id": CRED_DEF_ID, @@ -677,25 +663,23 @@ async def test_credential_exchange_send_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_credential_manager.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -704,30 +688,30 @@ async def test_credential_exchange_send_free_offer_x(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_bound_offer(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_offer.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_offer(self.request) @@ -737,67 +721,67 @@ async def test_credential_exchange_send_bound_offer(self): ) async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_ACKED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) @@ -805,59 +789,59 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_not_ready(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_request(self.request) @@ -867,36 +851,36 @@ async def test_credential_exchange_send_request(self): ) async def test_credential_exchange_send_request_no_conn(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "OobRecord", autospec=True - ) as mock_oob_rec, async_mock.patch.object( + ) as mock_oob_rec, mock.patch.object( test_module, "default_did_from_verkey", autospec=True - ) as mock_default_did_from_verkey, async_mock.patch.object( + ) as mock_default_did_from_verkey, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.AsyncMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) mock_cred_ex.retrieve_by_id.return_value.connection_id = None - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_request(self.request) @@ -910,107 +894,107 @@ async def test_credential_exchange_send_request_no_conn(self): mock_default_did_from_verkey.assert_called_once_with("our-recipient_key") async def test_credential_exchange_send_request_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() - mock_cred_ex.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock() + mock_cred_ex.retrieve_by_id.return_value = mock.MagicMock( state=mock_cred_ex.STATE_OFFER_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.create_offer = async_mock.AsyncMock() + mock_credential_manager.return_value.create_offer = mock.AsyncMock() mock_credential_manager.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_request(self.request) async def test_credential_exchange_issue(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.issue_credential.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_issue(self.request) @@ -1020,144 +1004,138 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: mock_cred_ex_rec.state = mock_cred_ex_cls.STATE_REQUEST_RECEIVED - mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_credential_manager.return_value.issue_credential = ( - async_mock.AsyncMock() - ) + mock_credential_manager.return_value.issue_credential = mock.AsyncMock() mock_credential_manager.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_credential_manager.return_value.issue_credential = ( - async_mock.AsyncMock() - ) + mock_credential_manager.return_value.issue_credential = mock.AsyncMock() mock_credential_manager.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: mock_cred_ex_cls.state = mock_cred_ex_cls.STATE_REQUEST_RECEIVED - mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.AsyncMock( - side_effect=test_module.IndyIssuerError() - ) + mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) mock_credential_manager.return_value.issue_credential = mock_issue_cred with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cred_ex_rec = async_mock.MagicMock( + mock_cred_ex_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex_cls: - mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_cred_ex_rec ) - mock_credential_manager.return_value = async_mock.MagicMock( - issue_credential=async_mock.AsyncMock( + mock_credential_manager.return_value = mock.MagicMock( + issue_credential=mock.AsyncMock( return_value=( mock_cred_ex_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -1165,31 +1143,31 @@ async def test_credential_exchange_issue_deser_x(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_store(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.store_credential.return_value = ( mock_cred_ex_record ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1199,33 +1177,33 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_credential_manager.return_value.store_credential.return_value = ( mock_cred_ex_record ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1235,42 +1213,42 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) async def test_credential_exchange_store_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cred_ex.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1279,65 +1257,63 @@ async def test_credential_exchange_store_no_conn_record(self): ) mock_credential_manager.return_value.send_credential_ack.return_value = ( mock_cred_ex, - async_mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: mock_cred_ex.connection_id = "conn-123" mock_cred_ex.thread_id = "conn-123" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_credential_manager, async_mock.patch.object( + ) as mock_credential_manager, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex_cls, async_mock.patch.object( + ) as mock_cred_ex_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex_record = async_mock.MagicMock( + mock_cred_ex_record = mock.MagicMock( state=mock_cred_ex_cls.STATE_CREDENTIAL_RECEIVED, - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_ex_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_ex_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock() ) - mock_credential_manager.return_value = async_mock.MagicMock( - store_credential=async_mock.AsyncMock(return_value=mock_cred_ex_record), - send_credential_ack=async_mock.AsyncMock( - return_value=(mock_cred_ex_record, async_mock.MagicMock()) + mock_credential_manager.return_value = mock.MagicMock( + store_credential=mock.AsyncMock(return_value=mock_cred_ex_record), + send_credential_ack=mock.AsyncMock( + return_value=(mock_cred_ex_record, mock.MagicMock()) ), ) @@ -1347,29 +1323,28 @@ async def test_credential_exchange_store_x(self): async def test_credential_exchange_remove(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value = mock_cred_ex - mock_cred_ex.delete_record = async_mock.AsyncMock() + mock_cred_ex.delete_record = mock.AsyncMock() await test_module.credential_exchange_remove(self.request) mock_response.assert_called_once_with({}) async def test_credential_exchange_remove_bad_cred_ex_id(self): - mock = async_mock.MagicMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1377,45 +1352,40 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_remove_x(self): - mock = async_mock.MagicMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: # Emulate storage not found (bad cred ex id) - mock_rec = async_mock.MagicMock( - delete_record=async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_rec = mock.MagicMock( + delete_record=mock.AsyncMock(side_effect=test_module.StorageError()) ) - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock(return_value=mock_rec) + mock_cred_ex.retrieve_by_id = mock.AsyncMock(return_value=mock_rec) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V10CredentialExchange", autospec=True - ) as mock_cred_ex, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1428,15 +1398,15 @@ async def test_credential_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_credential_exchange_problem_report_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1444,21 +1414,21 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): await test_module.credential_exchange_problem_report(self.request) async def test_credential_exchange_problem_report_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "CredentialManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V10CredentialExchange", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + save_error_state=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1468,13 +1438,13 @@ async def test_credential_exchange_problem_report_x(self): await test_module.credential_exchange_problem_report(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py index 5594d6625a..e9ce6eef88 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/indy/tests/test_handler.py @@ -2,7 +2,7 @@ from time import time import json from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from .. import handler as test_module @@ -198,27 +198,23 @@ async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Ledger - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -228,11 +224,11 @@ async def asyncSetUp(self): self.context.injector.bind_instance(BaseCache, self.cache) # Issuer - self.issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + self.issuer = mock.MagicMock(IndyIssuer, autospec=True) self.context.injector.bind_instance(IndyIssuer, self.issuer) # Holder - self.holder = async_mock.MagicMock(IndyHolder, autospec=True) + self.holder = mock.MagicMock(IndyHolder, autospec=True) self.context.injector.bind_instance(IndyHolder, self.holder) self.handler = IndyCredFormatHandler(self.profile) @@ -286,33 +282,33 @@ async def test_get_indy_detail_record(self): await details_indy[0].save(self.session) await details_indy[1].save(self.session) # exercise logger warning on get() - with async_mock.patch.object( - INDY_LOGGER, "warning", async_mock.MagicMock() + with mock.patch.object( + INDY_LOGGER, "warning", mock.MagicMock() ) as mock_warning: assert await self.handler.get_detail_record(cred_ex_id) in details_indy mock_warning.assert_called_once() async def test_check_uniqueness(self): - with async_mock.patch.object( + with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_indy_query: mock_indy_query.return_value = [] await self.handler._check_uniqueness("dummy-cx-id") - with async_mock.patch.object( + with mock.patch.object( self.handler.format.detail, "query_by_cred_ex_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_indy_query: - mock_indy_query.return_value = [async_mock.MagicMock()] + mock_indy_query.return_value = [mock.MagicMock()] with self.assertRaises(V20CredFormatError) as context: await self.handler._check_uniqueness("dummy-cx-id") assert "detail record already exists" in str(context.exception) async def test_create_proposal(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() proposal_data = {"schema_id": SCHEMA_ID} (cred_format, attachment) = await self.handler.create_proposal( @@ -329,7 +325,7 @@ async def test_create_proposal(self): assert attachment.data.base64 async def test_create_proposal_none(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() proposal_data = None (cred_format, attachment) = await self.handler.create_proposal( @@ -340,8 +336,8 @@ async def test_create_proposal_none(self): assert attachment.content == {} async def test_receive_proposal(self): - cred_ex_record = async_mock.MagicMock() - cred_proposal_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_proposal_message = mock.MagicMock() # Not much to assert. Receive proposal doesn't do anything await self.handler.receive_proposal(cred_ex_record, cred_proposal_message) @@ -387,7 +383,7 @@ async def test_create_offer(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -453,7 +449,7 @@ async def test_create_offer_no_cache(self): await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -497,7 +493,7 @@ async def test_create_offer_attr_mismatch(self): ) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) cred_def_record = StorageRecord( @@ -515,13 +511,13 @@ async def test_create_offer_attr_mismatch(self): ) await self.session.storage.add_record(cred_def_record) - self.issuer.create_credential_offer = async_mock.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): with self.assertRaises(V20CredFormatError): await self.handler.create_offer(cred_proposal) @@ -539,7 +535,7 @@ async def test_create_offer_no_matching_sent_cred_def(self): filters_attach=[AttachDecorator.data_base64({}, ident="0")], ) - self.issuer.create_credential_offer = async_mock.AsyncMock( + self.issuer.create_credential_offer = mock.AsyncMock( return_value=json.dumps(INDY_OFFER) ) @@ -548,8 +544,8 @@ async def test_create_offer_no_matching_sent_cred_def(self): assert "Issuer has no operable cred def" in str(context.exception) async def test_receive_offer(self): - cred_ex_record = async_mock.MagicMock() - cred_offer_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_offer_message = mock.MagicMock() # Not much to assert. Receive offer doesn't do anything await self.handler.receive_offer(cred_ex_record, cred_offer_message) @@ -575,12 +571,10 @@ async def test_create_request(self): ) cred_def = {"cred": "def"} - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=cred_def - ) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=cred_def) cred_req_meta = {} - self.holder.create_credential_request = async_mock.AsyncMock( + self.holder.create_credential_request = mock.AsyncMock( return_value=(json.dumps(INDY_CRED_REQ), json.dumps(cred_req_meta)) ) @@ -610,12 +604,12 @@ async def test_create_request(self): cred_ex_record._id = "dummy-id3" self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): await self.handler.create_request( cred_ex_record, {"holder_did": holder_did} @@ -643,8 +637,8 @@ async def test_create_request_bad_state(self): async def test_create_request_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_OFFER_RECEIVED) - with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.AsyncMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -656,15 +650,15 @@ async def test_create_request_not_unique_x(self): assert "indy detail record already exists" in str(context.exception) async def test_receive_request(self): - cred_ex_record = async_mock.MagicMock() - cred_request_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_request_message = mock.MagicMock() # Not much to assert. Receive request doesn't do anything await self.handler.receive_request(cred_ex_record, cred_request_message) async def test_receive_request_no_offer(self): - cred_ex_record = async_mock.MagicMock(cred_offer=None) - cred_request_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock(cred_offer=None) + cred_request_message = mock.MagicMock() with self.assertRaises(V20CredFormatError) as context: await self.handler.receive_request(cred_ex_record, cred_request_message) @@ -719,21 +713,19 @@ async def test_issue_credential_revocable(self): ) cred_rev_id = "1000" - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), max_creds=10, ), ) @@ -807,20 +799,18 @@ async def test_issue_credential_non_revocable(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), None) ) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF_NR - ) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF_NR) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), ): (cred_format, attachment) = await self.handler.issue_credential( cred_ex_record, retries=0 @@ -847,8 +837,8 @@ async def test_issue_credential_non_revocable(self): async def test_issue_credential_not_unique_x(self): cred_ex_record = V20CredExRecord(state=V20CredExRecord.STATE_REQUEST_RECEIVED) - with async_mock.patch.object( - self.handler, "_check_uniqueness", async_mock.AsyncMock() + with mock.patch.object( + self.handler, "_check_uniqueness", mock.AsyncMock() ) as mock_unique: mock_unique.side_effect = ( V20CredFormatError("indy detail record already exists"), @@ -905,14 +895,12 @@ async def test_issue_credential_no_active_rr_no_retries(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=() ) with self.assertRaises(V20CredFormatError) as context: @@ -965,24 +953,22 @@ async def test_issue_credential_no_active_rr_retry(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( side_effect=[ None, ( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ), ] @@ -1038,21 +1024,19 @@ async def test_issue_credential_rr_full(self): state=V20CredExRecord.STATE_REQUEST_RECEIVED, ) - self.issuer.create_credential = async_mock.AsyncMock( + self.issuer.create_credential = mock.AsyncMock( side_effect=test_module.IndyIssuerRevocationRegistryFullError("Nope") ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_or_create_active_registry = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_or_create_active_registry = mock.AsyncMock( return_value=( - async_mock.MagicMock( # active_rev_reg_rec + mock.MagicMock( # active_rev_reg_rec revoc_reg_id=REV_REG_ID, - set_state=async_mock.AsyncMock(), + set_state=mock.AsyncMock(), ), - async_mock.MagicMock( # rev_reg + mock.MagicMock( # rev_reg tails_local_path="dummy-path", - get_or_fetch_local_tails_path=(async_mock.AsyncMock()), + get_or_fetch_local_tails_path=(mock.AsyncMock()), ), ) ) @@ -1062,8 +1046,8 @@ async def test_issue_credential_rr_full(self): assert "has no active revocation registry" in str(context.exception) async def test_receive_credential(self): - cred_ex_record = async_mock.MagicMock() - cred_issue_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_issue_message = mock.MagicMock() # Not much to assert. Receive credential doesn't do anything await self.handler.receive_credential(cred_ex_record, cred_issue_message) @@ -1136,18 +1120,18 @@ async def test_store_credential(self): cred_id = "cred-id" - self.holder.store_credential = async_mock.AsyncMock(return_value=cred_id) + self.holder.store_credential = mock.AsyncMock(return_value=cred_id) stored_cred = {"stored": "cred"} - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps(stored_cred) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationRegistry", autospec=True ) as mock_rev_reg: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) with self.assertRaises(V20CredFormatError) as context: @@ -1155,25 +1139,25 @@ async def test_store_credential(self): assert "No credential exchange " in str(context.exception) self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( test_module, "RevocationRegistry", autospec=True - ) as mock_rev_reg, async_mock.patch.object( + ) as mock_rev_reg, mock.patch.object( test_module.IndyCredFormatHandler, "get_detail_record", autospec=True ) as mock_get_detail_record: - mock_rev_reg.from_definition = async_mock.MagicMock( - return_value=async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg.from_definition = mock.MagicMock( + return_value=mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) ) - mock_get_detail_record.return_value = async_mock.MagicMock( + mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) self.ledger.get_credential_definition.reset_mock() @@ -1257,21 +1241,21 @@ async def test_store_credential_holder_store_indy_error(self): ) cred_id = "cred-id" - self.holder.store_credential = async_mock.AsyncMock( + self.holder.store_credential = mock.AsyncMock( side_effect=test_module.IndyHolderError("Problem", {"message": "Nope"}) ) - with async_mock.patch.object( + with mock.patch.object( test_module.IndyCredFormatHandler, "get_detail_record", autospec=True - ) as mock_get_detail_record, async_mock.patch.object( - test_module.RevocationRegistry, "from_definition", async_mock.MagicMock() + ) as mock_get_detail_record, mock.patch.object( + test_module.RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_rev_reg: - mock_get_detail_record.return_value = async_mock.MagicMock( + mock_get_detail_record.return_value = mock.MagicMock( cred_request_metadata=cred_req_meta, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) - mock_rev_reg.return_value = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg.return_value = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) with self.assertRaises(test_module.IndyHolderError) as context: await self.handler.store_credential(stored_cx_rec, cred_id) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py index f636e33375..5cc37b415d 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/formats/ld_proof/tests/test_handler.py @@ -1,7 +1,7 @@ from copy import deepcopy from .......vc.ld_proofs.error import LinkedDataProofException from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from unittest.mock import patch from marshmallow import ValidationError @@ -133,17 +133,15 @@ class TestV20LDProofCredFormatHandler(IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) + self.holder = mock.MagicMock() + self.wallet = mock.MagicMock(BaseWallet, autospec=True) self.session = InMemoryProfile.test_session( bind={VCHolder: self.holder, BaseWallet: self.wallet} ) self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Set custom document loader self.context.injector.bind_instance(DocumentLoader, custom_document_loader) @@ -213,8 +211,8 @@ async def test_get_ld_proof_detail_record(self): await details_ld_proof[0].save(self.session) await details_ld_proof[1].save(self.session) # exercise logger warning on get() - with async_mock.patch.object( - LD_PROOF_LOGGER, "warning", async_mock.MagicMock() + with mock.patch.object( + LD_PROOF_LOGGER, "warning", mock.MagicMock() ) as mock_warning: assert await self.handler.get_detail_record(cred_ex_id) in details_ld_proof mock_warning.assert_called_once() @@ -237,10 +235,10 @@ async def test_assert_can_issue_with_id_and_proof_type(self): context.exception ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_did_info: did_info = DIDInfo( did=TEST_DID_SOV, @@ -279,7 +277,7 @@ async def test_assert_can_issue_with_id_and_proof_type(self): assert "Issuer did did:key:notfound not found" in str(context.exception) async def test_get_did_info_for_did_sov(self): - self.wallet.get_local_did = async_mock.AsyncMock() + self.wallet.get_local_did = mock.AsyncMock() did_info = await self.handler._did_info_for_did(TEST_DID_SOV) self.wallet.get_local_did.assert_called_once_with( @@ -297,14 +295,14 @@ async def test_get_did_info_for_did_key(self): async def test_get_suite_for_detail(self): detail: LDProofVCDetail = LDProofVCDetail.deserialize(LD_PROOF_VC_DETAIL) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.AsyncMock(), - ) as mock_can_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_can_issue, mock.patch.object( LDProofCredFormatHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_did_info: suite = await self.handler._get_suite_for_detail(detail) @@ -321,8 +319,8 @@ async def test_get_suite_for_detail(self): mock_did_info.assert_called_once_with(detail.credential.issuer_id) async def test_get_suite(self): - proof = async_mock.MagicMock() - did_info = async_mock.MagicMock() + proof = mock.MagicMock() + did_info = mock.MagicMock() suite = await self.handler._get_suite( proof_type=BbsBlsSignature2020.signature_type, @@ -407,7 +405,7 @@ async def test_prepare_detail_ed25519_2020(self): assert SECURITY_CONTEXT_ED25519_2020_URL in detail.credential.context_urls async def test_create_proposal(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL) @@ -423,7 +421,7 @@ async def test_create_proposal(self): assert attachment.data.base64 async def test_create_proposal_adds_bbs_context(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL_BBS) @@ -433,7 +431,7 @@ async def test_create_proposal_adds_bbs_context(self): assert SECURITY_CONTEXT_BBS_URL in attachment.content["credential"]["@context"] async def test_create_proposal_adds_ed25519_2020_context(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() (cred_format, attachment) = await self.handler.create_proposal( cred_ex_record, deepcopy(LD_PROOF_VC_DETAIL_ED25519_2020) @@ -446,17 +444,17 @@ async def test_create_proposal_adds_ed25519_2020_context(self): ) async def test_receive_proposal(self): - cred_ex_record = async_mock.MagicMock() - cred_proposal_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_proposal_message = mock.MagicMock() # Not much to assert. Receive proposal doesn't do anything await self.handler.receive_proposal(cred_ex_record, cred_proposal_message) async def test_create_offer(self): - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_can_issue, patch.object( test_module, "get_properties_without_context", return_value=[] ): @@ -493,10 +491,10 @@ async def test_create_offer_adds_bbs_context(self): ], ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.AsyncMock(), + mock.AsyncMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -518,10 +516,10 @@ async def test_create_offer_adds_ed25519_2020_context(self): ], ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.AsyncMock(), + mock.AsyncMock(), ), patch.object(test_module, "get_properties_without_context", return_value=[]): (cred_format, attachment) = await self.handler.create_offer(cred_proposal) @@ -540,10 +538,10 @@ async def test_create_offer_x_no_proposal(self): async def test_create_offer_x_wrong_attributes(self): missing_properties = ["foo"] - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_assert_can_issue_with_id_and_proof_type", - async_mock.AsyncMock(), + mock.AsyncMock(), ), patch.object( test_module, "get_properties_without_context", @@ -560,8 +558,8 @@ async def test_create_offer_x_wrong_attributes(self): ) async def test_receive_offer(self): - cred_ex_record = async_mock.MagicMock() - cred_offer_message = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() + cred_offer_message = mock.MagicMock() # Not much to assert. Receive offer doesn't do anything await self.handler.receive_offer(cred_ex_record, cred_offer_message) @@ -624,9 +622,9 @@ async def test_create_request_x_no_data(self): ) async def test_receive_request_no_offer(self): - cred_ex_record = async_mock.MagicMock() + cred_ex_record = mock.MagicMock() cred_ex_record.cred_offer = None - cred_request_message = async_mock.MagicMock() + cred_request_message = mock.MagicMock() # Not much to assert. Receive request doesn't do anything if no prior offer await self.handler.receive_request(cred_ex_record, cred_request_message) @@ -789,13 +787,13 @@ async def test_issue_credential(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -842,13 +840,13 @@ async def test_issue_credential_adds_bbs_context(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -886,13 +884,13 @@ async def test_issue_credential_adds_ed25519_2020_context(self): cred_request=cred_request, ) - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite_for_detail", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( - test_module, "issue", async_mock.AsyncMock(return_value=LD_PROOF_VC) - ) as mock_issue, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( + test_module, "issue", mock.AsyncMock(return_value=LD_PROOF_VC) + ) as mock_issue, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -1143,19 +1141,17 @@ async def test_store_credential(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.AsyncMock() + self.holder.store_credential = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.AsyncMock( - return_value=DocumentVerificationResult(verified=True) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.AsyncMock(return_value=DocumentVerificationResult(verified=True)), + ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose: @@ -1206,19 +1202,17 @@ async def test_store_credential_x_not_verified(self): ) cred_id = "cred_id" - self.holder.store_credential = async_mock.AsyncMock() + self.holder.store_credential = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( LDProofCredFormatHandler, "_get_suite", - async_mock.AsyncMock(), - ) as mock_get_suite, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_get_suite, mock.patch.object( test_module, "verify_credential", - async_mock.AsyncMock( - return_value=DocumentVerificationResult(verified=False) - ), - ) as mock_verify_credential, async_mock.patch.object( + mock.AsyncMock(return_value=DocumentVerificationResult(verified=False)), + ) as mock_verify_credential, mock.patch.object( LDProofCredFormatHandler, "_get_proof_purpose", ) as mock_get_proof_purpose, self.assertRaises( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py index 5b8168bb00..9bebdb14e8 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -15,19 +15,19 @@ class TestCredentialAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential_ack = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential_ack = mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = True handler = test_module.V20CredAckHandler() @@ -47,12 +47,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_cred_ack = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_cred_ack = mock.AsyncMock() request_context.message = V20CredAck() request_context.connection_ready = False handler = test_module.V20CredAckHandler() @@ -69,8 +69,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py index 3c48ef0c0b..a1b3b3cdff 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_issue_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = True handler_inst = test_module.V20CredIssueHandler() @@ -48,22 +48,22 @@ async def test_called_auto_store(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.AsyncMock(), - store_credential=async_mock.AsyncMock(), - send_cred_ack=async_mock.AsyncMock(return_value="cred_ack_message"), + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock(), + store_credential=mock.AsyncMock(), + send_cred_ack=mock.AsyncMock(return_value="cred_ack_message"), ) request_context.message = V20CredIssue() request_context.connection_ready = True @@ -84,31 +84,29 @@ async def test_called_auto_store_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_store_credential"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - receive_credential=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value = mock.MagicMock( + receive_credential=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - store_credential=async_mock.AsyncMock( + store_credential=mock.AsyncMock( side_effect=[ test_module.IndyHolderError, test_module.StorageError(), ] ), - send_cred_ack=async_mock.AsyncMock(), + send_cred_ack=mock.AsyncMock(), ) request_context.message = V20CredIssue() @@ -123,12 +121,12 @@ async def test_called_auto_store_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_credential = mock.AsyncMock() request_context.message = V20CredIssue() request_context.connection_ready = False handler_inst = test_module.V20CredIssueHandler() @@ -143,8 +141,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py index 659c63dee7..1ec77403c0 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -16,19 +16,19 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = True handler_inst = test_module.V20CredOfferHandler() @@ -48,21 +48,21 @@ async def test_called_auto_request(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock( return_value=(None, "cred_request_message") ) request_context.message = V20CredOffer() @@ -88,25 +88,23 @@ async def test_called_auto_request_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_credential_offer"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.my_did = "dummy" - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -115,10 +113,10 @@ async def test_called_auto_request_x(self): handler = test_module.V20CredOfferHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -126,12 +124,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_offer = mock.AsyncMock() request_context.message = V20CredOffer() request_context.connection_ready = False handler_inst = test_module.V20CredOfferHandler() @@ -149,8 +147,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py index ab38598f83..fa86a31bd5 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,12 +14,12 @@ class TestCredProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.connection_ready = True request_context.message = V20CredProblemReport( description={ @@ -40,13 +40,13 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: request_context.connection_ready = True - mock_cred_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = V20CredProblemReport( @@ -68,7 +68,7 @@ async def test_called_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_ready = False request_context.message = V20CredProblemReport( diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py index b28c0be8ab..4f4a069cfe 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,13 +14,13 @@ class TestV20CredProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = False request_context.message = V20CredProposal() @@ -38,16 +38,16 @@ async def test_called(self): async def test_called_auto_offer(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( return_value=(None, "cred_offer_message") ) request_context.message = V20CredProposal() @@ -69,18 +69,16 @@ async def test_called_auto_offer(self): async def test_called_auto_offer_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_cred_mgr.return_value.receive_proposal.return_value.auto_offer = True - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_offer = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -89,10 +87,10 @@ async def test_called_auto_offer_x(self): handler = test_module.V20CredProposalHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -100,12 +98,12 @@ async def test_called_auto_offer_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_proposal = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_proposal = mock.AsyncMock() request_context.message = V20CredProposal() request_context.connection_ready = False handler_inst = test_module.V20CredProposalHandler() diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py index 7a31325246..398bb2f339 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -18,21 +18,19 @@ class TestV20CredRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = False request_context.message = V20CredRequest() @@ -50,26 +48,24 @@ async def test_called(self): async def test_called_auto_issue(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) cred_ex_rec = V20CredExRecord() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( return_value=(None, "cred_issue_message") ) request_context.message = V20CredRequest() @@ -94,28 +90,26 @@ async def test_called_auto_issue(self): async def test_called_auto_issue_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() cred_ex_rec = V20CredExRecord() - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( - cred_ex_rec, "save_error_state", async_mock.AsyncMock() + ) as mock_cred_mgr, mock.patch.object( + cred_ex_rec, "save_error_state", mock.AsyncMock() ): - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.receive_request = mock.AsyncMock( return_value=cred_ex_rec ) mock_cred_mgr.return_value.receive_request.return_value.auto_issue = True - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock( + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock( side_effect=test_module.IndyIssuerError() ) @@ -124,10 +118,10 @@ async def test_called_auto_issue_x(self): handler = test_module.V20CredRequestHandler() responder = MockResponder() - with async_mock.patch.object( - responder, "send_reply", async_mock.AsyncMock() - ) as mock_send_reply, async_mock.patch.object( - handler._logger, "exception", async_mock.AsyncMock() + with mock.patch.object( + responder, "send_reply", mock.AsyncMock() + ) as mock_send_reply, mock.patch.object( + handler._logger, "exception", mock.AsyncMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -135,12 +129,12 @@ async def test_called_auto_issue_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = V20CredRequest() request_context.connection_ready = False handler = test_module.V20CredRequestHandler() @@ -158,8 +152,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py index 422fd2ab1e..a2b363edcf 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_ack.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....didcomm_prefix import DIDCommPrefix @@ -22,8 +22,8 @@ async def test_deserialize(self): """Test deserialization.""" obj = V20CredAck() - with async_mock.patch.object( - test_module.V20CredAckSchema, "load", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredAckSchema, "load", mock.MagicMock() ) as mock_load: cred_ack = V20CredAck.deserialize(obj) mock_load.assert_called_once_with(obj) @@ -34,8 +34,8 @@ async def test_serialize(self): """Test serialization.""" obj = V20CredAck() - with async_mock.patch.object( - test_module.V20CredAckSchema, "dump", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredAckSchema, "dump", mock.MagicMock() ) as mock_dump: cred_ack_dict = obj.serialize() mock_dump.assert_called_once_with(obj) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py index 527585209c..8e4428943a 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_issue.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.decorators.attach_decorator import AttachDecorator @@ -161,8 +161,8 @@ async def test_serialize(self): """Test serialization.""" obj = TestV20CredIssue.CRED_ISSUE - with async_mock.patch.object( - test_module.V20CredIssueSchema, "dump", async_mock.MagicMock() + with mock.patch.object( + test_module.V20CredIssueSchema, "dump", mock.MagicMock() ) as mock_dump: cred_issue_dict = obj.serialize() mock_dump.assert_called_once_with(obj) diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py index 91a92f4c37..b39254d7dc 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/models/tests/test_cred_ex_record.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -126,10 +126,10 @@ async def test_save_error_state(self): record.state = V20CredExRecord.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="test") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py index e711de9d29..fb264a5de3 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_manager.py @@ -1,7 +1,7 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....cache.base import BaseCache @@ -84,19 +84,15 @@ async def asyncSetUp(self): self.session = InMemoryProfile.test_session() self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock(return_value=SCHEMA) - self.ledger.get_credential_definition = async_mock.AsyncMock( - return_value=CRED_DEF - ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock(return_value=REV_REG_DEF) - self.ledger.__aenter__ = async_mock.AsyncMock(return_value=self.ledger) - self.ledger.credential_definition_id2schema_id = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=SCHEMA) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=CRED_DEF) + self.ledger.get_revoc_reg_def = mock.AsyncMock(return_value=REV_REG_DEF) + self.ledger.__aenter__ = mock.AsyncMock(return_value=self.ledger) + self.ledger.credential_definition_id2schema_id = mock.AsyncMock( return_value=SCHEMA_ID ) self.context.injector.bind_instance(BaseLedger, self.ledger) @@ -129,10 +125,10 @@ async def test_prepare_send(self): ) ], ) - with async_mock.patch.object( + with mock.patch.object( self.manager, "create_offer", autospec=True ) as create_offer: - create_offer.return_value = (async_mock.MagicMock(), async_mock.MagicMock()) + create_offer.return_value = (mock.MagicMock(), mock.MagicMock()) ret_cred_ex_rec, ret_cred_offer = await self.manager.prepare_send( connection_id, cred_proposal, replacement_id="123" ) @@ -156,12 +152,12 @@ async def test_create_proposal(self): ) ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.AsyncMock( + mock_handler.return_value.create_proposal = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -199,12 +195,12 @@ async def test_create_proposal_no_preview(self): connection_id = "test_conn_id" comment = "comment" - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_proposal = async_mock.AsyncMock( + mock_handler.return_value.create_proposal = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -250,12 +246,12 @@ async def test_receive_proposal(self): ) ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_proposal = async_mock.AsyncMock() + mock_handler.return_value.receive_proposal = mock.AsyncMock() cred_proposal = V20CredProposal( credential_preview=cred_preview, @@ -323,12 +319,12 @@ async def test_create_free_offer(self): cred_proposal=cred_proposal, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.AsyncMock( + mock_handler.return_value.create_offer = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -399,12 +395,12 @@ async def test_create_bound_offer(self): cred_proposal=cred_proposal, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_offer = async_mock.AsyncMock( + mock_handler.return_value.create_offer = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -509,16 +505,16 @@ async def test_receive_offer_proposed(self): thread_id=thread_id, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(return_value=stored_cx_rec), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(return_value=stored_cx_rec), + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.AsyncMock() + mock_handler.return_value.receive_offer = mock.AsyncMock() cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -563,17 +559,17 @@ async def test_receive_free_offer(self): cred_offer.assign_thread_id(thread_id) self.context.message = cred_offer - self.context.conn_record = async_mock.MagicMock() + self.context.conn_record = mock.MagicMock() self.context.conn_record.connection_id = connection_id - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_offer = async_mock.AsyncMock() + mock_handler.return_value.receive_offer = mock.AsyncMock() mock_retrieve.side_effect = (StorageNotFoundError(),) cx_rec = await self.manager.receive_offer(cred_offer, connection_id) @@ -619,12 +615,12 @@ async def test_create_bound_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.AsyncMock( + mock_handler.return_value.create_request = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -706,12 +702,12 @@ async def test_create_free_request(self): self.cache = InMemoryCache() self.context.injector.bind_instance(BaseCache, self.cache) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.create_request = async_mock.AsyncMock( + mock_handler.return_value.create_request = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.LD_PROOF.api, @@ -758,7 +754,7 @@ async def test_create_request_bad_state(self): assert " state " in str(context.exception) async def test_receive_request(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_cx_rec = V20CredExRecord( cred_ex_id="dummy-cxid", connection_id=mock_conn.connection_id, @@ -778,15 +774,15 @@ async def test_receive_request(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() # mock_retrieve.return_value = stored_cx_rec cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -825,18 +821,18 @@ async def test_receive_request_no_connection_cred_request(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") - mock_oob = async_mock.MagicMock() + mock_conn = mock.MagicMock(connection_id="test_conn_id") + mock_oob = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.return_value = stored_cx_rec - mock_handler.return_value.receive_request = async_mock.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() cx_rec = await self.manager.receive_request( cred_request, mock_conn, mock_oob @@ -857,7 +853,7 @@ async def test_receive_request_no_connection_cred_request(self): assert cx_rec.connection_id == "test_conn_id" async def test_receive_request_no_cred_ex_with_offer_found(self): - mock_conn = async_mock.MagicMock(connection_id="test_conn_id") + mock_conn = mock.MagicMock(connection_id="test_conn_id") stored_cx_rec = V20CredExRecord( cred_ex_id="dummy-cxid", initiator=V20CredExRecord.INITIATOR_EXTERNAL, @@ -877,15 +873,15 @@ async def test_receive_request_no_cred_ex_with_offer_found(self): requests_attach=[AttachDecorator.data_base64(INDY_CRED_REQ, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_save, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_retrieve.side_effect = (StorageNotFoundError(),) - mock_handler.return_value.receive_request = async_mock.AsyncMock() + mock_handler.return_value.receive_request = mock.AsyncMock() cx_rec = await self.manager.receive_request(cred_request, mock_conn, None) @@ -969,19 +965,19 @@ async def test_issue_credential(self): thread_id=thread_id, ) - issuer = async_mock.MagicMock() + issuer = mock.MagicMock() cred_rev_id = "1000" - issuer.create_credential = async_mock.AsyncMock( + issuer.create_credential = mock.AsyncMock( return_value=(json.dumps(INDY_CRED), cred_rev_id) ) self.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.issue_credential = async_mock.AsyncMock( + mock_handler.return_value.issue_credential = mock.AsyncMock( return_value=( V20CredFormat( attach_id=V20CredFormat.Format.INDY.api, @@ -1084,16 +1080,16 @@ async def test_receive_cred(self): credentials_attach=[AttachDecorator.data_base64(INDY_CRED, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.receive_credential = async_mock.AsyncMock() + mock_handler.return_value.receive_credential = mock.AsyncMock() mock_retrieve.return_value = stored_cx_rec ret_cx_rec = await self.manager.receive_credential( cred_issue, @@ -1154,10 +1150,10 @@ async def test_receive_cred_x_extra_formats(self): credentials_attach=[AttachDecorator.data_base64(LD_PROOF_VC, ident="1")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1192,10 +1188,10 @@ async def test_receive_cred_x_no_formats(self): credentials_attach=[AttachDecorator.data_base64(LD_PROOF_VC, ident="0")], ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.return_value = stored_cx_rec @@ -1233,14 +1229,14 @@ async def test_store_credential(self): thread_id=thread_id, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True - ) as mock_delete, async_mock.patch.object( + ) as mock_delete, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_handler.return_value.store_credential = async_mock.AsyncMock() + mock_handler.return_value.store_credential = mock.AsyncMock() ret_cx_rec = await self.manager.store_credential( stored_cx_rec, cred_id=cred_id @@ -1280,14 +1276,14 @@ async def test_send_cred_ack(self): auto_remove=True, ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save_ex, async_mock.patch.object( + ) as mock_save_ex, mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete_ex, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_log_exception, async_mock.patch.object( - test_module.LOGGER, "warning", async_mock.MagicMock() + ) as mock_delete_ex, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_log_exception, mock.patch.object( + test_module.LOGGER, "warning", mock.MagicMock() ) as mock_log_warning: mock_delete_ex.side_effect = test_module.StorageError() (_, ack) = await self.manager.send_cred_ack(stored_exchange) @@ -1312,13 +1308,13 @@ async def test_receive_cred_ack(self): ack = V20CredAck() - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as mock_save, async_mock.patch.object( + ) as mock_save, mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_conn_and_thread", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_conn_and_thread", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( test_module.V20CredManager, "delete_cred_ex_record", autospec=True ) as mock_delete: mock_retrieve.return_value = stored_cx_rec @@ -1339,21 +1335,21 @@ async def test_receive_cred_ack(self): mock_delete.assert_called_once() async def test_delete_cred_ex_record(self): - stored_cx_rec = async_mock.MagicMock(delete_record=async_mock.AsyncMock()) - stored_indy = async_mock.MagicMock(delete_record=async_mock.AsyncMock()) + stored_cx_rec = mock.MagicMock(delete_record=mock.AsyncMock()) + stored_indy = mock.MagicMock(delete_record=mock.AsyncMock()) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "delete_record", autospec=True - ) as mock_delete, async_mock.patch.object( - V20CredExRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( - test_module, "V20CredFormat", async_mock.MagicMock() + ) as mock_delete, mock.patch.object( + V20CredExRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( + test_module, "V20CredFormat", mock.MagicMock() ) as mock_cred_format: mock_retrieve.return_value = stored_cx_rec mock_cred_format.Format = [ - async_mock.MagicMock( - detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.AsyncMock( + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.AsyncMock( return_value=[ stored_indy, stored_indy, @@ -1361,9 +1357,9 @@ async def test_delete_cred_ex_record(self): ) ) ), - async_mock.MagicMock( - detail=async_mock.MagicMock( - query_by_cred_ex_id=async_mock.AsyncMock(return_value=[]) + mock.MagicMock( + detail=mock.MagicMock( + query_by_cred_ex_id=mock.AsyncMock(return_value=[]) ) ), ] @@ -1384,12 +1380,12 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.return_value = stored_exchange @@ -1418,10 +1414,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20CredExRecord, "retrieve_by_conn_and_thread", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py index 385898da58..8af79157eb 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/tests/test_routes.py @@ -1,5 +1,5 @@ from .....vc.ld_proofs.error import LinkedDataProofException -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....admin.request_context import AdminRequestContext @@ -21,9 +21,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -90,17 +90,13 @@ async def test_credential_exchange_list(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.query = async_mock.AsyncMock(return_value=[mock_cx_rec]) - mock_cx_rec.serialize = async_mock.MagicMock( - return_value={"hello": "world"} - ) + mock_cx_rec.query = mock.AsyncMock(return_value=[mock_cx_rec]) + mock_cx_rec.serialize = mock.MagicMock(return_value={"hello": "world"}) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_list(self.request) mock_response.assert_called_once_with( { @@ -122,44 +118,40 @@ async def test_credential_exchange_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.query = async_mock.AsyncMock( - side_effect=test_module.StorageError() - ) + mock_cx_rec.query = mock.AsyncMock(side_effect=test_module.StorageError()) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_list(self.request) async def test_credential_exchange_retrieve(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock() + mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( { @@ -172,32 +164,30 @@ async def test_credential_exchange_retrieve(self): async def test_credential_exchange_retrieve_indy_ld_proof(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock() + mock_cx_rec.serialize = mock.MagicMock() mock_cx_rec.serialize.return_value = {"hello": "world"} - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"in": "dy"}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"in": "dy"}) ), - async_mock.MagicMock( # ld_proof - serialize=async_mock.MagicMock(return_value={"ld": "proof"}) + mock.MagicMock( # ld_proof + serialize=mock.MagicMock(return_value={"ld": "proof"}) ), ] ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.credential_exchange_retrieve(self.request) mock_response.assert_called_once_with( { @@ -210,12 +200,12 @@ async def test_credential_exchange_retrieve_indy_ld_proof(self): async def test_credential_exchange_retrieve_not_found(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) with self.assertRaises(test_module.web.HTTPNotFound): @@ -224,20 +214,20 @@ async def test_credential_exchange_retrieve_not_found(self): async def test_credential_exchange_retrieve_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec, async_mock.patch.object( + ) as mock_cx_rec, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value = mock_cx_rec - mock_cx_rec.serialize = async_mock.MagicMock( + mock_cx_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( return_value=None ) @@ -245,26 +235,26 @@ async def test_credential_exchange_retrieve_x(self): await test_module.credential_exchange_retrieve(self.request) async def test_credential_exchange_create(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - mock_cx_rec = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_cred_mgr.return_value.prepare_send.return_value = ( mock_cx_rec, @@ -276,22 +266,22 @@ async def test_credential_exchange_create(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_connection_record, async_mock.patch.object( + ) as mock_connection_record, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) mock_cred_mgr.return_value.prepare_send.side_effect = ( @@ -304,7 +294,7 @@ async def test_credential_exchange_create_x(self): async def test_credential_exchange_create_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": { @@ -318,26 +308,26 @@ async def test_credential_exchange_create_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True - ) as mock_cred_preview_deser, async_mock.patch.object( + ) as mock_cred_preview_deser, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) - mock_cx_rec = async_mock.MagicMock() - mock_cred_offer = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() + mock_cred_offer = mock.MagicMock() mock_cred_mgr.return_value.prepare_send.return_value = ( mock_cx_rec, @@ -349,36 +339,36 @@ async def test_credential_exchange_send(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_request_no_conn_no_holder_did(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "OobRecord", autospec=True - ) as mock_oob_rec, async_mock.patch.object( + ) as mock_oob_rec, mock.patch.object( test_module, "default_did_from_verkey", autospec=True - ) as mock_default_did_from_verkey, async_mock.patch.object( + ) as mock_default_did_from_verkey, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cred_ex, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_oob_rec.retrieve_by_tag_filter = async_mock.AsyncMock( - return_value=async_mock.MagicMock(our_recipient_key="our-recipient_key") + mock_oob_rec.retrieve_by_tag_filter = mock.AsyncMock( + return_value=mock.MagicMock(our_recipient_key="our-recipient_key") ) mock_default_did_from_verkey.return_value = "holder-did" - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock() + mock_cred_ex.retrieve_by_id = mock.AsyncMock() mock_cred_ex.retrieve_by_id.return_value.state = ( mock_cred_ex.STATE_OFFER_RECEIVED ) mock_cred_ex.retrieve_by_id.return_value.connection_id = None - mock_cred_ex_record = async_mock.MagicMock() + mock_cred_ex_record = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cred_ex_record, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_request(self.request) @@ -395,26 +385,26 @@ async def test_credential_exchange_send_no_conn_record(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): @@ -424,7 +414,7 @@ async def test_credential_exchange_send_not_ready(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -432,46 +422,44 @@ async def test_credential_exchange_send_not_ready(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: mock_conn_rec.retrieve_by_id.return_value.is_ready = False mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send(self.request) async def test_credential_exchange_send_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_cred_preview_deser: - mock_cred_ex_record = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cred_ex_record = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_offer = async_mock.MagicMock() - mock_cred_mgr.return_value = async_mock.AsyncMock( - create_offer=async_mock.AsyncMock( + mock_cred_offer = mock.MagicMock() + mock_cred_mgr.return_value = mock.AsyncMock( + create_offer=mock.AsyncMock( return_value=( - async_mock.AsyncMock(), - async_mock.AsyncMock(), + mock.AsyncMock(), + mock.AsyncMock(), ) ), - prepare_send=async_mock.AsyncMock( + prepare_send=mock.AsyncMock( return_value=( mock_cred_ex_record, mock_cred_offer, @@ -486,7 +474,7 @@ async def test_credential_exchange_send_proposal(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -494,14 +482,14 @@ async def test_credential_exchange_send_proposal(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec await test_module.credential_exchange_send_proposal(self.request) @@ -512,7 +500,7 @@ async def test_credential_exchange_send_proposal(self): async def test_credential_exchange_send_proposal_no_filter(self): connection_id = "connection-id" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "comment", "connection_id": connection_id, @@ -524,23 +512,21 @@ async def test_credential_exchange_send_proposal_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_proposal.return_value = ( - async_mock.MagicMock() - ) + mock_cred_mgr.return_value.create_proposal.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_proposal(self.request) @@ -549,7 +535,7 @@ async def test_credential_exchange_send_proposal_x(self): connection_id = "connection-id" preview_spec = {"attributes": [{"name": "attr", "value": "value"}]} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": connection_id, "credential_preview": preview_spec, @@ -557,16 +543,14 @@ async def test_credential_exchange_send_proposal_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) mock_cred_mgr.return_value.create_proposal.return_value = mock_cx_rec @@ -574,28 +558,26 @@ async def test_credential_exchange_send_proposal_x(self): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.V20CredPreview, "deserialize", autospec=True ) as mock_preview_deser: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_proposal.return_value = ( - async_mock.MagicMock() - ) + mock_cred_mgr.return_value.create_proposal.return_value = mock.MagicMock() with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_proposal(self.request) async def test_credential_exchange_create_free_offer(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -606,18 +588,18 @@ async def test_credential_exchange_create_free_offer(self): ) self.context.update_settings({"debug.auto_respond_credential_offer": True}) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_create_free_offer(self.request) @@ -625,7 +607,7 @@ async def test_credential_exchange_create_free_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_create_free_offer_no_filter(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -639,7 +621,7 @@ async def test_credential_exchange_create_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_create_free_offer_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -649,22 +631,22 @@ async def test_credential_exchange_create_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.BaseModelError(), ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_cred_mgr.return_value = async_mock.MagicMock( - create_offer=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + create_offer=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -672,7 +654,7 @@ async def test_credential_exchange_create_free_offer_x(self): await test_module.credential_exchange_create_free_offer(self.request) async def test_credential_exchange_send_free_offer(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -682,25 +664,25 @@ async def test_credential_exchange_send_free_offer(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_offer(self.request) mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_free_offer_no_filter(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "comment", "credential_preview": { @@ -714,7 +696,7 @@ async def test_credential_exchange_send_free_offer_no_filter(self): assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_offer_no_conn_record(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -724,27 +706,27 @@ async def test_credential_exchange_send_free_offer_no_conn_record(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_not_ready(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": True, "credential_preview": { @@ -754,26 +736,26 @@ async def test_credential_exchange_send_free_offer_not_ready(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_free_offer_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "auto_issue": False, "credential_preview": { @@ -783,24 +765,22 @@ async def test_credential_exchange_send_free_offer_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec = async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + mock_cx_rec = mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cred_mgr.return_value = async_mock.AsyncMock( - create_offer=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.AsyncMock( + create_offer=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) @@ -809,30 +789,30 @@ async def test_credential_exchange_send_free_offer_x(self): await test_module.credential_exchange_send_free_offer(self.request) async def test_credential_exchange_send_bound_offer(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_offer.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_offer(self.request) @@ -840,26 +820,26 @@ async def test_credential_exchange_send_bound_offer(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_bound_offer_linked_data_error(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() exception_message = "ex" mock_cred_mgr.return_value.create_offer.side_effect = ( @@ -871,67 +851,67 @@ async def test_credential_exchange_send_bound_offer_linked_data_error(self): assert exception_message in str(error.exception) async def test_credential_exchange_send_bound_offer_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_no_conn_record(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_PROPOSAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_bad_state(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_DONE, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) @@ -939,59 +919,59 @@ async def test_credential_exchange_send_bound_offer_bad_state(self): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_bound_offer_not_ready(self): - self.request.json = async_mock.AsyncMock(return_value={}) + self.request.json = mock.AsyncMock(return_value={}) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_PROPOSAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_offer(self.request) async def test_credential_exchange_send_request(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_bound_request(self.request) @@ -999,105 +979,105 @@ async def test_credential_exchange_send_request(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_request_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() - mock_cx_rec.retrieve_by_id.return_value = async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock() + mock_cx_rec.retrieve_by_id.return_value = mock.MagicMock( state=mock_cx_rec.STATE_OFFER_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_request_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_OFFER_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_offer = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_offer = mock.AsyncMock() mock_cred_mgr.return_value.create_offer.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_bound_request(self.request) async def test_credential_exchange_send_free_request(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.create_request.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_send_free_request(self.request) @@ -1105,85 +1085,85 @@ async def test_credential_exchange_send_free_request(self): mock_response.assert_called_once_with(mock_cx_rec.serialize.return_value) async def test_credential_exchange_send_free_request_no_filter(self): - self.request.json = async_mock.AsyncMock(return_value={"comment": "comment"}) + self.request.json = mock.AsyncMock(return_value={"comment": "comment"}) with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_send_free_request(self.request) assert "Missing filter" in str(context.exception) async def test_credential_exchange_send_free_request_no_conn_record(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() mock_cred_mgr.return_value.create_request.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_not_ready(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock() + mock_cred_mgr.return_value.create_request = mock.AsyncMock() mock_cred_mgr.return_value.create_request.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_send_free_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "filter": {"ld_proof": LD_PROOF_VC_DETAIL}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value.create_request = async_mock.AsyncMock( + mock_cred_mgr.return_value.create_request = mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), ] ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() with self.assertRaises(test_module.web.HTTPBadRequest): # ledger error await test_module.credential_exchange_send_free_request(self.request) @@ -1191,30 +1171,30 @@ async def test_credential_exchange_send_free_request_x(self): await test_module.credential_exchange_send_free_request(self.request) async def test_credential_exchange_issue(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1222,7 +1202,7 @@ async def test_credential_exchange_issue(self): mock_cred_mgr.return_value.issue_credential.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_issue(self.request) @@ -1236,147 +1216,139 @@ async def test_credential_exchange_issue(self): ) async def test_credential_exchange_issue_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( conn_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: mock_cx_rec.state = mock_cx_rec_cls.STATE_REQUEST_RECEIVED - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=mock_cx_rec - ) + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() mock_cred_mgr.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_REQUEST_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False - mock_cred_mgr.return_value.issue_credential = async_mock.AsyncMock() + mock_cred_mgr.return_value.issue_credential = mock.AsyncMock() mock_cred_mgr.return_value.issue_credential.return_value = ( - async_mock.MagicMock(), - async_mock.MagicMock(), + mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_rev_reg_full(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( conn_id="dummy", - serialize=async_mock.MagicMock(), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: mock_cx_rec.state = mock_cx_rec_cls.STATE_REQUEST_RECEIVED - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=mock_cx_rec - ) + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = True - mock_issue_cred = async_mock.AsyncMock( - side_effect=test_module.IndyIssuerError() - ) + mock_issue_cred = mock.AsyncMock(side_effect=test_module.IndyIssuerError()) mock_cred_mgr.return_value.issue_credential = mock_issue_cred with self.assertRaises(test_module.web.HTTPBadRequest) as context: await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_issue_deser_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( connection_id="dummy", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec_cls: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=mock_cx_rec - ) - mock_cred_mgr.return_value = async_mock.MagicMock( - issue_credential=async_mock.AsyncMock( + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock(return_value=mock_cx_rec) + mock_cred_mgr.return_value = mock.MagicMock( + issue_credential=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ) ) - mock_cred_mgr.return_value.get_detail_record = async_mock.AsyncMock( + mock_cred_mgr.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] @@ -1386,39 +1358,39 @@ async def test_credential_exchange_issue_deser_x(self): await test_module.credential_exchange_issue(self.request) async def test_credential_exchange_store(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1432,40 +1404,40 @@ async def test_credential_exchange_store(self): ) async def test_credential_exchange_store_bad_cred_id_json(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( side_effect=test_module.JSONDecodeError("Nope", "Nope", 0) ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( LDProofCredFormatHandler, "get_detail_record", autospec=True - ) as mock_ld_proof_get_detail_record, async_mock.patch.object( + ) as mock_ld_proof_get_detail_record, mock.patch.object( IndyCredFormatHandler, "get_detail_record", autospec=True ) as mock_indy_get_detail_record: - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock() mock_cx_rec_cls.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) - mock_cx_rec = async_mock.MagicMock() + mock_cx_rec = mock.MagicMock() - mock_indy_get_detail_record.return_value = async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock_indy_get_detail_record.return_value = mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ) mock_ld_proof_get_detail_record.return_value = None # ld_proof mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) await test_module.credential_exchange_store(self.request) @@ -1479,119 +1451,117 @@ async def test_credential_exchange_store_bad_cred_id_json(self): ) async def test_credential_exchange_store_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_cx_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_cx_rec.STATE_CREDENTIAL_RECEIVED, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) # Emulate storage not found (bad connection id) - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) mock_cred_mgr.return_value.store_credential.return_value = mock_cx_rec mock_cred_mgr.return_value.send_cred_ack.return_value = ( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cx_rec: mock_cx_rec.connection_id = "conn-123" mock_cx_rec.thread_id = "conn-123" - mock_cx_rec.retrieve_by_id = async_mock.AsyncMock() + mock_cx_rec.retrieve_by_id = mock.AsyncMock() mock_cx_rec.retrieve_by_id.return_value.state = ( test_module.V20CredExRecord.STATE_CREDENTIAL_RECEIVED ) # Emulate connection not ready - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock() + mock_conn_rec.retrieve_by_id = mock.AsyncMock() mock_conn_rec.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.credential_exchange_store(self.request) async def test_credential_exchange_store_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cx_rec_cls, async_mock.patch.object( + ) as mock_cx_rec_cls, mock.patch.object( test_module.web, "json_response" - ) as mock_response, async_mock.patch.object( + ) as mock_response, mock.patch.object( V20CredFormat.Format, "handler" ) as mock_handler: - mock_cx_rec = async_mock.MagicMock( + mock_cx_rec = mock.MagicMock( state=mock_cx_rec_cls.STATE_CREDENTIAL_RECEIVED, - serialize=async_mock.MagicMock( - side_effect=test_module.BaseModelError() - ), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - mock_cx_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_cx_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock() ) - mock_handler.return_value.get_detail_record = async_mock.AsyncMock( + mock_handler.return_value.get_detail_record = mock.AsyncMock( side_effect=[ - async_mock.MagicMock( # indy - serialize=async_mock.MagicMock(return_value={"...": "..."}) + mock.MagicMock( # indy + serialize=mock.MagicMock(return_value={"...": "..."}) ), None, # ld_proof ] ) - mock_cred_mgr.return_value = async_mock.MagicMock( - store_credential=async_mock.AsyncMock(return_value=mock_cx_rec), - send_cred_ack=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + store_credential=mock.AsyncMock(return_value=mock_cx_rec), + send_cred_ack=mock.AsyncMock( return_value=( mock_cx_rec, - async_mock.MagicMock(), + mock.MagicMock(), ) ), ) @@ -1602,13 +1572,13 @@ async def test_credential_exchange_store_x(self): async def test_credential_exchange_remove(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr, async_mock.patch.object( + ) as mock_cred_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.AsyncMock() + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock() ) await test_module.credential_exchange_remove(self.request) @@ -1617,11 +1587,11 @@ async def test_credential_exchange_remove(self): async def test_credential_exchange_remove_bad_cred_ex_id(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1632,11 +1602,11 @@ async def test_credential_exchange_remove_bad_cred_ex_id(self): async def test_credential_exchange_remove_x(self): self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True ) as mock_cred_mgr: - mock_cred_mgr.return_value = async_mock.MagicMock( - delete_cred_ex_record=async_mock.AsyncMock( + mock_cred_mgr.return_value = mock.MagicMock( + delete_cred_ex_record=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1645,25 +1615,23 @@ async def test_credential_exchange_remove_x(self): await test_module.credential_exchange_remove(self.request) async def test_credential_exchange_problem_report(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "V20CredExRecord", autospec=True - ) as mock_cred_ex, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_ex, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1676,17 +1644,17 @@ async def test_credential_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_credential_exchange_problem_report_bad_cred_ex_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1694,21 +1662,21 @@ async def test_credential_exchange_problem_report_bad_cred_ex_id(self): await test_module.credential_exchange_problem_report(self.request) async def test_credential_exchange_problem_report_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"cred_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20CredManager", autospec=True - ) as mock_cred_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_cred_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20CredExRecord", autospec=True ) as mock_cred_ex: - mock_cred_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock( + mock_cred_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + save_error_state=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1718,13 +1686,13 @@ async def test_credential_exchange_problem_report_x(self): await test_module.credential_exchange_problem_report(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py index c92888d24d..2389b5aade 100644 --- a/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py +++ b/aries_cloudagent/protocols/notification/v1_0/handlers/tests/test_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,7 +14,7 @@ class TestNotificationAckHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message = V10Ack(status="OK") handler = test_module.V10AckHandler() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py index b6b001bfd0..791bd14bec 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py @@ -1,7 +1,7 @@ """Test Problem Report Handler.""" import pytest -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -36,9 +36,9 @@ async def session(request_context) -> ProfileSession: class TestOOBProblemReportHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = OOBProblemReport( description={ "en": "No such connection", @@ -55,9 +55,9 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_problem_report = mock.AsyncMock() mock_oob_mgr.return_value.receive_problem_report.side_effect = ( OutOfBandManagerError("error") ) @@ -68,8 +68,8 @@ async def test_exception(self, mock_oob_mgr, request_context, connection_record) } ) handler = test_module.OOBProblemReportMessageHandler() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_exc_logger: responder = MockResponder() await handler.handle(context=request_context, responder=responder) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py index 1c3567c43c..71bc022e56 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py @@ -1,7 +1,7 @@ """Test Reuse Accept Message Handler.""" import pytest -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -36,11 +36,9 @@ async def session(request_context) -> ProfileSession: class TestHandshakeReuseAcceptHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.AsyncMock() - ) + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.AsyncMock() request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() @@ -52,11 +50,9 @@ async def test_called(self, mock_oob_mgr, request_context, connection_record): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context, connection_record): - mock_oob_mgr.return_value.receive_reuse_accepted_message = ( - async_mock.AsyncMock() - ) + mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.AsyncMock() mock_oob_mgr.return_value.receive_reuse_accepted_message.side_effect = ( OutOfBandManagerError("error") ) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py index 860743bd99..d05f7b860a 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py @@ -1,7 +1,7 @@ """Test Reuse Message Handler.""" import pytest -from unittest import mock as async_mock +from unittest import mock from ......connections.models.conn_record import ConnRecord from ......core.profile import ProfileSession @@ -29,9 +29,9 @@ async def session(request_context) -> ProfileSession: class TestHandshakeReuseHandler: @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_called(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() request_context.message = HandshakeReuse() handler = test_module.HandshakeReuseMessageHandler() request_context.connection_record = ConnRecord() @@ -44,9 +44,9 @@ async def test_called(self, mock_oob_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_reuse_accepted(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() reuse_accepted = HandshakeReuseAccept() mock_oob_mgr.return_value.receive_reuse_message.return_value = reuse_accepted request_context.message = HandshakeReuse() @@ -61,9 +61,9 @@ async def test_reuse_accepted(self, mock_oob_mgr, request_context): ) @pytest.mark.asyncio - @async_mock.patch.object(test_module, "OutOfBandManager") + @mock.patch.object(test_module, "OutOfBandManager") async def test_exception(self, mock_oob_mgr, request_context): - mock_oob_mgr.return_value.receive_reuse_message = async_mock.AsyncMock() + mock_oob_mgr.return_value.receive_reuse_message = mock.AsyncMock() mock_oob_mgr.return_value.receive_reuse_message.side_effect = ( OutOfBandManagerError("error") ) diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py index 90b8d70078..b3b181c6b7 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_manager.py @@ -6,7 +6,7 @@ from typing import List from unittest.mock import ANY -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....connections.models.conn_record import ConnRecord @@ -312,7 +312,7 @@ def make_did_doc(self, did, verkey): class TestOOBManager(IsolatedAsyncioTestCase, TestConfig): def setUp(self): self.responder = MockResponder() - self.responder.send = async_mock.AsyncMock() + self.responder.send = mock.AsyncMock() self.test_mediator_routing_keys = [ "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRR" @@ -320,8 +320,8 @@ def setUp(self): self.test_mediator_conn_id = "mediator-conn-id" self.test_mediator_endpoint = "http://mediator.example.com" - self.route_manager = async_mock.MagicMock(RouteManager) - self.route_manager.routing_info = async_mock.AsyncMock( + self.route_manager = mock.MagicMock(RouteManager) + self.route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) @@ -340,39 +340,39 @@ def setUp(self): self.profile.context.injector.bind_instance(BaseResponder, self.responder) self.profile.context.injector.bind_instance( - EventBus, async_mock.MagicMock(notify=async_mock.AsyncMock()) + EventBus, mock.MagicMock(notify=mock.AsyncMock()) ) - self.mt_mgr = async_mock.MagicMock() - self.mt_mgr = async_mock.create_autospec(MultitenantManager) + self.mt_mgr = mock.MagicMock() + self.mt_mgr = mock.create_autospec(MultitenantManager) self.profile.context.injector.bind_instance(BaseMultitenantManager, self.mt_mgr) - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) self.profile.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) self.manager = OutOfBandManager(self.profile) assert self.manager.profile - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], [], ) - self.test_conn_rec = async_mock.MagicMock( + self.test_conn_rec = mock.MagicMock( connection_id="dummy", my_did=TestConfig.test_did, their_did=TestConfig.test_target_did, their_role=ConnRecord.Role.REQUESTER, state=ConnRecord.State.COMPLETED, their_public_did=self.their_public_did, - save=async_mock.AsyncMock(), + save=mock.AsyncMock(), ) async def test_create_invitation_handshake_succeeds(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -406,9 +406,9 @@ async def test_create_invitation_multitenant_local(self): } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_signing_key", autospec=True - ) as mock_wallet_create_signing_key, async_mock.patch.object( + ) as mock_wallet_create_signing_key, mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_wallet_create_signing_key.return_value = KeyInfo( @@ -432,7 +432,7 @@ async def test_create_invitation_multitenant_public(self): } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -452,7 +452,7 @@ async def test_create_invitation_multitenant_public(self): async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self): async with self.profile.session() as session: - mock_conn_rec = async_mock.MagicMock() + mock_conn_rec = mock.MagicMock() mediation_record = MediationRecord( role=MediationRecord.ROLE_CLIENT, @@ -462,11 +462,11 @@ async def test_create_invitation_mediation_overwrites_routing_and_endpoint(self) endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( MediationManager, "get_default_mediator_id", - ) as mock_get_default_mediator, async_mock.patch.object( - mock_conn_rec, "metadata_set", async_mock.AsyncMock() + ) as mock_get_default_mediator, mock.patch.object( + mock_conn_rec, "metadata_set", mock.AsyncMock() ) as mock_metadata_set: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -503,12 +503,12 @@ async def test_create_invitation_no_handshake_no_attachments_x(self): async def test_create_invitation_attachment_v1_0_cred_offer(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -517,7 +517,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): method=SOV, key_type=ED25519, ) - mock_retrieve_cxid.return_value = async_mock.MagicMock( + mock_retrieve_cxid.return_value = mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 ) invi_rec = await self.manager.create_invitation( @@ -537,12 +537,12 @@ async def test_create_invitation_attachment_v1_0_cred_offer(self): async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( V10CredentialExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -551,7 +551,7 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): method=SOV, key_type=ED25519, ) - mock_retrieve_cxid.return_value = async_mock.MagicMock( + mock_retrieve_cxid.return_value = mock.MagicMock( credential_offer_dict=self.CRED_OFFER_V1 ) invi_rec = await self.manager.create_invitation( @@ -571,16 +571,16 @@ async def test_create_invitation_attachment_v1_0_cred_offer_no_handshake(self): } async def test_create_invitation_attachment_v2_0_cred_offer(self): - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10CredentialExchange, "retrieve_by_id", - async_mock.AsyncMock(), - ) as mock_retrieve_cxid_v1, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_cxid_v1, mock.patch.object( test_module.V20CredExRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_cxid_v2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -590,9 +590,9 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): key_type=ED25519, ) mock_retrieve_cxid_v1.side_effect = test_module.StorageNotFoundError() - mock_retrieve_cxid_v2.return_value = async_mock.MagicMock( - cred_offer=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"cred": "offer"}) + mock_retrieve_cxid_v2.return_value = mock.MagicMock( + cred_offer=mock.MagicMock( + serialize=mock.MagicMock(return_value={"cred": "offer"}) ) ) invi_rec = await self.manager.create_invitation( @@ -613,12 +613,12 @@ async def test_create_invitation_attachment_v2_0_cred_offer(self): async def test_create_invitation_attachment_present_proof_v1_0(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_pxid: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -627,7 +627,7 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): method=SOV, key_type=ED25519, ) - mock_retrieve_pxid.return_value = async_mock.MagicMock( + mock_retrieve_pxid.return_value = mock.MagicMock( presentation_request_dict=self.PRES_REQ_V1 ) invi_rec = await self.manager.create_invitation( @@ -648,16 +648,16 @@ async def test_create_invitation_attachment_present_proof_v1_0(self): async def test_create_invitation_attachment_present_proof_v2_0(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True - ) as mock_wallet_get_public_did, async_mock.patch.object( + ) as mock_wallet_get_public_did, mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.AsyncMock(), - ) as mock_retrieve_pxid_1, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve_pxid_1, mock.patch.object( test_module.V20PresExRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_pxid_2: mock_wallet_get_public_did.return_value = DIDInfo( TestConfig.test_did, @@ -667,7 +667,7 @@ async def test_create_invitation_attachment_present_proof_v2_0(self): key_type=ED25519, ) mock_retrieve_pxid_1.side_effect = StorageNotFoundError() - mock_retrieve_pxid_2.return_value = async_mock.MagicMock( + mock_retrieve_pxid_2.return_value = mock.MagicMock( pres_request=TestConfig.PRES_REQ_V2 ) invi_rec = await self.manager.create_invitation( @@ -726,7 +726,7 @@ async def test_create_invitation_requests_attach_x_multi_use(self): async def test_create_invitation_public_x_no_public_did(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = None @@ -743,7 +743,7 @@ async def test_create_invitation_public_x_no_public_did(self): async def test_create_invitation_attachment_x(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -779,7 +779,7 @@ async def test_create_invitation_peer_did(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( + with mock.patch.object( self.multitenant_mgr, "get_default_mediator" ) as mock_get_default_mediator: mock_get_default_mediator.return_value = mediation_record @@ -828,7 +828,7 @@ async def test_create_invitation_metadata_assigned(self): async def test_create_invitation_x_public_metadata(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "get_public_did", autospec=True ) as mock_wallet_get_public_did: mock_wallet_get_public_did.return_value = DIDInfo( @@ -851,13 +851,11 @@ async def test_create_invitation_x_public_metadata(self): ) async def test_wait_for_conn_rec_active_retrieve_by_id(self): - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - connection_id="the-retrieved-connection-id" - ) + mock.AsyncMock( + return_value=mock.MagicMock(connection_id="the-retrieved-connection-id") ), ): conn_rec = await self.manager._wait_for_conn_rec_active("a-connection-id") @@ -866,14 +864,14 @@ async def test_wait_for_conn_rec_active_retrieve_by_id(self): async def test_create_handshake_reuse_msg(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=self.test_conn_rec), + mock.AsyncMock(return_value=self.test_conn_rec), ): oob_mgr_fetch_conn.return_value = ConnectionTarget( did=TestConfig.test_did, @@ -908,7 +906,7 @@ async def test_create_handshake_reuse_msg(self): async def test_create_handshake_reuse_msg_catch_exception(self): self.profile.context.update_settings({"public_invites": True}) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, @@ -916,7 +914,7 @@ async def test_create_handshake_reuse_msg_catch_exception(self): oob_mgr_fetch_conn.side_effect = StorageNotFoundError() with self.assertRaises(OutOfBandManagerError) as context: await self.manager._create_handshake_reuse_message( - async_mock.MagicMock(), self.test_conn_rec, "1.0" + mock.MagicMock(), self.test_conn_rec, "1.0" ) assert "Error on creating and sending a handshake reuse message" in str( context.exception @@ -936,20 +934,20 @@ async def test_receive_reuse_message_existing_found(self): self.test_conn_rec.invitation_msg_id = "test_123" self.test_conn_rec.state = ConnRecord.State.COMPLETED.rfc160 - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True, - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "notify", autospec=True ) as mock_notify: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=False, ) @@ -993,20 +991,20 @@ async def test_receive_reuse_message_existing_found_multi_use(self): self.test_conn_rec.invitation_msg_id = "test_123" self.test_conn_rec.state = ConnRecord.State.COMPLETED.rfc160 - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True, - ) as oob_mgr_fetch_conn, async_mock.patch.object( + ) as oob_mgr_fetch_conn, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True, - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "notify", autospec=True ) as mock_notify: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), multi_use=True, ) @@ -1047,14 +1045,14 @@ async def test_receive_reuse_accepted(self): reuse_msg_accepted = HandshakeReuseAccept() reuse_msg_accepted.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( self.profile, "notify", autospec=True - ) as mock_notify, async_mock.patch.object( + ) as mock_notify, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) await self.manager.receive_reuse_accepted_message( @@ -1084,9 +1082,9 @@ async def test_receive_reuse_accepted_x(self): reuse_msg_accepted = HandshakeReuseAccept() reuse_msg_accepted.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( self.profile, "notify", autospec=True - ) as mock_notify, async_mock.patch.object( + ) as mock_notify, mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError,) @@ -1123,13 +1121,13 @@ async def test_receive_problem_report(self): ) problem_report.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: - mock_retrieve_oob.return_value = async_mock.MagicMock( - emit_event=async_mock.AsyncMock(), - delete_record=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), + mock_retrieve_oob.return_value = mock.MagicMock( + emit_event=mock.AsyncMock(), + delete_record=mock.AsyncMock(), + save=mock.AsyncMock(), ) await self.manager.receive_problem_report( @@ -1157,7 +1155,7 @@ async def test_receive_problem_report_x(self): ) problem_report.assign_thread_id(thid="the-thread-id", pthid="the-pthid") - with async_mock.patch.object( + with mock.patch.object( OobRecord, "retrieve_by_tag_filter", autospec=True ) as mock_retrieve_oob: mock_retrieve_oob.side_effect = (StorageNotFoundError(),) @@ -1169,7 +1167,7 @@ async def test_receive_problem_report_x(self): assert "Error processing problem report message " in err.exception.message async def test_receive_invitation_with_valid_mediation(self): - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") async with self.profile.session() as session: self.profile.context.update_settings({"public_invites": True}) @@ -1181,10 +1179,10 @@ async def test_receive_invitation_with_valid_mediation(self): endpoint=self.test_mediator_endpoint, ) await mediation_record.save(session) - with async_mock.patch.object( - DIDXManager, "receive_invitation", async_mock.AsyncMock() - ) as mock_didx_recv_invi, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + with mock.patch.object( + DIDXManager, "receive_invitation", mock.AsyncMock() + ) as mock_didx_recv_invi, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1208,16 +1206,16 @@ async def test_receive_invitation_with_valid_mediation(self): ) async def test_receive_invitation_with_invalid_mediation(self): - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( DIDXManager, "receive_invitation", - async_mock.AsyncMock(), - ) as mock_didx_recv_invi, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_didx_recv_invi, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve_conn_by_id: invite = await self.manager.create_invitation( my_endpoint=TestConfig.test_endpoint, @@ -1227,7 +1225,7 @@ async def test_receive_invitation_with_invalid_mediation(self): mock_didx_recv_invi.return_value = mock_conn mock_retrieve_conn_by_id.return_value = mock_conn invi_msg = invite.invitation - self.route_manager.mediation_record_if_id = async_mock.AsyncMock( + self.route_manager.mediation_record_if_id = mock.AsyncMock( side_effect=StorageNotFoundError ) await self.manager.receive_invitation( @@ -1245,15 +1243,15 @@ async def test_receive_invitation_with_invalid_mediation(self): async def test_receive_invitation_didx_services_with_service_block(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as didx_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as didx_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_retrieve_conn_by_id: - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) mock_retrieve_conn_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1274,15 +1272,15 @@ async def test_receive_invitation_didx_services_with_service_block(self): async def test_receive_invitation_connection_protocol(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy-connection") + mock_conn = mock.MagicMock(connection_id="dummy-connection") - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as conn_mgr_cls, async_mock.patch.object( - ConnRecord, "retrieve_by_id", async_mock.AsyncMock() + ) as conn_mgr_cls, mock.patch.object( + ConnRecord, "retrieve_by_id", mock.AsyncMock() ) as mock_conn_retrieve_by_id: - conn_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + conn_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) mock_conn_retrieve_by_id.return_value = mock_conn oob_invitation = InvitationMessage( @@ -1365,15 +1363,15 @@ async def test_existing_conn_record_public_did(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(), - ) as oob_mgr_find_existing_conn, async_mock.patch.object( - OobRecord, "save", async_mock.AsyncMock() - ) as oob_record_save, async_mock.patch.object( - OobRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as oob_record_retrieve_by_id, async_mock.patch.object( + mock.AsyncMock(), + ) as oob_mgr_find_existing_conn, mock.patch.object( + OobRecord, "save", mock.AsyncMock() + ) as oob_record_save, mock.patch.object( + OobRecord, "retrieve_by_id", mock.AsyncMock() + ) as oob_record_retrieve_by_id, mock.patch.object( OutOfBandManager, "fetch_connection_targets", autospec=True ) as oob_mgr_fetch_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn @@ -1386,7 +1384,7 @@ async def test_existing_conn_record_public_did(self): requests_attach=[], ) - oob_record_retrieve_by_id.return_value = async_mock.MagicMock( + oob_record_retrieve_by_id.return_value = mock.MagicMock( state=OobRecord.STATE_ACCEPTED ) @@ -1412,18 +1410,18 @@ async def test_receive_invitation_handshake_reuse(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.AsyncMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.AsyncMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.AsyncMock(), - ) as perform_handshake, async_mock.patch.object( + mock.AsyncMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(return_value=test_exist_conn), + mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1433,7 +1431,7 @@ async def test_receive_invitation_handshake_reuse(self): requests_attach=[], ) - handle_handshake_reuse.return_value = async_mock.MagicMock( + handle_handshake_reuse.return_value = mock.MagicMock( state=OobRecord.STATE_ACCEPTED ) @@ -1460,22 +1458,22 @@ async def test_receive_invitation_handshake_reuse_failed(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( test_module.OutOfBandManager, "_handle_hanshake_reuse", - async_mock.AsyncMock(), - ) as handle_handshake_reuse, async_mock.patch.object( + mock.AsyncMock(), + ) as handle_handshake_reuse, mock.patch.object( test_module.OutOfBandManager, "_perform_handshake", - async_mock.AsyncMock(), - ) as perform_handshake, async_mock.patch.object( + mock.AsyncMock(), + ) as perform_handshake, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(return_value=test_exist_conn), - ), async_mock.patch.object( + mock.AsyncMock(return_value=test_exist_conn), + ), mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=test_exist_conn), + mock.AsyncMock(return_value=test_exist_conn), ): oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1485,13 +1483,13 @@ async def test_receive_invitation_handshake_reuse_failed(self): requests_attach=[], ) - mock_oob = async_mock.MagicMock( - delete_record=async_mock.AsyncMock(), - emit_event=async_mock.AsyncMock(), + mock_oob = mock.MagicMock( + delete_record=mock.AsyncMock(), + emit_event=mock.AsyncMock(), ) perform_handshake.return_value = mock_oob - handle_handshake_reuse.return_value = async_mock.MagicMock( + handle_handshake_reuse.return_value = mock.MagicMock( state=OobRecord.STATE_NOT_ACCEPTED ) @@ -1522,17 +1520,17 @@ async def test_receive_invitation_handshake_reuse_failed(self): async def test_receive_invitation_services_with_service_did(self): self.profile.context.update_settings({"public_invites": True}) - mock_conn = async_mock.MagicMock(connection_id="dummy") + mock_conn = mock.MagicMock(connection_id="dummy") - with async_mock.patch.object( + with mock.patch.object( test_module, "DIDXManager", autospec=True - ) as didx_mgr_cls, async_mock.patch.object( + ) as didx_mgr_cls, mock.patch.object( ConnRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=mock_conn), + mock.AsyncMock(return_value=mock_conn), ): - didx_mgr_cls.return_value = async_mock.MagicMock( - receive_invitation=async_mock.AsyncMock(return_value=mock_conn) + didx_mgr_cls.return_value = mock.MagicMock( + receive_invitation=mock.AsyncMock(return_value=mock_conn) ) oob_invitation = InvitationMessage( handshake_protocols=[ @@ -1550,7 +1548,7 @@ async def test_request_attach_oob_message_processor_connectionless(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = async_mock.MagicMock(handle_message=async_mock.AsyncMock()) + mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) @@ -1559,14 +1557,14 @@ async def test_request_attach_oob_message_processor_connectionless(self): endpoint=self.test_endpoint, recipient_keys=[self.test_verkey] ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "create_signing_key", - async_mock.AsyncMock(), - ) as mock_create_signing_key, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_signing_key, mock.patch.object( OutOfBandManager, "_service_decorator_from_service", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_service_decorator_from_service: mock_create_signing_key.return_value = KeyInfo( verkey="a-verkey", metadata={}, key_type=ED25519 @@ -1611,17 +1609,15 @@ async def test_request_attach_oob_message_processor_connection(self): AttachDecorator.deserialize(deepcopy(TestConfig.req_attach_v1)) ] - mock_oob_processor = async_mock.MagicMock( - handle_message=async_mock.AsyncMock() - ) + mock_oob_processor = mock.MagicMock(handle_message=mock.AsyncMock()) self.profile.context.injector.bind_instance( OobMessageProcessor, mock_oob_processor ) - with async_mock.patch.object( + with mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn oob_invitation = InvitationMessage( @@ -1654,12 +1650,12 @@ async def test_request_attach_wait_for_conn_rec_active(self): their_role=ConnRecord.Role.REQUESTER, ) - with async_mock.patch.object( + with mock.patch.object( OutOfBandManager, "_wait_for_conn_rec_active" - ) as mock_wait_for_conn_rec_active, async_mock.patch.object( + ) as mock_wait_for_conn_rec_active, mock.patch.object( ConnRecord, "find_existing_connection", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as oob_mgr_find_existing_conn: oob_mgr_find_existing_conn.return_value = test_exist_conn mock_wait_for_conn_rec_active.return_value = None @@ -1685,7 +1681,7 @@ async def test_request_attach_wait_for_conn_rec_active(self): async def test_service_decorator_from_service_did(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( TestConfig.test_endpoint, [TestConfig.test_verkey], @@ -1718,7 +1714,7 @@ async def test_service_decorator_from_service_object(self): async def test_service_decorator_from_service_str_empty_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( "", # empty endpoint [TestConfig.test_verkey], @@ -1732,7 +1728,7 @@ async def test_service_decorator_from_service_str_empty_endpoint(self): async def test_service_decorator_from_service_str_none_endpoint(self): did = "did:sov:something" - self.manager.resolve_invitation = async_mock.AsyncMock() + self.manager.resolve_invitation = mock.AsyncMock() self.manager.resolve_invitation.return_value = ( None, # None endpoint [TestConfig.test_verkey], @@ -1795,10 +1791,10 @@ async def test_delete_stale_connection_by_invitation(self): updated_at=datetime_to_str(older_datetime), ) ] - with async_mock.patch.object( - ConnRecord, "query", async_mock.AsyncMock() - ) as mock_connrecord_query, async_mock.patch.object( - ConnRecord, "delete_record", async_mock.AsyncMock() + with mock.patch.object( + ConnRecord, "query", mock.AsyncMock() + ) as mock_connrecord_query, mock.patch.object( + ConnRecord, "delete_record", mock.AsyncMock() ) as mock_connrecord_delete: mock_connrecord_query.return_value = records await self.manager.delete_stale_connection_by_invitation("test123") diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py index 03e4422e1f..385f7b977a 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext from .....connections.models.conn_record import ConnRecord @@ -13,9 +13,9 @@ async def asyncSetUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -28,21 +28,21 @@ async def test_invitation_create(self): "auto_accept": "true", } body = { - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [test_module.HSProto.RFC23.name], "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"abc": "123"}) ) ) @@ -70,22 +70,22 @@ async def test_invitation_create_with_accept(self): "auto_accept": "true", } body = { - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [test_module.HSProto.RFC23.name], "accept": ["didcomm/aip1", "didcomm/aip2;env=rfc19"], "use_public_did": True, "metadata": {"hello": "world"}, } - self.request.json = async_mock.AsyncMock(return_value=body) + self.request.json = mock.AsyncMock(return_value=body) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value={"abc": "123"}) + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value={"abc": "123"}) ) ) @@ -109,20 +109,20 @@ async def test_invitation_create_with_accept(self): async def test_invitation_create_x(self): self.request.query = {"multi_use": "true"} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ - "attachments": async_mock.MagicMock(), + "attachments": mock.MagicMock(), "handshake_protocols": [23], "use_public_did": True, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.create_invitation = async_mock.AsyncMock( + mock_oob_mgr.return_value.create_invitation = mock.AsyncMock( side_effect=test_module.OutOfBandManagerError() ) @@ -131,17 +131,17 @@ async def test_invitation_create_x(self): mock_json_response.assert_not_called() async def test_invitation_receive(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() expected_connection_record = ConnRecord(connection_id="some-id") - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.InvitationMessage, "deserialize", async_mock.Mock() - ), async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.InvitationMessage, "deserialize", mock.Mock() + ), mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.AsyncMock( return_value=expected_connection_record ) @@ -156,16 +156,16 @@ async def test_invitation_receive_forbidden_x(self): await test_module.invitation_receive(self.request) async def test_invitation_receive_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "OutOfBandManager", autospec=True - ) as mock_oob_mgr, async_mock.patch.object( - test_module.InvitationMessage, "deserialize", async_mock.Mock() - ) as mock_invi_deser, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_oob_mgr, mock.patch.object( + test_module.InvitationMessage, "deserialize", mock.Mock() + ) as mock_invi_deser, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_oob_mgr.return_value.receive_invitation = async_mock.AsyncMock( + mock_oob_mgr.return_value.receive_invitation = mock.AsyncMock( side_effect=test_module.StorageError("cannot write") ) @@ -173,13 +173,13 @@ async def test_invitation_receive_x(self): await test_module.invitation_receive(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py index 055604e6a3..e6b324c3b4 100644 --- a/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py +++ b/aries_cloudagent/protocols/present_proof/dif/tests/test_pres_exch_handler.py @@ -4,7 +4,7 @@ from typing import Sequence from uuid import uuid4 -import mock as async_mock +import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2, ED25519 @@ -1844,7 +1844,7 @@ async def test_reveal_doc_d(self, profile): @pytest.mark.asyncio async def test_credential_subject_as_list(self, profile): dif_pres_exch_handler = DIFPresExchHandler(profile) - with async_mock.patch.object( + with mock.patch.object( dif_pres_exch_handler, "new_credential_builder", autospec=True ) as mock_cred_builder: mock_cred_builder.return_value = {} @@ -2037,10 +2037,10 @@ async def test_get_sign_key_credential_subject_id(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2102,10 +2102,10 @@ async def test_get_sign_key_credential_subject_id_error(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_did_info: did_info = DIDInfo( did="did:sov:LjgpST2rjsoxYegQDRm7EL", @@ -2170,10 +2170,10 @@ async def test_get_sign_key_credential_subject_id_bbsbls(self, profile): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_did_info: did_info = DIDInfo( did="did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", @@ -2240,29 +2240,29 @@ async def test_create_vp_no_issuer(self, profile, setup_tuple): cred_tags={"some": "tag"}, ), ] - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (VC_RECORDS, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1"} @@ -2293,33 +2293,33 @@ async def test_create_vp_with_bbs_suite(self, profile, setup_tuple): profile, proof_type=BbsBlsSignature2020.signature_type ) cred_list, pd_list = setup_tuple - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_vp, mock.patch.object( test_module, "sign_presentation", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_sign_vp: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (cred_list, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1", "@context": ["test"]} @@ -2351,33 +2351,33 @@ async def test_create_vp_no_issuer_with_bbs_suite(self, profile, setup_tuple): profile, proof_type=BbsBlsSignature2020.signature_type ) cred_list, pd_list = setup_tuple - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "_did_info_for_did", - async_mock.AsyncMock(), - ) as mock_did_info, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_did_info, mock.patch.object( DIFPresExchHandler, "make_requirement", - async_mock.AsyncMock(), - ) as mock_make_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_make_req, mock.patch.object( DIFPresExchHandler, "apply_requirements", - async_mock.AsyncMock(), - ) as mock_apply_req, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_apply_req, mock.patch.object( DIFPresExchHandler, "merge", - async_mock.AsyncMock(), - ) as mock_merge, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_merge, mock.patch.object( test_module, "create_presentation", - async_mock.AsyncMock(), - ) as mock_create_vp, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_create_vp, mock.patch.object( DIFPresExchHandler, "get_sign_key_credential_subject_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_sign_key_cred_subject: - mock_make_req.return_value = async_mock.MagicMock() - mock_apply_req.return_value = async_mock.MagicMock() + mock_make_req.return_value = mock.MagicMock() + mock_apply_req.return_value = mock.MagicMock() mock_merge.return_value = (cred_list, {}) dif_pres_exch_handler.is_holder = True mock_create_vp.return_value = {"test": "1", "@context": ["test"]} @@ -3290,8 +3290,8 @@ async def test_apply_constraint_received_cred_path_update(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3326,8 +3326,8 @@ async def test_apply_constraint_received_cred_invalid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3344,8 +3344,8 @@ async def test_apply_constraint_received_cred_invalid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3370,8 +3370,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3388,8 +3388,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3416,8 +3416,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3460,8 +3460,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3478,8 +3478,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3496,8 +3496,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3514,8 +3514,8 @@ async def test_apply_constraint_received_cred_valid(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 assert await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3538,8 +3538,8 @@ async def test_apply_constraint_received_cred_no_sel_disc(self, profile): ], } constraint = Constraints.deserialize(constraint) - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 assert not await dif_pres_exch_handler.apply_constraint_received_cred( @@ -3625,8 +3625,8 @@ async def test_filter_by_field_keyerror(self, profile): "@type": "fhir:resource-types#Patient", "address": {"@id": "urn:bnid:_:c14n1", "city": "Рума"}, } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3650,8 +3650,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:integer", "@value": "10", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3671,8 +3671,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:dateTime", "@value": "2020-09-28T11:00:00+00:00", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3693,8 +3693,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:boolean", "@value": "false", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3710,8 +3710,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "type": "xsd:double", "@value": "10.2", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) @@ -3726,8 +3726,8 @@ async def test_filter_by_field_xsd_parser(self, profile): "@id": "test", "test": "val", } - with async_mock.patch.object( - test_module.jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 vc_record_cred = dif_pres_exch_handler.create_vcrecord(cred_dict) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py index 458b71b077..1e259345c5 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,20 +17,20 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() request_context.message = PresentationAck() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationAckHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -44,12 +44,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation_ack = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation_ack = mock.AsyncMock() request_context.message = PresentationAck() request_context.connection_ready = False handler = test_module.PresentationAckHandler() @@ -64,8 +64,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py index 4855579113..176d896eab 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,21 +17,19 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = False - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -47,22 +45,20 @@ async def test_called_auto_verify(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_presentation = async_mock.AsyncMock() - mock_pres_mgr.return_value.verify_presentation = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_presentation = mock.AsyncMock() + mock_pres_mgr.return_value.verify_presentation = mock.AsyncMock() request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -78,36 +74,32 @@ async def test_called_auto_verify_x(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value = async_mock.MagicMock( - receive_presentation=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value = mock.MagicMock( + receive_presentation=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - verify_presentation=async_mock.AsyncMock( + verify_presentation=mock.AsyncMock( side_effect=test_module.LedgerError() ), ) request_context.message = Presentation() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py index f4c3b39e25..95ad42faeb 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -17,13 +17,13 @@ class TestPresentationProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = PresentationProblemReport( description={ "en": "Change of plans", @@ -43,13 +43,13 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: request_context.connection_ready = True - mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = PresentationProblemReport( diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py index 254b92d647..20167b6b6d 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -15,17 +15,17 @@ async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = False - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) request_context.message = PresentationProposal() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.PresentationProposalHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -38,19 +38,19 @@ async def test_called(self): async def test_called_auto_request(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_proposal.return_value, "presentation_request_message", @@ -77,21 +77,19 @@ async def test_called_auto_request(self): async def test_called_auto_request_x(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -100,8 +98,8 @@ async def test_called_auto_request_x(self): handler = test_module.PresentationProposalHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -109,12 +107,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_proposal = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_proposal = mock.AsyncMock() request_context.message = PresentationProposal() request_context.connection_ready = False handler = test_module.PresentationProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py index 2446afc031..03b67c8230 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/handlers/tests/test_presentation_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -67,17 +67,17 @@ class TestPresentationRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value=INDY_PROOF_REQ ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -98,17 +98,17 @@ async def test_called(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -127,17 +127,17 @@ async def test_called(self): async def test_called_not_found(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value=INDY_PROOF_REQ ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -158,18 +158,18 @@ async def test_called_not_found(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( side_effect=StorageNotFoundError ) mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( + return_value=mock.MagicMock() ) mock_pres_mgr.return_value.receive_request.return_value.auto_present = False @@ -188,10 +188,10 @@ async def test_called_not_found(self): async def test_called_auto_present(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -226,33 +226,33 @@ async def test_called_auto_present(self): auto_present=True, ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.AsyncMock( + mock_holder = mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.AsyncMock( return_value=[{"cred_info": {"referent": "dummy"}}] ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -275,10 +275,10 @@ async def test_called_auto_present(self): async def test_called_auto_present_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -308,41 +308,39 @@ async def test_called_auto_present_x(self): presentation_proposal = PresentationProposal( comment="Hello World", presentation_proposal=PRES_PREVIEW ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( presentation_proposal_dict=presentation_proposal, auto_present=True, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = mock_px_rec - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -350,18 +348,18 @@ async def test_called_auto_present_x(self): handler = test_module.PresentationRequestHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() async def test_called_auto_present_no_preview(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -390,14 +388,14 @@ async def test_called_auto_present_no_preview(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -408,20 +406,20 @@ async def test_called_auto_present_no_preview(self): request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -444,10 +442,10 @@ async def test_called_auto_present_no_preview(self): async def test_called_auto_present_pred_no_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -470,33 +468,33 @@ async def test_called_auto_present_pred_no_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=[]) + mock.AsyncMock(return_value=[]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -515,10 +513,10 @@ async def test_called_auto_present_pred_no_match(self): async def test_called_auto_present_pred_single_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -541,35 +539,33 @@ async def test_called_auto_present_pred_single_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy-0"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy-0"}}]) ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -592,10 +588,10 @@ async def test_called_auto_present_pred_single_match(self): async def test_called_auto_present_pred_multi_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -618,14 +614,14 @@ async def test_called_auto_present_pred_multi_match(self): request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V10PresentationExchange(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -636,20 +632,20 @@ async def test_called_auto_present_pred_multi_match(self): request_context.injector.bind_instance(IndyHolder, mock_holder) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -672,10 +668,10 @@ async def test_called_auto_present_pred_multi_match(self): async def test_called_auto_present_multi_cred_match_reft(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -718,14 +714,14 @@ async def test_called_auto_present_multi_cred_match_reft(self): auto_present=True, ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ { "cred_info": { @@ -767,20 +763,20 @@ async def test_called_auto_present_multi_cred_match_reft(self): request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -803,10 +799,10 @@ async def test_called_auto_present_multi_cred_match_reft(self): async def test_called_auto_present_bait_and_switch(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = PresentationRequest() - request_context.message.indy_proof_request = async_mock.MagicMock( + request_context.message.indy_proof_request = mock.MagicMock( return_value={ "name": "proof-request", "version": "1.0", @@ -840,7 +836,7 @@ async def test_called_auto_present_bait_and_switch(self): auto_present=True, ) - by_reft = async_mock.AsyncMock( + by_reft = mock.AsyncMock( return_value=[ { "cred_info": { @@ -868,32 +864,32 @@ async def test_called_auto_present_bait_and_switch(self): }, ] ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=by_reft ) request_context.injector.bind_instance(IndyHolder, mock_holder) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V10PresentationExchange", autospec=True ) as mock_pres_ex_cls: mock_pres_ex_cls.return_value = px_rec_instance - mock_pres_ex_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_presentation = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_presentation = mock.AsyncMock( return_value=(px_rec_instance, "presentation_message") ) request_context.connection_ready = True @@ -914,12 +910,12 @@ async def test_called_auto_present_bait_and_switch(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "PresentationManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_request = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_request = mock.AsyncMock() request_context.message = PresentationRequest() request_context.connection_ready = False handler = test_module.PresentationRequestHandler() @@ -937,8 +933,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py index a55fc8e04b..c19035f3a1 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -130,10 +130,10 @@ async def test_save_error_state(self): record.state = V10PresentationExchange.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="testing") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py index 18c14e9c13..5a8fa5c89c 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_manager.py @@ -2,7 +2,7 @@ from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import ( @@ -219,15 +219,13 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -243,7 +241,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -252,7 +250,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -264,15 +262,15 @@ async def asyncSetUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -287,7 +285,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -297,8 +295,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -309,11 +307,9 @@ async def asyncSetUp(self): ) injector.bind_instance(IndyHolder, self.holder) - Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) + Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.AsyncMock( - return_value=("true", []) - ) + self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) injector.bind_instance(IndyVerifier, self.verifier) self.manager = PresentationManager(self.profile) @@ -354,9 +350,9 @@ async def test_record_eq(self): async def test_create_exchange_for_proposal(self): proposal = PresentationProposal() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( PresentationProposal, "serialize", autospec=True ): exchange = await self.manager.create_exchange_for_proposal( @@ -374,10 +370,10 @@ async def test_create_exchange_for_proposal(self): assert exchange.auto_remove is True async def test_receive_proposal(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) proposal = PresentationProposal() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange = await self.manager.receive_proposal(proposal, connection_record) @@ -393,7 +389,7 @@ async def test_create_bound_request(self): presentation_proposal_dict=proposal.serialize(), role=V10PresentationExchange.ROLE_VERIFIER, ) - exchange.save = async_mock.AsyncMock() + exchange.save = mock.AsyncMock() (ret_exchange, pres_req_msg) = await self.manager.create_bound_request( presentation_exchange_record=exchange, name=PROOF_REQ_NAME, @@ -420,7 +416,7 @@ async def test_create_exchange_for_request(self): ] ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange = await self.manager.create_exchange_for_request( @@ -439,7 +435,7 @@ async def test_create_exchange_for_request(self): async def test_receive_request(self): exchange_in = V10PresentationExchange() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.receive_request(exchange_in) @@ -458,21 +454,21 @@ async def test_create_presentation(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -501,21 +497,21 @@ async def test_create_presentation_proof_req_non_revoc_interval_none(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -562,21 +558,21 @@ async def test_create_presentation_self_asserted(self): exchange_in.presentation_request = indy_proof_req - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -594,12 +590,10 @@ async def test_create_presentation_self_asserted(self): assert exchange_out.state == V10PresentationExchange.STATE_PRESENTATION_SENT async def test_create_presentation_no_revocation(self): - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -614,9 +608,9 @@ async def test_create_presentation_no_revocation(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -629,7 +623,7 @@ async def test_create_presentation_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -639,17 +633,17 @@ async def test_create_presentation_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.AsyncMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( - test_indy_util_module.LOGGER, "info", async_mock.MagicMock() + ) as mock_attach_decorator, mock.patch.object( + test_indy_util_module.LOGGER, "info", mock.MagicMock() ) as mock_log_info: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -680,9 +674,9 @@ async def test_create_presentation_bad_revoc_state(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -696,7 +690,7 @@ async def test_create_presentation_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -706,27 +700,27 @@ async def test_create_presentation_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( side_effect=IndyHolderError("Problem", {"message": "Nope"}) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -748,9 +742,9 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): exchange_in.presentation_request = indy_proof_req - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -777,7 +771,7 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -787,8 +781,8 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -799,21 +793,21 @@ async def test_create_presentation_multi_matching_proposal_creds_names(self): ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_module, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -838,7 +832,7 @@ async def test_no_matching_creds_for_proof_req(self): nonce=PROOF_REQ_NONCE, profile=self.profile, ) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -846,7 +840,7 @@ async def test_no_matching_creds_for_proof_req(self): indy_proof_req, holder=self.holder ) - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -861,7 +855,7 @@ async def test_no_matching_creds_for_proof_req(self): self.holder.get_credentials_for_presentation_request_by_referent = get_creds async def test_receive_presentation(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange( presentation_proposal_dict={ @@ -950,14 +944,14 @@ async def test_receive_presentation(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [exchange_dummy] exchange_out = await self.manager.receive_presentation( @@ -1064,14 +1058,14 @@ async def test_receive_presentation_oob(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [exchange_dummy] exchange_out = await self.manager.receive_presentation(PRES, None, None) @@ -1085,7 +1079,7 @@ async def test_receive_presentation_oob(self): ) async def test_receive_presentation_bait_and_switch(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange( presentation_proposal_dict={ @@ -1174,9 +1168,9 @@ async def test_receive_presentation_bait_and_switch(self): }, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1186,14 +1180,14 @@ async def test_receive_presentation_bait_and_switch(self): async def test_receive_presentation_connectionless(self): exchange_dummy = V10PresentationExchange() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = exchange_dummy exchange_out = await self.manager.receive_presentation(PRES, None, None) @@ -1232,7 +1226,7 @@ async def test_verify_presentation(self): presentation=INDY_PROOF, ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.verify_presentation(exchange_in) @@ -1260,7 +1254,7 @@ async def test_verify_presentation_with_revocation(self): ] } - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True ) as save_ex: exchange_out = await self.manager.verify_presentation(exchange_in) @@ -1285,12 +1279,12 @@ async def test_send_presentation_ack_oob(self): responder = MockResponder() self.profile.context.injector.bind_instance(BaseResponder, responder) - with async_mock.patch.object( + with mock.patch.object( test_module.OobRecord, "retrieve_by_tag_filter" - ) as mock_retrieve_oob, async_mock.patch.object( + ) as mock_retrieve_oob, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: await self.manager.send_presentation_ack(exchange) messages = responder.messages @@ -1306,14 +1300,14 @@ async def test_send_presentation_ack_no_responder(self): await self.manager.send_presentation_ack(exchange) async def test_receive_presentation_ack_a(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange() - message = async_mock.MagicMock() + message = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1327,14 +1321,14 @@ async def test_receive_presentation_ack_a(self): ) async def test_receive_presentation_ack_b(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) exchange_dummy = V10PresentationExchange() - message = async_mock.MagicMock(_verification_result="true") + message = mock.MagicMock(_verification_result="true") - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = exchange_dummy @@ -1365,16 +1359,16 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.AsyncMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.AsyncMock(), + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = stored_exchange @@ -1407,10 +1401,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V10PresentationExchange, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = test_module.StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py index b3b7a2e848..c4716e0df9 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py @@ -1,6 +1,6 @@ import importlib -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from marshmallow import ValidationError @@ -21,9 +21,9 @@ def setUp(self): self.profile = self.context.profile self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -61,7 +61,7 @@ async def test_presentation_exchange_list(self): "state": "dummy", } - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -71,16 +71,14 @@ async def test_presentation_exchange_list(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.AsyncMock() + mock_presentation_exchange.query = mock.AsyncMock() mock_presentation_exchange.query.return_value = [mock_presentation_exchange] - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_list(self.request) mock_response.assert_called_once_with( {"results": [mock_presentation_exchange.serialize.return_value]} @@ -94,7 +92,7 @@ async def test_presentation_exchange_list_x(self): "state": "dummy", } - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -104,7 +102,7 @@ async def test_presentation_exchange_list_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.query = async_mock.AsyncMock( + mock_presentation_exchange.query = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -114,7 +112,7 @@ async def test_presentation_exchange_list_x(self): async def test_presentation_exchange_credentials_list_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -124,7 +122,7 @@ async def test_presentation_exchange_credentials_list_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock() + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_presentation_exchange.retrieve_by_id.side_effect = StorageNotFoundError @@ -141,15 +139,15 @@ async def test_presentation_exchange_credentials_x(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -174,14 +172,14 @@ async def test_presentation_exchange_credentials_list_single_referent(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=async_mock.AsyncMock( + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=mock.AsyncMock( return_value=returned_credentials ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -195,9 +193,7 @@ async def test_presentation_exchange_credentials_list_single_referent(self): mock_presentation_exchange ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_credentials_list(self.request) mock_response.assert_called_once_with(returned_credentials) @@ -211,14 +207,14 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(return_value=returned_credentials) ) ), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -232,16 +228,14 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): mock_presentation_exchange ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_credentials_list(self.request) mock_response.assert_called_once_with(returned_credentials) async def test_presentation_exchange_retrieve(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -251,14 +245,12 @@ async def test_presentation_exchange_retrieve(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.AsyncMock() mock_pres_ex.retrieve_by_id.return_value = mock_pres_ex - mock_pres_ex.serialize = async_mock.MagicMock() + mock_pres_ex.serialize = mock.MagicMock() mock_pres_ex.serialize.return_value = {"thread_id": "sample-thread-id"} - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_retrieve(self.request) mock_response.assert_called_once_with( mock_pres_ex.serialize.return_value @@ -267,7 +259,7 @@ async def test_presentation_exchange_retrieve(self): async def test_presentation_exchange_retrieve_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -277,7 +269,7 @@ async def test_presentation_exchange_retrieve_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock() + mock_pres_ex.retrieve_by_id = mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex.retrieve_by_id.side_effect = StorageNotFoundError @@ -288,12 +280,12 @@ async def test_presentation_exchange_retrieve_not_found(self): async def test_presentation_exchange_retrieve_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - mock_pres_ex_rec = async_mock.MagicMock( + mock_pres_ex_rec = mock.MagicMock( connection_id="abc123", thread_id="thid123", - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -303,10 +295,8 @@ async def test_presentation_exchange_retrieve_x(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=mock_pres_ex_rec - ) - mock_pres_ex_rec.serialize = async_mock.MagicMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock(return_value=mock_pres_ex_rec) + mock_pres_ex_rec.serialize = mock.MagicMock( side_effect=test_module.BaseModelError() ) @@ -314,40 +304,38 @@ async def test_presentation_exchange_retrieve_x(self): await test_module.presentation_exchange_retrieve(self.request) async def test_presentation_exchange_send_proposal(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, ) as mock_preview: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.AsyncMock(return_value=mock_presentation_exchange_record) + mock.AsyncMock(return_value=mock_presentation_exchange_record) ) - mock_preview.return_value.deserialize.return_value = async_mock.MagicMock() + mock_preview.return_value.deserialize.return_value = mock.MagicMock() - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_proposal(self.request) mock_response.assert_called_once_with( mock_presentation_exchange_record.serialize.return_value ) async def test_presentation_exchange_send_proposal_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: @@ -355,7 +343,7 @@ async def test_presentation_exchange_send_proposal_no_conn_record(self): importlib.reload(test_module) # Emulate storage not found (bad connection id) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -363,15 +351,15 @@ async def test_presentation_exchange_send_proposal_no_conn_record(self): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch( + ) as mock_preview, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "messages.presentation_proposal.PresentationProposal" @@ -381,36 +369,36 @@ async def test_presentation_exchange_send_proposal_not_ready(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() mock_connection_record.retrieve_by_id.return_value.is_ready = False with self.assertRaises(test_module.web.HTTPForbidden): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_send_proposal_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, ) as mock_preview: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_proposal = ( - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -419,95 +407,93 @@ async def test_presentation_exchange_send_proposal_x(self): await test_module.presentation_exchange_send_proposal(self.request) async def test_presentation_exchange_create_request(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"comment": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_presentation_exchange, async_mock.patch( + ) as mock_presentation_exchange, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, ) as mock_generate_nonce: # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.AsyncMock() + mock_generate_nonce = mock.AsyncMock() - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_presentation_exchange ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_create_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_create_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"comment": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_presentation_exchange, async_mock.patch( + ) as mock_presentation_exchange, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, ) as mock_generate_nonce: # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -516,7 +502,7 @@ async def test_presentation_exchange_create_request_x(self): await test_module.presentation_exchange_create_request(self.request) async def test_presentation_exchange_send_free_request(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -524,24 +510,24 @@ async def test_presentation_exchange_send_free_request(self): } ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch( + ) as mock_generate_nonce, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -551,56 +537,52 @@ async def test_presentation_exchange_send_free_request(self): # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } - mock_mgr = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_presentation_exchange ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_free_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_free_request_not_found(self): - self.request.json = async_mock.AsyncMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.AsyncMock(return_value={"connection_id": "dummy"}) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: # Since we are mocking import importlib.reload(test_module) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_not_ready(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": "dummy", "proof_request": {}} ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, ) as mock_connection_record: @@ -608,7 +590,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): importlib.reload(test_module) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -616,7 +598,7 @@ async def test_presentation_exchange_send_free_request_not_ready(self): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_free_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -624,23 +606,23 @@ async def test_presentation_exchange_send_free_request_x(self): } ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -650,24 +632,24 @@ async def test_presentation_exchange_send_free_request_x(self): # Since we are mocking import importlib.reload(test_module) - mock_generate_nonce = async_mock.AsyncMock() + mock_generate_nonce = mock.AsyncMock() - mock_presentation_exchange_record = async_mock.MagicMock() + mock_presentation_exchange_record = mock.MagicMock() mock_presentation_manager.return_value.create_exchange_for_request = ( - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -675,40 +657,40 @@ async def test_presentation_exchange_send_free_request_x(self): await test_module.presentation_exchange_send_free_request(self.request) async def test_presentation_exchange_send_bound_request(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange", autospec=True, @@ -720,54 +702,52 @@ async def test_presentation_exchange_send_bound_request(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id" } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.AsyncMock( return_value=(mock_presentation_exchange, mock_presentation_request) ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_bound_request(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_bound_request_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -781,37 +761,37 @@ async def test_presentation_exchange_send_bound_request_not_found(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock() + mock_connection_record.retrieve_by_id = mock.AsyncMock() mock_connection_record.retrieve_by_id.side_effect = StorageNotFoundError with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_not_ready(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -825,12 +805,12 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): mock_presentation_exchange.state = ( test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -838,13 +818,13 @@ async def test_presentation_exchange_send_bound_request_not_ready(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -852,10 +832,10 @@ async def test_presentation_exchange_send_bound_request_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_send_bound_request_bad_state(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -866,8 +846,8 @@ async def test_presentation_exchange_send_bound_request_bad_state(self): importlib.reload(test_module) mock_presentation_exchange.connection_id = "dummy" - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -875,26 +855,26 @@ async def test_presentation_exchange_send_bound_request_bad_state(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_bound_request_x(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -909,20 +889,20 @@ async def test_presentation_exchange_send_bound_request_x(self): test_module.V10PresentationExchange.STATE_PROPOSAL_RECEIVED ) mock_presentation_exchange.connection_id = "abc123" - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( return_value=mock_presentation_exchange ) - mock_presentation_exchange.serialize = async_mock.MagicMock() + mock_presentation_exchange.serialize = mock.MagicMock() mock_presentation_exchange.serialize.return_value = { "thread_id": "sample-thread-id", } mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_bound_request=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -937,7 +917,7 @@ async def test_presentation_exchange_send_bound_request_x(self): await test_module.presentation_exchange_send_bound_request(self.request) async def test_presentation_exchange_send_presentation(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -948,27 +928,27 @@ async def test_presentation_exchange_send_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch.object( + ) as mock_presentation_manager, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch( + ) as mock_presentation_proposal, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -982,42 +962,40 @@ async def test_presentation_exchange_send_presentation(self): test_module.V10PresentationExchange.STATE_REQUEST_RECEIVED ) mock_presentation_exchange.connection_id = "dummy" - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.AsyncMock( - return_value=(mock_presentation_exchange, async_mock.MagicMock()) + mock_mgr = mock.MagicMock( + create_presentation=mock.AsyncMock( + return_value=(mock_presentation_exchange, mock.MagicMock()) ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_send_presentation(self.request) mock_response.assert_called_once_with( mock_presentation_exchange.serialize.return_value ) async def test_presentation_exchange_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1025,26 +1003,26 @@ async def test_presentation_exchange_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_send_presentation_not_found(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1054,14 +1032,14 @@ async def test_presentation_exchange_send_presentation_not_found(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1069,26 +1047,26 @@ async def test_presentation_exchange_send_presentation_not_found(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1098,15 +1076,15 @@ async def test_presentation_exchange_send_presentation_not_ready(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", ) ) mock_connection_record.is_ready = False - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) @@ -1114,10 +1092,10 @@ async def test_presentation_exchange_send_presentation_not_ready(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_bad_state(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1127,8 +1105,8 @@ async def test_presentation_exchange_send_presentation_bad_state(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1136,7 +1114,7 @@ async def test_presentation_exchange_send_presentation_bad_state(self): await test_module.presentation_exchange_send_presentation(self.request) async def test_presentation_exchange_send_presentation_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "self_attested_attributes": {}, @@ -1146,23 +1124,23 @@ async def test_presentation_exchange_send_presentation_x(self): ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch.object( + ) as mock_generate_nonce, mock.patch.object( test_module, "IndyPresPreview", autospec=True - ) as mock_presentation_proposal, async_mock.patch.object( + ) as mock_presentation_proposal, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1172,22 +1150,22 @@ async def test_presentation_exchange_send_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_REQUEST_RECEIVED, connection_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ), ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - create_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + create_presentation=mock.AsyncMock( side_effect=test_module.LedgerError() ) ) @@ -1199,24 +1177,24 @@ async def test_presentation_exchange_send_presentation_x(self): async def test_presentation_exchange_verify_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( "aries_cloudagent.indy.util.generate_pr_nonce", autospec=True, - ) as mock_generate_nonce, async_mock.patch( + ) as mock_generate_nonce, mock.patch( "aries_cloudagent.indy.models.pres_preview.IndyPresPreview", autospec=True, - ) as mock_preview, async_mock.patch.object( + ) as mock_preview, mock.patch.object( test_module, "PresentationRequest", autospec=True - ) as mock_presentation_request, async_mock.patch( + ) as mock_presentation_request, mock.patch( "aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator", autospec=True, - ) as mock_attach_decorator, async_mock.patch( + ) as mock_attach_decorator, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1226,43 +1204,41 @@ async def test_presentation_exchange_verify_presentation(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", thread_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.AsyncMock( return_value=mock_presentation_exchange.retrieve_by_id.return_value ) ) mock_presentation_manager.return_value = mock_mgr - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_verify_presentation( self.request ) mock_response.assert_called_once_with({"thread_id": "sample-thread-id"}) async def test_presentation_exchange_verify_presentation_px_rec_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module.V10PresentationExchange, "retrieve_by_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError("no such record") with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1272,10 +1248,10 @@ async def test_presentation_exchange_verify_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_presentation_exchange_verify_presentation_bad_state(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1285,8 +1261,8 @@ async def test_presentation_exchange_verify_presentation_bad_state(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_ACKED ) ) @@ -1299,25 +1275,25 @@ async def test_presentation_exchange_verify_presentation_x(self): self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch( + with mock.patch( "aries_cloudagent.connections.models.conn_record.ConnRecord", autospec=True, - ) as mock_connection_record, async_mock.patch( + ) as mock_connection_record, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_presentation_manager, async_mock.patch( + ) as mock_presentation_manager, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1327,24 +1303,24 @@ async def test_presentation_exchange_verify_presentation_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_PRESENTATION_RECEIVED, connection_id="dummy", thread_id="dummy", - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) mock_connection_record.is_ready = True - mock_connection_record.retrieve_by_id = async_mock.AsyncMock( + mock_connection_record.retrieve_by_id = mock.AsyncMock( return_value=mock_connection_record ) - mock_mgr = async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock( + mock_mgr = mock.MagicMock( + verify_presentation=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -1363,31 +1339,29 @@ async def test_presentation_exchange_verify_presentation_x(self): ) async def test_presentation_exchange_problem_report(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_pres_ex, async_mock.patch( + ) as mock_pres_ex, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_ex.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -1397,15 +1371,15 @@ async def test_presentation_exchange_problem_report(self): mock_response.assert_called_once_with({}) async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'no: problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch( + ) as mock_pres_mgr_cls, mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1415,7 +1389,7 @@ async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -1423,27 +1397,27 @@ async def test_presentation_exchange_problem_report_bad_pres_ex_id(self): await test_module.presentation_exchange_problem_report(self.request) async def test_presentation_exchange_problem_report_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" ), autospec=True, - ) as mock_pres_ex, async_mock.patch( + ) as mock_pres_ex, mock.patch( "aries_cloudagent.protocols.present_proof.v1_0.manager.PresentationManager", autospec=True, - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module.web, "json_response" ) as mock_response: # Since we are mocking import importlib.reload(test_module) - mock_pres_ex.retrieve_by_id = async_mock.AsyncMock( + mock_pres_ex.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -1453,7 +1427,7 @@ async def test_presentation_exchange_problem_report_x(self): async def test_presentation_exchange_remove(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1463,25 +1437,23 @@ async def test_presentation_exchange_remove(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) ) - with async_mock.patch.object( - test_module.web, "json_response" - ) as mock_response: + with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_remove(self.request) mock_response.assert_called_once_with({}) async def test_presentation_exchange_remove_not_found(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1492,7 +1464,7 @@ async def test_presentation_exchange_remove_not_found(self): importlib.reload(test_module) # Emulate storage not found (bad pres ex id) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError ) @@ -1502,7 +1474,7 @@ async def test_presentation_exchange_remove_not_found(self): async def test_presentation_exchange_remove_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch( + with mock.patch( ( "aries_cloudagent.protocols.present_proof.v1_0." "models.presentation_exchange.V10PresentationExchange" @@ -1512,11 +1484,11 @@ async def test_presentation_exchange_remove_x(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_presentation_exchange.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=mock_presentation_exchange.STATE_VERIFIED, connection_id="dummy", - delete_record=async_mock.AsyncMock( + delete_record=mock.AsyncMock( side_effect=test_module.StorageError() ), ) @@ -1526,13 +1498,13 @@ async def test_presentation_exchange_remove_x(self): await test_module.presentation_exchange_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py index 3377dc39ca..63e3bc6ea7 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/formats/dif/tests/test_handler.py @@ -1,6 +1,6 @@ from copy import deepcopy from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from pyld import jsonld @@ -365,17 +365,15 @@ class TestDIFFormatHandler(IsolatedAsyncioTestCase): async def asyncSetUp(self): - self.holder = async_mock.MagicMock() - self.wallet = async_mock.MagicMock(BaseWallet, autospec=True) + self.holder = mock.MagicMock() + self.wallet = mock.MagicMock(BaseWallet, autospec=True) self.session = InMemoryProfile.test_session( bind={VCHolder: self.holder, BaseWallet: self.wallet} ) self.profile = self.session.profile self.context = self.profile.context - setattr( - self.profile, "session", async_mock.MagicMock(return_value=self.session) - ) + setattr(self.profile, "session", mock.MagicMock(return_value=self.session)) # Set custom document loader self.context.injector.bind_instance(DocumentLoader, custom_document_loader) @@ -601,10 +599,10 @@ async def test_create_pres(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -644,10 +642,10 @@ async def test_create_pres_pd_schema_uri(self): error_msg="error", ) request_data = {} - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -686,10 +684,10 @@ async def test_create_pres_prover_proof_spec(self): ) request_data = {} request_data["dif"] = dif_pres_spec - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -754,19 +752,19 @@ async def test_create_pres_prover_proof_spec_with_record_ids(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -848,19 +846,19 @@ async def test_create_pres_prover_proof_spec_with_reveal_doc(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -931,19 +929,19 @@ async def test_create_pres_one_of_filter(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -981,10 +979,10 @@ async def test_create_pres_no_challenge(self): error_msg="error", ) request_data = {} - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, request_data) @@ -1022,10 +1020,10 @@ async def test_create_pres_storage_not_found(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1069,10 +1067,10 @@ async def test_create_pres_pd_claim_format_ed255(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1112,10 +1110,10 @@ async def test_create_pres_pd_claim_format_bls12381g2(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1163,22 +1161,18 @@ async def test_verify_pres_sequence(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), + mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), ): output = await self.handler.verify_pres(record) assert output.verified - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=False) - ), + mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), ): output = await self.handler.verify_pres(record) assert output.verified == "false" @@ -1220,12 +1214,10 @@ async def test_verify_pres(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( test_module, "verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), + mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), ) as mock_vr: output = await self.handler.verify_pres(record) assert output.verified @@ -1413,10 +1405,10 @@ async def test_create_pres_cred_no_tag_query(self): error_msg="error", ) - with async_mock.patch.object( + with mock.patch.object( DIFPresExchHandler, "create_vp", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_create_vp: mock_create_vp.return_value = DIF_PRES output = await self.handler.create_pres(record, {}) @@ -1836,8 +1828,8 @@ async def test_verify_received_limit_disclosure_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -1915,8 +1907,8 @@ async def test_verify_received_limit_disclosure_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_1 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -1967,8 +1959,8 @@ async def test_verify_received_pres_invalid_jsonpath(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2020,8 +2012,8 @@ async def test_verify_received_pres_no_match_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2073,8 +2065,8 @@ async def test_verify_received_pres_no_match_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2123,8 +2115,8 @@ async def test_verify_received_pres_limit_disclosure_fail_a(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2173,8 +2165,8 @@ async def test_verify_received_pres_limit_disclosure_fail_b(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() ) as mock_log_err: await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) mock_log_err.assert_called_once() @@ -2263,10 +2255,10 @@ async def test_verify_received_pres_fail_schema_filter(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() - ) as mock_log_err, async_mock.patch.object( - jsonld, "expand", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() + ) as mock_log_err, mock.patch.object( + jsonld, "expand", mock.MagicMock() ) as mock_jsonld_expand: mock_jsonld_expand.return_value = EXPANDED_CRED_FHIR_TYPE_2 await self.handler.receive_pres(message=dif_pres, pres_ex_record=record) @@ -2275,9 +2267,7 @@ async def test_verify_received_pres_fail_schema_filter(self): async def test_create_pres_catch_typeerror(self): self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock(side_effect=TypeError) - ), + mock.MagicMock(search_credentials=mock.MagicMock(side_effect=TypeError)), ) test_pd = deepcopy(DIF_PRES_REQUEST_B) dif_pres_request = V20PresRequest( @@ -2332,10 +2322,10 @@ async def test_create_pres_catch_diferror(self): ] self.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=cred_list) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=cred_list) ) ) ), @@ -2366,8 +2356,8 @@ async def test_create_pres_catch_diferror(self): auto_present=True, error_msg="error", ) - with async_mock.patch.object( - DIFPresExchHandler, "create_vp", async_mock.MagicMock() + with mock.patch.object( + DIFPresExchHandler, "create_vp", mock.MagicMock() ) as mock_create_vp: mock_create_vp.side_effect = DIFPresExchError("TEST") await self.handler.create_pres(record) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py index 438a833bb3..0f1b42277e 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_ack_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,20 +17,20 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() session = request_context.session() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() request_context.message = V20PresAck() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresAckHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -44,12 +44,12 @@ async def test_called(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_ack = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_ack = mock.AsyncMock() request_context.message = V20PresAck() request_context.connection_ready = False handler = test_module.V20PresAckHandler() @@ -64,8 +64,8 @@ async def test_called_no_connection_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py index 76b31a36d1..99371ec03e 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -17,21 +17,19 @@ async def test_called(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = False - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -47,22 +45,20 @@ async def test_called_auto_verify(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres = async_mock.AsyncMock() - mock_pres_mgr.return_value.verify_pres = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres = mock.AsyncMock() + mock_pres_mgr.return_value.verify_pres = mock.AsyncMock() request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -78,34 +74,30 @@ async def test_called_auto_verify_x(self): request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_verify_presentation"] = True - oob_record = async_mock.MagicMock() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=oob_record - ) + oob_record = mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock(return_value=oob_record) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value = async_mock.MagicMock( - receive_pres=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value = mock.MagicMock( + receive_pres=mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ), - verify_pres=async_mock.AsyncMock(side_effect=test_module.LedgerError()), + verify_pres=mock.AsyncMock(side_effect=test_module.LedgerError()), ) request_context.message = V20Pres() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py index 8b3e3175d6..998cd77c37 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_problem_report_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -14,12 +14,12 @@ class TestV20PresProblemReportHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock() request_context.message = V20PresProblemReport( description={ "en": "Change of plans", @@ -39,12 +39,12 @@ async def test_called(self): async def test_called_x(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_problem_report = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_problem_report = mock.AsyncMock( side_effect=test_module.StorageError("Disk full") ) request_context.message = V20PresProblemReport( diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py index 6f1295d08e..87cc342853 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_proposal_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......messaging.request_context import RequestContext @@ -13,19 +13,19 @@ class TestV20PresProposalHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = False - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + return_value=mock.MagicMock() ) request_context.message = V20PresProposal() request_context.connection_ready = True - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() handler = test_module.V20PresProposalHandler() responder = MockResponder() await handler.handle(request_context, responder) @@ -38,19 +38,19 @@ async def test_called(self): async def test_called_auto_request(self): request_context = RequestContext.test_context() - request_context.message = async_mock.MagicMock() - request_context.connection_record = async_mock.MagicMock() + request_context.message = mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( return_value="presentation_exchange_record" ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( return_value=( mock_pres_mgr.return_value.receive_pres_proposal.return_value, "presentation_request_message", @@ -77,21 +77,19 @@ async def test_called_auto_request(self): async def test_called_auto_request_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() - request_context.message = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() + request_context.message = mock.MagicMock() request_context.message.comment = "hello world" request_context.message_receipt = MessageReceipt() request_context.settings["debug.auto_respond_presentation_proposal"] = True - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) - mock_pres_mgr.return_value.create_bound_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_bound_request = mock.AsyncMock( side_effect=test_module.LedgerError() ) @@ -100,8 +98,8 @@ async def test_called_auto_request_x(self): handler = test_module.V20PresProposalHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() @@ -109,12 +107,12 @@ async def test_called_auto_request_x(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_proposal = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_proposal = mock.AsyncMock() request_context.message = V20PresProposal() request_context.connection_ready = False handler = test_module.V20PresProposalHandler() diff --git a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py index efc8a3dbde..588d747632 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/handlers/tests/test_pres_request_handler.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.oob_processor import OobMessageProcessor @@ -183,17 +183,17 @@ class TestPresRequestHandler(IsolatedAsyncioTestCase): async def test_called(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=async_mock.MagicMock() + request_context.message.attachment = mock.MagicMock( + return_value=mock.MagicMock() ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -214,17 +214,17 @@ async def test_called(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -242,17 +242,17 @@ async def test_called(self): async def test_called_not_found(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message_receipt = MessageReceipt() request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=async_mock.MagicMock() + request_context.message.attachment = mock.MagicMock( + return_value=mock.MagicMock() ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -273,18 +273,18 @@ async def test_called_not_found(self): auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( side_effect=StorageNotFoundError ) mock_px_rec_cls.return_value = px_rec_instance - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( - return_value=async_mock.MagicMock(auto_present=False) + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( + return_value=mock.MagicMock(auto_present=False) ) request_context.connection_ready = True @@ -302,12 +302,10 @@ async def test_called_not_found(self): async def test_called_auto_present_x(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( @@ -321,41 +319,39 @@ async def test_called_auto_present_x(self): AttachDecorator.data_base64(INDY_PROOF_REQ, ident="indy") ], ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( side_effect=test_module.IndyHolderError() ) @@ -363,25 +359,23 @@ async def test_called_auto_present_x(self): handler = test_module.V20PresRequestHandler() responder = MockResponder() - with async_mock.patch.object( - handler._logger, "exception", async_mock.MagicMock() + with mock.patch.object( + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() async def test_called_auto_present_indy(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -402,29 +396,27 @@ async def test_called_auto_present_indy(self): auto_present=True, ) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(mock_px_rec, "pres message") ) @@ -449,7 +441,7 @@ async def test_called_auto_present_indy(self): async def test_called_auto_present_dif(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -459,14 +451,12 @@ async def test_called_auto_present_dif(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=DIF_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=DIF_PROOF_REQ) request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) @@ -485,20 +475,20 @@ async def test_called_auto_present_dif(self): pres_proposal=pres_proposal, auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -521,7 +511,7 @@ async def test_called_auto_present_dif(self): async def test_called_auto_present_no_preview(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -531,21 +521,19 @@ async def test_called_auto_present_no_preview(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -555,20 +543,20 @@ async def test_called_auto_present_no_preview(self): ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -591,12 +579,10 @@ async def test_called_auto_present_no_preview(self): async def test_called_auto_present_pred_no_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest() - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( formats=[ @@ -609,40 +595,40 @@ async def test_called_auto_present_pred_no_match(self): AttachDecorator.data_base64(INDY_PROOF_REQ, ident="indy") ], ) - mock_px_rec = async_mock.MagicMock( + mock_px_rec = mock.MagicMock( pres_proposal=pres_proposal.serialize(), auto_present=True, - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=[]) + mock.AsyncMock(return_value=[]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = mock_px_rec - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=mock_px_rec ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( side_effect=test_indy_handler.V20PresFormatHandlerError ) request_context.connection_ready = True @@ -661,7 +647,7 @@ async def test_called_auto_present_pred_no_match(self): async def test_called_auto_present_pred_single_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -671,42 +657,40 @@ async def test_called_auto_present_pred_single_match(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( + request_context.message.attachment = mock.MagicMock( return_value=INDY_PROOF_REQ_PRED ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( - return_value=[{"cred_info": {"referent": "dummy-0"}}] - ) + mock.AsyncMock(return_value=[{"cred_info": {"referent": "dummy-0"}}]) ) ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -729,7 +713,7 @@ async def test_called_auto_present_pred_single_match(self): async def test_called_auto_present_pred_multi_match(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -739,22 +723,22 @@ async def test_called_auto_present_pred_multi_match(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( + request_context.message.attachment = mock.MagicMock( return_value=INDY_PROOF_REQ_PRED ) request_context.message_receipt = MessageReceipt() px_rec_instance = test_module.V20PresExRecord(auto_present=True) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ {"cred_info": {"referent": "dummy-0"}}, {"cred_info": {"referent": "dummy-1"}}, @@ -764,20 +748,20 @@ async def test_called_auto_present_pred_multi_match(self): ) request_context.injector.bind_instance(IndyHolder, mock_holder) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -800,7 +784,7 @@ async def test_called_auto_present_pred_multi_match(self): async def test_called_auto_present_multi_cred_match_reft(self): request_context = RequestContext.test_context() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() request_context.connection_record.connection_id = "dummy" request_context.message = V20PresRequest( formats=[ @@ -810,9 +794,7 @@ async def test_called_auto_present_multi_cred_match_reft(self): ) ] ) - request_context.message.attachment = async_mock.MagicMock( - return_value=INDY_PROOF_REQ - ) + request_context.message.attachment = mock.MagicMock(return_value=INDY_PROOF_REQ) request_context.message_receipt = MessageReceipt() pres_proposal = V20PresProposal( formats=[ @@ -826,16 +808,16 @@ async def test_called_auto_present_multi_cred_match_reft(self): ], ) - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( - return_value=async_mock.MagicMock() + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( + return_value=mock.MagicMock() ) ) request_context.injector.bind_instance(OobMessageProcessor, mock_oob_processor) - mock_holder = async_mock.MagicMock( + mock_holder = mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ { "cred_info": { @@ -880,20 +862,20 @@ async def test_called_auto_present_multi_cred_match_reft(self): pres_proposal=pres_proposal.serialize(), auto_present=True, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: mock_pres_ex_rec_cls.return_value = px_rec_instance - mock_pres_ex_rec_cls.retrieve_by_tag_filter = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_tag_filter = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock( + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock( return_value=px_rec_instance ) - mock_pres_mgr.return_value.create_pres = async_mock.AsyncMock( + mock_pres_mgr.return_value.create_pres = mock.AsyncMock( return_value=(px_rec_instance, "pres message") ) request_context.connection_ready = True @@ -917,12 +899,12 @@ async def test_called_auto_present_multi_cred_match_reft(self): async def test_called_not_ready(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - request_context.connection_record = async_mock.MagicMock() + request_context.connection_record = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.receive_pres_request = async_mock.AsyncMock() + mock_pres_mgr.return_value.receive_pres_request = mock.AsyncMock() request_context.message = V20PresRequest() request_context.connection_ready = False handler = test_module.V20PresRequestHandler() @@ -940,8 +922,8 @@ async def test_no_conn_no_oob(self): request_context = RequestContext.test_context() request_context.message_receipt = MessageReceipt() - mock_oob_processor = async_mock.MagicMock( - find_oob_record_for_inbound_message=async_mock.AsyncMock( + mock_oob_processor = mock.MagicMock( + find_oob_record_for_inbound_message=mock.AsyncMock( # No oob record found return_value=None ) diff --git a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py index 4bfbbbd249..977114228b 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/models/tests/test_record.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ......core.in_memory import InMemoryProfile @@ -127,10 +127,10 @@ async def test_save_error_state(self): record.state = V20PresExRecord.STATE_PROPOSAL_RECEIVED await record.save(session) - with async_mock.patch.object( - record, "save", async_mock.AsyncMock() - ) as mock_save, async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() + with mock.patch.object( + record, "save", mock.AsyncMock() + ) as mock_save, mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() ) as mock_log_exc: mock_save.side_effect = test_module.StorageError() await record.save_error_state(session, reason="testing") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py index 9e2e5ade6a..810858dba5 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_manager.py @@ -3,7 +3,7 @@ from copy import deepcopy from time import time -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .....core.in_memory import InMemoryProfile @@ -387,15 +387,13 @@ async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -411,7 +409,7 @@ async def asyncSetUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -420,7 +418,7 @@ async def asyncSetUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -432,16 +430,16 @@ async def asyncSetUp(self): injector.bind_instance(BaseLedger, self.ledger) injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), ) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -456,7 +454,7 @@ async def asyncSetUp(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -466,8 +464,8 @@ async def asyncSetUp(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -478,11 +476,9 @@ async def asyncSetUp(self): ) injector.bind_instance(IndyHolder, self.holder) - Verifier = async_mock.MagicMock(IndyVerifier, autospec=True) + Verifier = mock.MagicMock(IndyVerifier, autospec=True) self.verifier = Verifier() - self.verifier.verify_presentation = async_mock.AsyncMock( - return_value=("true", []) - ) + self.verifier.verify_presentation = mock.AsyncMock(return_value=("true", [])) injector.bind_instance(IndyVerifier, self.verifier) self.manager = V20PresManager(self.profile) @@ -527,11 +523,9 @@ async def test_create_exchange_for_proposal(self): ] ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( - V20PresProposal, "serialize", autospec=True - ): + ) as save_ex, mock.patch.object(V20PresProposal, "serialize", autospec=True): px_rec = await self.manager.create_exchange_for_proposal( CONN_ID, proposal, @@ -547,13 +541,13 @@ async def test_create_exchange_for_proposal(self): assert px_rec.auto_remove is True async def test_receive_proposal(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) proposal = V20PresProposal( formats=[ V20PresFormat(attach_id="indy", format_=V20PresFormat.Format.INDY.aries) ] ) - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec = await self.manager.receive_pres_proposal( proposal, connection_record, @@ -582,7 +576,7 @@ async def test_create_bound_request_a(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.AsyncMock() + px_rec.save = mock.AsyncMock() request_data = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -616,7 +610,7 @@ async def test_create_bound_request_b(self): pres_proposal=proposal.serialize(), role=V20PresExRecord.ROLE_VERIFIER, ) - px_rec.save = async_mock.AsyncMock() + px_rec.save = mock.AsyncMock() (ret_px_rec, pres_req_msg) = await self.manager.create_bound_request( pres_ex_record=px_rec, comment=comment, @@ -674,7 +668,7 @@ async def test_create_pres_catch_diferror(self): ], ).serialize(), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresFormatHandler, "create_pres", autospec=True ) as mock_create_pres: mock_create_pres.return_value = None @@ -689,7 +683,7 @@ async def test_create_pres_catch_diferror(self): ) async def test_receive_pres_catch_diferror(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_x = V20Pres( formats=[ V20PresFormat( @@ -721,9 +715,9 @@ async def test_receive_pres_catch_diferror(self): pres_request=pres_req.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( DIFPresFormatHandler, "receive_pres", autospec=True - ) as mock_receive_pres, async_mock.patch.object( + ) as mock_receive_pres, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: mock_receive_pres.return_value = False @@ -750,7 +744,7 @@ async def test_create_exchange_for_request(self): ) pres_req.assign_thread_id("dummy") - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec = await self.manager.create_exchange_for_request( CONN_ID, pres_req, @@ -767,7 +761,7 @@ async def test_create_exchange_for_request(self): async def test_receive_pres_request(self): px_rec_in = V20PresExRecord() - with async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + with mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.receive_pres_request(px_rec_in) save_ex.assert_called_once() @@ -788,21 +782,21 @@ async def test_create_pres_indy(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -842,23 +836,23 @@ async def test_create_pres_indy_and_dif(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator_indy, async_mock.patch.object( + ) as mock_attach_decorator_indy, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True - ) as mock_rr, async_mock.patch.object( + ) as mock_rr, mock.patch.object( DIFPresFormatHandler, "create_pres", autospec=True ) as mock_create_pres: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator_indy.data_base64 = async_mock.MagicMock( + mock_attach_decorator_indy.data_base64 = mock.MagicMock( return_value=mock_attach_decorator_indy ) @@ -899,29 +893,29 @@ async def test_create_pres_proof_req_non_revoc_interval_none(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object( + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -955,21 +949,21 @@ async def test_create_pres_self_asserted(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -989,12 +983,10 @@ async def test_create_pres_self_asserted(self): assert px_rec_out.state == V20PresExRecord.STATE_PRESENTATION_SENT async def test_create_pres_no_revocation(self): - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": None}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -1014,9 +1006,9 @@ async def test_create_pres_no_revocation(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1029,7 +1021,7 @@ async def test_create_pres_no_revocation(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1039,17 +1031,17 @@ async def test_create_pres_no_revocation(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") + self.holder.create_presentation = mock.AsyncMock(return_value="{}") self.profile.context.injector.bind_instance(IndyHolder, self.holder) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( - test_indy_util_module.LOGGER, "info", async_mock.MagicMock() + ) as mock_attach_decorator, mock.patch.object( + test_indy_util_module.LOGGER, "info", mock.MagicMock() ) as mock_log_info: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -1099,9 +1091,9 @@ async def test_create_pres_bad_revoc_state(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1115,7 +1107,7 @@ async def test_create_pres_bad_revoc_state(self): ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1125,31 +1117,31 @@ async def test_create_pres_bad_revoc_state(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( side_effect=test_indy_util_module.IndyHolderError( "Problem", {"message": "Nope"} ) ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True - ) as mock_rr, async_mock.patch.object( - test_indy_util_module.LOGGER, "error", async_mock.MagicMock() + ) as mock_rr, mock.patch.object( + test_indy_util_module.LOGGER, "error", mock.MagicMock() ) as mock_log_error: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) request_data = {} @@ -1172,9 +1164,9 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - Holder = async_mock.MagicMock(IndyHolder, autospec=True) + Holder = mock.MagicMock(IndyHolder, autospec=True) self.holder = Holder() - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": { @@ -1201,7 +1193,7 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) ) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - self.holder.get_credential = async_mock.AsyncMock( + self.holder.get_credential = mock.AsyncMock( return_value=json.dumps( { "schema_id": S_ID, @@ -1211,8 +1203,8 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): } ) ) - self.holder.create_presentation = async_mock.AsyncMock(return_value="{}") - self.holder.create_revocation_state = async_mock.AsyncMock( + self.holder.create_presentation = mock.AsyncMock(return_value="{}") + self.holder.create_revocation_state = mock.AsyncMock( return_value=json.dumps( { "witness": {"omega": "1 ..."}, @@ -1223,21 +1215,21 @@ async def test_create_pres_multi_matching_proposal_creds_names(self): ) self.profile.context.injector.bind_instance(IndyHolder, self.holder) - more_magic_rr = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock( + more_magic_rr = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock( return_value="/tmp/sample/tails/path" ) ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True - ) as mock_attach_decorator, async_mock.patch.object( + ) as mock_attach_decorator, mock.patch.object( test_indy_util_module, "RevocationRegistry", autospec=True ) as mock_rr: - mock_rr.from_definition = async_mock.MagicMock(return_value=more_magic_rr) + mock_rr.from_definition = mock.MagicMock(return_value=more_magic_rr) - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) @@ -1269,7 +1261,7 @@ async def test_no_matching_creds_for_proof_req(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds with self.assertRaises(ValueError): @@ -1277,7 +1269,7 @@ async def test_no_matching_creds_for_proof_req(self): INDY_PROOF_REQ_NAMES, preview=None, holder=self.holder ) - get_creds = async_mock.AsyncMock( + get_creds = mock.AsyncMock( return_value=( { "cred_info": {"referent": "dummy_reft"}, @@ -1309,15 +1301,15 @@ async def test_no_matching_creds_indy_handler(self): ], ) px_rec_in = V20PresExRecord(pres_request=pres_request.serialize()) - get_creds = async_mock.AsyncMock(return_value=()) + get_creds = mock.AsyncMock(return_value=()) self.holder.get_credentials_for_presentation_request_by_referent = get_creds - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( test_indy_handler, "AttachDecorator", autospec=True ) as mock_attach_decorator: - mock_attach_decorator.data_base64 = async_mock.MagicMock( + mock_attach_decorator.data_base64 = mock.MagicMock( return_value=mock_attach_decorator ) request_data = {} @@ -1330,7 +1322,7 @@ async def test_no_matching_creds_indy_handler(self): assert "No matching Indy" in str(context.exception) async def test_receive_pres(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_proposal = V20PresProposal( formats=[ V20PresFormat( @@ -1381,14 +1373,14 @@ async def test_receive_pres(self): assert by_format.get("pres_proposal").get("indy") == INDY_PROOF_REQ_NAME assert by_format.get("pres_request").get("indy") == INDY_PROOF_REQ_NAME - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1401,7 +1393,7 @@ async def test_receive_pres(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) pres_proposal = V20PresProposal( formats=[ V20PresFormat( @@ -1456,14 +1448,14 @@ async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): assert by_format.get("pres_proposal").get("indy") == INDY_PROOF_REQ_NAME assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1476,7 +1468,7 @@ async def test_receive_pres_receive_pred_value_mismatch_punt_to_indy(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_indy_no_predicate_restrictions(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -1538,14 +1530,14 @@ async def test_receive_pres_indy_no_predicate_restrictions(self): assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1558,7 +1550,7 @@ async def test_receive_pres_indy_no_predicate_restrictions(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_indy_no_attr_restrictions(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = { "name": PROOF_REQ_NAME, "version": PROOF_REQ_VERSION, @@ -1614,14 +1606,14 @@ async def test_receive_pres_indy_no_attr_restrictions(self): assert by_format.get("pres_request").get("indy") == indy_proof_req - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True - ) as retrieve_ex, async_mock.patch.object( + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.side_effect = [px_rec_dummy] px_rec_out = await self.manager.receive_pres(pres, connection_record, None) @@ -1634,7 +1626,7 @@ async def test_receive_pres_indy_no_attr_restrictions(self): assert px_rec_out.state == (V20PresExRecord.STATE_PRESENTATION_RECEIVED) async def test_receive_pres_bait_and_switch_attr_name(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAME) indy_proof_req["requested_attributes"]["0_screencapture_uuid"]["restrictions"][ 0 @@ -1683,9 +1675,9 @@ async def test_receive_pres_bait_and_switch_attr_name(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1739,9 +1731,9 @@ async def test_receive_pres_bait_and_switch_attr_name(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1750,7 +1742,7 @@ async def test_receive_pres_bait_and_switch_attr_name(self): assert "Presentation referent" in str(context.exception) async def test_receive_pres_bait_and_switch_attr_names(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAMES) indy_proof_req["requested_attributes"]["0_player_uuid"]["restrictions"][0][ "attr::screenCapture::value" @@ -1798,9 +1790,9 @@ async def test_receive_pres_bait_and_switch_attr_names(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1854,9 +1846,9 @@ async def test_receive_pres_bait_and_switch_attr_names(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1865,7 +1857,7 @@ async def test_receive_pres_bait_and_switch_attr_names(self): assert "Presentation referent" in str(context.exception) async def test_receive_pres_bait_and_switch_pred(self): - connection_record = async_mock.MagicMock(connection_id=CONN_ID) + connection_record = mock.MagicMock(connection_id=CONN_ID) indy_proof_req = deepcopy(INDY_PROOF_REQ_NAME) indy_proof_req["requested_predicates"] = {} pres_proposal = V20PresProposal( @@ -1911,9 +1903,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -1969,9 +1961,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2027,9 +2019,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2085,9 +2077,9 @@ async def test_receive_pres_bait_and_switch_pred(self): pres_request=pres_request.serialize(), pres=pres_x.serialize(), ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2129,13 +2121,13 @@ async def test_verify_pres(self): ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() @@ -2189,34 +2181,30 @@ async def test_verify_pres_indy_and_dif(self): ) self.profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch.object(V20PresExRecord, "save", autospec=True) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) save_ex.assert_called_once() assert px_rec_out.state == (V20PresExRecord.STATE_DONE) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), - ), async_mock.patch( + mock.AsyncMock(return_value=("test_ledger_id", self.ledger)), + ), mock.patch( "aries_cloudagent.vc.vc_ld.verify.verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=False) - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=PresentationVerificationResult(verified=False)), + ), mock.patch.object( IndyVerifier, "verify_presentation", - async_mock.AsyncMock( - return_value=PresentationVerificationResult(verified=True) - ), - ), async_mock.patch.object( + mock.AsyncMock(return_value=PresentationVerificationResult(verified=True)), + ), mock.patch.object( V20PresExRecord, "save", autospec=True ) as save_ex: px_rec_out = await self.manager.verify_pres(px_rec_in) @@ -2259,14 +2247,14 @@ async def test_send_pres_ack_no_responder(self): await self.manager.send_pres_ack(px_rec) async def test_receive_pres_ack_a(self): - conn_record = async_mock.MagicMock(connection_id=CONN_ID) + conn_record = mock.MagicMock(connection_id=CONN_ID) px_rec_dummy = V20PresExRecord() - message = async_mock.MagicMock() + message = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2276,14 +2264,14 @@ async def test_receive_pres_ack_a(self): assert px_rec_out.state == V20PresExRecord.STATE_DONE async def test_receive_pres_ack_b(self): - conn_record = async_mock.MagicMock(connection_id=CONN_ID) + conn_record = mock.MagicMock(connection_id=CONN_ID) px_rec_dummy = V20PresExRecord() - message = async_mock.MagicMock(_verification_result="true") + message = mock.MagicMock(_verification_result="true") - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", autospec=True ) as retrieve_ex: retrieve_ex.return_value = px_rec_dummy @@ -2310,16 +2298,16 @@ async def test_receive_problem_report(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "save", autospec=True - ) as save_ex, async_mock.patch.object( + ) as save_ex, mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), - ) as retrieve_ex, async_mock.patch.object( + mock.AsyncMock(), + ) as retrieve_ex, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), + mock.MagicMock(return_value=self.profile.session()), ) as session: retrieve_ex.return_value = stored_exchange @@ -2352,10 +2340,10 @@ async def test_receive_problem_report_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( V20PresExRecord, "retrieve_by_tag_filter", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as retrieve_ex: retrieve_ex.side_effect = StorageNotFoundError("No such record") diff --git a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py index fa794969ac..b366b9c6ef 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/tests/test_routes.py @@ -1,6 +1,6 @@ from copy import deepcopy from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError from time import time from unittest.mock import ANY @@ -130,15 +130,13 @@ def setUp(self): self.profile = self.context.profile injector = self.profile.context.injector - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_schema = async_mock.AsyncMock( - return_value=async_mock.MagicMock() - ) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_schema = mock.AsyncMock(return_value=mock.MagicMock()) + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": {"...": "..."}}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock( + self.ledger.get_revoc_reg_def = mock.AsyncMock( return_value={ "ver": "1.0", "id": RR_ID, @@ -154,7 +152,7 @@ def setUp(self): }, } ) - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -163,7 +161,7 @@ def setUp(self): NOW, ) ) - self.ledger.get_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.get_revoc_reg_entry = mock.AsyncMock( return_value=( { "ver": "1.0", @@ -176,9 +174,9 @@ def setUp(self): self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -249,17 +247,15 @@ async def test_present_proof_list(self): "state": "dummy", } - mock_pres_ex_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_pres_ex_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.query = async_mock.AsyncMock( + mock_pres_ex_rec_cls.query = mock.AsyncMock( return_value=[mock_pres_ex_rec_inst] ) @@ -276,10 +272,10 @@ async def test_present_proof_list_x(self): "state": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.query = async_mock.AsyncMock( + mock_pres_ex_rec_cls.query = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -289,10 +285,10 @@ async def test_present_proof_list_x(self): async def test_present_proof_credentials_list_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock() + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock() # Emulate storage not found (bad presentation exchange id) mock_pres_ex_rec_cls.retrieve_by_id.side_effect = StorageNotFoundError() @@ -309,18 +305,18 @@ async def test_present_proof_credentials_x(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(side_effect=test_module.IndyHolderError()) + mock.AsyncMock(side_effect=test_module.IndyHolderError()) ) ), ) - mock_px_rec = async_mock.MagicMock(save_error_state=async_mock.AsyncMock()) + mock_px_rec = mock.MagicMock(save_error_state=mock.AsyncMock()) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec ) @@ -337,20 +333,20 @@ async def test_present_proof_credentials_list_single_referent(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(return_value=returned_credentials) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.AsyncMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.AsyncMock() ) await test_module.present_proof_credentials_list(self.request) @@ -366,20 +362,20 @@ async def test_present_proof_credentials_list_multiple_referents(self): returned_credentials = [{"name": "Credential1"}, {"name": "Credential2"}] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( + mock.MagicMock( get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock(return_value=returned_credentials) + mock.AsyncMock(return_value=returned_credentials) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.return_value = async_mock.MagicMock( - retrieve_by_id=async_mock.AsyncMock() + mock_pres_ex_rec_cls.return_value = mock.MagicMock( + retrieve_by_id=mock.AsyncMock() ) await test_module.present_proof_credentials_list(self.request) @@ -392,23 +388,21 @@ async def test_present_proof_credentials_list_dif(self): self.request.query = {"extra_query": {}} returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -442,10 +436,10 @@ async def test_present_proof_credentials_list_dif(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -464,27 +458,21 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): self.request.query = {"extra_query": {}} returned_credentials = [ - async_mock.MagicMock( - cred_value={"name": "Credential1"}, record_id="test_1" - ), - async_mock.MagicMock( - cred_value={"name": "Credential2"}, record_id="test_2" - ), + mock.MagicMock(cred_value={"name": "Credential1"}, record_id="test_1"), + mock.MagicMock(cred_value={"name": "Credential2"}, record_id="test_2"), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -528,10 +516,10 @@ async def test_present_proof_credentials_list_dif_one_of_filter(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -556,23 +544,21 @@ async def test_present_proof_credentials_dif_no_tag_query(self): "required" ] = False returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -606,10 +592,10 @@ async def test_present_proof_credentials_dif_no_tag_query(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -634,23 +620,21 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): "limit_disclosure" ] returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -684,10 +668,10 @@ async def test_present_proof_credentials_single_ldp_vp_claim_format(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -712,23 +696,21 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): "limit_disclosure" ] returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), @@ -762,10 +744,10 @@ async def test_present_proof_credentials_double_ldp_vp_claim_format(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -820,21 +802,19 @@ async def test_present_proof_credentials_single_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -883,21 +863,19 @@ async def test_present_proof_credentials_double_ldp_vp_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -943,21 +921,19 @@ async def test_present_proof_credentials_list_limit_disclosure_no_bbs(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1006,21 +982,19 @@ async def test_present_proof_credentials_no_ldp_vp(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock(search_credentials=async_mock.AsyncMock()), + mock.MagicMock(search_credentials=mock.AsyncMock()), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1066,32 +1040,30 @@ async def test_present_proof_credentials_list_schema_uri(self): ) returned_credentials = [ - async_mock.MagicMock(cred_value={"name": "Credential1"}), - async_mock.MagicMock(cred_value={"name": "Credential2"}), + mock.MagicMock(cred_value={"name": "Credential1"}), + mock.MagicMock(cred_value={"name": "Credential2"}), ] self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock(return_value=returned_credentials) + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock(return_value=returned_credentials) ) ) ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: mock_pres_ex_rec_cls.retrieve_by_id.return_value = record await test_module.present_proof_credentials_list(self.request) @@ -1110,18 +1082,16 @@ async def test_present_proof_credentials_list_dif_error(self): self.profile.context.injector.bind_instance( IndyHolder, - async_mock.MagicMock( - get_credentials_for_presentation_request_by_referent=( - async_mock.AsyncMock() - ) + mock.MagicMock( + get_credentials_for_presentation_request_by_referent=(mock.AsyncMock()) ), ) self.profile.context.injector.bind_instance( VCHolder, - async_mock.MagicMock( - search_credentials=async_mock.MagicMock( - return_value=async_mock.MagicMock( - fetch=async_mock.AsyncMock( + mock.MagicMock( + search_credentials=mock.MagicMock( + return_value=mock.MagicMock( + fetch=mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) ) @@ -1157,10 +1127,10 @@ async def test_present_proof_credentials_list_dif_error(self): error_msg=None, ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: with self.assertRaises(test_module.web.HTTPBadRequest): mock_pres_ex_rec_cls.retrieve_by_id.return_value = record @@ -1169,14 +1139,14 @@ async def test_present_proof_credentials_list_dif_error(self): async def test_present_proof_retrieve(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ) ) @@ -1188,10 +1158,10 @@ async def test_present_proof_retrieve(self): async def test_present_proof_retrieve_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1201,16 +1171,16 @@ async def test_present_proof_retrieve_not_found(self): async def test_present_proof_retrieve_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - mock_pres_ex_rec_inst = async_mock.MagicMock( + mock_pres_ex_rec_inst = mock.MagicMock( connection_id="abc123", thread_id="thid123", - serialize=async_mock.MagicMock(side_effect=test_module.BaseModelError()), - save_error_state=async_mock.AsyncMock(), + serialize=mock.MagicMock(side_effect=test_module.BaseModelError()), + save_error_state=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_pres_ex_rec_cls: - mock_pres_ex_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_pres_ex_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_pres_ex_rec_inst ) @@ -1218,7 +1188,7 @@ async def test_present_proof_retrieve_x(self): await test_module.present_proof_retrieve(self.request) async def test_present_proof_send_proposal(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy-conn-id", "presentation_proposal": { @@ -1227,21 +1197,21 @@ async def test_present_proof_send_proposal(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr, async_mock.patch.object( + ) as mock_pres_mgr, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(is_ready=True) + mock_conn_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(is_ready=True) ) - mock_px_rec_inst = async_mock.MagicMock() - mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.AsyncMock(return_value=mock_px_rec_inst) + mock_px_rec_inst = mock.MagicMock() + mock_pres_mgr.return_value.create_exchange_for_proposal = mock.AsyncMock( + return_value=mock_px_rec_inst ) await test_module.present_proof_send_proposal(self.request) @@ -1250,12 +1220,12 @@ async def test_present_proof_send_proposal(self): ) async def test_present_proof_send_proposal_no_conn_record(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True ) as mock_conn_rec: - mock_conn_rec.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1263,36 +1233,32 @@ async def test_present_proof_send_proposal_no_conn_record(self): await test_module.present_proof_send_proposal(self.request) async def test_present_proof_send_proposal_not_ready(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresProposal", autospec=True ) as mock_proposal: - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(is_ready=False) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.present_proof_send_proposal(self.request) async def test_present_proof_send_proposal_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec, async_mock.patch.object( + ) as mock_conn_rec, mock.patch.object( test_module, "V20PresManager", autospec=True ) as mock_pres_mgr: - mock_pres_mgr.return_value.create_exchange_for_proposal = ( - async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( - side_effect=test_module.StorageError() - ), - save_error_state=async_mock.AsyncMock(), - ) + mock_pres_mgr.return_value.create_exchange_for_proposal = mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(side_effect=test_module.StorageError()), + save_error_state=mock.AsyncMock(), ) ) @@ -1303,27 +1269,25 @@ async def test_present_proof_create_request(self): indy_proof_req = deepcopy(INDY_PROOF_REQ) indy_proof_req.pop("nonce") # exercise _add_nonce() - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: indy_proof_req}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_request, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1335,28 +1299,28 @@ async def test_present_proof_create_request(self): ) async def test_present_proof_create_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "comment": "dummy", "presentation_request": {V20PresFormat.Format.INDY.api: INDY_PROOF_REQ}, } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_request, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock() - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock() + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -1366,7 +1330,7 @@ async def test_present_proof_create_request_x(self): await test_module.present_proof_create_request(self.request) async def test_present_proof_send_free_request(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1374,24 +1338,24 @@ async def test_present_proof_send_free_request(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( + ) as mock_pres_request, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_pres_ex_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_pres_ex_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock() - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock({"thread_id": "sample-thread-id"}) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock() + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock({"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( return_value=mock_px_rec_inst ) ) @@ -1403,14 +1367,12 @@ async def test_present_proof_send_free_request(self): ) async def test_present_proof_send_free_request_not_found(self): - self.request.json = async_mock.AsyncMock( - return_value={"connection_id": "dummy"} - ) + self.request.json = mock.AsyncMock(return_value={"connection_id": "dummy"}) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1418,15 +1380,15 @@ async def test_present_proof_send_free_request_not_found(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_not_ready(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"connection_id": "dummy", "proof_request": {}} ) - with async_mock.patch.object( - test_module, "ConnRecord", async_mock.MagicMock() + with mock.patch.object( + test_module, "ConnRecord", mock.MagicMock() ) as mock_conn_rec_cls: - mock_conn_rec_inst = async_mock.MagicMock(is_ready=False) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=False) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1434,7 +1396,7 @@ async def test_present_proof_send_free_request_not_ready(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_free_request_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "connection_id": "dummy", "comment": "dummy", @@ -1442,31 +1404,29 @@ async def test_present_proof_send_free_request_x(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresRequest", autospec=True - ) as mock_pres_request, async_mock.patch.object( + ) as mock_pres_request, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_conn_rec_inst = async_mock.MagicMock() - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock() + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_px_rec_inst = async_mock.MagicMock( - serialize=async_mock.MagicMock( - return_value={"thread_id": "sample-thread-id"} - ) + mock_px_rec_inst = mock.MagicMock( + serialize=mock.MagicMock(return_value={"thread_id": "sample-thread-id"}) ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_exchange_for_request=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock( + mock_pres_mgr_inst = mock.MagicMock( + create_exchange_for_request=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock( side_effect=test_module.StorageError() ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) ) ) @@ -1476,52 +1436,52 @@ async def test_present_proof_send_free_request_x(self): await test_module.present_proof_send_free_request(self.request) async def test_present_proof_send_bound_request(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_request = async_mock.MagicMock() + mock_pres_request = mock.MagicMock() - mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.AsyncMock( return_value=(mock_px_rec_inst, mock_pres_request) ) ) @@ -1533,39 +1493,39 @@ async def test_present_proof_send_bound_request(self): ) async def test_present_proof_send_bound_request_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1573,42 +1533,42 @@ async def test_present_proof_send_bound_request_not_found(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_not_ready(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=False, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) @@ -1616,13 +1576,13 @@ async def test_present_proof_send_bound_request_not_ready(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_px_rec_not_found(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) with self.assertRaises(test_module.web.HTTPNotFound) as context: @@ -1630,34 +1590,34 @@ async def test_present_proof_send_bound_request_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_bound_request_bad_state(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -1665,50 +1625,50 @@ async def test_present_proof_send_bound_request_bad_state(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_bound_request_x(self): - self.request.json = async_mock.AsyncMock(return_value={"trace": False}) + self.request.json = mock.AsyncMock(return_value={"trace": False}) self.request.match_info = {"pres_ex_id": "dummy"} self.profile.context.injector.bind_instance( BaseLedger, - async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(), - __aexit__=async_mock.AsyncMock(), + mock.MagicMock( + __aenter__=mock.AsyncMock(), + __aexit__=mock.AsyncMock(), ), ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PROPOSAL_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock( + mock_conn_rec_inst = mock.MagicMock( is_ready=True, ) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_bound_request=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_bound_request=mock.AsyncMock( side_effect=test_module.StorageError() ) ) @@ -1718,7 +1678,7 @@ async def test_present_proof_send_bound_request_x(self): await test_module.present_proof_send_bound_request(self.request) async def test_present_proof_send_presentation(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1733,39 +1693,39 @@ async def test_present_proof_send_presentation(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1778,7 +1738,7 @@ async def test_present_proof_send_presentation(self): async def test_present_proof_send_presentation_dif(self): proof_req = deepcopy(DIF_PROOF_REQ) proof_req["issuer_id"] = "test123" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "dif": proof_req, } @@ -1788,39 +1748,39 @@ async def test_present_proof_send_presentation_dif(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( - return_value=(mock_px_rec_inst, async_mock.MagicMock()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( + return_value=(mock_px_rec_inst, mock.MagicMock()) ) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -1831,7 +1791,7 @@ async def test_present_proof_send_presentation_dif(self): ) async def test_present_proof_send_presentation_dif_error(self): - self.request.json = async_mock.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) + self.request.json = mock.AsyncMock(return_value={"dif": DIF_PROOF_REQ}) self.request.match_info = { "pres_ex_id": "dummy", } @@ -1865,31 +1825,31 @@ async def test_present_proof_send_presentation_dif_error(self): ) self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=px_rec_instance ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock(side_effect=test_module.LedgerError()) + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock(side_effect=test_module.LedgerError()) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst with self.assertRaises(test_module.web.HTTPBadRequest): @@ -1897,7 +1857,7 @@ async def test_present_proof_send_presentation_dif_error(self): mock_response.assert_called_once_with(px_rec_instance.serialize()) async def test_present_proof_send_presentation_px_rec_not_found(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1911,10 +1871,10 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): "pres_ex_id": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -1923,7 +1883,7 @@ async def test_present_proof_send_presentation_px_rec_not_found(self): assert "no such record" in str(context.exception) async def test_present_proof_send_presentation_not_found(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1938,29 +1898,29 @@ async def test_present_proof_send_presentation_not_found(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -1968,7 +1928,7 @@ async def test_present_proof_send_presentation_not_found(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_not_ready(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -1983,37 +1943,37 @@ async def test_present_proof_send_presentation_not_ready(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock(is_ready=False) + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(is_ready=False) ) with self.assertRaises(test_module.web.HTTPForbidden): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_bad_state(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2027,17 +1987,17 @@ async def test_present_proof_send_presentation_bad_state(self): "pres_ex_id": "dummy", } - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id=None, state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2045,7 +2005,7 @@ async def test_present_proof_send_presentation_bad_state(self): await test_module.present_proof_send_presentation(self.request) async def test_present_proof_send_presentation_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "indy": { "comment": "dummy", @@ -2060,39 +2020,39 @@ async def test_present_proof_send_presentation_x(self): } self.profile.context.injector.bind_instance( IndyVerifier, - async_mock.MagicMock( - verify_presentation=async_mock.AsyncMock(), + mock.MagicMock( + verify_presentation=mock.AsyncMock(), ), ) - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( + ) as mock_px_rec_cls, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_REQUEST_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - create_pres=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + create_pres=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2109,32 +2069,32 @@ async def test_present_proof_send_presentation_x(self): async def test_present_proof_verify_presentation(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.AsyncMock(return_value=mock_px_rec_inst) + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.AsyncMock(return_value=mock_px_rec_inst) ) mock_pres_mgr_cls.return_value = mock_pres_mgr_inst @@ -2144,10 +2104,10 @@ async def test_present_proof_verify_presentation(self): async def test_present_proof_verify_presentation_px_rec_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError("no such record") ) @@ -2158,17 +2118,17 @@ async def test_present_proof_verify_presentation_px_rec_not_found(self): async def test_present_proof_verify_presentation_bad_state(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec_cls: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_DONE, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) @@ -2178,33 +2138,33 @@ async def test_present_proof_verify_presentation_bad_state(self): async def test_present_proof_verify_presentation_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "ConnRecord", autospec=True - ) as mock_conn_rec_cls, async_mock.patch.object( + ) as mock_conn_rec_cls, mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec_cls, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec_cls, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec_inst = async_mock.MagicMock( + mock_px_rec_inst = mock.MagicMock( connection_id="dummy", state=test_module.V20PresExRecord.STATE_PRESENTATION_RECEIVED, - serialize=async_mock.MagicMock( + serialize=mock.MagicMock( return_value={"thread_id": "sample-thread-id"} ), - save_error_state=async_mock.AsyncMock(), + save_error_state=mock.AsyncMock(), ) - mock_px_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_px_rec_inst ) - mock_conn_rec_inst = async_mock.MagicMock(is_ready=True) - mock_conn_rec_cls.retrieve_by_id = async_mock.AsyncMock( + mock_conn_rec_inst = mock.MagicMock(is_ready=True) + mock_conn_rec_cls.retrieve_by_id = mock.AsyncMock( return_value=mock_conn_rec_inst ) - mock_pres_mgr_inst = async_mock.MagicMock( - verify_pres=async_mock.AsyncMock( + mock_pres_mgr_inst = mock.MagicMock( + verify_pres=mock.AsyncMock( side_effect=[ test_module.LedgerError(), test_module.StorageError(), @@ -2219,25 +2179,23 @@ async def test_present_proof_verify_presentation_x(self): await test_module.present_proof_verify_presentation(self.request) async def test_present_proof_problem_report(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - magic_report = async_mock.MagicMock() + magic_report = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec, async_mock.patch.object( + ) as mock_px_rec, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( - save_error_state=async_mock.AsyncMock() - ) + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock(save_error_state=mock.AsyncMock()) ) mock_problem_report.return_value = magic_report @@ -2247,15 +2205,15 @@ async def test_present_proof_problem_report(self): mock_response.assert_called_once_with({}) async def test_present_proof_problem_report_bad_pres_ex_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -2263,19 +2221,19 @@ async def test_present_proof_problem_report_bad_pres_ex_id(self): await test_module.present_proof_problem_report(self.request) async def test_present_proof_problem_report_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"description": "Did I say no problem? I meant 'No! Problem.'"} ) self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresManager", autospec=True - ) as mock_pres_mgr_cls, async_mock.patch.object( - test_module, "problem_report_for_record", async_mock.MagicMock() - ) as mock_problem_report, async_mock.patch.object( + ) as mock_pres_mgr_cls, mock.patch.object( + test_module, "problem_report_for_record", mock.MagicMock() + ) as mock_problem_report, mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=test_module.StorageError() ) @@ -2285,16 +2243,16 @@ async def test_present_proof_problem_report_x(self): async def test_present_proof_remove(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True - ) as mock_px_rec, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + ) as mock_px_rec, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as mock_response: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.AsyncMock(), + delete_record=mock.AsyncMock(), ) ) @@ -2304,10 +2262,10 @@ async def test_present_proof_remove(self): async def test_present_proof_remove_px_rec_not_found(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( side_effect=StorageNotFoundError() ) @@ -2317,14 +2275,14 @@ async def test_present_proof_remove_px_rec_not_found(self): async def test_present_proof_remove_x(self): self.request.match_info = {"pres_ex_id": "dummy"} - with async_mock.patch.object( + with mock.patch.object( test_module, "V20PresExRecord", autospec=True ) as mock_px_rec: - mock_px_rec.retrieve_by_id = async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_px_rec.retrieve_by_id = mock.AsyncMock( + return_value=mock.MagicMock( state=test_module.V20PresExRecord.STATE_DONE, connection_id="dummy", - delete_record=async_mock.AsyncMock( + delete_record=mock.AsyncMock( side_effect=test_module.StorageError() ), ) @@ -2334,14 +2292,14 @@ async def test_present_proof_remove_x(self): await test_module.present_proof_remove(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] @@ -2425,7 +2383,7 @@ async def test_retrieve_uri_list_from_schema_filter(self): assert test_one_of_uri_groups == [["test123", "test321"]] async def test_send_presentation_no_specification(self): - self.request.json = async_mock.AsyncMock(return_value={"comment": "test"}) + self.request.json = mock.AsyncMock(return_value={"comment": "test"}) self.request.match_info = { "pres_ex_id": "dummy", } diff --git a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py index 6cac3fcb96..a645da0bd6 100644 --- a/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py +++ b/aries_cloudagent/protocols/routing/v1_0/handlers/tests/test_forward_handler.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock import json from ......connections.models.connection_target import ConnectionTarget @@ -29,24 +29,22 @@ async def test_handle(self): handler = test_module.ForwardHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "RoutingManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "ConnectionManager", autospec=True - ) as mock_connection_mgr, async_mock.patch.object( + ) as mock_connection_mgr, mock.patch.object( self.context.profile, "notify", autospec=True ) as mock_notify: - mock_mgr.return_value.get_recipient = async_mock.AsyncMock( + mock_mgr.return_value.get_recipient = mock.AsyncMock( return_value=RouteRecord(connection_id="dummy") ) - mock_connection_mgr.return_value.get_connection_targets = ( - async_mock.AsyncMock( - return_value=[ - ConnectionTarget( - recipient_keys=["recip_key"], - ) - ] - ) + mock_connection_mgr.return_value.get_connection_targets = mock.AsyncMock( + return_value=[ + ConnectionTarget( + recipient_keys=["recip_key"], + ) + ] ) await handler.handle(self.context, responder) @@ -77,10 +75,10 @@ async def test_handle_cannot_resolve_recipient(self): handler = test_module.ForwardHandler() responder = MockResponder() - with async_mock.patch.object( + with mock.patch.object( test_module, "RoutingManager", autospec=True ) as mock_mgr: - mock_mgr.return_value.get_recipient = async_mock.AsyncMock( + mock_mgr.return_value.get_recipient = mock.AsyncMock( side_effect=test_module.RoutingManagerError() ) diff --git a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py index 2abf1a81e5..a3a6b4af35 100644 --- a/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py +++ b/aries_cloudagent/protocols/routing/v1_0/tests/test_routing_manager.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from marshmallow import ValidationError @@ -70,8 +70,8 @@ async def test_get_recipient_no_verkey(self): assert "Must pass non-empty" in str(context.exception) async def test_get_recipient_duplicate_routes(self): - with async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.AsyncMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageDuplicateError() with self.assertRaises(RouteNotFoundError) as context: @@ -79,8 +79,8 @@ async def test_get_recipient_duplicate_routes(self): assert "More than one route" in str(context.exception) async def test_get_recipient_no_routes(self): - with async_mock.patch.object( - RouteRecord, "retrieve_by_recipient_key", async_mock.AsyncMock() + with mock.patch.object( + RouteRecord, "retrieve_by_recipient_key", mock.AsyncMock() ) as mock_retrieve: mock_retrieve.side_effect = StorageNotFoundError() with self.assertRaises(RouteNotFoundError) as context: diff --git a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py index 7534548007..b69fb53b47 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/trustping/v1_0/tests/test_routes.py @@ -1,5 +1,5 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from .....admin.request_context import AdminRequestContext @@ -12,9 +12,9 @@ def setUp(self): self.context = AdminRequestContext.test_context(self.session_inject) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -22,62 +22,56 @@ def setUp(self): ) async def test_connections_send_ping(self): - self.request.json = async_mock.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( - test_module, "Ping", async_mock.MagicMock() - ) as mock_ping, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( + test_module, "Ping", mock.MagicMock() + ) as mock_ping, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: - mock_ping.return_value = async_mock.MagicMock(_thread_id="dummy") - mock_retrieve.return_value = async_mock.MagicMock(is_ready=True) + mock_ping.return_value = mock.MagicMock(_thread_id="dummy") + mock_retrieve.return_value = mock.MagicMock(is_ready=True) result = await test_module.connections_send_ping(self.request) json_response.assert_called_once_with({"thread_id": "dummy"}) assert result is json_response.return_value async def test_connections_send_ping_no_conn(self): - self.request.json = async_mock.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: mock_retrieve.side_effect = test_module.StorageNotFoundError() with self.assertRaises(test_module.web.HTTPNotFound): await test_module.connections_send_ping(self.request) async def test_connections_send_ping_not_ready(self): - self.request.json = async_mock.AsyncMock( - return_value={"comment": "some comment"} - ) + self.request.json = mock.AsyncMock(return_value={"comment": "some comment"}) self.request.match_info = {"conn_id": "dummy"} - with async_mock.patch.object( - test_module.ConnRecord, "retrieve_by_id", async_mock.AsyncMock() - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.MagicMock() + with mock.patch.object( + test_module.ConnRecord, "retrieve_by_id", mock.AsyncMock() + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.MagicMock() ) as json_response: - mock_retrieve.return_value = async_mock.MagicMock(is_ready=False) + mock_retrieve.return_value = mock.MagicMock(is_ready=False) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.connections_send_ping(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/resolver/default/tests/test_indy.py b/aries_cloudagent/resolver/default/tests/test_indy.py index e614ee832c..128684b93f 100644 --- a/aries_cloudagent/resolver/default/tests/test_indy.py +++ b/aries_cloudagent/resolver/default/tests/test_indy.py @@ -2,7 +2,7 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -31,14 +31,14 @@ def resolver(): @pytest.fixture def ledger(): """Ledger fixture.""" - ledger = async_mock.MagicMock(spec=BaseLedger) - ledger.get_all_endpoints_for_did = async_mock.AsyncMock( + ledger = mock.MagicMock(spec=BaseLedger) + ledger.get_all_endpoints_for_did = mock.AsyncMock( return_value={ "endpoint": "https://github.com/", "profile": "https://example.com/profile", } ) - ledger.get_key_for_did = async_mock.AsyncMock(return_value="key") + ledger.get_key_for_did = mock.AsyncMock(return_value="key") yield ledger @@ -48,8 +48,8 @@ def profile(ledger): profile = InMemoryProfile.test_profile() profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock(return_value=(None, ledger)) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, ledger)) ), ) yield profile @@ -83,12 +83,12 @@ async def test_resolve_multitenant( """Test resolve method.""" profile.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=("test_ledger_id", ledger)), + mock.AsyncMock(return_value=("test_ledger_id", ledger)), ): assert await resolver.resolve(profile, TEST_DID0) @@ -99,10 +99,8 @@ async def test_resolve_x_no_ledger( """Test resolve method with no ledger.""" profile.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( - return_value=(None, None) - ) + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock(return_value=(None, None)) ), ) with pytest.raises(ResolverError): @@ -130,7 +128,7 @@ async def test_supports_updated_did_sov_rules( "linked_domains": "https://example.com", } - ledger.get_all_endpoints_for_did = async_mock.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.AsyncMock(return_value=example) assert await resolver.resolve(profile, TEST_DID0) @pytest.mark.asyncio @@ -143,7 +141,7 @@ async def test_supports_updated_did_sov_rules_no_endpoint_url( "types": ["DIDComm", "did-communication", "endpoint"], } - ledger.get_all_endpoints_for_did = async_mock.AsyncMock(return_value=example) + ledger.get_all_endpoints_for_did = mock.AsyncMock(return_value=example) result = await resolver.resolve(profile, TEST_DID0) assert "service" not in result diff --git a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py index c447859c07..b9f577b368 100644 --- a/aries_cloudagent/resolver/default/tests/test_legacy_peer.py +++ b/aries_cloudagent/resolver/default/tests/test_legacy_peer.py @@ -1,6 +1,6 @@ """Test LegacyPeerDIDResolver.""" -from unittest import mock as async_mock +from unittest import mock import pydid import pytest @@ -37,9 +37,9 @@ class TestLegacyPeerDIDResolver: @pytest.mark.asyncio async def test_supports(self, resolver: LegacyPeerDIDResolver, profile: Profile): """Test supports.""" - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.AsyncMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -51,9 +51,9 @@ async def test_supports_no_cache( ): """Test supports.""" profile.context.injector.clear_binding(BaseCache) - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.AsyncMock( + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -71,26 +71,24 @@ async def test_supports_x_unknown_did( self, resolver: LegacyPeerDIDResolver, profile: Profile ): """Test supports returns false for unknown DID.""" - with async_mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.AsyncMock( - side_effect=StorageNotFoundError - ) + with mock.patch.object(test_module, "BaseConnectionManager") as mock_mgr: + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock(side_effect=StorageNotFoundError) ) assert not await resolver.supports(profile, TEST_DID2) @pytest.mark.asyncio async def test_resolve(self, resolver: LegacyPeerDIDResolver, profile: Profile): """Test resolve.""" - with async_mock.patch.object( + with mock.patch.object( test_module, "BaseConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "LegacyDocCorrections" ) as mock_corrections: doc = object() - mock_corrections.apply = async_mock.MagicMock(return_value=doc) - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.AsyncMock( + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock( return_value=(DIDDoc(TEST_DID0), None) ) ) @@ -105,21 +103,19 @@ async def test_resolve_x_not_found( This should be impossible in practice but still. """ - with async_mock.patch.object( + with mock.patch.object( test_module, "BaseConnectionManager" - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module, "LegacyDocCorrections" ) as mock_corrections, pytest.raises( test_module.DIDNotFound ): doc = object - mock_corrections.apply = async_mock.MagicMock(return_value=doc) - mock_mgr.return_value = async_mock.MagicMock( - fetch_did_document=async_mock.AsyncMock( - side_effect=StorageNotFoundError - ) + mock_corrections.apply = mock.MagicMock(return_value=doc) + mock_mgr.return_value = mock.MagicMock( + fetch_did_document=mock.AsyncMock(side_effect=StorageNotFoundError) ) - resolver.supports = async_mock.AsyncMock(return_value=True) + resolver.supports = mock.AsyncMock(return_value=True) result = await resolver.resolve(profile, TEST_DID0) assert result == doc diff --git a/aries_cloudagent/resolver/default/tests/test_universal.py b/aries_cloudagent/resolver/default/tests/test_universal.py index ac60dcede2..c6b5fe5073 100644 --- a/aries_cloudagent/resolver/default/tests/test_universal.py +++ b/aries_cloudagent/resolver/default/tests/test_universal.py @@ -3,7 +3,7 @@ import re from typing import Dict, Union -from unittest import mock as async_mock +from unittest import mock import pytest from ....config.settings import Settings @@ -122,10 +122,10 @@ async def test_fetch_resolver_props(mock_client_session: MockClientSession): @pytest.mark.asyncio async def test_get_supported_did_regex(): props = {"example": {"http": {"pattern": "match a test string"}}} - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_fetch_resolver_props", - async_mock.AsyncMock(return_value=props), + mock.AsyncMock(return_value=props), ): pattern = await UniversalResolver()._get_supported_did_regex() assert pattern.fullmatch("match a test string") @@ -147,12 +147,12 @@ async def test_setup_endpoint_regex_set(resolver: UniversalResolver): "resolver.universal.supported": "test", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( test_module, "_compile_supported_did_regex", - async_mock.MagicMock(return_value="pattern"), + mock.MagicMock(return_value="pattern"), ): await resolver.setup(context) @@ -167,12 +167,12 @@ async def test_setup_endpoint_set(resolver: UniversalResolver): "resolver.universal": "http://example.com", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.AsyncMock(return_value="pattern"), + mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) @@ -187,12 +187,12 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): "resolver.universal": "DEFAULT", } ) - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.AsyncMock(return_value="pattern"), + mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) @@ -203,12 +203,12 @@ async def test_setup_endpoint_default(resolver: UniversalResolver): @pytest.mark.asyncio async def test_setup_endpoint_unset(resolver: UniversalResolver): settings = Settings() - context = async_mock.MagicMock() + context = mock.MagicMock() context.settings = settings - with async_mock.patch.object( + with mock.patch.object( UniversalResolver, "_get_supported_did_regex", - async_mock.AsyncMock(return_value="pattern"), + mock.AsyncMock(return_value="pattern"), ): await resolver.setup(context) diff --git a/aries_cloudagent/resolver/tests/test_base.py b/aries_cloudagent/resolver/tests/test_base.py index b3e3cfa13f..5d3a77e159 100644 --- a/aries_cloudagent/resolver/tests/test_base.py +++ b/aries_cloudagent/resolver/tests/test_base.py @@ -3,7 +3,7 @@ import pytest import re -from unittest import mock as async_mock +from unittest import mock from pydid import DIDDocument from ..base import BaseDIDResolver, DIDMethodNotSupported, ResolverType @@ -40,7 +40,7 @@ def non_native_resolver(): @pytest.fixture def profile(): - yield async_mock.MagicMock() + yield mock.MagicMock() def test_native_on_native(native_resolver): diff --git a/aries_cloudagent/resolver/tests/test_routes.py b/aries_cloudagent/resolver/tests/test_routes.py index 50e3813af1..ca8bb55088 100644 --- a/aries_cloudagent/resolver/tests/test_routes.py +++ b/aries_cloudagent/resolver/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from unittest import mock as async_mock +from unittest import mock from pydid import DIDDocument from ...core.in_memory import InMemoryProfile @@ -40,7 +40,7 @@ def resolution_result(did_doc): @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -49,39 +49,37 @@ def mock_response(): @pytest.fixture def mock_resolver(resolution_result): - did_resolver = async_mock.MagicMock() - did_resolver.resolve = async_mock.AsyncMock(return_value=did_doc) - did_resolver.resolve_with_metadata = async_mock.AsyncMock( - return_value=resolution_result - ) + did_resolver = mock.MagicMock() + did_resolver.resolve = mock.AsyncMock(return_value=did_doc) + did_resolver.resolve_with_metadata = mock.AsyncMock(return_value=resolution_result) yield did_resolver @pytest.mark.asyncio -async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_doc): +async def test_resolver(mock_resolver, mock_response: mock.MagicMock, did_doc): profile = InMemoryProfile.test_profile() context = profile.context setattr(context, "profile", profile) session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = async_mock.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={ "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( context.profile, "session", - async_mock.MagicMock(return_value=session), + mock.MagicMock(return_value=session), ) as mock_session: await test_module.resolve_did(request) mock_response.call_args[0][0] == did_doc.serialize() @@ -98,9 +96,7 @@ async def test_resolver(mock_resolver, mock_response: async_mock.MagicMock, did_ ], ) async def test_resolver_not_found_error(mock_resolver, side_effect, error): - mock_resolver.resolve_with_metadata = async_mock.AsyncMock( - side_effect=side_effect() - ) + mock_resolver.resolve_with_metadata = mock.AsyncMock(side_effect=side_effect()) profile = InMemoryProfile.test_profile() context = profile.context @@ -108,23 +104,23 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): session = await profile.session() session.context.injector.bind_instance(DIDResolver, mock_resolver) - outbound_message_router = async_mock.AsyncMock() + outbound_message_router = mock.AsyncMock() request_dict = { "context": context, "outbound_message_router": outbound_message_router, } - request = async_mock.MagicMock( + request = mock.MagicMock( match_info={ "did": "did:ethr:mainnet:0xb9c5714089478a327f09197987f16f9e5d936e8a", }, query={}, - json=async_mock.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( context.profile, "session", - async_mock.MagicMock(return_value=session), + mock.MagicMock(return_value=session), ) as mock_session: with pytest.raises(error): await test_module.resolve_did(request) @@ -132,14 +128,14 @@ async def test_resolver_not_found_error(mock_resolver, side_effect, error): @pytest.mark.asyncio async def test_register(): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() @pytest.mark.asyncio async def test_post_process_routes(): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] diff --git a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py index 9329dc7c99..d7cf28721d 100644 --- a/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py +++ b/aries_cloudagent/revocation/models/tests/test_issuer_rev_reg_record.py @@ -4,7 +4,7 @@ from os.path import join from typing import Any, Mapping, Type -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile, InMemoryProfileSession @@ -60,15 +60,15 @@ async def asyncSetUp(self): ) self.context = self.profile.context - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.send_revoc_reg_def = async_mock.AsyncMock() - self.ledger.send_revoc_reg_entry = async_mock.AsyncMock() + self.ledger.send_revoc_reg_def = mock.AsyncMock() + self.ledger.send_revoc_reg_entry = mock.AsyncMock() self.profile.context.injector.bind_instance(BaseLedger, self.ledger) - TailsServer = async_mock.MagicMock(BaseTailsServer, autospec=True) + TailsServer = mock.MagicMock(BaseTailsServer, autospec=True) self.tails_server = TailsServer() - self.tails_server.upload_tails_file = async_mock.AsyncMock( + self.tails_server.upload_tails_file = mock.AsyncMock( return_value=(True, "http://1.2.3.4:8088/rev-reg-id") ) self.profile.context.injector.bind_instance(BaseTailsServer, self.tails_server) @@ -172,17 +172,17 @@ def __init__( def handle(self): if self.handle_counter == 0: self.handle_counter = self.handle_counter + 1 - return async_mock.MagicMock( - fetch=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.AsyncMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_cred_def) ) ) ) else: - return async_mock.MagicMock( - fetch=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + return mock.MagicMock( + fetch=mock.AsyncMock( + return_value=mock.MagicMock( value_json=json.dumps(mock_reg_rev_def_private), ), ) @@ -214,13 +214,13 @@ def handle(self): "ver": "1.0", "value": {"accum": "ACCUM", "issued": [1, 2], "revoked": [3, 4]}, } - self.ledger.get_revoc_reg_delta = async_mock.AsyncMock( + self.ledger.get_revoc_reg_delta = mock.AsyncMock( return_value=( _test_rev_reg_delta, 1234567890, ) ) - self.ledger.send_revoc_reg_entry = async_mock.AsyncMock( + self.ledger.send_revoc_reg_entry = mock.AsyncMock( return_value={ "result": {"...": "..."}, }, @@ -230,10 +230,10 @@ def handle(self): ) _test_profile = _test_session.profile _test_profile.context.injector.bind_instance(BaseLedger, self.ledger) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.AsyncMock( + mock.AsyncMock( return_value=[ test_module.IssuerCredRevRecord( record_id=test_module.UUID4_EXAMPLE, @@ -244,14 +244,14 @@ def handle(self): ) ] ), - ), async_mock.patch.object( + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.AsyncMock(return_value=rec), - ), async_mock.patch.object( + mock.AsyncMock(return_value=rec), + ), mock.patch.object( test_module, "generate_ledger_rrrecovery_txn", - async_mock.AsyncMock(return_value=rev_reg_delta), + mock.AsyncMock(return_value=rev_reg_delta), ): assert ( _test_rev_reg_delta, @@ -274,11 +274,11 @@ async def test_generate_registry_etc(self): cred_def_id=CRED_DEF_ID, revoc_reg_id=REV_REG_ID, ) - issuer = async_mock.MagicMock(IndyIssuer) + issuer = mock.MagicMock(IndyIssuer) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( - issuer, "create_and_store_revocation_registry", async_mock.AsyncMock() + with mock.patch.object( + issuer, "create_and_store_revocation_registry", mock.AsyncMock() ) as mock_create_store_rr: mock_create_store_rr.side_effect = IndyIssuerError("Not this time") @@ -291,9 +291,7 @@ async def test_generate_registry_etc(self): json.dumps(REV_REG_ENTRY), ) - with async_mock.patch.object( - test_module, "move", async_mock.MagicMock() - ) as mock_move: + with mock.patch.object(test_module, "move", mock.MagicMock()) as mock_move: await rec.generate_registry(self.profile) assert rec.revoc_reg_id == REV_REG_ID @@ -313,7 +311,7 @@ async def test_generate_registry_etc(self): assert rec.state == IssuerRevRegRecord.STATE_POSTED self.ledger.send_revoc_reg_def.assert_called_once() - with async_mock.patch.object(test_module.Path, "is_file", lambda _: True): + with mock.patch.object(test_module.Path, "is_file", lambda _: True): await rec.upload_tails_file(self.profile) assert ( rec.tails_public_uri diff --git a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py index 4ee40798e5..d28d6ac6df 100644 --- a/aries_cloudagent/revocation/models/tests/test_revocation_registry.py +++ b/aries_cloudagent/revocation/models/tests/test_revocation_registry.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from copy import deepcopy from pathlib import Path @@ -84,7 +84,7 @@ async def test_tails_local_path(self): rev_reg_loc = RevocationRegistry.from_definition(REV_REG_DEF, public_def=False) assert rev_reg_loc.get_receiving_tails_local_path() == TAILS_LOCAL - with async_mock.patch.object(Path, "is_file", autospec=True) as mock_is_file: + with mock.patch.object(Path, "is_file", autospec=True) as mock_is_file: mock_is_file.return_value = True assert await rev_reg_loc.get_or_fetch_local_tails_path() == TAILS_LOCAL @@ -102,14 +102,12 @@ async def test_retrieve_tails(self): rr_def_public["value"]["tailsLocation"] = "http://sample.ca:8088/path" rev_reg = RevocationRegistry.from_definition(rr_def_public, public_def=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( - test_module, "Session", autospec=True - ) as mock_session: - mock_session.return_value.__enter__ = async_mock.MagicMock( + more_magic = mock.MagicMock() + with mock.patch.object(test_module, "Session", autospec=True) as mock_session: + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( + more_magic.get = mock.MagicMock( side_effect=test_module.RequestException("Not this time") ) @@ -119,18 +117,14 @@ async def test_retrieve_tails(self): rmtree(TAILS_DIR, ignore_errors=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( - test_module, "Session", autospec=True - ) as mock_session: - mock_session.return_value.__enter__ = async_mock.MagicMock( + more_magic = mock.MagicMock() + with mock.patch.object(test_module, "Session", autospec=True) as mock_session: + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( - return_value=async_mock.MagicMock( - iter_content=async_mock.MagicMock( - side_effect=[(b"abcd1234",), (b"",)] - ) + more_magic.get = mock.MagicMock( + return_value=mock.MagicMock( + iter_content=mock.MagicMock(side_effect=[(b"abcd1234",), (b"",)]) ) ) @@ -142,28 +136,26 @@ async def test_retrieve_tails(self): rmtree(TAILS_DIR, ignore_errors=True) - more_magic = async_mock.MagicMock() - with async_mock.patch.object( + more_magic = mock.MagicMock() + with mock.patch.object( test_module, "Session", autospec=True - ) as mock_session, async_mock.patch.object( - base58, "b58encode", async_mock.MagicMock() - ) as mock_b58enc, async_mock.patch.object( + ) as mock_session, mock.patch.object( + base58, "b58encode", mock.MagicMock() + ) as mock_b58enc, mock.patch.object( Path, "is_file", autospec=True ) as mock_is_file: - mock_session.return_value.__enter__ = async_mock.MagicMock( + mock_session.return_value.__enter__ = mock.MagicMock( return_value=more_magic ) - more_magic.get = async_mock.MagicMock( - return_value=async_mock.MagicMock( - iter_content=async_mock.MagicMock( - side_effect=[(b"abcd1234",), (b"",)] - ) + more_magic.get = mock.MagicMock( + return_value=mock.MagicMock( + iter_content=mock.MagicMock(side_effect=[(b"abcd1234",), (b"",)]) ) ) mock_is_file.return_value = False - mock_b58enc.return_value = async_mock.MagicMock( - decode=async_mock.MagicMock(return_value=TAILS_HASH) + mock_b58enc.return_value = mock.MagicMock( + decode=mock.MagicMock(return_value=TAILS_HASH) ) await rev_reg.get_or_fetch_local_tails_path() diff --git a/aries_cloudagent/revocation/tests/test_indy.py b/aries_cloudagent/revocation/tests/test_indy.py index dd3d97f255..ccdf3e2a46 100644 --- a/aries_cloudagent/revocation/tests/test_indy.py +++ b/aries_cloudagent/revocation/tests/test_indy.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...core.in_memory import InMemoryProfile @@ -24,17 +24,17 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() self.context = self.profile.context - Ledger = async_mock.MagicMock(BaseLedger, autospec=True) + Ledger = mock.MagicMock(BaseLedger, autospec=True) self.ledger = Ledger() - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": True}} ) - self.ledger.get_revoc_reg_def = async_mock.AsyncMock() + self.ledger.get_revoc_reg_def = mock.AsyncMock() self.context.injector.bind_instance(BaseLedger, self.ledger) self.context.injector.bind_instance( IndyLedgerRequestsExecutor, - async_mock.MagicMock( - get_ledger_for_identifier=async_mock.AsyncMock( + mock.MagicMock( + get_ledger_for_identifier=mock.AsyncMock( return_value=(None, self.ledger) ) ), @@ -56,12 +56,12 @@ async def test_init_issuer_registry(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=(None, self.ledger)), + mock.AsyncMock(return_value=(None, self.ledger)), ): result = await self.revoc.init_issuer_registry(CRED_DEF_ID) assert result.cred_def_id == CRED_DEF_ID @@ -74,7 +74,7 @@ async def test_init_issuer_registry_no_cred_def(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.AsyncMock(return_value=None) + self.ledger.get_credential_definition = mock.AsyncMock(return_value=None) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) with self.assertRaises(RevocationNotSupportedError) as x_revo: @@ -85,7 +85,7 @@ async def test_init_issuer_registry_bad_size(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {"revocation": "..."}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -118,7 +118,7 @@ async def test_init_issuer_registry_no_revocation(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.profile.context.injector.clear_binding(BaseLedger) - self.ledger.get_credential_definition = async_mock.AsyncMock( + self.ledger.get_credential_definition = mock.AsyncMock( return_value={"value": {}} ) self.profile.context.injector.bind_instance(BaseLedger, self.ledger) @@ -132,10 +132,10 @@ async def test_get_issuer_rev_reg_record(self): rec = await self.revoc.init_issuer_registry(CRED_DEF_ID) rec.revoc_reg_id = "dummy" - rec.generate_registry = async_mock.AsyncMock() + rec.generate_registry = mock.AsyncMock() - with async_mock.patch.object( - IssuerRevRegRecord, "retrieve_by_revoc_reg_id", async_mock.AsyncMock() + with mock.patch.object( + IssuerRevRegRecord, "retrieve_by_revoc_reg_id", mock.AsyncMock() ) as mock_retrieve_by_rr_id: mock_retrieve_by_rr_id.return_value = rec await rec.generate_registry(self.profile, None) @@ -222,8 +222,8 @@ async def test_decommission_issuer_registries(self): async def test_get_ledger_registry(self): CRED_DEF_ID = "{self.test_did}:3:CL:1234:default" - with async_mock.patch.object( - RevocationRegistry, "from_definition", async_mock.MagicMock() + with mock.patch.object( + RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_from_def: result = await self.revoc.get_ledger_registry("dummy") assert result == mock_from_def.return_value @@ -237,14 +237,14 @@ async def test_get_ledger_registry(self): self.context.injector.bind_instance( BaseMultitenantManager, - async_mock.MagicMock(MultitenantManager, autospec=True), + mock.MagicMock(MultitenantManager, autospec=True), ) - with async_mock.patch.object( + with mock.patch.object( IndyLedgerRequestsExecutor, "get_ledger_for_identifier", - async_mock.AsyncMock(return_value=(None, self.ledger)), - ), async_mock.patch.object( - RevocationRegistry, "from_definition", async_mock.MagicMock() + mock.AsyncMock(return_value=(None, self.ledger)), + ), mock.patch.object( + RevocationRegistry, "from_definition", mock.MagicMock() ) as mock_from_def: result = await self.revoc.get_ledger_registry("dummy2") assert result == mock_from_def.return_value diff --git a/aries_cloudagent/revocation/tests/test_manager.py b/aries_cloudagent/revocation/tests/test_manager.py index eb0356d8cd..d51f41e0fc 100644 --- a/aries_cloudagent/revocation/tests/test_manager.py +++ b/aries_cloudagent/revocation/tests/test_manager.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from aries_cloudagent.revocation.models.issuer_cred_rev_record import ( @@ -38,15 +38,15 @@ async def asyncSetUp(self): async def test_revoke_credential_publish(self): CRED_EX_ID = "dummy-cxid" CRED_REV_ID = "1" - mock_issuer_rev_reg_record = async_mock.MagicMock( + mock_issuer_rev_reg_record = mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), pending_pub=["2"], ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.revoke_credentials = mock.AsyncMock( return_value=( json.dumps( { @@ -63,27 +63,27 @@ async def test_revoke_credential_publish(self): ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - mock_retrieve.return_value = async_mock.MagicMock( + mock_retrieve.return_value = mock.MagicMock( rev_reg_id="dummy-rr-id", cred_rev_id=CRED_REV_ID ) - mock_rev_reg = async_mock.MagicMock( - get_or_fetch_local_tails_path=async_mock.AsyncMock() + mock_rev_reg = mock.MagicMock( + get_or_fetch_local_tails_path=mock.AsyncMock() ) - revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) - revoc.return_value.get_ledger_registry = async_mock.AsyncMock( + revoc.return_value.get_ledger_registry = mock.AsyncMock( return_value=mock_rev_reg ) @@ -99,14 +99,14 @@ async def test_revoke_credential_publish(self): async def test_revoke_cred_by_cxid_not_found(self): CRED_EX_ID = "dummy-cxid" - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(RevocationManagerError): @@ -122,14 +122,12 @@ async def test_revoke_credential_no_rev_reg_rec(self): revoc_reg_id=REV_REG_ID, ) - with async_mock.patch.object( - test_module, "IndyRevocation", autospec=True - ) as revoc: - revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( + with mock.patch.object(test_module, "IndyRevocation", autospec=True) as revoc: + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( return_value=None ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) with self.assertRaises(RevocationManagerError): @@ -137,28 +135,26 @@ async def test_revoke_credential_no_rev_reg_rec(self): async def test_revoke_credential_pend(self): CRED_REV_ID = "1" - mock_issuer_rev_reg_record = async_mock.MagicMock( - mark_pending=async_mock.AsyncMock() - ) - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) + mock_issuer_rev_reg_record = mock.MagicMock(mark_pending=mock.AsyncMock()) + issuer = mock.MagicMock(IndyIssuer, autospec=True) self.profile.context.injector.bind_instance(IndyIssuer, issuer) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as revoc, async_mock.patch.object( + ) as revoc, mock.patch.object( self.profile, "session", - async_mock.MagicMock(return_value=self.profile.session()), - ) as session, async_mock.patch.object( + mock.MagicMock(return_value=self.profile.session()), + ) as session, mock.patch.object( self.profile, "transaction", - async_mock.MagicMock(return_value=session.return_value), - ) as session, async_mock.patch.object( + mock.MagicMock(return_value=session.return_value), + ) as session, mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - revoc.return_value.get_issuer_rev_reg_record = async_mock.AsyncMock( + revoc.return_value.get_issuer_rev_reg_record = mock.AsyncMock( return_value=mock_issuer_rev_reg_record ) @@ -185,28 +181,26 @@ async def test_publish_pending_revocations_basic(self): }, ] - mock_issuer_rev_reg_record = async_mock.MagicMock( + mock_issuer_rev_reg_record = mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), - ), async_mock.patch.object( + mock.AsyncMock(return_value=[mock_issuer_rev_reg_record]), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_record), + mock.AsyncMock(return_value=mock_issuer_rev_reg_record), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -232,40 +226,38 @@ async def test_publish_pending_revocations_1_rev_reg_all(self): ] mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( record_id=0, revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - async_mock.MagicMock( + mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock( + mock.AsyncMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -292,40 +284,38 @@ async def test_publish_pending_revocations_1_rev_reg_some(self): ] mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( record_id=0, revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - async_mock.MagicMock( + mock.MagicMock( record_id=1, revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - send_entry=async_mock.AsyncMock(), - clear_pending=async_mock.AsyncMock(), + send_entry=mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), - ), async_mock.patch.object( + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + ), mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_id", - async_mock.AsyncMock( + mock.AsyncMock( side_effect=lambda _, id, **args: mock_issuer_rev_reg_records[id] ), ): - issuer = async_mock.MagicMock(IndyIssuer, autospec=True) - issuer.merge_revocation_registry_deltas = async_mock.AsyncMock( - side_effect=deltas - ) + issuer = mock.MagicMock(IndyIssuer, autospec=True) + issuer.merge_revocation_registry_deltas = mock.AsyncMock(side_effect=deltas) - issuer.revoke_credentials = async_mock.AsyncMock( + issuer.revoke_credentials = mock.AsyncMock( side_effect=[(json.dumps(delta), []) for delta in deltas] ) self.profile.context.injector.bind_instance(IndyIssuer, issuer) @@ -337,46 +327,46 @@ async def test_publish_pending_revocations_1_rev_reg_some(self): async def test_clear_pending(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=[], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations() assert result == {} async def test_clear_pending_1_rev_reg_all(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["9", "99"], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: None}) assert result == { @@ -386,23 +376,23 @@ async def test_clear_pending_1_rev_reg_all(self): async def test_clear_pending_1_rev_reg_some(self): mock_issuer_rev_reg_records = [ - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=REV_REG_ID, tails_local_path=TAILS_LOCAL, pending_pub=["1", "2"], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), - async_mock.MagicMock( + mock.MagicMock( revoc_reg_id=f"{TEST_DID}:4:{CRED_DEF_ID}:CL_ACCUM:tag2", tails_local_path=TAILS_LOCAL, pending_pub=["99"], - clear_pending=async_mock.AsyncMock(), + clear_pending=mock.AsyncMock(), ), ] - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "query_by_pending", - async_mock.AsyncMock(return_value=mock_issuer_rev_reg_records), + mock.AsyncMock(return_value=mock_issuer_rev_reg_records), ) as record: result = await self.manager.clear_pending_revocations({REV_REG_ID: ["9"]}) assert result == { diff --git a/aries_cloudagent/revocation/tests/test_routes.py b/aries_cloudagent/revocation/tests/test_routes.py index b0d86f7563..7c65b16e94 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -4,7 +4,7 @@ from aiohttp.web import HTTPBadRequest, HTTPNotFound from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.revocation.error import RevocationError @@ -20,9 +20,9 @@ def setUp(self): setattr(self.context, "profile", self.profile) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -75,7 +75,7 @@ async def test_validate_cred_rev_rec_qs_and_revoke_req(self): ) async def test_revoke(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -83,38 +83,38 @@ async def test_revoke(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.AsyncMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_by_cred_ex_id(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "cred_ex_id": "dummy-cxid", "publish": "false", } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.AsyncMock() + mock_mgr.return_value.revoke_credential = mock.AsyncMock() await test_module.revoke(self.request) mock_response.assert_called_once_with({}) async def test_revoke_not_found(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "rev_reg_id": "rr_id", "cred_rev_id": "23", @@ -122,12 +122,12 @@ async def test_revoke_not_found(self): } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - mock_mgr.return_value.revoke_credential = async_mock.AsyncMock( + mock_mgr.return_value.revoke_credential = mock.AsyncMock( side_effect=test_module.StorageNotFoundError() ) @@ -135,14 +135,14 @@ async def test_revoke_not_found(self): await test_module.revoke(self.request) async def test_publish_revocations(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - pub_pending = async_mock.AsyncMock() + pub_pending = mock.AsyncMock() mock_mgr.return_value.publish_pending_revocations = pub_pending await test_module.publish_revocations(self.request) @@ -152,28 +152,26 @@ async def test_publish_revocations(self): ) async def test_publish_revocations_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True ) as mock_mgr: - pub_pending = async_mock.AsyncMock( - side_effect=test_module.RevocationError() - ) + pub_pending = mock.AsyncMock(side_effect=test_module.RevocationError()) mock_mgr.return_value.publish_pending_revocations = pub_pending with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.publish_revocations(self.request) async def test_clear_pending_revocations(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.AsyncMock() + clear_pending = mock.AsyncMock() mock_mgr.return_value.clear_pending_revocations = clear_pending await test_module.clear_pending_revocations(self.request) @@ -183,14 +181,14 @@ async def test_clear_pending_revocations(self): ) async def test_clear_pending_revocations_x(self): - self.request.json = async_mock.AsyncMock() + self.request.json = mock.AsyncMock() - with async_mock.patch.object( + with mock.patch.object( test_module, "RevocationManager", autospec=True - ) as mock_mgr, async_mock.patch.object( + ) as mock_mgr, mock.patch.object( test_module.web, "json_response" ) as mock_response: - clear_pending = async_mock.AsyncMock(side_effect=test_module.StorageError()) + clear_pending = mock.AsyncMock(side_effect=test_module.StorageError()) mock_mgr.return_value.clear_pending_revocations = clear_pending with self.assertRaises(test_module.web.HTTPBadRequest): @@ -198,26 +196,26 @@ async def test_clear_pending_revocations_x(self): async def test_create_rev_reg(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( + ) as mock_find, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find.return_value = True - mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - generate_registry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.AsyncMock( + return_value=mock.MagicMock( + generate_registry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -228,17 +226,17 @@ async def test_create_rev_reg(self): async def test_create_rev_reg_no_such_cred_def(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_find, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find.return_value = False @@ -248,23 +246,23 @@ async def test_create_rev_reg_no_such_cred_def(self): async def test_create_rev_reg_no_revo_support(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", "credential_definition_id": CRED_DEF_ID, } ) - with async_mock.patch.object( + with mock.patch.object( InMemoryStorage, "find_all_records", autospec=True - ) as mock_find, async_mock.patch.object( + ) as mock_find, mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_find = True - mock_indy_revoc.return_value = async_mock.MagicMock( - init_issuer_registry=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + init_issuer_registry=mock.AsyncMock( side_effect=test_module.RevocationNotSupportedError( error_code="dummy" ) @@ -283,12 +281,12 @@ async def test_rev_regs_created(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( - test_module.IssuerRevRegRecord, "query", async_mock.AsyncMock() - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.IssuerRevRegRecord, "query", mock.AsyncMock() + ) as mock_query, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_query.return_value = [async_mock.MagicMock(revoc_reg_id="dummy")] + mock_query.return_value = [mock.MagicMock(revoc_reg_id="dummy")] result = await test_module.rev_regs_created(self.request) mock_json_response.assert_called_once_with({"rev_reg_ids": ["dummy"]}) @@ -300,15 +298,15 @@ async def test_get_rev_reg(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -323,13 +321,13 @@ async def test_get_rev_reg_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -344,16 +342,16 @@ async def test_get_rev_reg_issued(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( test_module.IssuerCredRevRecord, "query_by_ids", - async_mock.AsyncMock(), - ) as mock_query, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) as mock_query, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: mock_query.return_value = return_value = [{"...": "..."}, {"...": "..."}] result = await test_module.get_rev_reg_issued_count(self.request) @@ -367,10 +365,10 @@ async def test_get_rev_reg_issued_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerRevRegRecord, "retrieve_by_revoc_reg_id", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") @@ -388,15 +386,15 @@ async def test_get_cred_rev_record(self): "cred_rev_id": CRED_REV_ID, } - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) result = await test_module.get_cred_rev_record(self.request) @@ -408,15 +406,15 @@ async def test_get_cred_rev_record_by_cred_ex_id(self): self.request.query = {"cred_ex_id": CRED_EX_ID} - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_cred_ex_id", - async_mock.AsyncMock(), - ) as mock_retrieve, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + mock.AsyncMock(), + ) as mock_retrieve, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_retrieve.return_value = async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_retrieve.return_value = mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) result = await test_module.get_cred_rev_record(self.request) @@ -429,17 +427,17 @@ async def test_get_cred_rev_record_not_found(self): ) CRED_REV_ID = "1" - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "rev_reg_id": REV_REG_ID, "cred_rev_id": CRED_REV_ID, } ) - with async_mock.patch.object( + with mock.patch.object( test_module.IssuerCredRevRecord, "retrieve_by_ids", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_retrieve: mock_retrieve.side_effect = test_module.StorageNotFoundError("no such rec") with self.assertRaises(test_module.web.HTTPNotFound): @@ -449,15 +447,15 @@ async def test_get_active_rev_reg(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - serialize=async_mock.MagicMock(return_value="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_active_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + serialize=mock.MagicMock(return_value="dummy") ) ) ) @@ -470,13 +468,13 @@ async def test_get_active_rev_reg_not_found(self): CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default" self.request.match_info = {"cred_def_id": CRED_DEF_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_active_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_active_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -491,14 +489,14 @@ async def test_get_tails_file(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock(tails_local_path="dummy") + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock(tails_local_path="dummy") ) ) @@ -512,13 +510,13 @@ async def test_get_tails_file_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_file_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -533,15 +531,15 @@ async def test_upload_tails_file_basic(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_upload = async_mock.AsyncMock() - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_upload = mock.AsyncMock() + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -559,12 +557,12 @@ async def test_upload_tails_file_no_local_tails_file(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=False, ) @@ -580,13 +578,13 @@ async def test_upload_tails_file_fail(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_upload = async_mock.AsyncMock(side_effect=RevocationError("test")) - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( + mock_upload = mock.AsyncMock(side_effect=RevocationError("test")) + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( tails_local_path=f"/tmp/tails/{REV_REG_ID}", has_local_tails_file=True, upload_tails_file=mock_upload, @@ -603,17 +601,17 @@ async def test_send_rev_reg_def(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - send_def=async_mock.AsyncMock(), - send_entry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_def=mock.AsyncMock(), + send_entry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -628,13 +626,13 @@ async def test_send_rev_reg_def_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -649,13 +647,13 @@ async def test_send_rev_reg_def_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - send_def=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_def=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -671,16 +669,16 @@ async def test_send_rev_reg_entry(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_entry=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -695,13 +693,13 @@ async def test_send_rev_reg_entry_not_found(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -716,13 +714,13 @@ async def test_send_rev_reg_entry_x(self): ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - send_entry=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + send_entry=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -737,23 +735,23 @@ async def test_update_rev_reg(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.AsyncMock(), + save=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -767,19 +765,19 @@ async def test_update_rev_reg_not_found(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -793,19 +791,19 @@ async def test_update_rev_reg_x(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "tails_public_uri": f"http://sample.ca:8181/tails/{REV_REG_ID}" } ) - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True ) as mock_indy_revoc: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - set_tails_file_public_uri=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_tails_file_public_uri=mock.AsyncMock( side_effect=test_module.RevocationError() ), ) @@ -820,7 +818,7 @@ async def test_set_rev_reg_state(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -829,17 +827,17 @@ async def test_set_rev_reg_state(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - set_state=async_mock.AsyncMock(), - save=async_mock.AsyncMock(), - serialize=async_mock.MagicMock(return_value="dummy"), + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( + return_value=mock.MagicMock( + set_state=mock.AsyncMock(), + save=mock.AsyncMock(), + serialize=mock.MagicMock(return_value="dummy"), ) ) ) @@ -853,7 +851,7 @@ async def test_set_rev_reg_state_not_found(self): self.test_did, self.test_did ) self.request.match_info = {"rev_reg_id": REV_REG_ID} - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "max_cred_num": "1000", } @@ -862,13 +860,13 @@ async def test_set_rev_reg_state_not_found(self): "state": test_module.IssuerRevRegRecord.STATE_ACTIVE, } - with async_mock.patch.object( + with mock.patch.object( test_module, "IndyRevocation", autospec=True - ) as mock_indy_revoc, async_mock.patch.object( - test_module.web, "FileResponse", async_mock.Mock() + ) as mock_indy_revoc, mock.patch.object( + test_module.web, "FileResponse", mock.Mock() ) as mock_json_response: - mock_indy_revoc.return_value = async_mock.MagicMock( - get_issuer_rev_reg_record=async_mock.AsyncMock( + mock_indy_revoc.return_value = mock.MagicMock( + get_issuer_rev_reg_record=mock.AsyncMock( side_effect=test_module.StorageNotFoundError(error_code="dummy") ) ) @@ -878,14 +876,14 @@ async def test_set_rev_reg_state_not_found(self): mock_json_response.assert_not_called() async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock( + mock_app = mock.MagicMock( _state={ "swagger_dict": { "paths": { diff --git a/aries_cloudagent/settings/tests/test_routes.py b/aries_cloudagent/settings/tests/test_routes.py index 0cd27a58eb..5e9fab046e 100644 --- a/aries_cloudagent/settings/tests/test_routes.py +++ b/aries_cloudagent/settings/tests/test_routes.py @@ -3,7 +3,7 @@ # pylint: disable=redefined-outer-name import pytest -from unittest import mock as async_mock +from unittest import mock from ...admin.request_context import AdminRequestContext from ...core.in_memory import InMemoryProfile @@ -15,7 +15,7 @@ @pytest.fixture def mock_response(): - json_response = async_mock.MagicMock() + json_response = mock.MagicMock() temp_value = test_module.web.json_response test_module.web.json_response = json_response yield json_response @@ -41,9 +41,9 @@ async def test_get_profile_settings(mock_response): profile=profile, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) await test_module.get_profile_settings(request) @@ -71,16 +71,16 @@ async def test_get_profile_settings(mock_response): }, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.AsyncMock(return_value={}), + json=mock.AsyncMock(return_value={}), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( multi_tenant_manager, "get_wallet_and_profile" ) as get_wallet_and_profile: get_wallet_and_profile.return_value = ( - async_mock.MagicMock( + mock.MagicMock( settings={ "admin.admin_client_max_request_size": 1, "debug.auto_respond_credential_offer": True, @@ -120,9 +120,9 @@ async def test_update_profile_settings(mock_response): profile=profile, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.AsyncMock( + json=mock.AsyncMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -161,9 +161,9 @@ async def test_update_profile_settings(mock_response): }, ), } - request = async_mock.MagicMock( + request = mock.MagicMock( query={}, - json=async_mock.AsyncMock( + json=mock.AsyncMock( return_value={ "extra_settings": { "ACAPY_INVITE_PUBLIC": False, @@ -176,13 +176,13 @@ async def test_update_profile_settings(mock_response): ), __getitem__=lambda _, k: request_dict[k], ) - with async_mock.patch.object( + with mock.patch.object( multi_tenant_manager, "update_wallet" - ) as update_wallet, async_mock.patch.object( + ) as update_wallet, mock.patch.object( multi_tenant_manager, "get_wallet_and_profile" ) as get_wallet_and_profile: get_wallet_and_profile.return_value = ( - async_mock.MagicMock( + mock.MagicMock( settings={ "admin.admin_client_max_request_size": 1, "debug.auto_respond_credential_offer": True, @@ -198,7 +198,7 @@ async def test_update_profile_settings(mock_response): ), profile, ) - update_wallet.return_value = async_mock.MagicMock( + update_wallet.return_value = mock.MagicMock( settings={ "public_invites": False, "debug.invite_public": False, diff --git a/aries_cloudagent/storage/tests/test_askar_storage.py b/aries_cloudagent/storage/tests/test_askar_storage.py index c8ae18dbf4..0400c3f433 100644 --- a/aries_cloudagent/storage/tests/test_askar_storage.py +++ b/aries_cloudagent/storage/tests/test_askar_storage.py @@ -2,7 +2,7 @@ import pytest import os -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -49,16 +49,16 @@ class TestAskarStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.skip @pytest.mark.asyncio async def test_record(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -148,8 +148,8 @@ async def test_record(self): with pytest.raises(StorageError): await storage.get_record("connection", None) - with async_mock.patch.object( - test_module.non_secrets, "get_wallet_record", async_mock.AsyncMock() + with mock.patch.object( + test_module.non_secrets, "get_wallet_record", mock.AsyncMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -157,18 +157,18 @@ async def test_record(self): with pytest.raises(test_module.StorageError): await storage.get_record("connection", "dummy-id") - with async_mock.patch.object( + with mock.patch.object( test_module.non_secrets, "update_wallet_record_value", - async_mock.AsyncMock(), - ) as mock_update_value, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_value, mock.patch.object( test_module.non_secrets, "update_wallet_record_tags", - async_mock.AsyncMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_tags, mock.patch.object( test_module.non_secrets, "delete_wallet_record", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( test_module.ErrorCode.CommonInvalidStructure @@ -212,16 +212,16 @@ async def test_record(self): @pytest.mark.skip @pytest.mark.asyncio async def test_storage_search_x(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: fake_wallet = AskarWallet( { @@ -249,10 +249,10 @@ async def test_storage_search_x(self): with pytest.raises(StorageSearchError): await search.fetch(10) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -260,14 +260,14 @@ async def test_storage_search_x(self): await search.open() await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.AsyncMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -276,10 +276,10 @@ async def test_storage_search_x(self): await search.fetch(10) await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -362,11 +362,9 @@ class TestAskarStorageSearchSession(IsolatedAsyncioTestCase): async def test_askar_storage_search_session(self): profile = "profileId" - with async_mock.patch( - "aries_cloudagent.storage.askar.AskarProfile" - ) as AskarProfile: + with mock.patch("aries_cloudagent.storage.askar.AskarProfile") as AskarProfile: askar_profile = AskarProfile(None, True) - askar_profile_scan = async_mock.MagicMock() + askar_profile_scan = mock.MagicMock() askar_profile.store.scan.return_value = askar_profile_scan askar_profile.settings.get.return_value = profile diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index 8cc6ebf557..ca8136f182 100644 --- a/aries_cloudagent/storage/tests/test_in_memory_storage.py +++ b/aries_cloudagent/storage/tests/test_in_memory_storage.py @@ -1,6 +1,6 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...storage.error import ( @@ -182,11 +182,9 @@ async def test_search(self, store_search): # search again with with iterator mystery error search = store_search.search_records(record.type, {}, None) - with async_mock.patch.object( - search, "fetch", async_mock.AsyncMock() - ) as mock_fetch: - mock_fetch.return_value = async_mock.MagicMock( - pop=async_mock.MagicMock(side_effect=IndexError()) + with mock.patch.object(search, "fetch", mock.AsyncMock()) as mock_fetch: + mock_fetch.return_value = mock.MagicMock( + pop=mock.MagicMock(side_effect=IndexError()) ) async for row in search: pytest.fail("Should not arrive here") diff --git a/aries_cloudagent/storage/tests/test_indy_storage.py b/aries_cloudagent/storage/tests/test_indy_storage.py index 96606b9c87..9b41966b6b 100644 --- a/aries_cloudagent/storage/tests/test_indy_storage.py +++ b/aries_cloudagent/storage/tests/test_indy_storage.py @@ -9,7 +9,7 @@ import indy.wallet from indy.error import ErrorCode -from unittest import mock as async_mock +from unittest import mock from ...config.injection_context import InjectionContext from ...indy.sdk.profile import IndySdkProfileManager, IndySdkProfile @@ -28,7 +28,7 @@ async def make_profile(): key = await IndySdkWallet.generate_wallet_key() context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): return await IndySdkProfileManager().provision( context, { @@ -63,20 +63,20 @@ class TestIndySdkStorage(test_in_memory_storage.TestInMemoryStorage): @pytest.mark.asyncio async def test_record(self): - with async_mock.patch( + with mock.patch( "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): config = { @@ -171,8 +171,8 @@ async def test_record(self): with pytest.raises(StorageError): await storage.get_record("connection", None) - with async_mock.patch.object( - indy.non_secrets, "get_wallet_record", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "get_wallet_record", mock.AsyncMock() ) as mock_get_record: mock_get_record.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -180,18 +180,18 @@ async def test_record(self): with pytest.raises(test_module.StorageError): await storage.get_record("connection", "dummy-id") - with async_mock.patch.object( + with mock.patch.object( indy.non_secrets, "update_wallet_record_value", - async_mock.AsyncMock(), - ) as mock_update_value, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_value, mock.patch.object( indy.non_secrets, "update_wallet_record_tags", - async_mock.AsyncMock(), - ) as mock_update_tags, async_mock.patch.object( + mock.AsyncMock(), + ) as mock_update_tags, mock.patch.object( indy.non_secrets, "delete_wallet_record", - async_mock.AsyncMock(), + mock.AsyncMock(), ) as mock_delete: mock_update_value.side_effect = test_module.IndyError( ErrorCode.CommonInvalidStructure @@ -234,20 +234,20 @@ async def test_record(self): @pytest.mark.asyncio async def test_storage_search_x(self): - with async_mock.patch( + with mock.patch( "aries_cloudagent.indy.sdk.wallet_plugin.load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): context = InjectionContext() @@ -279,10 +279,10 @@ async def test_storage_search_x(self): with pytest.raises(StorageSearchError): await search.fetch(10) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_open_search.side_effect = test_module.IndyError("no open") search = storage.search_records("connection") @@ -290,14 +290,14 @@ async def test_storage_search_x(self): await search.fetch() await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( indy.non_secrets, "fetch_wallet_search_next_records", - async_mock.AsyncMock(), - ) as mock_indy_fetch, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + mock.AsyncMock(), + ) as mock_indy_fetch, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_fetch.side_effect = test_module.IndyError("no fetch") search = storage.search_records("connection") @@ -305,10 +305,10 @@ async def test_storage_search_x(self): await search.fetch(10) await search.close() - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") search = storage.search_records("connection") @@ -317,17 +317,17 @@ async def test_storage_search_x(self): @pytest.mark.asyncio async def test_storage_del_close(self): - with async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() - ) as mock_delete, async_mock.patch.object( + with mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() + ) as mock_delete, mock.patch.object( IndySdkProfile, "_make_finalizer" ): context = InjectionContext() @@ -345,10 +345,10 @@ async def test_storage_del_close(self): session = await fake_profile.session() storage = session.inject(BaseStorage) - with async_mock.patch.object( - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_open_search.return_value = 1 search = storage.search_records("connection") @@ -363,10 +363,10 @@ async def test_storage_del_close(self): c += 1 mock_indy_close_search.assert_awaited_with(1) - with async_mock.patch.object( # error on close - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() + with mock.patch.object( # error on close + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() ) as mock_indy_close_search: mock_indy_close_search.side_effect = test_module.IndyError("no close") mock_indy_open_search.return_value = 1 @@ -375,18 +375,18 @@ async def test_storage_del_close(self): with pytest.raises(StorageSearchError): await search.close() - with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() - ) as mock_indy_close_search, async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + with mock.patch.object( # run on event loop until complete + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() + ) as mock_indy_close_search, mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: coros = [] - mock_get_event_loop.return_value = async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( create_task=lambda c: coros.append(c), - is_running=async_mock.MagicMock(return_value=False), - run_until_complete=async_mock.MagicMock(), + is_running=mock.MagicMock(return_value=False), + run_until_complete=mock.MagicMock(), ) mock_indy_open_search.return_value = 1 search = storage.search_records("connection") @@ -401,18 +401,18 @@ async def test_storage_del_close(self): for coro in coros: await coro - with async_mock.patch.object( # run on event loop until complete - indy.non_secrets, "open_wallet_search", async_mock.AsyncMock() - ) as mock_indy_open_search, async_mock.patch.object( - indy.non_secrets, "close_wallet_search", async_mock.AsyncMock() - ) as mock_indy_close_search, async_mock.patch.object( - asyncio, "get_event_loop", async_mock.MagicMock() + with mock.patch.object( # run on event loop until complete + indy.non_secrets, "open_wallet_search", mock.AsyncMock() + ) as mock_indy_open_search, mock.patch.object( + indy.non_secrets, "close_wallet_search", mock.AsyncMock() + ) as mock_indy_close_search, mock.patch.object( + asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop: coros = [] - mock_get_event_loop.return_value = async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( create_task=lambda c: coros.append(c), - is_running=async_mock.MagicMock(return_value=False), - run_until_complete=async_mock.MagicMock(), + is_running=mock.MagicMock(return_value=False), + run_until_complete=mock.MagicMock(), ) mock_indy_open_search.return_value = 1 mock_indy_close_search.side_effect = ValueError("Dave's not here") diff --git a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py index f4d08d9a28..e1afe2a2bc 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py @@ -1,5 +1,5 @@ import pytest -from unittest import mock as async_mock +from unittest import mock from ....config.injection_context import InjectionContext @@ -27,7 +27,7 @@ async def make_profile(): context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): return await IndySdkProfileManager().provision( context, { diff --git a/aries_cloudagent/tails/tests/test_indy.py b/aries_cloudagent/tails/tests/test_indy.py index eb961e0bfb..305ee21703 100644 --- a/aries_cloudagent/tails/tests/test_indy.py +++ b/aries_cloudagent/tails/tests/test_indy.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ...config.injection_context import InjectionContext @@ -30,9 +30,7 @@ async def test_upload(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( context, @@ -49,8 +47,8 @@ async def test_upload_indy_sdk(self): profile.settings["tails_server_upload_url"] = "http://1.2.3.4:8088" profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_write_ledgers=async_mock.AsyncMock( + mock.MagicMock( + get_write_ledgers=mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -58,12 +56,10 @@ async def test_upload_indy_sdk(self): ) ), ) - profile.context.injector.bind_instance(BaseLedger, async_mock.MagicMock()) + profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -80,8 +76,8 @@ async def test_upload_indy_vdr(self): profile.settings["tails_server_upload_url"] = "http://1.2.3.4:8088" profile.context.injector.bind_instance( BaseMultipleLedgerManager, - async_mock.MagicMock( - get_write_ledgers=async_mock.AsyncMock( + mock.MagicMock( + get_write_ledgers=mock.AsyncMock( return_value=[ "test_ledger_id_1", "test_ledger_id_2", @@ -89,12 +85,10 @@ async def test_upload_indy_vdr(self): ) ), ) - profile.context.injector.bind_instance(BaseLedger, async_mock.MagicMock()) + profile.context.injector.bind_instance(BaseLedger, mock.MagicMock()) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.return_value = "tails-hash" (ok, text) = await indy_tails.upload_tails_file( profile.context, @@ -115,9 +109,7 @@ async def test_upload_x(self): ) indy_tails = test_module.IndyTailsServer() - with async_mock.patch.object( - test_module, "put_file", async_mock.AsyncMock() - ) as mock_put: + with mock.patch.object(test_module, "put_file", mock.AsyncMock()) as mock_put: mock_put.side_effect = test_module.PutError("Server down for maintenance") (ok, text) = await indy_tails.upload_tails_file( diff --git a/aries_cloudagent/transport/inbound/tests/test_http_transport.py b/aries_cloudagent/transport/inbound/tests/test_http_transport.py index 2e3c793bed..0b3b582a79 100644 --- a/aries_cloudagent/transport/inbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ import json from aiohttp.test_utils import AioHTTPTestCase, unused_port -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile from ....core.profile import Profile @@ -61,7 +61,7 @@ def receive_message( message: InboundMessage, can_respond: bool = False, ): - message.wait_processing_complete = async_mock.AsyncMock() + message.wait_processing_complete = mock.AsyncMock() self.message_results.append((message.payload, message.receipt, can_respond)) if self.result_event: self.result_event.set() @@ -72,11 +72,11 @@ def get_application(self): return self.transport.make_application() async def test_start_x(self): - with async_mock.patch.object( - test_module.web, "TCPSite", async_mock.MagicMock() + with mock.patch.object( + test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: - mock_site.return_value = async_mock.MagicMock( - start=async_mock.AsyncMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.AsyncMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() @@ -113,30 +113,28 @@ async def test_send_message_outliers(self): await self.transport.start() test_message = {"test": "message"} - with async_mock.patch.object( - test_module.HttpTransport, "create_session", async_mock.AsyncMock() + with mock.patch.object( + test_module.HttpTransport, "create_session", mock.AsyncMock() ) as mock_session: - mock_session.return_value = async_mock.MagicMock( - receive=async_mock.AsyncMock( - return_value=async_mock.MagicMock( - receipt=async_mock.MagicMock(direct_response_requested=True), - wait_processing_complete=async_mock.AsyncMock(), + mock_session.return_value = mock.MagicMock( + receive=mock.AsyncMock( + return_value=mock.MagicMock( + receipt=mock.MagicMock(direct_response_requested=True), + wait_processing_complete=mock.AsyncMock(), ) ), can_respond=True, profile=InMemoryProfile.test_profile(), - clear_response=async_mock.MagicMock(), - wait_response=async_mock.AsyncMock(return_value=b"Hello world"), + clear_response=mock.MagicMock(), + wait_response=mock.AsyncMock(return_value=b"Hello world"), response_buffer="something", ) async with self.client.post("/", data=test_message) as resp: result = await resp.text() assert result == "Hello world" - mock_session.return_value = async_mock.MagicMock( - receive=async_mock.AsyncMock( - side_effect=test_module.WireFormatParseError() - ), + mock_session.return_value = mock.MagicMock( + receive=mock.AsyncMock(side_effect=test_module.WireFormatParseError()), profile=InMemoryProfile.test_profile(), ) async with self.client.post("/", data=test_message) as resp: @@ -150,12 +148,12 @@ async def test_send_message_outliers(self): async def test_invite_message_handler(self): await self.transport.start() - request = async_mock.MagicMock(query={"c_i": "dummy"}) + request = mock.MagicMock(query={"c_i": "dummy"}) resp = await self.transport.invite_message_handler(request) assert b"You have received a connection invitation" in resp.body assert resp.status == 200 - request = async_mock.MagicMock(query={}) + request = mock.MagicMock(query={}) resp = await self.transport.invite_message_handler(request) assert resp.body is None assert resp.status == 200 diff --git a/aries_cloudagent/transport/inbound/tests/test_manager.py b/aries_cloudagent/transport/inbound/tests/test_manager.py index 8a27c3fa41..e7192211e0 100644 --- a/aries_cloudagent/transport/inbound/tests/test_manager.py +++ b/aries_cloudagent/transport/inbound/tests/test_manager.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -45,7 +45,7 @@ async def test_setup(self): ) mgr = InboundTransportManager(self.profile, None) - with async_mock.patch.object(mgr, "register") as mock_register: + with mock.patch.object(mgr, "register") as mock_register: await mgr.setup() mock_register.assert_called_once() tcfg: InboundTransportConfiguration = mock_register.call_args[0][0] @@ -58,9 +58,9 @@ async def test_setup(self): assert mgr.undelivered_queue async def test_start_stop(self): - transport = async_mock.MagicMock() - transport.start = async_mock.AsyncMock() - transport.stop = async_mock.AsyncMock() + transport = mock.MagicMock() + transport.start = mock.AsyncMock() + transport.stop = mock.AsyncMock() mgr = InboundTransportManager(self.profile, None) mgr.register_transport(transport, "transport_cls") @@ -73,10 +73,10 @@ async def test_start_stop(self): transport.stop.assert_awaited_once_with() async def test_create_session(self): - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() self.profile.context.injector.bind_instance(BaseWireFormat, test_wire_format) - test_inbound_handler = async_mock.AsyncMock() + test_inbound_handler = mock.AsyncMock() mgr = InboundTransportManager(self.profile, test_inbound_handler) test_transport = "http" test_accept = True @@ -104,14 +104,14 @@ async def test_create_session(self): async def test_return_to_session(self): mgr = InboundTransportManager(self.profile, None) - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() session = await mgr.create_session("http", wire_format=test_wire_format) test_outbound = OutboundMessage(payload=None) test_outbound.reply_session_id = session.session_id - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: assert mgr.return_to_session(test_outbound) is True @@ -120,22 +120,22 @@ async def test_return_to_session(self): test_outbound = OutboundMessage(payload=None) test_outbound.reply_session_id = None - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=False ) as mock_accept: assert mgr.return_to_session(test_outbound) is False mock_accept.assert_called_once_with(test_outbound) - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: assert mgr.return_to_session(test_outbound) is True mock_accept.assert_called_once_with(test_outbound) async def test_close_return(self): - test_return = async_mock.MagicMock() + test_return = mock.MagicMock() mgr = InboundTransportManager(self.profile, None, return_inbound=test_return) - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() session = await mgr.create_session("http", wire_format=test_wire_format) @@ -147,8 +147,8 @@ async def test_close_return(self): async def test_dispatch_complete_undelivered(self): mgr = InboundTransportManager(self.profile, None) - test_wire_format = async_mock.MagicMock( - parse_message=async_mock.AsyncMock(return_value=("payload", "receipt")) + test_wire_format = mock.MagicMock( + parse_message=mock.AsyncMock(return_value=("payload", "receipt")) ) session = await mgr.create_session( "http", wire_format=test_wire_format, accept_undelivered=True @@ -158,7 +158,7 @@ async def test_dispatch_complete_undelivered(self): async def test_close_x(self): mgr = InboundTransportManager(self.profile, None) - mock_session = async_mock.MagicMock(response_buffer=async_mock.MagicMock()) + mock_session = mock.MagicMock(response_buffer=mock.MagicMock()) mgr.closed_session(mock_session) async def test_process_undelivered(self): @@ -166,7 +166,7 @@ async def test_process_undelivered(self): {"transport.enable_undelivered_queue": True} ) test_verkey = "test-verkey" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() mgr = InboundTransportManager(self.profile, None) await mgr.setup() @@ -180,7 +180,7 @@ async def test_process_undelivered(self): ) session.add_reply_verkeys(test_verkey) - with async_mock.patch.object( + with mock.patch.object( session, "accept_response", return_value=True ) as mock_accept: mgr.process_undelivered(session) @@ -192,7 +192,7 @@ async def test_return_undelivered_false(self): {"transport.enable_undelivered_queue": False} ) test_verkey = "test-verkey" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() mgr = InboundTransportManager(self.profile, None) await mgr.setup() diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index 3dac5fb85f..51ce83811f 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -1,7 +1,7 @@ import asyncio import pytest -from unittest import mock as async_mock +from unittest import mock from unittest import TestCase from ....admin.server import AdminResponder @@ -23,11 +23,11 @@ def setUp(self): self.profile = InMemoryProfile.test_profile() def test_init(self): - test_inbound = async_mock.MagicMock() + test_inbound = mock.MagicMock() test_session_id = "session-id" - test_wire_format = async_mock.MagicMock() + test_wire_format = mock.MagicMock() test_client_info = {"client": "info"} - test_close = async_mock.MagicMock() + test_close = mock.MagicMock() test_reply_mode = MessageReceipt.REPLY_MODE_ALL test_reply_thread_ids = {"1", "2"} test_reply_verkeys = {"3", "4"} @@ -54,8 +54,8 @@ def test_init(self): assert "1" in sess.reply_thread_ids assert "3" in sess.reply_verkeys - test_msg = async_mock.MagicMock() - with async_mock.patch.object(sess, "process_inbound") as process: + test_msg = mock.MagicMock() + with mock.patch.object(sess, "process_inbound") as process: sess.receive_inbound(test_msg) process.assert_called_once_with(test_msg) test_inbound.assert_called_once_with( @@ -89,10 +89,10 @@ def test_setters(self): async def test_parse_inbound(self): test_session_id = "session-id" test_transport_type = "transport-type" - test_wire_format = async_mock.MagicMock() - test_wire_format.parse_message = async_mock.AsyncMock() + test_wire_format = mock.MagicMock() + test_wire_format.parse_message = mock.AsyncMock() test_parsed = "parsed-payload" - test_receipt = async_mock.MagicMock() + test_receipt = mock.MagicMock() test_wire_format.parse_message.return_value = (test_parsed, test_receipt) sess = InboundSession( profile=self.profile, @@ -103,7 +103,7 @@ async def test_parse_inbound(self): ) session = self.profile.session() - setattr(self.profile, "session", async_mock.MagicMock(return_value=session)) + setattr(self.profile, "session", mock.MagicMock(return_value=session)) test_payload = "{}" result = await sess.parse_inbound(test_payload) @@ -114,18 +114,18 @@ async def test_parse_inbound(self): assert result.transport_type == test_transport_type async def test_receive(self): - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.AsyncMock( - return_value=[async_mock.MagicMock(is_managed=True)] + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( + return_value=[mock.MagicMock(is_managed=True)] ) - self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( return_value=self.profile ) self.profile.context.injector.bind_instance( BaseMultitenantManager, self.multitenant_mgr ) self.profile.context.update_settings({"multitenant.enabled": True}) - self.base_responder = async_mock.MagicMock(AdminResponder, autospec=True) + self.base_responder = mock.MagicMock(AdminResponder, autospec=True) self.profile.context.injector.bind_instance(BaseResponder, self.base_responder) sess = InboundSession( @@ -134,12 +134,12 @@ async def test_receive(self): session_id=None, wire_format=None, ) - test_msg = async_mock.MagicMock() + test_msg = mock.MagicMock() - with async_mock.patch.object( - sess, "parse_inbound", async_mock.AsyncMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.AsyncMock() + ) as encode, mock.patch.object( + sess, "receive_inbound", mock.MagicMock() ) as receive: result = await sess.receive(test_msg) encode.assert_awaited_once_with(test_msg) @@ -147,11 +147,11 @@ async def test_receive(self): assert result is encode.return_value async def test_receive_no_wallet_found(self): - self.multitenant_mgr = async_mock.MagicMock(MultitenantManager, autospec=True) - self.multitenant_mgr.get_wallets_by_message = async_mock.AsyncMock( + self.multitenant_mgr = mock.MagicMock(MultitenantManager, autospec=True) + self.multitenant_mgr.get_wallets_by_message = mock.AsyncMock( side_effect=ValueError("no such wallet") ) - self.multitenant_mgr.get_wallet_profile = async_mock.AsyncMock( + self.multitenant_mgr.get_wallet_profile = mock.AsyncMock( return_value=self.profile ) self.profile.context.injector.bind_instance( @@ -165,12 +165,12 @@ async def test_receive_no_wallet_found(self): session_id=None, wire_format=None, ) - test_msg = async_mock.MagicMock() + test_msg = mock.MagicMock() - with async_mock.patch.object( - sess, "parse_inbound", async_mock.AsyncMock() - ) as encode, async_mock.patch.object( - sess, "receive_inbound", async_mock.MagicMock() + with mock.patch.object( + sess, "parse_inbound", mock.AsyncMock() + ) as encode, mock.patch.object( + sess, "receive_inbound", mock.MagicMock() ) as receive: result = await sess.receive(test_msg) encode.assert_awaited_once_with(test_msg) @@ -267,9 +267,7 @@ async def test_wait_response(self): assert sess.response_event.is_set() assert sess.response_buffered - with async_mock.patch.object( - sess, "encode_outbound", async_mock.AsyncMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) assert encode.awaited_once_with(test_msg) assert result is encode.return_value @@ -292,9 +290,7 @@ async def test_wait_response_x(self): assert sess.response_event.is_set() assert sess.response_buffered - with async_mock.patch.object( - sess, "encode_outbound", async_mock.AsyncMock() - ) as encode: + with mock.patch.object(sess, "encode_outbound", mock.AsyncMock()) as encode: encode.side_effect = WireFormatError() with pytest.raises(asyncio.TimeoutError): await asyncio.wait_for(sess.wait_response(), 0.1) @@ -305,8 +301,8 @@ async def test_wait_response_x(self): assert await asyncio.wait_for(sess.wait_response(), 0.1) is None async def test_encode_response(self): - test_wire_format = async_mock.MagicMock() - test_wire_format.encode_message = async_mock.AsyncMock() + test_wire_format = mock.MagicMock() + test_wire_format.encode_message = mock.AsyncMock() sess = InboundSession( profile=self.profile, inbound_handler=None, @@ -318,7 +314,7 @@ async def test_encode_response(self): test_to_verkey = "to-verkey" session = self.profile.session() - setattr(self.profile, "session", async_mock.MagicMock(return_value=session)) + setattr(self.profile, "session", mock.MagicMock(return_value=session)) with self.assertRaises(WireFormatError): await sess.encode_outbound(test_msg) @@ -347,7 +343,7 @@ async def test_accept_response(self): ) test_msg = OutboundMessage(payload=None) - with async_mock.patch.object(sess, "select_outbound") as selector: + with mock.patch.object(sess, "select_outbound") as selector: selector.return_value = False accepted = sess.accept_response(test_msg) diff --git a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py index dc049db5c0..765b725fdc 100644 --- a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py @@ -3,7 +3,7 @@ import pytest from aiohttp.test_utils import AioHTTPTestCase, unused_port -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile @@ -68,11 +68,11 @@ def receive_message( self.result_event.set() async def test_start_x(self): - with async_mock.patch.object( - test_module.web, "TCPSite", async_mock.MagicMock() + with mock.patch.object( + test_module.web, "TCPSite", mock.MagicMock() ) as mock_site: - mock_site.return_value = async_mock.MagicMock( - start=async_mock.AsyncMock(side_effect=OSError()) + mock_site.return_value = mock.MagicMock( + start=mock.AsyncMock(side_effect=OSError()) ) with pytest.raises(test_module.InboundTransportSetupError): await self.transport.start() diff --git a/aries_cloudagent/transport/outbound/tests/test_http_transport.py b/aries_cloudagent/transport/outbound/tests/test_http_transport.py index b8826afb5f..c7b203c38f 100644 --- a/aries_cloudagent/transport/outbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ from aiohttp.test_utils import AioHTTPTestCase from aiohttp import web -from unittest import mock as async_mock +from unittest import mock from ....core.in_memory import InMemoryProfile from ....utils.stats import Collector @@ -129,13 +129,13 @@ async def test_transport_coverage(self): with pytest.raises(OutboundTransportError): await transport.handle_message(None, None, None) - with async_mock.patch.object( - transport, "client_session", async_mock.MagicMock() + with mock.patch.object( + transport, "client_session", mock.MagicMock() ) as mock_session: - mock_response = async_mock.MagicMock(status=404) - mock_session.post = async_mock.MagicMock( - return_value=async_mock.MagicMock( - __aenter__=async_mock.AsyncMock(return_value=mock_response) + mock_response = mock.MagicMock(status=404) + mock_session.post = mock.MagicMock( + return_value=mock.MagicMock( + __aenter__=mock.AsyncMock(return_value=mock_response) ) ) with pytest.raises(OutboundTransportError): diff --git a/aries_cloudagent/transport/outbound/tests/test_manager.py b/aries_cloudagent/transport/outbound/tests/test_manager.py index 28095cc4e7..9f6e1c551d 100644 --- a/aries_cloudagent/transport/outbound/tests/test_manager.py +++ b/aries_cloudagent/transport/outbound/tests/test_manager.py @@ -1,6 +1,6 @@ import json -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ....core.in_memory import InMemoryProfile @@ -41,7 +41,7 @@ def test_maximum_retry_count(self): async def test_setup(self): profile = InMemoryProfile.test_profile({"transport.outbound_configs": ["http"]}) mgr = OutboundTransportManager(profile) - with async_mock.patch.object(mgr, "register") as mock_register: + with mock.patch.object(mgr, "register") as mock_register: await mgr.setup() mock_register.assert_called_once_with("http") @@ -49,19 +49,19 @@ async def test_send_message(self): profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - transport_cls = async_mock.Mock(spec=[]) + transport_cls = mock.Mock(spec=[]) with self.assertRaises(OutboundTransportRegistrationError): mgr.register_class(transport_cls, "transport_cls") - transport = async_mock.MagicMock() - transport.handle_message = async_mock.AsyncMock() - transport.wire_format.encode_message = async_mock.AsyncMock() - transport.start = async_mock.AsyncMock() - transport.stop = async_mock.AsyncMock() + transport = mock.MagicMock() + transport.handle_message = mock.AsyncMock() + transport.wire_format.encode_message = mock.AsyncMock() + transport.start = mock.AsyncMock() + transport.stop = mock.AsyncMock() transport.schemes = ["http"] transport.is_external = False - transport_cls = async_mock.MagicMock() + transport_cls = mock.MagicMock() transport_cls.schemes = ["http"] transport_cls.return_value = transport mgr.register_class(transport_cls, "transport_cls") @@ -83,9 +83,7 @@ async def test_send_message(self): send_session = InMemoryProfile.test_session() send_profile = send_session.profile - setattr( - send_profile, "session", async_mock.MagicMock(return_value=send_session) - ) + setattr(send_profile, "session", mock.MagicMock(return_value=send_session)) await mgr.enqueue_message(send_profile, message) await mgr.flush() @@ -125,8 +123,8 @@ async def test_send_message(self): async def test_stop_cancel(self): profile = InMemoryProfile.test_profile({"transport.outbound_configs": ["http"]}) mgr = OutboundTransportManager(profile) - mgr._process_task = async_mock.MagicMock( - done=async_mock.MagicMock(return_value=False), cancel=async_mock.MagicMock() + mgr._process_task = mock.MagicMock( + done=mock.MagicMock(return_value=False), cancel=mock.MagicMock() ) mgr.running_transports = {} await mgr.stop() @@ -146,15 +144,15 @@ async def test_enqueue_webhook(self): test_topic, test_payload, test_endpoint, max_attempts=test_attempts ) - transport_cls = async_mock.MagicMock() + transport_cls = mock.MagicMock() transport_cls.schemes = ["http"] - transport_cls.return_value = async_mock.MagicMock() + transport_cls.return_value = mock.MagicMock() transport_cls.return_value.schemes = ["http"] - transport_cls.return_value.start = async_mock.AsyncMock() + transport_cls.return_value.start = mock.AsyncMock() tid = mgr.register_class(transport_cls, "transport_cls") await mgr.start_transport(tid) - with async_mock.patch.object(mgr, "process_queued") as mock_process: + with mock.patch.object(mgr, "process_queued") as mock_process: mgr.enqueue_webhook( test_topic, test_payload, test_endpoint, max_attempts=test_attempts ) @@ -167,47 +165,47 @@ async def test_enqueue_webhook(self): assert queued.state == QueuedOutboundMessage.STATE_PENDING async def test_process_done_x(self): - mock_task = async_mock.MagicMock( - done=async_mock.MagicMock(return_value=True), - exception=async_mock.MagicMock(return_value=KeyError("No such key")), + mock_task = mock.MagicMock( + done=mock.MagicMock(return_value=True), + exception=mock.MagicMock(return_value=KeyError("No such key")), ) profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - with async_mock.patch.object( - mgr, "_process_task", async_mock.MagicMock() + with mock.patch.object( + mgr, "_process_task", mock.MagicMock() ) as mock_mgr_process: - mock_mgr_process.done = async_mock.MagicMock(return_value=True) + mock_mgr_process.done = mock.MagicMock(return_value=True) mgr._process_done(mock_task) async def test_process_finished_x(self): - mock_queued = async_mock.MagicMock(retries=1) - mock_task = async_mock.MagicMock( + mock_queued = mock.MagicMock(retries=1) + mock_task = mock.MagicMock( exc_info=(KeyError, KeyError("nope"), None), ) profile = InMemoryProfile.test_profile() mgr = OutboundTransportManager(profile) - with async_mock.patch.object( - mgr, "process_queued", async_mock.MagicMock() + with mock.patch.object( + mgr, "process_queued", mock.MagicMock() ) as mock_mgr_process: mgr.finished_encode(mock_queued, mock_task) mgr.finished_deliver(mock_queued, mock_task) mgr.finished_deliver(mock_queued, mock_task) async def test_process_loop_retry_now(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_RETRY, retry_at=test_module.get_timer() - 1, ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_trace.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -215,18 +213,18 @@ async def test_process_loop_retry_now(self): assert mock_queued.retry_at is None async def test_process_loop_retry_later(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_RETRY, retry_at=test_module.get_timer() + 3600, ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module.asyncio, "sleep", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "sleep", mock.AsyncMock() ) as mock_sleep_x: mock_sleep_x.side_effect = KeyError() with self.assertRaises(KeyError): # cover retry logic and bail @@ -235,21 +233,21 @@ async def test_process_loop_retry_later(self): async def test_process_loop_new(self): profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_new = [ - async_mock.MagicMock( + mock.MagicMock( state=test_module.QueuedOutboundMessage.STATE_NEW, - message=async_mock.MagicMock(enc_payload=b"encr"), + message=mock.MagicMock(enc_payload=b"encr"), ) ] - with async_mock.patch.object( - mgr, "deliver_queued_message", async_mock.MagicMock() - ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + mgr, "deliver_queued_message", mock.MagicMock() + ) as mock_deliver, mock.patch.object( + mgr.outbound_event, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_wait.side_effect = KeyError() # cover state=NEW logic and bail @@ -258,21 +256,21 @@ async def test_process_loop_new(self): async def test_process_loop_new_deliver(self): profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_new = [ - async_mock.MagicMock( + mock.MagicMock( state=test_module.QueuedOutboundMessage.STATE_DELIVER, - message=async_mock.MagicMock(enc_payload=b"encr"), + message=mock.MagicMock(enc_payload=b"encr"), ) ] - with async_mock.patch.object( - mgr, "deliver_queued_message", async_mock.MagicMock() - ) as mock_deliver, async_mock.patch.object( - mgr.outbound_event, "wait", async_mock.AsyncMock() - ) as mock_wait, async_mock.patch.object( - test_module, "trace_event", async_mock.MagicMock() + with mock.patch.object( + mgr, "deliver_queued_message", mock.MagicMock() + ) as mock_deliver, mock.patch.object( + mgr.outbound_event, "wait", mock.AsyncMock() + ) as mock_wait, mock.patch.object( + test_module, "trace_event", mock.MagicMock() ) as mock_trace: mock_wait.side_effect = KeyError() # cover state=DELIVER logic and bail @@ -280,7 +278,7 @@ async def test_process_loop_new_deliver(self): await mgr._process_loop() async def test_process_loop_x(self): - mock_queued = async_mock.MagicMock( + mock_queued = mock.MagicMock( state=QueuedOutboundMessage.STATE_DONE, error=KeyError(), endpoint="http://1.2.3.4:8081", @@ -288,30 +286,28 @@ async def test_process_loop_x(self): ) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) await mgr._process_loop() async def test_finished_deliver_x_log_debug(self): - mock_queued = async_mock.MagicMock( - state=QueuedOutboundMessage.STATE_DONE, retries=1 - ) - mock_completed_x = async_mock.MagicMock(exc_info=KeyError("an error occurred")) + mock_queued = mock.MagicMock(state=QueuedOutboundMessage.STATE_DONE, retries=1) + mock_completed_x = mock.MagicMock(exc_info=KeyError("an error occurred")) profile = InMemoryProfile.test_profile() - mock_handle_not_delivered = async_mock.MagicMock() + mock_handle_not_delivered = mock.MagicMock() mgr = OutboundTransportManager(profile, mock_handle_not_delivered) mgr.outbound_buffer.append(mock_queued) - with async_mock.patch.object( - test_module.LOGGER, "exception", async_mock.MagicMock() - ) as mock_logger_exception, async_mock.patch.object( - test_module.LOGGER, "error", async_mock.MagicMock() - ) as mock_logger_error, async_mock.patch.object( - test_module.LOGGER, "isEnabledFor", async_mock.MagicMock() - ) as mock_logger_enabled, async_mock.patch.object( - mgr, "process_queued", async_mock.MagicMock() + with mock.patch.object( + test_module.LOGGER, "exception", mock.MagicMock() + ) as mock_logger_exception, mock.patch.object( + test_module.LOGGER, "error", mock.MagicMock() + ) as mock_logger_error, mock.patch.object( + test_module.LOGGER, "isEnabledFor", mock.MagicMock() + ) as mock_logger_enabled, mock.patch.object( + mgr, "process_queued", mock.MagicMock() ) as mock_process: mock_logger_enabled.return_value = True # cover debug logging mgr.finished_deliver(mock_queued, mock_completed_x) @@ -319,11 +315,11 @@ async def test_finished_deliver_x_log_debug(self): async def test_should_encode_outbound_message(self): base_wire_format = BaseWireFormat() encoded_msg = "encoded_message" - base_wire_format.encode_message = async_mock.AsyncMock(return_value=encoded_msg) + base_wire_format.encode_message = mock.AsyncMock(return_value=encoded_msg) profile = InMemoryProfile.test_profile(bind={BaseWireFormat: base_wire_format}) - profile.session = async_mock.AsyncMock(return_value=async_mock.MagicMock()) - outbound = async_mock.MagicMock(payload="payload", enc_payload=None) - target = async_mock.MagicMock() + profile.session = mock.AsyncMock(return_value=mock.MagicMock()) + outbound = mock.MagicMock(payload="payload", enc_payload=None) + target = mock.MagicMock() mgr = OutboundTransportManager(profile) result = await mgr.encode_outbound_message(profile, outbound, target) @@ -340,8 +336,8 @@ async def test_should_encode_outbound_message(self): async def test_should_not_encode_already_packed_message(self): profile = InMemoryProfile.test_session().profile enc_payload = "enc_payload" - outbound = async_mock.MagicMock(enc_payload=enc_payload) - target = async_mock.MagicMock() + outbound = mock.MagicMock(enc_payload=enc_payload) + target = mock.MagicMock() mgr = OutboundTransportManager(profile) result = await mgr.encode_outbound_message(profile, outbound, target) diff --git a/aries_cloudagent/transport/queue/tests/test_basic_queue.py b/aries_cloudagent/transport/queue/tests/test_basic_queue.py index 3772cfed3c..969b578c94 100644 --- a/aries_cloudagent/transport/queue/tests/test_basic_queue.py +++ b/aries_cloudagent/transport/queue/tests/test_basic_queue.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from .. import basic as test_module @@ -37,26 +37,22 @@ async def test_dequeue_x(self): test_value = "test value" await queue.enqueue(test_value) - with async_mock.patch.object( - test_module.asyncio, "get_event_loop", async_mock.MagicMock() - ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "get_event_loop", mock.MagicMock() + ) as mock_get_event_loop, mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: mock_wait.return_value = ( - async_mock.MagicMock(), - [ - async_mock.MagicMock( - done=async_mock.MagicMock(), cancel=async_mock.MagicMock() - ) - ], + mock.MagicMock(), + [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], ) - mock_get_event_loop.return_value = async_mock.MagicMock( - create_task=async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( + create_task=mock.MagicMock( side_effect=[ - async_mock.MagicMock(), # stopped - async_mock.MagicMock( # dequeued - done=async_mock.MagicMock(return_value=True), - exception=async_mock.MagicMock(return_value=KeyError()), + mock.MagicMock(), # stopped + mock.MagicMock( # dequeued + done=mock.MagicMock(return_value=True), + exception=mock.MagicMock(return_value=KeyError()), ), ] ) @@ -69,27 +65,23 @@ async def test_dequeue_none(self): test_value = "test value" await queue.enqueue(test_value) - with async_mock.patch.object( - test_module.asyncio, "get_event_loop", async_mock.MagicMock() - ) as mock_get_event_loop, async_mock.patch.object( - test_module.asyncio, "wait", async_mock.AsyncMock() + with mock.patch.object( + test_module.asyncio, "get_event_loop", mock.MagicMock() + ) as mock_get_event_loop, mock.patch.object( + test_module.asyncio, "wait", mock.AsyncMock() ) as mock_wait: mock_wait.return_value = ( - async_mock.MagicMock(), - [ - async_mock.MagicMock( - done=async_mock.MagicMock(), cancel=async_mock.MagicMock() - ) - ], + mock.MagicMock(), + [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], ) - mock_get_event_loop.return_value = async_mock.MagicMock( - create_task=async_mock.MagicMock( + mock_get_event_loop.return_value = mock.MagicMock( + create_task=mock.MagicMock( side_effect=[ - async_mock.MagicMock( # stopped - done=async_mock.MagicMock(return_value=True) + mock.MagicMock( # stopped + done=mock.MagicMock(return_value=True) ), - async_mock.MagicMock( # dequeued - done=async_mock.MagicMock(return_value=False) + mock.MagicMock( # dequeued + done=mock.MagicMock(return_value=False) ), ] ) diff --git a/aries_cloudagent/transport/tests/test_pack_format.py b/aries_cloudagent/transport/tests/test_pack_format.py index 4bbaaf7ea4..a8a11fb892 100644 --- a/aries_cloudagent/transport/tests/test_pack_format.py +++ b/aries_cloudagent/transport/tests/test_pack_format.py @@ -2,7 +2,7 @@ from base64 import b64encode from unittest import IsolatedAsyncioTestCase -from unittest import mock as async_mock +from unittest import mock from ...core.in_memory import InMemoryProfile from ...protocols.didcomm_prefix import DIDCommPrefix @@ -54,9 +54,7 @@ async def test_errors(self): } serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.AsyncMock() - ) as mock_unpack: + with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: mock_unpack.return_value = "{missing-brace" with self.assertRaises(WireFormatParseError) as context: await serializer.parse_message(self.session, json.dumps(x_message)) @@ -64,9 +62,7 @@ async def test_errors(self): serializer = PackWireFormat() serializer.task_queue = None - with async_mock.patch.object( - serializer, "unpack", async_mock.AsyncMock() - ) as mock_unpack: + with mock.patch.object(serializer, "unpack", mock.AsyncMock()) as mock_unpack: mock_unpack.return_value = json.dumps([1, 2, 3]) with self.assertRaises(WireFormatParseError) as context: await serializer.parse_message(self.session, json.dumps(x_message)) @@ -92,25 +88,23 @@ async def test_pack_x(self): ["key"], ) - mock_wallet = async_mock.MagicMock( - pack_message=async_mock.AsyncMock(side_effect=WalletError()) + mock_wallet = mock.MagicMock( + pack_message=mock.AsyncMock(side_effect=WalletError()) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], None, ["key"]) - mock_wallet = async_mock.MagicMock( - pack_message=async_mock.AsyncMock( + mock_wallet = mock.MagicMock( + pack_message=mock.AsyncMock( side_effect=[json.dumps("message").encode("utf-8"), WalletError()] ) ) session = InMemoryProfile.test_session(bind={BaseWallet: mock_wallet}) - with async_mock.patch.object( - test_module, "Forward", async_mock.MagicMock() + with mock.patch.object( + test_module, "Forward", mock.MagicMock() ) as mock_forward: - mock_forward.return_value = async_mock.MagicMock( - to_json=async_mock.MagicMock() - ) + mock_forward.return_value = mock.MagicMock(to_json=mock.MagicMock()) with self.assertRaises(WireFormatEncodeError): await serializer.pack(session, None, ["key"], ["key"], ["key"]) diff --git a/aries_cloudagent/transport/tests/test_stats.py b/aries_cloudagent/transport/tests/test_stats.py index 3b0784e779..acddd20d2d 100644 --- a/aries_cloudagent/transport/tests/test_stats.py +++ b/aries_cloudagent/transport/tests/test_stats.py @@ -1,4 +1,4 @@ -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase @@ -7,9 +7,9 @@ class TestStatsTracer(IsolatedAsyncioTestCase): def setUp(self): - self.context = async_mock.MagicMock( - socket_timer=async_mock.MagicMock( - stop=async_mock.MagicMock(side_effect=AttributeError("wrong")) + self.context = mock.MagicMock( + socket_timer=mock.MagicMock( + stop=mock.MagicMock(side_effect=AttributeError("wrong")) ) ) self.tracer = test_module.StatsTracer(test_module.Collector(), "test") diff --git a/aries_cloudagent/utils/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py index 2b8f20c624..e8e5e676ff 100644 --- a/aries_cloudagent/utils/tests/test_task_queue.py +++ b/aries_cloudagent/utils/tests/test_task_queue.py @@ -1,6 +1,6 @@ import asyncio -from unittest import mock as async_mock +from unittest import mock from unittest import IsolatedAsyncioTestCase from ..task_queue import CompletedTask, PendingTask, TaskQueue, task_exc_info @@ -84,7 +84,7 @@ async def test_pending(self): assert pend.cancelled task.cancel() - with async_mock.patch.object(pend, "task_future", autospec=True) as mock_future: + with mock.patch.object(pend, "task_future", autospec=True) as mock_future: mock_future.cancelled.return_value = True pend.task = "a suffusion of yellow" mock_future.set_result.assert_not_called() @@ -106,10 +106,10 @@ def done(complete: CompletedTask): async def noop(): return - with async_mock.patch.object( - queue, "drain", async_mock.MagicMock() - ) as mock_drain, async_mock.patch.object( - queue, "wait_for", async_mock.AsyncMock() + with mock.patch.object( + queue, "drain", mock.MagicMock() + ) as mock_drain, mock.patch.object( + queue, "wait_for", mock.AsyncMock() ) as mock_wait_for: mock_drain.side_effect = [queue.loop.create_task(noop()), None] await queue.complete(cleanup=True) @@ -138,7 +138,7 @@ async def test_drain_done(self): queue = TaskQueue(1) queue.add_pending(pend) - with async_mock.patch.object( + with mock.patch.object( queue.pending_tasks[0], "task_future", autospec=True ) as mock_future: mock_future.cancelled.return_value = False diff --git a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py index d2e9353d96..a59e738916 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -1,4 +1,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from aries_cloudagent.wallet.key_type import ED25519 @@ -27,12 +27,12 @@ async def test_sign(self): key_type=ED25519, public_key_base58=public_key_base58, ) - signed = async_mock.MagicMock() + signed = mock.MagicMock() - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "sign_message", - async_mock.AsyncMock(return_value=signed), + mock.AsyncMock(return_value=signed), ) as sign_message: singed_ret = await key_pair.sign(b"Message") @@ -56,10 +56,10 @@ async def test_verify(self): public_key_base58=public_key_base58, ) - with async_mock.patch.object( + with mock.patch.object( InMemoryWallet, "verify_message", - async_mock.AsyncMock(return_value=True), + mock.AsyncMock(return_value=True), ) as verify_message: verified = await key_pair.verify(b"Message", b"signature") diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py index f8858b8a92..884006a36a 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ...validation_result import PurposeResult from ..controller_proof_purpose import ControllerProofPurpose @@ -33,18 +33,16 @@ async def test_validate(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) proof = { "challenge": "8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "example.com", } - document = async_mock.MagicMock() - suite = async_mock.MagicMock() + document = mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} - document_loader = async_mock.MagicMock() + document_loader = mock.MagicMock() result = proof_purpose.validate( proof=proof, @@ -67,9 +65,7 @@ async def test_validate_x_challenge_does_not_match(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) result = proof_purpose.validate( @@ -77,10 +73,10 @@ async def test_validate_x_challenge_does_not_match(self): "challenge": "another8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "example.com", }, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid assert "The challenge is not as expected" in str(result.error) @@ -90,9 +86,7 @@ async def test_validate_x_domain_does_not_match(self): challenge="8378c56e-4926-4a54-9587-0f2ef564619a", domain="example.com" ) - with async_mock.patch.object( - ControllerProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(ControllerProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult(valid=True) result = proof_purpose.validate( @@ -100,10 +94,10 @@ async def test_validate_x_domain_does_not_match(self): "challenge": "8378c56e-4926-4a54-9587-0f2ef564619a", "domain": "anotherexample.com", }, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid assert "The domain is not as expected" in str(result.error) diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py index b11641e071..052acd1603 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ....tests.data import TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519 from ....tests.document_loader import custom_document_loader @@ -31,7 +31,7 @@ async def test_validate(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -54,7 +54,7 @@ async def test_validate_controller_invalid_type(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -78,7 +78,7 @@ async def test_validate_x_not_authorized(self): document = TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = { "id": TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519["proof"][ "verificationMethod" @@ -100,15 +100,15 @@ async def test_validate_x_not_authorized(self): async def test_validate_x_super_invalid(self): proof_purpose = ControllerProofPurpose(term="assertionMethod") - with async_mock.patch.object(ProofPurpose, "validate") as validate_mock: - validate_mock.return_value = async_mock.MagicMock(valid=False) + with mock.patch.object(ProofPurpose, "validate") as validate_mock: + validate_mock.return_value = mock.MagicMock(valid=False) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py index 97c061b6bf..dfa4749fcc 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from ...validation_result import PurposeResult from ..assertion_proof_purpose import AssertionProofPurpose @@ -25,15 +25,13 @@ async def test_properties(self): async def test_validate(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": TEST_VC_DOCUMENT_SIGNED_ED25519["issuer"]} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -55,16 +53,14 @@ async def test_validate(self): async def test_validate_x_no_issuer(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": TEST_VC_DOCUMENT_SIGNED_ED25519["issuer"]} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() document.pop("issuer") proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -80,15 +76,13 @@ async def test_validate_x_no_issuer(self): async def test_validate_x_no_match_issuer(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: validate_mock.return_value = PurposeResult( valid=True, controller={"id": "random_controller_id"} ) document = TEST_VC_DOCUMENT_SIGNED_ED25519.copy() proof = document.pop("proof") - suite = async_mock.MagicMock() + suite = mock.MagicMock() verification_method = {"controller": "controller"} result = proof_purpose.validate( @@ -106,17 +100,15 @@ async def test_validate_x_no_match_issuer(self): async def test_validate_x_super_invalid(self): proof_purpose = CredentialIssuancePurpose() - with async_mock.patch.object( - AssertionProofPurpose, "validate" - ) as validate_mock: - validate_mock.return_value = async_mock.MagicMock(valid=False) + with mock.patch.object(AssertionProofPurpose, "validate") as validate_mock: + validate_mock.return_value = mock.MagicMock(valid=False) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py index 13e3d76c7c..4865f9c9c4 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py @@ -1,5 +1,5 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from .....messaging.util import datetime_to_str from ..proof_purpose import ProofPurpose @@ -24,11 +24,11 @@ async def test_validate(self): proof_purpose = ProofPurpose(term="ProofTerm", date=datetime.now()) result = proof_purpose.validate( - proof=async_mock.MagicMock(), - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + proof=mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert result.valid @@ -40,10 +40,10 @@ async def test_validate_timestamp_delta(self): result = proof_purpose.validate( proof={"created": datetime_to_str(date + timedelta(5))}, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert result.valid @@ -55,10 +55,10 @@ async def test_validate_timestamp_delta_out_of_rage(self): result = proof_purpose.validate( proof={"created": datetime_to_str(date + timedelta(15))}, - document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + document=mock.MagicMock(), + suite=mock.MagicMock(), + verification_method=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.valid diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py index ca4ccc453a..24ffe32e96 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py @@ -1,4 +1,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -138,9 +138,9 @@ async def test_verify_signature_x_invalid_proof_value(self): with self.assertRaises(LinkedDataProofException): await suite.verify_signature( - verify_data=async_mock.MagicMock(), - verification_method=async_mock.MagicMock(), - document=async_mock.MagicMock(), + verify_data=mock.MagicMock(), + verification_method=mock.MagicMock(), + document=mock.MagicMock(), proof={"proofValue": {"not": "a string"}}, - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py index 6f408e1729..4900ba7c25 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py @@ -1,4 +1,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 @@ -202,8 +202,8 @@ async def test_derive_proof_x_invalid_proof_type(self): with self.assertRaises(LinkedDataProofException): await suite.derive_proof( - reveal_document=async_mock.MagicMock(), - document=async_mock.MagicMock(), + reveal_document=mock.MagicMock(), + document=mock.MagicMock(), proof={"type": "incorrect type"}, - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) diff --git a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index 6866237672..7ed91bc6d1 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py @@ -1,4 +1,4 @@ -from unittest import IsolatedAsyncioTestCase, mock as async_mock +from unittest import IsolatedAsyncioTestCase, mock from datetime import datetime import pytest @@ -112,8 +112,8 @@ async def test_issue_x_invalid_credential_structure(self): with self.assertRaises(LinkedDataProofException) as context: await issue( credential=credential, - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert "invalid structure" in str(context.exception) @@ -124,9 +124,9 @@ async def test_derive_x_invalid_credential_structure(self): with self.assertRaises(LinkedDataProofException) as context: await derive_credential( credential=credential, - reveal_document=async_mock.MagicMock(), - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + reveal_document=mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert "invalid structure" in str(context.exception) @@ -163,7 +163,7 @@ async def test_verify_x_invalid_credential_structure(self): result = await verify_credential( credential=credential, suites=[], - document_loader=async_mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert not result.verified @@ -305,8 +305,8 @@ async def test_sign_presentation_x_no_purpose_challenge(self): with self.assertRaises(LinkedDataProofException) as context: await sign_presentation( presentation=PRESENTATION_UNSIGNED, - suite=async_mock.MagicMock(), - document_loader=async_mock.MagicMock(), + suite=mock.MagicMock(), + document_loader=mock.MagicMock(), ) assert 'A "challenge" param is required' in str(context.exception) diff --git a/aries_cloudagent/wallet/tests/test_indy_wallet.py b/aries_cloudagent/wallet/tests/test_indy_wallet.py index a2953d2f48..e1d049af6e 100644 --- a/aries_cloudagent/wallet/tests/test_indy_wallet.py +++ b/aries_cloudagent/wallet/tests/test_indy_wallet.py @@ -7,7 +7,7 @@ import indy.did import indy.wallet import pytest -from unittest import mock as async_mock +from unittest import mock from ...config.injection_context import InjectionContext from ...core.error import ProfileDuplicateError, ProfileError, ProfileNotFoundError @@ -39,7 +39,7 @@ async def wallet(): context = InjectionContext() context.injector.bind_instance(IndySdkLedgerPool, IndySdkLedgerPool("name")) context.injector.bind_instance(DIDMethods, DIDMethods()) - with async_mock.patch.object(IndySdkProfile, "_make_finalizer"): + with mock.patch.object(IndySdkProfile, "_make_finalizer"): profile = cast( IndySdkProfile, await IndySdkProfileManager().provision( @@ -68,8 +68,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): SOV, ED25519, self.test_seed, self.test_sov_did ) - with async_mock.patch.object( - indy.did, "replace_keys_start", async_mock.AsyncMock() + with mock.patch.object( + indy.did, "replace_keys_start", mock.AsyncMock() ) as mock_repl_start: mock_repl_start.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -78,8 +78,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): await wallet.rotate_did_keypair_start(self.test_sov_did) assert "outlier" in str(excinfo.value) - with async_mock.patch.object( - indy.did, "replace_keys_apply", async_mock.AsyncMock() + with mock.patch.object( + indy.did, "replace_keys_apply", mock.AsyncMock() ) as mock_repl_apply: mock_repl_apply.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -90,8 +90,8 @@ async def test_rotate_did_keypair_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_signing_key_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "create_key", async_mock.AsyncMock() + with mock.patch.object( + indy.crypto, "create_key", mock.AsyncMock() ) as mock_create_key: mock_create_key.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -102,8 +102,8 @@ async def test_create_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_create_local_did_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.did, "create_and_store_my_did", async_mock.AsyncMock() + with mock.patch.object( + indy.did, "create_and_store_my_did", mock.AsyncMock() ) as mock_create: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -114,8 +114,8 @@ async def test_create_local_did_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_set_did_endpoint_ledger(self, wallet: IndySdkWallet): - mock_ledger = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.AsyncMock() ) info_pub = await wallet.create_public_did( SOV, @@ -142,8 +142,8 @@ async def test_set_did_endpoint_ledger_with_routing_keys( self, wallet: IndySdkWallet ): routing_keys = ["3YJCx3TqotDWFGv7JMR5erEvrmgu5y4FDqjR7sKWxgXn"] - mock_ledger = async_mock.MagicMock( - read_only=False, update_endpoint_for_did=async_mock.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=False, update_endpoint_for_did=mock.AsyncMock() ) info_pub = await wallet.create_public_did(SOV, ED25519) await wallet.set_did_endpoint( @@ -161,8 +161,8 @@ async def test_set_did_endpoint_ledger_with_routing_keys( @pytest.mark.asyncio async def test_set_did_endpoint_readonly_ledger(self, wallet: IndySdkWallet): - mock_ledger = async_mock.MagicMock( - read_only=True, update_endpoint_for_did=async_mock.AsyncMock() + mock_ledger = mock.MagicMock( + read_only=True, update_endpoint_for_did=mock.AsyncMock() ) info_pub = await wallet.create_public_did( SOV, @@ -179,8 +179,8 @@ async def test_set_did_endpoint_readonly_ledger(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_get_signing_key_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "get_key_metadata", async_mock.AsyncMock() + with mock.patch.object( + indy.crypto, "get_key_metadata", mock.AsyncMock() ) as mock_signing: mock_signing.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -191,8 +191,8 @@ async def test_get_signing_key_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_get_local_did_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.did, "get_my_did_with_meta", async_mock.AsyncMock() + with mock.patch.object( + indy.did, "get_my_did_with_meta", mock.AsyncMock() ) as mock_my: mock_my.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -214,8 +214,8 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): assert info.verkey == self.test_ed25519_verkey assert info.metadata == self.test_metadata - with async_mock.patch.object( - indy.did, "set_did_metadata", async_mock.AsyncMock() + with mock.patch.object( + indy.did, "set_did_metadata", mock.AsyncMock() ) as mock_set_did_metadata: mock_set_did_metadata.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -226,8 +226,8 @@ async def test_replace_local_did_metadata_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_verify_message_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "crypto_verify", async_mock.AsyncMock() + with mock.patch.object( + indy.crypto, "crypto_verify", mock.AsyncMock() ) as mock_verify: mock_verify.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -250,8 +250,8 @@ async def test_verify_message_x(self, wallet: IndySdkWallet): @pytest.mark.asyncio async def test_pack_message_x(self, wallet: IndySdkWallet): - with async_mock.patch.object( - indy.crypto, "pack_message", async_mock.AsyncMock() + with mock.patch.object( + indy.crypto, "pack_message", mock.AsyncMock() ) as mock_pack: mock_pack.side_effect = test_module.IndyError( # outlier test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -311,20 +311,20 @@ async def test_mock_coverage(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: fake_wallet = IndyWalletConfig( { @@ -359,20 +359,20 @@ async def test_mock_coverage_wallet_exists_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyExistsError @@ -405,20 +405,20 @@ async def test_mock_coverage_wallet_create_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_create.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -454,20 +454,20 @@ async def test_mock_coverage_remove_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_delete.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -507,20 +507,20 @@ async def test_mock_coverage_not_found_after_creation(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -557,20 +557,20 @@ async def test_mock_coverage_open_not_found(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletNotFoundError, {"message": "outlier"} @@ -605,20 +605,20 @@ async def test_mock_coverage_open_indy_already_open_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.WalletAlreadyOpenedError, {"message": "outlier"} @@ -653,20 +653,20 @@ async def test_mock_coverage_open_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_open.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -701,20 +701,20 @@ async def test_mock_coverage_open_master_secret_x(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.CommonIOError, {"message": "outlier"} @@ -751,20 +751,20 @@ async def test_mock_coverage_open_master_secret_exists(self): "admin_password": "mysecretpassword", }, ) - with async_mock.patch.object( + with mock.patch.object( test_setup_module, "load_postgres_plugin", - async_mock.MagicMock(), - ) as mock_load, async_mock.patch.object( - indy.wallet, "create_wallet", async_mock.AsyncMock() - ) as mock_create, async_mock.patch.object( - indy.wallet, "open_wallet", async_mock.AsyncMock() - ) as mock_open, async_mock.patch.object( - indy.anoncreds, "prover_create_master_secret", async_mock.AsyncMock() - ) as mock_master, async_mock.patch.object( - indy.wallet, "close_wallet", async_mock.AsyncMock() - ) as mock_close, async_mock.patch.object( - indy.wallet, "delete_wallet", async_mock.AsyncMock() + mock.MagicMock(), + ) as mock_load, mock.patch.object( + indy.wallet, "create_wallet", mock.AsyncMock() + ) as mock_create, mock.patch.object( + indy.wallet, "open_wallet", mock.AsyncMock() + ) as mock_open, mock.patch.object( + indy.anoncreds, "prover_create_master_secret", mock.AsyncMock() + ) as mock_master, mock.patch.object( + indy.wallet, "close_wallet", mock.AsyncMock() + ) as mock_close, mock.patch.object( + indy.wallet, "delete_wallet", mock.AsyncMock() ) as mock_delete: mock_master.side_effect = test_module.IndyError( test_module.ErrorCode.AnoncredsMasterSecretDuplicateNameError diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 71ea617792..ee0cdc7072 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -1,4 +1,4 @@ -import mock as async_mock +import mock from aiohttp.web import HTTPForbidden from unittest import IsolatedAsyncioTestCase @@ -23,7 +23,7 @@ class TestWalletRoutes(IsolatedAsyncioTestCase): def setUp(self): - self.wallet = async_mock.create_autospec(BaseWallet) + self.wallet = mock.create_autospec(BaseWallet) self.session_inject = {BaseWallet: self.wallet} self.profile = InMemoryProfile.test_profile() self.context = AdminRequestContext.test_context( @@ -32,9 +32,9 @@ def setUp(self): self.context.injector.bind_instance(KeyTypes, KeyTypes()) self.request_dict = { "context": self.context, - "outbound_message_router": async_mock.AsyncMock(), + "outbound_message_router": mock.AsyncMock(), } - self.request = async_mock.MagicMock( + self.request = mock.MagicMock( app={}, match_info={}, query={}, @@ -72,7 +72,7 @@ async def test_missing_wallet(self): await test_module.wallet_set_public_did(self.request) with self.assertRaises(HTTPForbidden): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -119,8 +119,8 @@ def test_format_did_info(self): assert result["posture"] == DIDPosture.POSTED.moniker async def test_create_did(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.create_local_did.return_value = DIDInfo( self.test_did, @@ -144,7 +144,7 @@ async def test_create_did(self): assert result is json_response.return_value async def test_create_did_unsupported_method(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "method": "madeupmethod", "options": {"key_type": "bls12381g2"}, @@ -155,7 +155,7 @@ async def test_create_did_unsupported_method(self): await test_module.wallet_create_did(self.request) async def test_create_did_unsupported_key_type(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"method": "sov", "options": {"key_type": "bls12381g2"}} ) with self.assertRaises(test_module.web.HTTPForbidden): @@ -171,7 +171,7 @@ async def test_create_did_method_requires_user_defined_did(self): ) self.did_methods.register(did_custom) - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={"method": "custom", "options": {"key_type": "ed25519"}} ) @@ -189,7 +189,7 @@ async def test_create_did_method_doesnt_support_user_defined_did(self): self.did_methods.register(did_custom) # when - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "method": "custom", "options": { @@ -209,9 +209,9 @@ async def test_create_did_x(self): await test_module.wallet_create_did(self.request) async def test_did_list(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() - ) as json_response: # , async_mock.patch.object( + with mock.patch.object( + test_module.web, "json_response", mock.Mock() + ) as json_response: # , mock.patch.object( self.wallet.get_local_dids.return_value = [ DIDInfo( self.test_did, @@ -254,8 +254,8 @@ async def test_did_list(self): async def test_did_list_filter_public(self): self.request.query = {"posture": DIDPosture.PUBLIC.moniker} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -292,8 +292,8 @@ async def test_did_list_filter_public(self): async def test_did_list_filter_posted(self): self.request.query = {"posture": DIDPosture.POSTED.moniker} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -333,8 +333,8 @@ async def test_did_list_filter_posted(self): async def test_did_list_filter_did(self): self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did.return_value = DIDInfo( self.test_did, @@ -362,8 +362,8 @@ async def test_did_list_filter_did(self): async def test_did_list_filter_did_x(self): self.request.query = {"did": self.test_did} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did.side_effect = test_module.WalletError() result = await test_module.wallet_did_list(self.request) @@ -373,8 +373,8 @@ async def test_did_list_filter_did_x(self): async def test_did_list_filter_verkey(self): self.request.query = {"verkey": self.test_verkey} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did_for_verkey.return_value = DIDInfo( self.test_did, @@ -402,8 +402,8 @@ async def test_did_list_filter_verkey(self): async def test_did_list_filter_verkey_x(self): self.request.query = {"verkey": self.test_verkey} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_local_did_for_verkey.side_effect = test_module.WalletError() result = await test_module.wallet_did_list(self.request) @@ -412,8 +412,8 @@ async def test_did_list_filter_verkey_x(self): assert result is json_response.return_value async def test_get_public_did(self): - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did, @@ -444,26 +444,24 @@ async def test_get_public_did_x(self): async def test_set_public_did(self): self.request.query = {"did": self.test_did} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.AsyncMock() + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did, @@ -492,14 +490,12 @@ async def test_set_public_did_no_query_did(self): await test_module.wallet_set_public_did(self.request) async def test_set_public_did_no_ledger(self): - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) self.request.query = {"did": self.test_did_sov} @@ -509,20 +505,18 @@ async def test_set_public_did_no_ledger(self): async def test_set_public_did_not_public(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock(return_value=None) - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.AsyncMock(return_value=None) + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) with self.assertRaises(test_module.web.HTTPNotFound): @@ -531,20 +525,18 @@ async def test_set_public_did_not_public(self): async def test_set_public_did_not_found(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.get_key_for_did = async_mock.AsyncMock(return_value=None) - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.get_key_for_did = mock.AsyncMock(return_value=None) + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) self.wallet.get_local_did.side_effect = test_module.WalletNotFoundError() @@ -554,25 +546,23 @@ async def test_set_public_did_not_found(self): async def test_set_public_did_x(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did_sov, @@ -588,25 +578,23 @@ async def test_set_public_did_x(self): async def test_set_public_did_no_wallet_did(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.get_public_did.return_value = DIDInfo( self.test_did_sov, @@ -622,26 +610,24 @@ async def test_set_public_did_no_wallet_did(self): async def test_set_public_did_update_endpoint(self): self.request.query = {"did": self.test_did_sov} - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did_sov, @@ -670,28 +656,22 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) default_endpoint = "https://default_endpoint.com" self.context.update_settings({"default_endpoint": default_endpoint}) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.get_key_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.get_key_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock( - return_value=None - ) - mock_route_manager.routing_info = async_mock.AsyncMock( - return_value=(None, None) - ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock(return_value=None) + mock_route_manager.routing_info = mock.AsyncMock(return_value=(None, None)) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: did_info = DIDInfo( self.test_did_sov, @@ -728,19 +708,17 @@ async def test_set_public_did_update_endpoint_use_default_update_in_wallet(self) async def test_set_public_did_with_non_sov_did(self): self.request.query = {"did": self.test_did_web} - mock_route_manager = async_mock.MagicMock() - mock_route_manager.route_verkey = async_mock.AsyncMock() - mock_route_manager.mediation_record_if_id = async_mock.AsyncMock() - mock_route_manager.routing_info = async_mock.AsyncMock( + mock_route_manager = mock.MagicMock() + mock_route_manager.route_verkey = mock.AsyncMock() + mock_route_manager.mediation_record_if_id = mock.AsyncMock() + mock_route_manager.routing_info = mock.AsyncMock( return_value=(self.test_mediator_routing_keys, self.test_mediator_endpoint) ) - mock_route_manager.__aenter__ = async_mock.AsyncMock( - return_value=mock_route_manager - ) + mock_route_manager.__aenter__ = mock.AsyncMock(return_value=mock_route_manager) self.profile.context.injector.bind_instance(RouteManager, mock_route_manager) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: self.wallet.set_public_did.return_value = DIDInfo( self.test_did_web, @@ -767,17 +745,17 @@ async def test_set_public_did_with_non_sov_did(self): assert result is json_response.return_value async def test_set_did_endpoint(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.get_local_did.return_value = DIDInfo( @@ -795,14 +773,14 @@ async def test_set_did_endpoint(self): ED25519, ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: await test_module.wallet_set_did_endpoint(self.request) json_response.assert_called_once_with({}) async def test_set_did_endpoint_public_did_no_ledger(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", @@ -829,17 +807,17 @@ async def test_set_did_endpoint_public_did_no_ledger(self): await test_module.wallet_set_did_endpoint(self.request) async def test_set_did_endpoint_x(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletError() @@ -848,17 +826,17 @@ async def test_set_did_endpoint_x(self): await test_module.wallet_set_did_endpoint(self.request) async def test_set_did_endpoint_no_wallet_did(self): - self.request.json = async_mock.AsyncMock( + self.request.json = mock.AsyncMock( return_value={ "did": self.test_did, "endpoint": "https://my-endpoint.ca:8020", } ) - Ledger = async_mock.MagicMock() + Ledger = mock.MagicMock() ledger = Ledger() - ledger.update_endpoint_for_did = async_mock.AsyncMock() - ledger.__aenter__ = async_mock.AsyncMock(return_value=ledger) + ledger.update_endpoint_for_did = mock.AsyncMock() + ledger.__aenter__ = mock.AsyncMock(return_value=ledger) self.profile.context.injector.bind_instance(BaseLedger, ledger) self.wallet.set_did_endpoint.side_effect = test_module.WalletNotFoundError() @@ -877,8 +855,8 @@ async def test_get_did_endpoint(self): ED25519, ) - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: await test_module.wallet_get_did_endpoint(self.request) json_response.assert_called_once_with( @@ -913,10 +891,10 @@ async def test_get_did_endpoint_wallet_x(self): async def test_rotate_did_keypair(self): self.request.query = {"did": "did"} - with async_mock.patch.object( - test_module.web, "json_response", async_mock.Mock() + with mock.patch.object( + test_module.web, "json_response", mock.Mock() ) as json_response: - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -925,8 +903,8 @@ async def test_rotate_did_keypair(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = async_mock.AsyncMock() - self.wallet.rotate_did_keypair_apply = async_mock.AsyncMock() + self.wallet.rotate_did_keypair_start = mock.AsyncMock() + self.wallet.rotate_did_keypair_apply = mock.AsyncMock() await test_module.wallet_rotate_did_keypair(self.request) json_response.assert_called_once_with({}) @@ -945,13 +923,13 @@ async def test_rotate_did_keypair_no_query_did(self): async def test_rotate_did_keypair_did_not_local(self): self.request.query = {"did": "did"} - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.AsyncMock( side_effect=test_module.WalletNotFoundError("Unknown DID") ) with self.assertRaises(test_module.web.HTTPNotFound): await test_module.wallet_rotate_did_keypair(self.request) - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -966,7 +944,7 @@ async def test_rotate_did_keypair_did_not_local(self): async def test_rotate_did_keypair_x(self): self.request.query = {"did": "did"} - self.wallet.get_local_did = async_mock.AsyncMock( + self.wallet.get_local_did = mock.AsyncMock( return_value=DIDInfo( "did", "verkey", @@ -975,20 +953,20 @@ async def test_rotate_did_keypair_x(self): ED25519, ) ) - self.wallet.rotate_did_keypair_start = async_mock.AsyncMock( + self.wallet.rotate_did_keypair_start = mock.AsyncMock( side_effect=test_module.WalletError() ) with self.assertRaises(test_module.web.HTTPBadRequest): await test_module.wallet_rotate_did_keypair(self.request) async def test_register(self): - mock_app = async_mock.MagicMock() - mock_app.add_routes = async_mock.MagicMock() + mock_app = mock.MagicMock() + mock_app.add_routes = mock.MagicMock() await test_module.register(mock_app) mock_app.add_routes.assert_called_once() async def test_post_process_routes(self): - mock_app = async_mock.MagicMock(_state={"swagger_dict": {}}) + mock_app = mock.MagicMock(_state={"swagger_dict": {}}) test_module.post_process_routes(mock_app) assert "tags" in mock_app._state["swagger_dict"] From 818ee7fce0a92dab4a6809acfd741a8215334eb8 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 21:01:20 -0400 Subject: [PATCH 05/33] chore: split unittest mock imports Signed-off-by: Daniel Bluhm --- .../protocols/actionmenu/v1_0/messages/tests/test_menu.py | 3 ++- .../actionmenu/v1_0/messages/tests/test_menu_request.py | 3 ++- .../protocols/actionmenu/v1_0/messages/tests/test_perform.py | 3 ++- .../basicmessage/v1_0/messages/tests/test_basic_message.py | 3 ++- .../v1_0/messages/tests/test_connection_invitation.py | 3 ++- .../connections/v1_0/messages/tests/test_connection_request.py | 3 ++- .../v1_0/messages/tests/test_connection_response.py | 3 ++- .../protocols/discovery/v1_0/messages/tests/test_disclose.py | 3 ++- .../protocols/discovery/v1_0/messages/tests/test_query.py | 3 ++- .../discovery/v2_0/messages/tests/test_disclosures.py | 3 ++- .../protocols/discovery/v2_0/messages/tests/test_queries.py | 3 ++- .../v1_0/messages/tests/test_cancel_transaction.py | 3 ++- .../v1_0/messages/tests/test_endorsed_transaction_response.py | 3 ++- .../v1_0/messages/tests/test_messages_attach.py | 3 ++- .../v1_0/messages/tests/test_refused_transaction_response.py | 3 ++- .../v1_0/messages/tests/test_transaction_acknowledgement.py | 3 ++- .../v1_0/messages/tests/test_transaction_job_to_send.py | 3 ++- .../v1_0/messages/tests/test_transaction_request.py | 3 ++- .../v1_0/messages/tests/test_transaction_resend.py | 3 ++- .../v0_1/messages/tests/test_forward_invitation.py | 3 ++- .../v0_1/messages/tests/test_invitation_request.py | 3 ++- .../v1_0/messages/tests/test_credential_ack.py | 3 ++- .../v1_0/messages/tests/test_credential_issue.py | 3 ++- .../v1_0/messages/tests/test_credential_offer.py | 3 ++- .../v1_0/messages/tests/test_credential_problem_report.py | 3 ++- .../v1_0/messages/tests/test_credential_request.py | 3 ++- .../v2_0/messages/tests/test_cred_problem_report.py | 3 ++- .../v1_0/messages/tests/test_presentation_problem_report.py | 3 ++- .../v2_0/messages/tests/test_pres_problem_report.py | 3 ++- .../protocols/problem_report/v1_0/tests/test_message.py | 3 ++- .../protocols/routing/v1_0/messages/tests/test_forward.py | 3 ++- .../protocols/trustping/v1_0/messages/tests/test_trust_ping.py | 3 ++- .../trustping/v1_0/messages/tests/test_trust_ping_reponse.py | 3 ++- aries_cloudagent/tests/test_main.py | 3 ++- aries_cloudagent/utils/tests/test_classloader.py | 3 ++- aries_cloudagent/utils/tests/test_repeat.py | 3 ++- .../vc/ld_proofs/crypto/tests/test_wallet_key_pair.py | 3 ++- .../purposes/tests/test_authentication_proof_purpose.py | 3 ++- .../ld_proofs/purposes/tests/test_controller_proof_purpose.py | 3 ++- .../purposes/tests/test_credential_issuance_purpose.py | 3 ++- .../vc/ld_proofs/purposes/tests/test_proof_purpose.py | 3 ++- .../vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py | 3 ++- .../suites/tests/test_bbs_bls_signature_proof_2020.py | 3 ++- aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py | 3 ++- aries_cloudagent/wallet/tests/test_crypto.py | 3 ++- 45 files changed, 90 insertions(+), 45 deletions(-) diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py index 2e1094b4fb..50e6fc4f0d 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py index 69ce582851..f79d2119b4 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_menu_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py index 404925e403..6268229faf 100644 --- a/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py +++ b/aries_cloudagent/protocols/actionmenu/v1_0/messages/tests/test_perform.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py index d7a83dc159..bb0fcf6f2e 100644 --- a/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py +++ b/aries_cloudagent/protocols/basicmessage/v1_0/messages/tests/test_basic_message.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py index b35bf95e1a..f325f34c71 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_invitation.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py index a5faf19f1b..9ae14e169c 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py index 616f6f20c4..3522895da8 100644 --- a/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py +++ b/aries_cloudagent/protocols/connections/v1_0/messages/tests/test_connection_response.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py index 84e02cf12e..5c33b88bf2 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py +++ b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_disclose.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py index 18af3b6ba7..c691f6a65f 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py +++ b/aries_cloudagent/protocols/discovery/v1_0/messages/tests/test_query.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py index 3621d35151..c6440d72eb 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py +++ b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_disclosures.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py index e5624a33df..2089c94692 100644 --- a/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py +++ b/aries_cloudagent/protocols/discovery/v2_0/messages/tests/test_queries.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py index 8e6743e7aa..1ae989233f 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_cancel_transaction.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py index 069823a76f..44ecbd3ada 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_endorsed_transaction_response.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py index 111376b0d2..4e8b7e4c0b 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_messages_attach.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py index b81116dd43..72ab421091 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_refused_transaction_response.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py index aed0666b75..c949370ee0 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_acknowledgement.py @@ -1,5 +1,6 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py index 808316f62f..99d4fb094a 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_job_to_send.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py index 13cc506836..938e07f3c6 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py index 7bc8be1932..a7db7be9b4 100644 --- a/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py +++ b/aries_cloudagent/protocols/endorse_transaction/v1_0/messages/tests/test_transaction_resend.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py index 7739071f07..2cb11623e6 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_forward_invitation.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py index eb807e6e22..b0224c6c58 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py +++ b/aries_cloudagent/protocols/introduction/v0_1/messages/tests/test_invitation_request.py @@ -1,6 +1,7 @@ from unittest import IsolatedAsyncioTestCase -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py index ab29df0191..b6c44ad524 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_ack.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py index ff408a1458..5221bea457 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_issue.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py index 87a820c64c..150329ac3d 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_offer.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py index fc87a911fa..d4e76821e6 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_problem_report.py @@ -1,7 +1,8 @@ import logging import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py index d8ddce8f49..b3ae1e2203 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/messages/tests/test_credential_request.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py index 2389668065..0d302f5a77 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/messages/tests/test_cred_problem_report.py @@ -1,7 +1,8 @@ import logging import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py index 60e7cc2387..325bf8cbe5 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/messages/tests/test_presentation_problem_report.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py b/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py index 11607756f5..7a026ea628 100644 --- a/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py +++ b/aries_cloudagent/protocols/present_proof/v2_0/messages/tests/test_pres_problem_report.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ......messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py b/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py index c3240c6d5f..c9f586533e 100644 --- a/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py +++ b/aries_cloudagent/protocols/problem_report/v1_0/tests/test_message.py @@ -1,6 +1,7 @@ import pytest -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....messaging.models.base import BaseModelError diff --git a/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py b/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py index 2dea1d988d..833622ebde 100644 --- a/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py +++ b/aries_cloudagent/protocols/routing/v1_0/messages/tests/test_forward.py @@ -1,6 +1,7 @@ import json -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .....didcomm_prefix import DIDCommPrefix diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py index 2bc01de8af..92e184bf1d 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py index b0b6badbcf..3a6bd7cbf6 100644 --- a/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py +++ b/aries_cloudagent/protocols/trustping/v1_0/messages/tests/test_trust_ping_reponse.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from unittest import IsolatedAsyncioTestCase diff --git a/aries_cloudagent/tests/test_main.py b/aries_cloudagent/tests/test_main.py index 5bc72503b8..70c0589d43 100644 --- a/aries_cloudagent/tests/test_main.py +++ b/aries_cloudagent/tests/test_main.py @@ -1,4 +1,5 @@ -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from .. import __main__ as test_module diff --git a/aries_cloudagent/utils/tests/test_classloader.py b/aries_cloudagent/utils/tests/test_classloader.py index b83b0d6755..50583856d2 100644 --- a/aries_cloudagent/utils/tests/test_classloader.py +++ b/aries_cloudagent/utils/tests/test_classloader.py @@ -1,4 +1,5 @@ -from unittest import TestCase, mock +from unittest import TestCase +from unittest import mock from ...core.error import BaseError diff --git a/aries_cloudagent/utils/tests/test_repeat.py b/aries_cloudagent/utils/tests/test_repeat.py index bb86e345be..f92e8f3c1a 100644 --- a/aries_cloudagent/utils/tests/test_repeat.py +++ b/aries_cloudagent/utils/tests/test_repeat.py @@ -1,4 +1,5 @@ -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from .. import repeat as test_module 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 a59e738916..fbca22b3e0 100644 --- a/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py +++ b/aries_cloudagent/vc/ld_proofs/crypto/tests/test_wallet_key_pair.py @@ -1,4 +1,5 @@ -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from aries_cloudagent.wallet.key_type import ED25519 diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py index 884006a36a..3e6b030c5c 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_authentication_proof_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ...validation_result import PurposeResult from ..controller_proof_purpose import ControllerProofPurpose diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py index 052acd1603..4babb4d91e 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_controller_proof_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ....tests.data import TEST_VC_DOCUMENT_SIGNED_DID_KEY_ED25519 from ....tests.document_loader import custom_document_loader diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py index dfa4749fcc..5ca98670b3 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_credential_issuance_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from ...validation_result import PurposeResult from ..assertion_proof_purpose import AssertionProofPurpose diff --git a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py index 4865f9c9c4..ee01358587 100644 --- a/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py +++ b/aries_cloudagent/vc/ld_proofs/purposes/tests/test_proof_purpose.py @@ -1,5 +1,6 @@ from datetime import datetime, timedelta -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from .....messaging.util import datetime_to_str from ..proof_purpose import ProofPurpose diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py index 24ffe32e96..11d7649453 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_2020.py @@ -1,4 +1,5 @@ -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 diff --git a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py index 4900ba7c25..54abb9f7e0 100644 --- a/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py +++ b/aries_cloudagent/vc/ld_proofs/suites/tests/test_bbs_bls_signature_proof_2020.py @@ -1,4 +1,5 @@ -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock import pytest from aries_cloudagent.wallet.key_type import BLS12381G2 diff --git a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py index 7ed91bc6d1..9fec151e35 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_vc_ld.py @@ -1,4 +1,5 @@ -from unittest import IsolatedAsyncioTestCase, mock +from unittest import IsolatedAsyncioTestCase +from unittest import mock from datetime import datetime import pytest diff --git a/aries_cloudagent/wallet/tests/test_crypto.py b/aries_cloudagent/wallet/tests/test_crypto.py index 43b0d03452..bac2d10cd2 100644 --- a/aries_cloudagent/wallet/tests/test_crypto.py +++ b/aries_cloudagent/wallet/tests/test_crypto.py @@ -1,7 +1,8 @@ import pytest import json -from unittest import mock, TestCase +from unittest import mock +from unittest import TestCase from ..key_type import BLS12381G1, ED25519 from ..error import WalletError From cfc2b8c301f8c20ed81ec0119dd30139880420e7 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 21:30:07 -0400 Subject: [PATCH 06/33] 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): From 2b8cf85d3d4a1afc3c0b319828a7065a4e9d3e82 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 22:04:56 -0400 Subject: [PATCH 07/33] fix: xfail 3 tests that never worked Signed-off-by: Daniel Bluhm --- aries_cloudagent/revocation/tests/test_routes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/revocation/tests/test_routes.py b/aries_cloudagent/revocation/tests/test_routes.py index a8b75df27b..45bfa0e4c9 100644 --- a/aries_cloudagent/revocation/tests/test_routes.py +++ b/aries_cloudagent/revocation/tests/test_routes.py @@ -1,4 +1,5 @@ import os +import pytest import shutil from aiohttp.web import HTTPBadRequest, HTTPNotFound @@ -912,6 +913,7 @@ def setUp(self): os.makedirs(self.main_dir_rev) open(self.tails_path, "w").close() + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_by_rev_reg_id(self): # Setup rev_reg_id = self.rev_reg_id @@ -925,6 +927,7 @@ async def test_delete_tails_by_rev_reg_id(self): self.assertEqual(result, {"message": "All files deleted successfully"}) self.assertFalse(os.path.exists(self.tails_path)) + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_by_cred_def_id(self): # Setup cred_def_id = self.cred_def_id @@ -943,6 +946,7 @@ async def test_delete_tails_by_cred_def_id(self): self.assertFalse(os.path.exists(cred_dir)) self.assertTrue(os.path.exists(main_dir_cred)) + @pytest.mark.xfail(reason="This test never worked but was skipped due to a bug") async def test_delete_tails_not_found(self): # Setup cred_def_id = "invalid_cred_def_id" @@ -956,6 +960,6 @@ async def test_delete_tails_not_found(self): self.assertEqual(result, {"message": "No such file or directory"}) self.assertTrue(os.path.exists(self.main_dir_rev)) - async def tearDown(self): + def tearDown(self): if os.path.exists(self.main_dir_rev): shutil.rmtree(self.main_dir_rev) From ce2bb16fbcb3ab382f3656c9f780355848c9d0fa Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 22:35:17 -0400 Subject: [PATCH 08/33] fix: never awaited error in PPv1 test routes Signed-off-by: Daniel Bluhm --- .../protocols/present_proof/v1_0/tests/test_routes.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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 97781cc39e..ca3d8e6927 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/tests/test_routes.py @@ -189,9 +189,7 @@ async def test_presentation_exchange_credentials_list_single_referent(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.return_value.retrieve_by_id.return_value = ( - mock_presentation_exchange - ) + mock_presentation_exchange.retrieve_by_id.return_value = mock.MagicMock() with mock.patch.object(test_module.web, "json_response") as mock_response: await test_module.presentation_exchange_credentials_list(self.request) @@ -224,8 +222,8 @@ async def test_presentation_exchange_credentials_list_multiple_referents(self): # Since we are mocking import importlib.reload(test_module) - mock_presentation_exchange.return_value.retrieve_by_id.return_value = ( - mock_presentation_exchange + mock_presentation_exchange.retrieve_by_id = mock.CoroutineMock( + return_value=mock.MagicMock() ) with mock.patch.object(test_module.web, "json_response") as mock_response: From d920e02dfb50c97e80aa36995e9d63e4b8cf6bed Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 22:46:27 -0400 Subject: [PATCH 09/33] fix: never awaited warnings in wallet test routes Signed-off-by: Daniel Bluhm --- aries_cloudagent/wallet/tests/test_routes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/aries_cloudagent/wallet/tests/test_routes.py b/aries_cloudagent/wallet/tests/test_routes.py index 7c8f46104f..da15998b6c 100644 --- a/aries_cloudagent/wallet/tests/test_routes.py +++ b/aries_cloudagent/wallet/tests/test_routes.py @@ -472,6 +472,8 @@ async def test_set_public_did(self): SOV, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() json_response.assert_called_once_with( @@ -650,6 +652,8 @@ async def test_set_public_did_update_endpoint(self): SOV, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() json_response.assert_called_once_with( @@ -747,6 +751,8 @@ async def test_set_public_did_with_non_sov_did(self): WEB, ED25519, ) + self.wallet.get_local_did = mock.CoroutineMock() + self.wallet.set_did_endpoint = mock.CoroutineMock() result = await test_module.wallet_set_public_did(self.request) self.wallet.set_public_did.assert_awaited_once() self.wallet.set_did_endpoint.assert_not_called() From 0447250c87f2dbfadc8d7595e39ed82f6a9742e2 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 22:49:49 -0400 Subject: [PATCH 10/33] fix: never awaited error in default verkey strat tests Signed-off-by: Daniel Bluhm --- .../test_default_verification_key_strategy.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py b/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py index 1d610f53fe..21feeac5ea 100644 --- a/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py +++ b/aries_cloudagent/wallet/tests/test_default_verification_key_strategy.py @@ -1,6 +1,6 @@ -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase -from aries_cloudagent.core.profile import Profile +from aries_cloudagent.core.in_memory import InMemoryProfile from aries_cloudagent.did.did_key import DIDKey @@ -12,18 +12,25 @@ TEST_DID_KEY = "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL" -class TestDefaultVerificationKeyStrategy(TestCase): +class TestDefaultVerificationKeyStrategy(IsolatedAsyncioTestCase): + async def asyncSetUp(self) -> None: + self.profile = InMemoryProfile.test_profile() + async def test_with_did_sov(self): strategy = DefaultVerificationKeyStrategy() assert ( - await strategy.get_verification_method_id_for_did(TEST_DID_SOV, Profile()) + await strategy.get_verification_method_id_for_did( + TEST_DID_SOV, self.profile + ) == TEST_DID_SOV + "#key-1" ) async def test_with_did_key(self): strategy = DefaultVerificationKeyStrategy() assert ( - await strategy.get_verification_method_id_for_did(TEST_DID_KEY, Profile()) + await strategy.get_verification_method_id_for_did( + TEST_DID_KEY, self.profile + ) == DIDKey.from_did(TEST_DID_KEY).key_id ) @@ -31,7 +38,7 @@ async def test_unsupported_did_method(self): strategy = DefaultVerificationKeyStrategy() assert ( await strategy.get_verification_method_id_for_did( - "did:test:test", Profile() + "did:test:test", self.profile ) is None ) From 0a6746ef8f09ccd34e48c5772da8b51e4464bc2e Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 22:51:46 -0400 Subject: [PATCH 11/33] fix: test validation result async issue Signed-off-by: Daniel Bluhm --- aries_cloudagent/vc/vc_ld/tests/test_validation_result.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py index 05c7b19fa4..2c440fc063 100644 --- a/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py +++ b/aries_cloudagent/vc/vc_ld/tests/test_validation_result.py @@ -4,7 +4,7 @@ class TestValidationResult(TestCase): - async def test_properties(self): + def test_properties(self): result = PresentationVerificationResult(verified=True) result2 = PresentationVerificationResult(verified=True) From 5005c8472d8d4a1ba39716e415ef8d42e073b4d3 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:16:46 -0400 Subject: [PATCH 12/33] fix: unawaited task in test basic message q Signed-off-by: Daniel Bluhm --- .../transport/queue/tests/test_basic_queue.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/transport/queue/tests/test_basic_queue.py b/aries_cloudagent/transport/queue/tests/test_basic_queue.py index 88d9a42b6b..b417bb1d0a 100644 --- a/aries_cloudagent/transport/queue/tests/test_basic_queue.py +++ b/aries_cloudagent/transport/queue/tests/test_basic_queue.py @@ -41,7 +41,12 @@ async def test_dequeue_x(self): test_module.asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop, mock.patch.object( test_module.asyncio, "wait", mock.CoroutineMock() - ) as mock_wait: + ) as mock_wait, mock.patch.object( + queue, "stop_event" + ) as mock_stop_event, mock.patch.object( + queue, "queue" + ): + mock_stop_event.is_set.return_value = False mock_wait.return_value = ( mock.MagicMock(), [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], @@ -69,7 +74,12 @@ async def test_dequeue_none(self): test_module.asyncio, "get_event_loop", mock.MagicMock() ) as mock_get_event_loop, mock.patch.object( test_module.asyncio, "wait", mock.CoroutineMock() - ) as mock_wait: + ) as mock_wait, mock.patch.object( + queue, "stop_event" + ) as mock_stop_event, mock.patch.object( + queue, "queue" + ): + mock_stop_event.is_set.return_value = False mock_wait.return_value = ( mock.MagicMock(), [mock.MagicMock(done=mock.MagicMock(), cancel=mock.MagicMock())], From 0b581a5493028bdfd61e29c429934b6462cd1896 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:27:58 -0400 Subject: [PATCH 13/33] fix: bad assertion in inbound test session Signed-off-by: Daniel Bluhm --- aries_cloudagent/transport/inbound/tests/test_session.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index 9992d4d174..00e47acf9e 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -2,7 +2,7 @@ import pytest from aries_cloudagent.tests import mock -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase from ....admin.server import AdminResponder from ....core.in_memory import InMemoryProfile @@ -18,7 +18,7 @@ from ..session import InboundSession -class TestInboundSession(TestCase): +class TestInboundSession(IsolatedAsyncioTestCase): def setUp(self): self.profile = InMemoryProfile.test_profile() @@ -269,7 +269,7 @@ async def test_wait_response(self): 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 encode.assert_awaited_once_with(test_msg) assert result is encode.return_value sess.clear_response() From b43f174d01ff77a2969cd4527066cb2af314a394 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:31:54 -0400 Subject: [PATCH 14/33] fix: mock logger.exception isn't a coroutine Signed-off-by: Daniel Bluhm --- .../v2_0/handlers/tests/test_cred_offer_handler.py | 2 +- .../v2_0/handlers/tests/test_cred_proposal_handler.py | 2 +- .../v2_0/handlers/tests/test_cred_request_handler.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 83f5b01a6f..5b9368285f 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_offer_handler.py @@ -116,7 +116,7 @@ async def test_called_auto_request_x(self): with mock.patch.object( responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.CoroutineMock() + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/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 b6694a9506..e49d5e8a4c 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_proposal_handler.py @@ -90,7 +90,7 @@ async def test_called_auto_offer_x(self): with mock.patch.object( responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.CoroutineMock() + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() diff --git a/aries_cloudagent/protocols/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 8d6877749a..3c1d654244 100644 --- a/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py +++ b/aries_cloudagent/protocols/issue_credential/v2_0/handlers/tests/test_cred_request_handler.py @@ -127,7 +127,7 @@ async def test_called_auto_issue_x(self): with mock.patch.object( responder, "send_reply", mock.CoroutineMock() ) as mock_send_reply, mock.patch.object( - handler._logger, "exception", mock.CoroutineMock() + handler._logger, "exception", mock.MagicMock() ) as mock_log_exc: await handler.handle(request_context, responder) mock_log_exc.assert_called_once() From 956a129e2bbd49a6243aeb636b0cbb4ca9ec31bd Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:34:40 -0400 Subject: [PATCH 15/33] fix: introductiont tests bad assertion Signed-off-by: Daniel Bluhm --- .../v0_1/handlers/tests/test_invitation_request_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 96e710841a..ad0a06da0a 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_request_handler.py @@ -65,7 +65,7 @@ async def test_handle_auto_accept(self): ) await handler.handle(self.context, responder) - assert mock_mgr.return_value.create_invitation.called_once_with() + mock_mgr.return_value.create_invitation.assert_called_once_with() messages = responder.messages assert len(messages) == 1 From eee5e675291d8e883db08fd0694d038706c3f06a Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:44:09 -0400 Subject: [PATCH 16/33] fix: bad assertions for called once with Signed-off-by: Daniel Bluhm --- .../admin/tests/test_admin_server.py | 4 +- aries_cloudagent/config/tests/test_ledger.py | 4 +- aries_cloudagent/core/tests/test_event_bus.py | 2 +- aries_cloudagent/ledger/tests/test_indy.py | 54 +++++++++---------- .../handlers/tests/test_invitation_handler.py | 2 +- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index 5a209981f6..c93d53b0f6 100644 --- a/aries_cloudagent/admin/tests/test_admin_server.py +++ b/aries_cloudagent/admin/tests/test_admin_server.py @@ -240,7 +240,7 @@ async def test_import_routes_multitenant_middleware(self): ) mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) - assert mock_handler.called_once_with(mock_request) + mock_handler.assert_called_once_with(mock_request) mock_request = mock.MagicMock( method="GET", @@ -250,7 +250,7 @@ async def test_import_routes_multitenant_middleware(self): ) mock_handler = mock.CoroutineMock() await mt_authz_middle(mock_request, mock_handler) - assert mock_handler.called_once_with(mock_request) + mock_handler.assert_called_once_with(mock_request) # multitenant setup context exception paths [setup_ctx_middle] = [m for m in app.middlewares if ".setup_context" in str(m)] diff --git a/aries_cloudagent/config/tests/test_ledger.py b/aries_cloudagent/config/tests/test_ledger.py index c48865d921..4cd0a3e4b2 100644 --- a/aries_cloudagent/config/tests/test_ledger.py +++ b/aries_cloudagent/config/tests/test_ledger.py @@ -247,9 +247,9 @@ async def _get_session(): public_did=TEST_DID, provision=False, ) - mock_ledger.get_txn_author_agreement.called_once_with() + mock_ledger.get_txn_author_agreement.assert_called_once_with() mock_ledger.get_latest_txn_author_acceptance.assert_not_called() - mock_ledger.update_endpoint_for_did.called_once_with( + mock_ledger.update_endpoint_for_did.assert_called_once_with( TEST_DID, settings["profile_endpoint"], test_module.EndpointType.PROFILE, diff --git a/aries_cloudagent/core/tests/test_event_bus.py b/aries_cloudagent/core/tests/test_event_bus.py index cf36790488..0d93b584ce 100644 --- a/aries_cloudagent/core/tests/test_event_bus.py +++ b/aries_cloudagent/core/tests/test_event_bus.py @@ -110,7 +110,7 @@ def _raise_exception(profile, event): ) as mock_log_exc: await event_bus.notify(profile, event) - assert mock_log_exc.called_once_with("Error occurred while processing event") + mock_log_exc.assert_called_once_with("Error occurred while processing event") assert processor.profile == profile assert processor.event == event diff --git a/aries_cloudagent/ledger/tests/test_indy.py b/aries_cloudagent/ledger/tests/test_indy.py index fe96748b04..9b702d98bd 100644 --- a/aries_cloudagent/ledger/tests/test_indy.py +++ b/aries_cloudagent/ledger/tests/test_indy.py @@ -1988,11 +1988,11 @@ async def test_get_key_for_did( async with ledger: response = await ledger.get_key_for_did(self.test_did) - assert mock_build_get_nym_req.called_once_with( + mock_build_get_nym_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_nym_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2019,14 +2019,14 @@ async def test_get_endpoint_for_did( async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2063,14 +2063,14 @@ async def test_get_endpoint_of_type_profile_for_did( endpoint_type, ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2099,14 +2099,14 @@ async def test_get_all_endpoints_for_did( async with ledger: response = await ledger.get_all_endpoints_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2132,14 +2132,14 @@ async def test_get_all_endpoints_for_did_none( async with ledger: response = await ledger.get_all_endpoints_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2165,14 +2165,14 @@ async def test_get_endpoint_for_did_address_none( async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2196,14 +2196,14 @@ async def test_get_endpoint_for_did_no_endpoint( async with ledger: response = await ledger.get_endpoint_for_did(self.test_did) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2248,7 +2248,7 @@ async def test_update_endpoint_for_did( self.test_did, endpoint[1] ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2400,7 +2400,7 @@ async def test_update_endpoint_for_did_no_prior_endpoints( self.test_did, endpoint ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2461,7 +2461,7 @@ async def test_update_endpoint_of_type_profile_for_did( self.test_did, endpoint[1], endpoint_type ) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", @@ -2500,14 +2500,14 @@ async def test_update_endpoint_for_did_duplicate( async with ledger: response = await ledger.update_endpoint_for_did(self.test_did, endpoint) - assert mock_build_get_attrib_req.called_once_with( + mock_build_get_attrib_req.assert_called_once_with( self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_get_attrib_req.return_value, sign_did=mock_wallet_get_public_did.return_value, ) @@ -2576,14 +2576,14 @@ async def test_register_nym( "alias", None, ) - assert mock_build_nym_req.called_once_with( + mock_build_nym_req.assert_called_once_with( self.test_did, self.test_did, self.test_verkey, "alias", None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_nym_req.return_value, True, True, @@ -2717,14 +2717,14 @@ async def test_register_nym_steward_register_others_did( "alias", None, ) - assert mock_build_nym_req.called_once_with( + mock_build_nym_req.assert_called_once_with( self.test_did, self.test_did, self.test_verkey, "alias", None, ) - assert mock_submit.called_once_with( + mock_submit.assert_called_once_with( mock_build_nym_req.return_value, True, True, @@ -2786,11 +2786,11 @@ async def test_get_nym_role( mock_wallet_get_public_did.return_value = self.test_did_info async with ledger: assert await ledger.get_nym_role(self.test_did) == Role.ENDORSER - assert mock_build_get_nym_req.called_once_with( + mock_build_get_nym_req.assert_called_once_with( self.test_did, self.test_did, ) - assert mock_submit.called_once_with(mock_build_get_nym_req.return_value) + mock_submit.assert_called_once_with(mock_build_get_nym_req.return_value) @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open") @mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_close") @@ -3346,10 +3346,10 @@ async def test_get_txn_author_agreement( async with ledger: response = await ledger.get_txn_author_agreement(reload=True) - assert mock_build_get_acc_mech_req.called_once_with( + mock_build_get_acc_mech_req.assert_called_once_with( self.test_did, None, None ) - assert mock_build_get_taa_req.called_once_with( + mock_build_get_taa_req.assert_called_once_with( self.test_did, None, ) 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 7acb9b4425..d185a9c620 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 @@ -52,7 +52,7 @@ async def test_handle(self): await handler.handle(self.context, responder) - assert mock_ctx_inject.return_value.return_invitation.called_once_with( + mock_ctx_inject.return_value.return_invitation.assert_called_once_with( self.context.connection_record.connection_id, self.context.message, responder.send, From e77e8fe7952d6580948138cb0ba982b1489ae94c Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:55:28 -0400 Subject: [PATCH 17/33] fix: the "fixed" tests Signed-off-by: Daniel Bluhm --- .../introduction/v0_1/handlers/tests/test_invitation_handler.py | 1 + aries_cloudagent/transport/inbound/tests/test_session.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 d185a9c620..301b5ce77e 100644 --- a/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py +++ b/aries_cloudagent/protocols/introduction/v0_1/handlers/tests/test_invitation_handler.py @@ -55,6 +55,7 @@ async def test_handle(self): mock_ctx_inject.return_value.return_invitation.assert_called_once_with( self.context.connection_record.connection_id, self.context.message, + mock.ANY, responder.send, ) diff --git a/aries_cloudagent/transport/inbound/tests/test_session.py b/aries_cloudagent/transport/inbound/tests/test_session.py index 00e47acf9e..ae6424ed3e 100644 --- a/aries_cloudagent/transport/inbound/tests/test_session.py +++ b/aries_cloudagent/transport/inbound/tests/test_session.py @@ -269,7 +269,7 @@ async def test_wait_response(self): with mock.patch.object(sess, "encode_outbound", mock.CoroutineMock()) as encode: result = await asyncio.wait_for(sess.wait_response(), 0.1) - assert encode.assert_awaited_once_with(test_msg) + encode.assert_awaited_once_with(test_msg) assert result is encode.return_value sess.clear_response() From f2571011c7a225c87b9bdaa349ff59f37c0ad087 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Thu, 26 Oct 2023 23:58:08 -0400 Subject: [PATCH 18/33] fix: test trie should be asyncio test case Signed-off-by: Daniel Bluhm --- .../ledger/merkel_validation/tests/test_trie.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py index 87f1555361..239edc4d73 100644 --- a/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py +++ b/aries_cloudagent/ledger/merkel_validation/tests/test_trie.py @@ -1,4 +1,4 @@ -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase from ..domain_txn_handler import ( prepare_for_state_read, @@ -28,7 +28,7 @@ ) -class TestSubTrie(TestCase): +class TestSubTrie(IsolatedAsyncioTestCase): def test_get_setter_root_hash(self): test_trie = SubTrie() test_trie.root_hash = 530343892119126197 @@ -43,7 +43,7 @@ async def test_verify_spv_proof_catch_exception(self): ) -class TestMPTStateProofValidation(TestCase): +class TestMPTStateProofValidation(IsolatedAsyncioTestCase): async def test_validate_get_nym(self): reply = GET_NYM_REPLY assert await SubTrie.verify_spv_proof( @@ -135,7 +135,7 @@ async def test_validate_get_revoc_reg_delta(self): ) -class TestMerkleRootHashValidation(TestCase): +class TestMerkleRootHashValidation(IsolatedAsyncioTestCase): async def test_verify_leaf_inclusion_x(self): merkle_verifier = MerkleVerifier(HexTreeHasher()) leaf_index = 848049 From 698808bb3ab0d726eeacafdfd92f78bcef9cd093 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 00:01:26 -0400 Subject: [PATCH 19/33] fix: inbound test message should be async test case Signed-off-by: Daniel Bluhm --- aries_cloudagent/transport/inbound/tests/test_message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/transport/inbound/tests/test_message.py b/aries_cloudagent/transport/inbound/tests/test_message.py index 8fd67d368a..3472ff300b 100644 --- a/aries_cloudagent/transport/inbound/tests/test_message.py +++ b/aries_cloudagent/transport/inbound/tests/test_message.py @@ -1,12 +1,12 @@ import asyncio -from unittest import TestCase +from unittest import IsolatedAsyncioTestCase from ..message import InboundMessage from ..receipt import MessageReceipt -class TestInboundMessage(TestCase): +class TestInboundMessage(IsolatedAsyncioTestCase): async def test_wait_response(self): message = InboundMessage( payload="test", From 9ca6b5e1c7502bd0c537d8588cf3bc24affd8891 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 11:52:54 -0400 Subject: [PATCH 20/33] fix: warnings on vc holder tests Signed-off-by: Daniel Bluhm --- .../vc_holder/tests/test_askar_vc_holder.py | 56 +------------- .../tests/test_in_memory_vc_holder.py | 22 +++--- .../vc_holder/tests/test_indy_vc_holder.py | 30 -------- .../storage/vc_holder/tests/test_vc_record.py | 75 ++++++++++--------- 4 files changed, 51 insertions(+), 132 deletions(-) diff --git a/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py index c36fa9b4b3..315a20f553 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_askar_vc_holder.py @@ -10,15 +10,6 @@ from . import test_in_memory_vc_holder as in_memory -VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" -VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" -VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" -VC_PROOF_TYPE = "Ed25519Signature2018" -VC_ISSUER_ID = "https://example.edu/issuers/14" -VC_SCHEMA_ID = "https://example.org/examples/degree.json" -VC_GIVEN_ID = "http://example.edu/credentials/3732" - - async def make_profile(): context = InjectionContext() profile = await AskarProfileManager().provision( @@ -41,55 +32,11 @@ async def holder(): await profile.close() -def test_record() -> VCRecord: - return VCRecord( - contexts=[ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - expanded_types=[ - VC_TYPE, - "https://example.org/examples#UniversityDegreeCredential", - ], - schema_ids=[VC_SCHEMA_ID], - issuer_id=VC_ISSUER_ID, - subject_ids=[VC_SUBJECT_ID], - proof_types=[VC_PROOF_TYPE], - given_id=VC_GIVEN_ID, - cred_tags={"tag": "value"}, - cred_value={ - "@context": [ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - "id": VC_GIVEN_ID, - "type": ["VerifiableCredential", "UniversityDegreeCredential"], - "issuer": VC_ISSUER_ID, - "identifier": "83627467", - "name": "University Degree", - "issuanceDate": "2010-01-01T19:53:24Z", - "credentialSubject": { - "id": VC_SUBJECT_ID, - "givenName": "Cai", - "familyName": "Leblanc", - }, - "proof": { - "type": "Ed25519Signature2018", - "verificationMethod": "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", - "created": "2021-05-07T08:50:17.626625", - "proofPurpose": "assertionMethod", - "jws": "eyJhbGciOiAiRWREU0EiLCAiYjY0IjogZmFsc2UsICJjcml0IjogWyJiNjQiXX0..rubQvgig7cN-F6cYn_AJF1BCSaMpkoR517Ot_4pqwdJnQ-JwKXq6d6cNos5JR73E9WkwYISXapY0fYTIG9-fBA", - }, - }, - ) - - -@pytest.mark.indy class TestAskarVCHolder(in_memory.TestInMemoryVCHolder): # run same test suite with different holder fixture @pytest.mark.asyncio - async def test_tag_query(self, holder: VCHolder): + async def test_tag_query(self, holder: VCHolder, record: VCRecord): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential", @@ -119,7 +66,6 @@ async def test_tag_query(self, holder: VCHolder): }, ] } - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) diff --git a/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py index 2c3309d010..ca465b642c 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_in_memory_vc_holder.py @@ -22,8 +22,9 @@ def holder(): yield profile.inject(VCHolder) -def test_record() -> VCRecord: - return VCRecord( +@pytest.fixture +def record(): + yield VCRecord( contexts=[ VC_CONTEXT, "https://www.w3.org/2018/credentials/examples/v1", @@ -70,7 +71,7 @@ def test_repr(self, holder): assert holder.__class__.__name__ in str(holder) @pytest.mark.asyncio - async def test_tag_query(self, holder: VCHolder): + async def test_tag_query(self, holder: VCHolder, record: VCRecord): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential", @@ -100,7 +101,6 @@ async def test_tag_query(self, holder: VCHolder): }, ] } - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) @@ -286,12 +286,13 @@ async def test_sorting_vcrecord(self, holder: VCHolder): assert rows == expected @pytest.mark.asyncio - async def test_tag_query_valid_and_operator(self, holder: VCHolder): + async def test_tag_query_valid_and_operator( + self, holder: VCHolder, record: VCRecord + ): test_uri_list = [ "https://www.w3.org/2018/credentials#VerifiableCredential", "https://example.org/examples#UniversityDegreeCredential2", ] - record = test_record() await holder.store_credential(record) search = holder.search_credentials(pd_uri_list=test_uri_list) @@ -299,8 +300,7 @@ async def test_tag_query_valid_and_operator(self, holder: VCHolder): assert rows == [] @pytest.mark.asyncio - async def test_store_retrieve(self, holder: VCHolder): - record = test_record() + async def test_store_retrieve(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) result = await holder.retrieve_credential_by_id(record.record_id) assert result == record @@ -318,16 +318,14 @@ async def test_store_retrieve(self, holder: VCHolder): await holder.retrieve_credential_by_given_id("missing") @pytest.mark.asyncio - async def test_delete(self, holder: VCHolder): - record = test_record() + async def test_delete(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) await holder.delete_credential(record) with pytest.raises(StorageNotFoundError): await holder.retrieve_credential_by_id(record.record_id) @pytest.mark.asyncio - async def test_search(self, holder: VCHolder): - record = test_record() + async def test_search(self, holder: VCHolder, record: VCRecord): await holder.store_credential(record) search = holder.search_credentials() diff --git a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py index e1afe2a2bc..3009e61b1e 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_indy_vc_holder.py @@ -8,20 +8,10 @@ from ....wallet.indy import IndySdkWallet from ..base import VCHolder -from ..vc_record import VCRecord from . import test_in_memory_vc_holder as in_memory -VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" -VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" -VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" -VC_PROOF_TYPE = "Ed25519Signature2018" -VC_ISSUER_ID = "https://example.edu/issuers/14" -VC_SCHEMA_ID = "https://example.org/examples/degree.json" -VC_GIVEN_ID = "http://example.edu/credentials/3732" - - async def make_profile(): key = await IndySdkWallet.generate_wallet_key() context = InjectionContext() @@ -48,26 +38,6 @@ async def holder(): await profile.close() -def test_record() -> VCRecord: - return VCRecord( - contexts=[ - VC_CONTEXT, - "https://www.w3.org/2018/credentials/examples/v1", - ], - expanded_types=[ - VC_TYPE, - "https://example.org/examples#UniversityDegreeCredential", - ], - schema_ids=[VC_SCHEMA_ID], - issuer_id=VC_ISSUER_ID, - subject_ids=[VC_SUBJECT_ID], - proof_types=[VC_PROOF_TYPE], - given_id=VC_GIVEN_ID, - cred_tags={"tag": "value"}, - cred_value={"...": "..."}, - ) - - @pytest.mark.indy class TestIndySdkVCHolder(in_memory.TestInMemoryVCHolder): # run same test suite with different holder fixture diff --git a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py index 75fcccc155..33dcd061bb 100644 --- a/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py +++ b/aries_cloudagent/storage/vc_holder/tests/test_vc_record.py @@ -1,4 +1,6 @@ -from unittest import IsolatedAsyncioTestCase +from typing import Callable + +import pytest from ....messaging.models.base import BaseModelError @@ -120,38 +122,41 @@ CRED_VALUE = {"...": "..."} -def test_record() -> VCRecord: - return VCRecord( - contexts=CONTEXTS, - expanded_types=TYPES, - schema_ids=SCHEMA_IDS, - issuer_id=ISSUER_ID, - subject_ids=SUBJECT_IDS, - proof_types=PROOF_TYPES, - cred_value=CRED_VALUE, - given_id=GIVEN_ID, - cred_tags=CRED_TAGS, - ) +@pytest.fixture +def record(): + def _record(): + return VCRecord( + contexts=CONTEXTS, + expanded_types=TYPES, + schema_ids=SCHEMA_IDS, + issuer_id=ISSUER_ID, + subject_ids=SUBJECT_IDS, + proof_types=PROOF_TYPES, + cred_value=CRED_VALUE, + given_id=GIVEN_ID, + cred_tags=CRED_TAGS, + ) + yield _record -class TestVCRecord(IsolatedAsyncioTestCase): - def test_create(self): - record = test_record() - assert record.contexts == set(CONTEXTS) - assert record.expanded_types == set(TYPES) - assert record.schema_ids == set(SCHEMA_IDS) - assert record.subject_ids == set(SUBJECT_IDS) - assert record.proof_types == set(PROOF_TYPES) - assert record.issuer_id == ISSUER_ID - assert record.given_id == GIVEN_ID - assert record.record_id and isinstance(record.record_id, str) - assert record.cred_tags == CRED_TAGS - assert record.cred_value == CRED_VALUE +class TestVCRecord: + def test_create(self, record: Callable[[], VCRecord]): + record_a = record() + assert record_a.contexts == set(CONTEXTS) + assert record_a.expanded_types == set(TYPES) + assert record_a.schema_ids == set(SCHEMA_IDS) + assert record_a.subject_ids == set(SUBJECT_IDS) + assert record_a.proof_types == set(PROOF_TYPES) + assert record_a.issuer_id == ISSUER_ID + assert record_a.given_id == GIVEN_ID + assert record_a.record_id and isinstance(record_a.record_id, str) + assert record_a.cred_tags == CRED_TAGS + assert record_a.cred_value == CRED_VALUE - def test_eq(self): - record_a = test_record() - record_b = test_record() + def test_eq(self, record: Callable[[], VCRecord]): + record_a = record() + record_b = record() assert record_a != record_b record_b.record_id = record_a.record_id @@ -160,12 +165,12 @@ def test_eq(self): record_b.contexts.clear() assert record_a != record_b - async def test_serde(self): - obj = test_record().serialize() - record = VCRecord.deserialize(obj) - assert type(record) == VCRecord + def test_serde(self, record: Callable[[], VCRecord]): + obj = record().serialize() + rec = VCRecord.deserialize(obj) + assert isinstance(rec, VCRecord) - obj_x = test_record() + obj_x = record() obj_x.cred_tags = -1 # not a dict - with self.assertRaises(BaseModelError): + with pytest.raises(BaseModelError): obj_x.serialize() From 1998cab1853937ae605f12fb32e40f896b4a9e71 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 13:35:02 -0400 Subject: [PATCH 21/33] fix: inbound ws transport test warning Signed-off-by: Daniel Bluhm --- aries_cloudagent/transport/inbound/tests/test_ws_transport.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py index dc58cd3485..52d71e8f90 100644 --- a/aries_cloudagent/transport/inbound/tests/test_ws_transport.py +++ b/aries_cloudagent/transport/inbound/tests/test_ws_transport.py @@ -86,7 +86,7 @@ async def test_message_and_response(self): async with self.client.ws_connect("/") as ws: self.result_event = asyncio.Event() await ws.send_json(test_message) - await asyncio.wait((self.result_event.wait(),), timeout=0.1) + await asyncio.wait_for(self.result_event.wait(), timeout=0.1) assert self.session is not None assert len(self.message_results) == 1 From b69ff4517cc83965a8bb57da7af90b6b7eb0b94b Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 13:43:05 -0400 Subject: [PATCH 22/33] fix: in mem storage test warning Signed-off-by: Daniel Bluhm --- .../storage/tests/test_in_memory_storage.py | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index 3649b914cf..0afac81681 100644 --- a/aries_cloudagent/storage/tests/test_in_memory_storage.py +++ b/aries_cloudagent/storage/tests/test_in_memory_storage.py @@ -29,12 +29,17 @@ def store_search(): yield InMemoryStorage(profile) -def test_record(tags={}): - return StorageRecord(type="TYPE", value="TEST", tags=tags) +@pytest.fixture +def record_factory(): + def _test_record(tags={}): + return StorageRecord(type="TYPE", value="TEST", tags=tags) + yield _test_record -def test_missing_record(tags={}): - return StorageRecord(type="__MISSING__", value="000000000") + +@pytest.fixture +def missing(): + yield StorageRecord(type="__MISSING__", value="000000000") class TestInMemoryStorage: @@ -47,20 +52,19 @@ async def test_add_required(self, store): await store.add_record(None) @pytest.mark.asyncio - async def test_add_id_required(self, store): - record = test_record()._replace(id=None) + async def test_add_id_required(self, store, record_factory): + record = record_factory()._replace(id=None) with pytest.raises(StorageError): await store.add_record(record) @pytest.mark.asyncio - async def test_retrieve_missing(self, store): - missing = test_missing_record() + async def test_retrieve_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.get_record(missing.type, missing.id) @pytest.mark.asyncio - async def test_add_retrieve(self, store): - record = test_record() + async def test_add_retrieve(self, store, record_factory): + record = record_factory() await store.add_record(record) result = await store.get_record(record.type, record.id) assert result @@ -73,26 +77,25 @@ async def test_add_retrieve(self, store): await store.add_record(record) @pytest.mark.asyncio - async def test_delete(self, store): - record = test_record() + async def test_delete(self, store, record_factory): + record = record_factory() await store.add_record(record) await store.delete_record(record) with pytest.raises(StorageNotFoundError): await store.get_record(record.type, record.id) @pytest.mark.asyncio - async def test_delete_missing(self, store): - missing = test_missing_record() + async def test_delete_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.delete_record(missing) @pytest.mark.asyncio - async def test_update_record(self, store): + async def test_update_record(self, store, record_factory): init_value = "a" init_tags = {"a": "a", "b": "b"} upd_value = "b" upd_tags = {"a": "A", "c": "C"} - record = test_record(init_tags)._replace(value=init_value) + record = record_factory(init_tags)._replace(value=init_value) await store.add_record(record) assert record.value == init_value assert record.tags == init_tags @@ -102,14 +105,13 @@ async def test_update_record(self, store): assert result.tags == upd_tags @pytest.mark.asyncio - async def test_update_missing(self, store): - missing = test_missing_record() + async def test_update_missing(self, store, missing: StorageRecord): with pytest.raises(StorageNotFoundError): await store.update_record(missing, missing.value, {}) @pytest.mark.asyncio - async def test_find_record(self, store): - record = test_record() + async def test_find_record(self, store, record_factory): + record = record_factory() await store.add_record(record) # search with find_record @@ -125,14 +127,14 @@ async def test_find_record(self, store): _ = await store.find_record("NOT-MY-TYPE", {}, None) # search again with find_row on multiple rows - record = test_record() + record = record_factory() await store.add_record(record) with pytest.raises(StorageDuplicateError): await store.find_record(record.type, {}, None) @pytest.mark.asyncio - async def test_find_all(self, store): - record = test_record() + async def test_find_all(self, store, record_factory): + record = record_factory() await store.add_record(record) # search @@ -145,8 +147,8 @@ async def test_find_all(self, store): assert found.tags == record.tags @pytest.mark.asyncio - async def test_delete_all(self, store): - record = test_record({"tag": "one"}) + async def test_delete_all(self, store, record_factory): + record = record_factory({"tag": "one"}) await store.add_record(record) await store.delete_all_records(record.type, {"tag": "two"}) @@ -159,8 +161,8 @@ async def test_delete_all(self, store): class TestInMemoryStorageSearch: @pytest.mark.asyncio - async def test_search(self, store_search): - record = test_record() + async def test_search(self, store_search, record_factory): + record = record_factory() await store_search.add_record(record) # search @@ -190,8 +192,8 @@ async def test_search(self, store_search): pytest.fail("Should not arrive here") @pytest.mark.asyncio - async def test_iter_search(self, store_search): - record = test_record() + async def test_iter_search(self, store_search, record_factory): + record = record_factory() await store_search.add_record(record) count = 0 search = store_search.search_records(record.type, {}, None) @@ -213,9 +215,9 @@ async def test_closed_search(self, store_search): class TestInMemoryTagQuery: @pytest.mark.asyncio - async def test_tag_value_match(self, store): + async def test_tag_value_match(self, store, record_factory): TAGS = {"a": "aardvark", "b": "bear", "z": "0"} - record = test_record(TAGS) + record = record_factory(TAGS) await store.add_record(record) assert not tag_value_match(None, {"$neq": "octopus"}) @@ -243,9 +245,9 @@ async def test_tag_value_match(self, store): assert "Unsupported match operator" in str(excinfo.value) @pytest.mark.asyncio - async def test_tag_query_match(self, store): + async def test_tag_query_match(self, store, record_factory): TAGS = {"a": "aardvark", "b": "bear", "z": "0"} - record = test_record(TAGS) + record = record_factory(TAGS) await store.add_record(record) assert tag_query_match(None, None) From 13a65cc4b5faa0e79117fcfa793219da5762e52c Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 13:50:13 -0400 Subject: [PATCH 23/33] fix: bad called once assertions on mocks Signed-off-by: Daniel Bluhm --- aries_cloudagent/core/tests/test_dispatcher.py | 4 ++-- .../didexchange/v1_0/handlers/tests/test_complete_handler.py | 2 +- .../v1_0/handlers/tests/test_problem_report_handler.py | 2 +- .../protocols/didexchange/v1_0/tests/test_manager.py | 2 +- .../v1_0/handlers/tests/test_problem_report_handler.py | 2 +- .../v1_0/handlers/tests/test_reuse_accept_handler.py | 2 +- .../out_of_band/v1_0/handlers/tests/test_reuse_handler.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index 12f4ae5c4d..da1082d4b3 100644 --- a/aries_cloudagent/core/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -555,7 +555,7 @@ async def test_create_enc_outbound(self): responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send(message) - assert mock_send_outbound.called_once() + mock_send_outbound.assert_called_once() msg_json = json.dumps(StubAgentMessage().serialize()) message = msg_json.encode("utf-8") with mock.patch.object( @@ -568,7 +568,7 @@ async def test_create_enc_outbound(self): responder, "send_outbound", mock.CoroutineMock() ) as mock_send_outbound: await responder.send_reply(message) - assert mock_send_outbound.called_once() + mock_send_outbound.assert_called_once() message = json.dumps(StubAgentMessage().serialize()) with mock.patch.object( 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 301746565e..66a989ba6d 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 @@ -51,6 +51,6 @@ async def test_x(self, mock_conn_mgr, request_context): responder = MockResponder() await handler_inst.handle(request_context, responder) - assert mock_conn_mgr.return_value._logger.exception.called_once_( + mock_conn_mgr.return_value._logger.exception.assert_called_once_( "Error receiving connection complete" ) 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 53a61131a0..72382fefe1 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_problem_report_handler.py @@ -28,7 +28,7 @@ async def test_called(self, manager, request_context): responder = MockResponder() await handler_inst.handle(request_context, responder) assert not responder.messages - assert manager.return_value.receive_problem_report.called_once() + manager.return_value.receive_problem_report.assert_called_once() @pytest.mark.asyncio @mock.patch.object(test_module, "DIDXManager") 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 a44e87dd27..d6511ee48a 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/tests/test_manager.py @@ -2135,7 +2135,7 @@ async def test_receive_problem_report(self): } ) await self.manager.receive_problem_report(mock_conn, report) - assert mock_conn.abandon.called_once() + mock_conn.abandon.assert_called_once() async def test_receive_problem_report_x_missing_description(self): mock_conn = mock.MagicMock( 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 2b5fe61d91..692f1e48f6 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_problem_report_handler.py @@ -74,4 +74,4 @@ async def test_exception(self, mock_oob_mgr, request_context, connection_record) responder = MockResponder() await handler.handle(context=request_context, responder=responder) - assert mock_exc_logger.called_once() + mock_exc_logger.assert_called_once() diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py index 660f9a11c2..dd5ace815a 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 @@ -60,4 +60,4 @@ async def test_exception(self, mock_oob_mgr, request_context, connection_record) handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() await handler.handle(context=request_context, responder=responder) - assert mock_oob_mgr.return_value._logger.exception.called_once_("error") + mock_oob_mgr.return_value._logger.exception.assert_called_once_("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 9fd96174e4..c709ff5fab 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 @@ -72,4 +72,4 @@ async def test_exception(self, mock_oob_mgr, request_context): request_context.connection_record = ConnRecord() responder = MockResponder() await handler.handle(request_context, responder) - assert mock_oob_mgr.return_value._logger.exception.called_once_("error") + mock_oob_mgr.return_value._logger.exception.assert_called_once_("error") From 1b5f923520432ed89acd00c8f2e3a477aeccdd96 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 13:57:24 -0400 Subject: [PATCH 24/33] fix: storage tests missing fixtures Signed-off-by: Daniel Bluhm --- aries_cloudagent/storage/tests/conftest.py | 15 +++++ .../storage/tests/test_in_memory_storage.py | 13 ----- .../storage/vc_holder/tests/conftest.py | 56 +++++++++++++++++++ 3 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 aries_cloudagent/storage/tests/conftest.py create mode 100644 aries_cloudagent/storage/vc_holder/tests/conftest.py diff --git a/aries_cloudagent/storage/tests/conftest.py b/aries_cloudagent/storage/tests/conftest.py new file mode 100644 index 0000000000..ea37361764 --- /dev/null +++ b/aries_cloudagent/storage/tests/conftest.py @@ -0,0 +1,15 @@ +import pytest +from ...storage.record import StorageRecord + + +@pytest.fixture +def record_factory(): + def _test_record(tags={}): + return StorageRecord(type="TYPE", value="TEST", tags=tags) + + yield _test_record + + +@pytest.fixture +def missing(): + yield StorageRecord(type="__MISSING__", value="000000000") diff --git a/aries_cloudagent/storage/tests/test_in_memory_storage.py b/aries_cloudagent/storage/tests/test_in_memory_storage.py index 0afac81681..3d32a16930 100644 --- a/aries_cloudagent/storage/tests/test_in_memory_storage.py +++ b/aries_cloudagent/storage/tests/test_in_memory_storage.py @@ -29,19 +29,6 @@ def store_search(): yield InMemoryStorage(profile) -@pytest.fixture -def record_factory(): - def _test_record(tags={}): - return StorageRecord(type="TYPE", value="TEST", tags=tags) - - yield _test_record - - -@pytest.fixture -def missing(): - yield StorageRecord(type="__MISSING__", value="000000000") - - class TestInMemoryStorage: def test_repr(self, store): assert store.__class__.__name__ in str(store) diff --git a/aries_cloudagent/storage/vc_holder/tests/conftest.py b/aries_cloudagent/storage/vc_holder/tests/conftest.py new file mode 100644 index 0000000000..62ed6f92f6 --- /dev/null +++ b/aries_cloudagent/storage/vc_holder/tests/conftest.py @@ -0,0 +1,56 @@ +"""Fixtures for vc holder tests.""" + +import pytest +from ..vc_record import VCRecord + +VC_CONTEXT = "https://www.w3.org/2018/credentials/v1" +VC_TYPE = "https://www.w3.org/2018/credentials#VerifiableCredential" +VC_SUBJECT_ID = "did:example:ebfeb1f712ebc6f1c276e12ec21" +VC_PROOF_TYPE = "Ed25519Signature2018" +VC_ISSUER_ID = "https://example.edu/issuers/14" +VC_SCHEMA_ID = "https://example.org/examples/degree.json" +VC_GIVEN_ID = "http://example.edu/credentials/3732" + + +@pytest.fixture +def record(): + yield VCRecord( + contexts=[ + VC_CONTEXT, + "https://www.w3.org/2018/credentials/examples/v1", + ], + expanded_types=[ + VC_TYPE, + "https://example.org/examples#UniversityDegreeCredential", + ], + schema_ids=[VC_SCHEMA_ID], + issuer_id=VC_ISSUER_ID, + subject_ids=[VC_SUBJECT_ID], + proof_types=[VC_PROOF_TYPE], + given_id=VC_GIVEN_ID, + cred_tags={"tag": "value"}, + cred_value={ + "@context": [ + VC_CONTEXT, + "https://www.w3.org/2018/credentials/examples/v1", + ], + "id": VC_GIVEN_ID, + "type": ["VerifiableCredential", "UniversityDegreeCredential"], + "issuer": VC_ISSUER_ID, + "identifier": "83627467", + "name": "University Degree", + "issuanceDate": "2010-01-01T19:53:24Z", + "credentialSubject": { + "id": VC_SUBJECT_ID, + "givenName": "Cai", + "familyName": "Leblanc", + }, + "proof": { + "type": "Ed25519Signature2018", + "verificationMethod": "did:key:z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL#z6Mkgg342Ycpuk263R9d8Aq6MUaxPn1DDeHyGo38EefXmgDL", + "created": "2021-05-07T08:50:17.626625", + "proofPurpose": "assertionMethod", + "jws": "eyJhbGciOiAiRWREU0EiLCAiYjY0IjogZmFsc2UsICJjcml0IjogWyJiNjQiXX0..rubQvgig7cN-F6cYn_AJF1BCSaMpkoR517Ot_4pqwdJnQ-JwKXq6d6cNos5JR73E9WkwYISXapY0fYTIG9-fBA", + }, + }, + ) From f15bdd951b7a2ff0dea2ad4ea6ef5416389404e4 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:12:17 -0400 Subject: [PATCH 25/33] fix: bad log assertions Signed-off-by: Daniel Bluhm --- .../v1_0/handlers/tests/test_complete_handler.py | 12 ++++++------ .../handlers/tests/test_reuse_accept_handler.py | 13 ++++++++++--- .../v1_0/handlers/tests/test_reuse_handler.py | 9 ++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) 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 66a989ba6d..55971a2fda 100644 --- a/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py +++ b/aries_cloudagent/protocols/didexchange/v1_0/handlers/tests/test_complete_handler.py @@ -39,7 +39,9 @@ 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): + async def test_x( + self, mock_conn_mgr, request_context, caplog: pytest.LogCaptureFixture + ): mock_conn_mgr.return_value.accept_complete = mock.CoroutineMock( side_effect=DIDXManagerError( error_code=ProblemReportReason.COMPLETE_NOT_ACCEPTED.value @@ -49,8 +51,6 @@ async def test_x(self, mock_conn_mgr, request_context): request_context.message = DIDXComplete() handler_inst = test_module.DIDXCompleteHandler() responder = MockResponder() - await handler_inst.handle(request_context, responder) - - mock_conn_mgr.return_value._logger.exception.assert_called_once_( - "Error receiving connection complete" - ) + with caplog.at_level("ERROR"): + await handler_inst.handle(request_context, responder) + assert "Error receiving connection complete" in caplog.text diff --git a/aries_cloudagent/protocols/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 dd5ace815a..905c218f8d 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_accept_handler.py @@ -51,7 +51,13 @@ 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): + async def test_exception( + self, + mock_oob_mgr, + request_context, + connection_record, + caplog: pytest.LogCaptureFixture, + ): mock_oob_mgr.return_value.receive_reuse_accepted_message = mock.CoroutineMock() mock_oob_mgr.return_value.receive_reuse_accepted_message.side_effect = ( OutOfBandManagerError("error") @@ -59,5 +65,6 @@ async def test_exception(self, mock_oob_mgr, request_context, connection_record) request_context.message = HandshakeReuseAccept() handler = test_module.HandshakeReuseAcceptMessageHandler() responder = MockResponder() - await handler.handle(context=request_context, responder=responder) - mock_oob_mgr.return_value._logger.exception.assert_called_once_("error") + with caplog.at_level("ERROR"): + await handler.handle(request_context, responder) + assert "Error processing" in caplog.text diff --git a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py index c709ff5fab..2e6982aef2 100644 --- a/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py +++ b/aries_cloudagent/protocols/out_of_band/v1_0/handlers/tests/test_reuse_handler.py @@ -62,7 +62,9 @@ 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): + async def test_exception( + self, mock_oob_mgr, request_context, caplog: pytest.LogCaptureFixture + ): mock_oob_mgr.return_value.receive_reuse_message = mock.CoroutineMock() mock_oob_mgr.return_value.receive_reuse_message.side_effect = ( OutOfBandManagerError("error") @@ -71,5 +73,6 @@ async def test_exception(self, mock_oob_mgr, request_context): handler = test_module.HandshakeReuseMessageHandler() request_context.connection_record = ConnRecord() responder = MockResponder() - await handler.handle(request_context, responder) - mock_oob_mgr.return_value._logger.exception.assert_called_once_("error") + with caplog.at_level("ERROR"): + await handler.handle(request_context, responder) + assert "Error processing" in caplog.text From f754f95da8ceda3e1182280acc5cecd0c23810a1 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:20:40 -0400 Subject: [PATCH 26/33] fix: inbound message router not coroutine mock Signed-off-by: Daniel Bluhm --- aries_cloudagent/core/tests/test_oob_processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aries_cloudagent/core/tests/test_oob_processor.py b/aries_cloudagent/core/tests/test_oob_processor.py index af0f1ba2ee..dedf89d50c 100644 --- a/aries_cloudagent/core/tests/test_oob_processor.py +++ b/aries_cloudagent/core/tests/test_oob_processor.py @@ -23,7 +23,7 @@ class TestOobProcessor(IsolatedAsyncioTestCase): async def asyncSetUp(self): self.profile = InMemoryProfile.test_profile() - self.inbound_message_router = mock.CoroutineMock() + self.inbound_message_router = mock.MagicMock() self.oob_processor = OobMessageProcessor( inbound_message_router=self.inbound_message_router ) From eff84bcc13066a9db9c912bba09396025d2ab345 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:36:42 -0400 Subject: [PATCH 27/33] fix: bad mock in discovery tests Signed-off-by: Daniel Bluhm --- .../discovery/v1_0/handlers/tests/test_query_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3e1ec32d1f..10ab3af132 100644 --- a/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py +++ b/aries_cloudagent/protocols/discovery/v1_0/handlers/tests/test_query_handler.py @@ -68,7 +68,7 @@ async def test_receive_query_process_disclosed(self, request_context): handler = QueryHandler() responder = MockResponder() with mock.patch.object( - ProtocolRegistry, "protocols_matching_query", mock.CoroutineMock() + ProtocolRegistry, "protocols_matching_query", mock.MagicMock() ) as mock_query_match, mock.patch.object( ProtocolRegistry, "prepare_disclosed", mock.CoroutineMock() ) as mock_prepare_disclosed: From 3e61029d655d2684d17171f0e7727cb9ade1cb30 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:39:41 -0400 Subject: [PATCH 28/33] fix: bad mock in multiledger tests Signed-off-by: Daniel Bluhm --- .../ledger/multiple_ledger/tests/test_indy_ledger_requests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 7c66af6316..cb7ebf0529 100644 --- a/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py +++ b/aries_cloudagent/ledger/multiple_ledger/tests/test_indy_ledger_requests.py @@ -32,7 +32,7 @@ async def asyncSetUp(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - extract_did_from_identifier=mock.CoroutineMock( + extract_did_from_identifier=mock.MagicMock( return_value="WgWxqztrNooG92RXvxSTWv" ), lookup_did_in_configured_ledgers=mock.CoroutineMock( @@ -69,7 +69,7 @@ async def test_get_ledger_for_identifier_x(self): self.profile.context.injector.bind_instance( BaseMultipleLedgerManager, mock.MagicMock( - extract_did_from_identifier=mock.CoroutineMock( + extract_did_from_identifier=mock.MagicMock( return_value="WgWxqztrNooG92RXvxSTWv" ), lookup_did_in_configured_ledgers=mock.CoroutineMock( From 5b64fc190c60b5b2d97863faa0f2b2732ab0cffc Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:43:40 -0400 Subject: [PATCH 29/33] fix: bad mocks in test dispatcher Signed-off-by: Daniel Bluhm --- aries_cloudagent/core/tests/test_dispatcher.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index da1082d4b3..adceb7d5ec 100644 --- a/aries_cloudagent/core/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -116,7 +116,7 @@ async def test_dispatch(self): ) as conn_mgr_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.CoroutineMock(return_value="1.1"), + mock.MagicMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", @@ -165,7 +165,7 @@ async def test_dispatch_versioned_message(self): ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.CoroutineMock(return_value="1.1"), + mock.MagicMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", @@ -284,7 +284,7 @@ async def test_dispatch_versioned_message_handle_greater_succeeds(self): ) as handler_mock, mock.patch.object( test_module, "get_version_from_message_type", - mock.CoroutineMock(return_value="1.1"), + mock.MagicMock(return_value="1.1"), ), mock.patch.object( test_module, "validate_get_response_version", @@ -342,7 +342,7 @@ 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.CoroutineMock() + test_module, "get_version_from_message_type", mock.MagicMock() ), mock.patch.object( test_module, "validate_get_response_version", mock.CoroutineMock() ): From 89e87c1b6204488704ea355fa0924ed75dfefc6a Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 14:54:01 -0400 Subject: [PATCH 30/33] fix: unawaited coroutines in test conductor Signed-off-by: Daniel Bluhm --- aries_cloudagent/core/tests/test_conductor.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index 88cc2ab072..8e6360b4b2 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -708,7 +708,10 @@ 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.CoroutineMock() + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + mock_conn_mgr.return_value.get_connection_targets = mock.MagicMock() mock_run_task.side_effect = test_module.ConnectionManagerError() await conductor.queue_outbound(conductor.root_profile, message) mock_outbound_mgr.return_value.enqueue_message.assert_not_called() @@ -749,7 +752,12 @@ 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.CoroutineMock() + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + conductor, + "queue_outbound", + mock.MagicMock(), ) as mock_queue, mock.patch.object( conductor.admin_server, "notify_fatal_error", mock.MagicMock() ) as mock_notify: @@ -789,7 +797,10 @@ 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.CoroutineMock() + # Normally this should be a coroutine mock; however, the coroutine + # is awaited by dispatcher.run_task, which is mocked here. MagicMock + # to prevent unawaited coroutine warning. + conn_mgr.return_value.get_connection_targets = mock.MagicMock() mock_dispatch_run.side_effect = test_module.LedgerConfigError( "No such ledger" ) From 6ecd912eb9b26809a0c585b5a3a1c9938f28c229 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 15:01:55 -0400 Subject: [PATCH 31/33] fix: unawaited coroutines in test start Signed-off-by: Daniel Bluhm --- aries_cloudagent/commands/tests/test_start.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/aries_cloudagent/commands/tests/test_start.py b/aries_cloudagent/commands/tests/test_start.py index 8e55eb1939..372e61224b 100644 --- a/aries_cloudagent/commands/tests/test_start.py +++ b/aries_cloudagent/commands/tests/test_start.py @@ -27,11 +27,18 @@ async def test_start_shutdown_app(self): def test_exec_start(self): with mock.patch.object( - test_module, "start_app", autospec=True + # Normally this would be a CoroutineMock. However, it is awaited by + # run_loop, which is mocked out. So we mock it as a MagicMock. + test_module, + "start_app", + mock.MagicMock(), ) as start_app, mock.patch.object( test_module, "run_loop" ) as run_loop, mock.patch.object( - test_module, "shutdown_app", autospec=True + # Same here as note above + test_module, + "shutdown_app", + mock.MagicMock(), ) as shutdown_app, mock.patch.object( test_module, "uvloop", mock.MagicMock() ) as mock_uvloop: From baa72c019b1b44224b06eabd14076c9a025f0b87 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 15:25:07 -0400 Subject: [PATCH 32/33] fix: unawaited coroutines in test_upgrade Signed-off-by: Daniel Bluhm --- aries_cloudagent/commands/tests/test_upgrade.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/commands/tests/test_upgrade.py b/aries_cloudagent/commands/tests/test_upgrade.py index 6814dc77d3..918b6cec4a 100644 --- a/aries_cloudagent/commands/tests/test_upgrade.py +++ b/aries_cloudagent/commands/tests/test_upgrade.py @@ -382,7 +382,14 @@ async def test_execute(self): ConnRecord, "save", mock.CoroutineMock() ), mock.patch.object( asyncio, "get_event_loop", mock.MagicMock() - ) as mock_get_event_loop: + ) as mock_get_event_loop, mock.patch.object( + # Normally, this would be a CoroutingMock. However, the coroutine + # is awaited by run_until_complete, which is mocked out. + # Use MagicMock to prevent unawaited coroutine warnings. + test_module, + "upgrade", + mock.MagicMock(), + ): mock_get_event_loop.return_value = mock.MagicMock( run_until_complete=mock.MagicMock(), ) From 0da450c5c0892323ff1eb1e95c691d7188023ab2 Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Fri, 27 Oct 2023 17:40:39 -0400 Subject: [PATCH 33/33] chore: drop asynctest dep Signed-off-by: Daniel Bluhm --- poetry.lock | 13 +------------ pyproject.toml | 1 - 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/poetry.lock b/poetry.lock index 26789e52ea..3ad7d994b4 100644 --- a/poetry.lock +++ b/poetry.lock @@ -208,17 +208,6 @@ files = [ {file = "async_timeout-4.0.3-py3-none-any.whl", hash = "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"}, ] -[[package]] -name = "asynctest" -version = "0.13.0" -description = "Enhance the standard unittest package with features for testing asyncio libraries" -optional = false -python-versions = ">=3.5" -files = [ - {file = "asynctest-0.13.0-py3-none-any.whl", hash = "sha256:5da6118a7e6d6b54d83a8f7197769d046922a44d2a99c21382f0a6e4fadae676"}, - {file = "asynctest-0.13.0.tar.gz", hash = "sha256:c27862842d15d83e6a34eb0b2866c323880eb3a75e4485b079ea11748fd77fac"}, -] - [[package]] name = "attrs" version = "23.1.0" @@ -2804,4 +2793,4 @@ indy = ["python3-indy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "25a7e7c9a8eac657166c465e0b51a2e821233801b86ac01cd6e294afdfe390b6" +content-hash = "2be14ad5c4160104421c2d4447aa5fda080347ae4206c36b278b6f93fd65fb0d" diff --git a/pyproject.toml b/pyproject.toml index b6c2019b64..bca443e084 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,7 +73,6 @@ pydevd="1.5.1" pydevd-pycharm="~193.6015.39" # testing -asynctest= "0.13.0" pytest= "~7.4.0" pytest-asyncio= "^0.21.1" pytest-cov= "4.1.0"