Skip to content

Commit

Permalink
update test_dispatcher to use mock, asyncMock
Browse files Browse the repository at this point in the history
Signed-off-by: Shaanjot Gill <[email protected]>
  • Loading branch information
shaangill025 committed Sep 23, 2022
1 parent ca8308f commit 8d332a8
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions aries_cloudagent/core/tests/test_dispatcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from async_case import IsolatedAsyncioTestCase
from asynctest import mock as async_mock
import mock as async_mock
import pytest

from marshmallow import EXCLUDE
Expand Down Expand Up @@ -114,14 +114,14 @@ async def test_dispatch(self):
) as conn_mgr_mock, async_mock.patch.object(
test_module,
"get_version_from_message_type",
async_mock.CoroutineMock(return_value="1.1"),
async_mock.AsyncMock(return_value="1.1"),
), async_mock.patch.object(
test_module,
"validate_get_response_version",
async_mock.CoroutineMock(return_value=("1.1", None)),
async_mock.AsyncMock(return_value=("1.1", None)),
):
conn_mgr_mock.return_value = async_mock.MagicMock(
find_inbound_connection=async_mock.CoroutineMock(
find_inbound_connection=async_mock.AsyncMock(
return_value=async_mock.MagicMock(connection_id="dummy")
)
)
Expand Down Expand Up @@ -163,11 +163,11 @@ async def test_dispatch_versioned_message(self):
) as handler_mock, async_mock.patch.object(
test_module,
"get_version_from_message_type",
async_mock.CoroutineMock(return_value="1.1"),
async_mock.AsyncMock(return_value="1.1"),
), async_mock.patch.object(
test_module,
"validate_get_response_version",
async_mock.CoroutineMock(return_value=("1.1", None)),
async_mock.AsyncMock(return_value=("1.1", None)),
):
await dispatcher.queue_message(
dispatcher.profile, make_inbound(message), rcv.send
Expand Down Expand Up @@ -284,11 +284,11 @@ async def test_dispatch_versioned_message_handle_greater_succeeds(self):
) as handler_mock, async_mock.patch.object(
test_module,
"get_version_from_message_type",
async_mock.CoroutineMock(return_value="1.1"),
async_mock.AsyncMock(return_value="1.1"),
), async_mock.patch.object(
test_module,
"validate_get_response_version",
async_mock.CoroutineMock(return_value=("1.1", None)),
async_mock.AsyncMock(return_value=("1.1", None)),
):
await dispatcher.queue_message(
dispatcher.profile, make_inbound(message), rcv.send
Expand Down Expand Up @@ -342,9 +342,9 @@ async def test_bad_message_dispatch_parse_x(self):
rcv = Receiver()
bad_messages = ["not even a dict", {"bad": "message"}]
with async_mock.patch.object(
test_module, "get_version_from_message_type", async_mock.CoroutineMock()
test_module, "get_version_from_message_type", async_mock.AsyncMock()
), async_mock.patch.object(
test_module, "validate_get_response_version", async_mock.CoroutineMock()
test_module, "validate_get_response_version", async_mock.AsyncMock()
):
for bad in bad_messages:
await dispatcher.queue_message(
Expand Down Expand Up @@ -416,7 +416,7 @@ async def test_create_send_outbound(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.CoroutineMock()):
with async_mock.patch.object(responder, "_send", async_mock.AsyncMock()):
await responder.send_outbound(outbound_message)

async def test_create_send_webhook(self):
Expand All @@ -433,7 +433,7 @@ async def test_create_enc_outbound(self):
message = b"abc123xyz7890000"
responder = test_module.DispatcherResponder(context, message, None)
with async_mock.patch.object(
responder, "send_outbound", async_mock.CoroutineMock()
responder, "send_outbound", async_mock.AsyncMock()
) as mock_send_outbound:
await responder.send(message)
assert mock_send_outbound.called_once()
Expand Down Expand Up @@ -474,11 +474,11 @@ def _smaller_scope():
# with async_mock.patch.object(
# test_module,
# "get_version_from_message_type",
# async_mock.CoroutineMock(return_value="1.1"),
# async_mock.AsyncMock(return_value="1.1"),
# ), async_mock.patch.object(
# test_module,
# "validate_get_response_version",
# async_mock.CoroutineMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")),
# async_mock.AsyncMock(return_value=("1.1", "fields-ignored-due-to-version-mismatch")),
# ):
# await dispatcher.queue_message(
# dispatcher.profile, make_inbound(message), rcv.send
Expand All @@ -503,11 +503,11 @@ def _smaller_scope():
# with async_mock.patch.object(
# test_module,
# "get_version_from_message_type",
# async_mock.CoroutineMock(return_value="1.1"),
# async_mock.AsyncMock(return_value="1.1"),
# ), async_mock.patch.object(
# test_module,
# "validate_get_response_version",
# async_mock.CoroutineMock(return_value=("1.1", "version-with-degraded-features")),
# async_mock.AsyncMock(return_value=("1.1", "version-with-degraded-features")),
# ):
# await dispatcher.queue_message(
# dispatcher.profile, make_inbound(message), rcv.send
Expand All @@ -532,11 +532,11 @@ def _smaller_scope():
# with async_mock.patch.object(
# test_module,
# "get_version_from_message_type",
# async_mock.CoroutineMock(return_value="1.1"),
# async_mock.AsyncMock(return_value="1.1"),
# ), async_mock.patch.object(
# test_module,
# "validate_get_response_version",
# async_mock.CoroutineMock(return_value=("1.1", "version-not-supported")),
# async_mock.AsyncMock(return_value=("1.1", "version-not-supported")),
# ):
# with self.assertRaises(test_module.MessageParseError):
# await dispatcher.queue_message(
Expand Down

0 comments on commit 8d332a8

Please sign in to comment.