本文整理匯總了Python中asynctest.mock.CoroutineMock方法的典型用法代碼示例。如果您正苦於以下問題:Python mock.CoroutineMock方法的具體用法?Python mock.CoroutineMock怎麽用?Python mock.CoroutineMock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類asynctest.mock
的用法示例。
在下文中一共展示了mock.CoroutineMock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_websocket_accept_connection
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_websocket_accept_connection(
scope: dict, headers: Headers, subprotocol: Optional[str], has_headers: bool
) -> None:
connection = ASGIWebsocketConnection(Quart(__name__), scope)
mock_send = CoroutineMock()
await connection.accept_connection(mock_send, headers, subprotocol)
if has_headers:
mock_send.assert_called_with(
{
"subprotocol": subprotocol,
"type": "websocket.accept",
"headers": _encode_headers(headers),
}
)
else:
mock_send.assert_called_with({"subprotocol": subprotocol, "type": "websocket.accept"})
示例2: test_run_loop
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_run_loop(self):
startup = async_mock.CoroutineMock()
startup_call = startup()
shutdown = async_mock.CoroutineMock()
shutdown_call = shutdown()
with async_mock.patch.object(command, "asyncio", autospec=True) as mock_asyncio:
command.run_loop(startup_call, shutdown_call)
mock_asyncio.get_event_loop.return_value.add_signal_handler.assert_called_once()
init_coro = mock_asyncio.ensure_future.call_args[0][0]
mock_asyncio.get_event_loop.return_value.run_forever.assert_called_once()
await init_coro
startup.assert_awaited_once()
done_calls = (
mock_asyncio.get_event_loop.return_value.add_signal_handler.call_args
)
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.Task.all_tasks.return_value = [task]
mock_asyncio.Task.current_task.return_value = task
await done_coro
shutdown.assert_awaited_once()
示例3: test_get_schema_not_found
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_get_schema_not_found(
self, mock_build_get_schema_req, mock_submit, mock_close, mock_open,
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
mock_wallet.get_public_did = async_mock.CoroutineMock()
mock_did = mock_wallet.get_public_did.return_value
mock_did.did = self.test_did
mock_submit.return_value = json.dumps({"result": {"seqNo": None}})
ledger = IndyLedger("name", mock_wallet, cache=BasicCache())
async with ledger:
response = await ledger.get_schema("schema_id")
mock_wallet.get_public_did.assert_called_once_with()
mock_build_get_schema_req.assert_called_once_with(mock_did.did, "schema_id")
mock_submit.assert_called_once_with(
mock_build_get_schema_req.return_value, sign_did=mock_did
)
assert response is None
示例4: test_send_credential_definition_no_such_schema
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_send_credential_definition_no_such_schema(
self, mock_close, mock_open, mock_get_schema,
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
mock_get_schema.return_value = {}
issuer = async_mock.MagicMock(BaseIssuer)
ledger = IndyLedger("name", mock_wallet)
schema_id = "schema_issuer_did:name:1.0"
tag = "default"
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock()
with self.assertRaises(LedgerError):
await ledger.create_and_send_credential_definition(
issuer, schema_id, None, tag
)
示例5: test_fetch_credential_definition_ledger_x
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_fetch_credential_definition_ledger_x(
self,
mock_parse_get_cred_def_resp,
mock_build_get_cred_def_req,
mock_submit,
mock_close,
mock_open,
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
mock_wallet.get_public_did = async_mock.CoroutineMock()
mock_did = mock_wallet.get_public_did.return_value
mock_parse_get_cred_def_resp.side_effect = IndyError(
error_code=ErrorCode.CommonInvalidParam1,
error_details={"message": "not today"},
)
ledger = IndyLedger("name", mock_wallet)
async with ledger:
with self.assertRaises(LedgerError) as context:
await ledger.fetch_credential_definition("cred_def_id")
assert "not today" in str(context.exception)
示例6: test_get_key_for_did
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
mock_submit.return_value = json.dumps(
{"result": {"data": json.dumps({"verkey": self.test_verkey})}}
)
ledger = IndyLedger("name", mock_wallet)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
response = await ledger.get_key_for_did(self.test_did)
assert mock_build_get_nym_req.called_once_with(
self.test_did, ledger.did_to_nym(self.test_did)
)
assert mock_submit.called_once_with(
mock_build_get_nym_req.return_value,
sign_did=mock_wallet.get_public_did.return_value,
)
assert response == self.test_verkey
示例7: test_get_endpoint_for_did_no_endpoint
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
mock_submit.return_value = json.dumps({"result": {"data": None}})
ledger = IndyLedger("name", mock_wallet)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
response = await ledger.get_endpoint_for_did(self.test_did)
assert mock_build_get_attrib_req.called_once_with(
self.test_did, ledger.did_to_nym(self.test_did), "endpoint", None, None
)
assert mock_submit.called_once_with(
mock_build_get_attrib_req.return_value,
sign_did=mock_wallet.get_public_did.return_value,
)
assert response is None
示例8: test_update_endpoint_for_did_read_only
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
endpoint = "http://aries.ca"
mock_submit.return_value = json.dumps(
{"result": {"data": json.dumps({"endpoint": {"endpoint": endpoint}})}}
)
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
with self.assertRaises(LedgerError) as context:
await ledger.update_endpoint_for_did(self.test_did, "distinct endpoint")
assert "read only" in str(context.exception)
示例9: test_register_nym
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_register_nym(
self, mock_submit, mock_build_nym_req, mock_close, mock_open
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
ledger = IndyLedger("name", mock_wallet)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
await ledger.register_nym(self.test_did, self.test_verkey, "alias", None)
assert mock_build_nym_req.called_once_with(
self.test_did, self.test_did, self.test_verkey, "alias", None
)
assert mock_submit.called_once_with(
mock_build_nym_req.return_value,
True,
True,
sign_did=mock_wallet.get_public_did.return_value,
)
示例10: test_rotate_public_did_keypair_no_nym
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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(
get_public_did=async_mock.CoroutineMock(return_value=self.test_did_info),
rotate_did_keypair_start=async_mock.CoroutineMock(
return_value=self.test_verkey
),
rotate_did_keypair_apply=async_mock.CoroutineMock(return_value=None),
)
mock_wallet.WALLET_TYPE = "indy"
mock_submit.return_value = json.dumps({"result": {"data": json.dumps(None)}})
ledger = IndyLedger("name", mock_wallet)
async with ledger:
with self.assertRaises(BadLedgerRequestError):
await ledger.rotate_public_did_keypair()
示例11: test_get_revoc_reg_def
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_get_revoc_reg_def(
self,
mock_indy_parse_get_rrdef_resp,
mock_indy_build_get_rrdef_req,
mock_submit,
mock_close,
mock_open,
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
mock_indy_parse_get_rrdef_resp.return_value = ("rr-id", '{"hello": "world"}')
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
result = await ledger.get_revoc_reg_def("rr-id")
assert result == {"hello": "world"}
示例12: test_get_revoc_reg_def_indy_x
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
mock_indy_build_get_rrdef_req.side_effect = IndyError(
error_code=ErrorCode.CommonInvalidParam1,
error_details={"message": "not today"},
)
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
with self.assertRaises(IndyError) as context:
await ledger.get_revoc_reg_def("rr-id")
assert "not today" in context.exception.message
示例13: test_get_revoc_reg_delta
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
def test_get_revoc_reg_delta(
self,
mock_indy_parse_get_rrd_resp,
mock_indy_build_get_rrd_req,
mock_submit,
mock_close,
mock_open,
):
mock_wallet = async_mock.MagicMock()
mock_wallet.WALLET_TYPE = "indy"
mock_indy_parse_get_rrd_resp.return_value = (
"rr-id",
'{"hello": "world"}',
1234567890,
)
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
(result, _) = await ledger.get_revoc_reg_delta("rr-id")
assert result == {"hello": "world"}
示例14: test_send_revoc_reg_def_public_did
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
mock_indy_build_rrdef_req.return_value = '{"hello": "world"}'
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_public_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
await ledger.send_revoc_reg_def({"rr": "def"}, issuer_did=None)
mock_wallet.get_public_did.assert_called_once()
assert not mock_wallet.get_local_did.called
mock_submit.assert_called_once_with(
mock_indy_build_rrdef_req.return_value, True, True, self.test_did_info
)
示例15: test_send_revoc_reg_def_local_did
# 需要導入模塊: from asynctest import mock [as 別名]
# 或者: from asynctest.mock import CoroutineMock [as 別名]
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.WALLET_TYPE = "indy"
mock_indy_build_rrdef_req.return_value = '{"hello": "world"}'
ledger = IndyLedger("name", mock_wallet, read_only=True)
async with ledger:
mock_wallet.get_local_did = async_mock.CoroutineMock(
return_value=self.test_did_info
)
await ledger.send_revoc_reg_def({"rr": "def"}, issuer_did=self.test_did)
mock_wallet.get_local_did.assert_called_once_with(self.test_did)
assert not mock_wallet.get_public_did.called
mock_submit.assert_called_once_with(
mock_indy_build_rrdef_req.return_value, True, True, self.test_did_info
)