Here are the examples of the python api asynctest.mock.CoroutineMock taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
474 Examples
3
Source : test_hub.py
with MIT License
from dib0
with MIT License
from dib0
async def hub():
hub = Hub("127.0.0.1", 1025, "ST_aaaaaaaaaaaa")
hub.sock.sendto = CoroutineMock()
return hub
@pytest.fixture
3
Source : test_hub.py
with MIT License
from dib0
with MIT License
from dib0
async def test_recv_data_sets_connected_on_name_response(hub):
hub.sock.recv = CoroutineMock(return_value=" NAME:ST_aaaaaaaaaaaa ")
assert hub.connected == False
await hub.receive_data()
assert hub.connected == True
async def test_recv_handles_answer_ok_response_correctly(hub):
3
Source : test_hub.py
with MIT License
from dib0
with MIT License
from dib0
async def test_recv_handles_answer_ok_response_correctly(hub):
hub.sock.recv = CoroutineMock(return_value=" {ST_answer_OK} ")
hub.handle_command = MagicMock()
await hub.receive_data()
hub.handle_command.assert_not_called()
async def test_recv_handles_commands_correctly(hub):
3
Source : test_hub.py
with MIT License
from dib0
with MIT License
from dib0
async def test_recv_handles_commands_correctly(hub):
hub.sock.recv = CoroutineMock(return_value=' {"params":"fortytwo"} ')
hub.handle_command = CoroutineMock()
await hub.receive_data()
hub.handle_command.assert_awaited_with("fortytwo")
async def test_update_on_new_device_adds_device(hub, update_data):
3
Source : test_storages.py
with MIT License
from ekonda
with MIT License
from ekonda
def with_mongodb_storage(coro):
@functools.wraps(coro)
async def wrapper(*args, **kwargs):
with patch("kutana.storages.mongodb.AsyncIOMotorClient") as client:
collection = Mock()
collection.update_one = CoroutineMock()
collection.create_index = CoroutineMock()
collection.find_one = CoroutineMock()
collection.delete_one = CoroutineMock()
client.return_value = {"kutana": {"storage": collection}}
return await coro(*args, storage=MongoDBStorage("mongo"), **kwargs)
return wrapper
def test_mongodb_storage():
3
Source : utils.py
with MIT License
from firemark
with MIT License
from firemark
def make_player(had_action=False, x=1, y=2):
player = Player(x=x, y=y, player_id=0)
player.had_action = had_action
connection = PlayerConnection(None, None)
connection.write = CoroutineMock(spec=connection.write)
player.set_connection(connection)
return player
def make_game(*players):
3
Source : test_connection.py
with MIT License
from firemark
with MIT License
from firemark
async def test_client_write_small_message():
writer = CoroutineMock()
writer.drain = CoroutineMock()
connection = PlayerConnection(reader=None, writer=writer)
await connection.write({'test': 'test'})
assert writer.method_calls == [
call.write(b'{"test": "test"}'),
call.write(b'\n'),
call.drain(),
]
3
Source : assigner_impl_test.py
with Apache License 2.0
from googleapis
with Apache License 2.0
from googleapis
def asyncio_sleep(monkeypatch, sleep_queues):
"""Requests.get() mocked to return {'mock_key':'mock_response'}."""
mock = CoroutineMock()
monkeypatch.setattr(asyncio, "sleep", mock)
async def sleeper(delay: float):
await make_queue_waiter(
sleep_queues[delay].called, sleep_queues[delay].results
)(delay)
mock.side_effect = sleeper
return mock
@pytest.fixture()
3
Source : retrying_connection_test.py
with Apache License 2.0
from googleapis
with Apache License 2.0
from googleapis
def asyncio_sleep(monkeypatch):
"""Requests.get() mocked to return {'mock_key':'mock_response'}."""
mock = CoroutineMock()
monkeypatch.setattr(asyncio, "sleep", mock)
return mock
async def test_permanent_error_on_reinitializer(
3
Source : test_player_network_interface.py
with MIT License
from hsahovic
with MIT License
from hsahovic
async def test_change_avatar():
player = PlayerNetworkChild(
player_configuration=player_configuration,
avatar=12,
server_configuration=server_configuration,
start_listening=False,
)
player._send_message = CoroutineMock()
player._logged_in.set()
await player._change_avatar(8)
player._send_message.assert_called_once_with("/avatar 8")
@pytest.mark.asyncio
3
Source : test_player_network_interface.py
with MIT License
from hsahovic
with MIT License
from hsahovic
async def test_send_message():
player = PlayerNetworkChild(
player_configuration=player_configuration,
avatar=12,
server_configuration=server_configuration,
start_listening=False,
)
player._websocket = CoroutineMock()
player._websocket.send = CoroutineMock()
await player._send_message("hey", "home")
player._websocket.send.assert_called_once_with("home|hey")
await player._send_message("hey", "home", "hey again")
player._websocket.send.assert_called_with("home|hey|hey again")
3
Source : test_admin_server.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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.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)
3
Source : test_conductor.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
def get_invite_store_mock(
invite_string: str, invite_already_used: bool = False
) -> async_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.CoroutineMock(
return_value=unused_invite
),
mark_default_invite_as_used=async_mock.CoroutineMock(return_value=used_invite),
)
class TestConductorMediationSetup(AsyncTestCase, Config):
3
Source : test_conductor.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_setup_ledger_both_multiple_and_base(self):
builder: ContextBuilder = StubContextBuilder(self.test_settings)
builder.update_settings({"ledger.genesis_transactions": "..."})
builder.update_settings({"ledger.ledger_config_list": [{"...": "..."}]})
conductor = test_module.Conductor(builder)
with async_mock.patch.object(
test_module,
"load_multiple_genesis_transactions_from_config",
async_mock.CoroutineMock(),
) as mock_multiple_genesis_load, async_mock.patch.object(
test_module, "get_genesis_transactions", async_mock.CoroutineMock()
) as mock_genesis_load:
await conductor.setup()
mock_multiple_genesis_load.assert_called_once()
mock_genesis_load.assert_called_once()
async def test_setup_ledger_only_base(self):
3
Source : test_conductor.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_setup_ledger_only_base(self):
builder: ContextBuilder = StubContextBuilder(self.test_settings)
builder.update_settings({"ledger.genesis_transactions": "..."})
conductor = test_module.Conductor(builder)
with async_mock.patch.object(
test_module, "get_genesis_transactions", async_mock.CoroutineMock()
) as mock_genesis_load:
await conductor.setup()
mock_genesis_load.assert_called_once()
async def test_startup_x_version_mismatch(self):
3
Source : test_indy_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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.CoroutineMock()
) as mock_wait:
mock_build_get_nym_req.return_value = async_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")
3
Source : test_indy_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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.CoroutineMock()
) as mock_wait:
mock_build_get_nym_req.return_value = async_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")
3
Source : test_indy_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait:
mock_build_get_nym_req.return_value = async_mock.MagicMock()
mock_submit.return_value = json.dumps(GET_NYM_REPLY)
mock_wait.return_value = mock_submit.return_value
(
ledger_id,
ledger_inst,
) = await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=True
)
assert ledger_id == "test_prod_1"
assert ledger_inst.pool.name == "test_prod_1"
@async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open")
3
Source : test_indy_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait, async_mock.patch.object(
test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock()
) as mock_verify_spv_proof:
mock_build_get_nym_req.return_value = async_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
with self.assertRaises(MultipleLedgerManagerError) as cm:
await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=True
)
assert "not found in any of the ledgers total: (production: " in cm
@async_mock.patch("aries_cloudagent.ledger.indy.IndySdkLedgerPool.context_open")
3
Source : test_indy_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait:
mock_build_get_nym_req.return_value = async_mock.MagicMock()
mock_submit.return_value = json.dumps(GET_NYM_REPLY)
mock_wait.return_value = mock_submit.return_value
(
ledger_id,
ledger_inst,
) = await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=False
)
assert ledger_id == "test_prod_1"
assert ledger_inst.pool.name == "test_prod_1"
async def test_lookup_did_in_configured_ledgers_cached_prod_ledger(self):
3
Source : test_indy_vdr_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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.CoroutineMock()
) as mock_wait:
mock_build_get_nym_req.return_value = async_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")
3
Source : test_indy_vdr_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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.CoroutineMock()
) as mock_wait:
mock_build_get_nym_req.return_value = async_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")
3
Source : test_indy_vdr_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait:
mock_build_get_nym_req.return_value = async_mock.MagicMock()
mock_submit.return_value = json.dumps(GET_NYM_INDY_VDR_REPLY)
mock_wait.return_value = mock_submit.return_value
(
ledger_id,
ledger_inst,
) = await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=True
)
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")
3
Source : test_indy_vdr_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait, async_mock.patch.object(
test_module.SubTrie, "verify_spv_proof", async_mock.CoroutineMock()
) as mock_verify_spv_proof:
mock_build_get_nym_req.return_value = async_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
with self.assertRaises(MultipleLedgerManagerError) as cm:
await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=True
)
assert "not found in any of the ledgers total: (production: " in cm
@async_mock.patch("aries_cloudagent.ledger.indy_vdr.IndyVdrLedgerPool.context_open")
3
Source : test_indy_vdr_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wait:
mock_build_get_nym_req.return_value = async_mock.MagicMock()
mock_submit.return_value = GET_NYM_INDY_VDR_REPLY
mock_wait.return_value = mock_submit.return_value
(
ledger_id,
ledger_inst,
) = await self.manager.lookup_did_in_configured_ledgers(
"Av63wJYM7xYR4AiygYq4c3", cache_did=False
)
assert ledger_id == "test_prod_1"
assert ledger_inst.pool.name == "test_prod_1"
async def test_lookup_did_in_configured_ledgers_cached_prod_ledger(self):
3
Source : test_indy_vdr.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_rotate_did_keypair(self, ledger: IndyVdrLedger):
wallet = (await ledger.profile.session()).wallet
public_did = await wallet.create_public_did(DIDMethod.SOV, KeyType.ED25519)
async with ledger:
with async_mock.patch.object(
ledger.pool_handle,
"submit_request",
async_mock.CoroutineMock(
side_effect=[
{"data": json.dumps({"seqNo": 1234})},
{"data": {"txn": {"data": {"role": "101", "alias": "Billy"}}}},
{"data": "ok"},
]
),
):
await ledger.rotate_public_did_keypair()
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_send_credential_definition_no_ledger(self):
self.request.json = async_mock.CoroutineMock(
return_value={
"schema_id": "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0",
"support_revocation": False,
"tag": "tag",
}
)
self.context.injector.clear_binding(BaseLedger)
self.profile_injector.clear_binding(BaseLedger)
with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.credential_definitions_send_credential_definition(
self.request
)
async def test_send_credential_definition_ledger_x(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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(
return_value=(None, None)
)
),
)
self.request.match_info = {"cred_def_id": CRED_DEF_ID}
self.context.injector.clear_binding(BaseLedger)
self.profile_injector.clear_binding(BaseLedger)
with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.credential_definitions_get_credential_definition(
self.request
)
async def test_register(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
def mock_sign_credential():
temp = test_module.sign_credential
sign_credential = async_mock.CoroutineMock(return_value="fake_signage")
test_module.sign_credential = sign_credential
yield test_module.sign_credential
test_module.sign_credential = temp
@pytest.fixture
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
def mock_verify_credential():
temp = test_module.verify_credential
verify_credential = async_mock.CoroutineMock(return_value="fake_verify")
test_module.verify_credential = verify_credential
yield test_module.verify_credential
test_module.verify_credential = temp
@pytest.fixture
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_sign_bad_req_error(mock_sign_request, mock_response, error):
test_module.sign_credential = async_mock.CoroutineMock(side_effect=error())
await test_module.sign(mock_sign_request)
assert "error" in mock_response.call_args[0][0]
@pytest.mark.parametrize("error", [WalletError])
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_sign_bad_req_http_error(mock_sign_request, mock_response, error):
test_module.sign_credential = async_mock.CoroutineMock(side_effect=error())
with pytest.raises(web.HTTPForbidden):
await test_module.sign(mock_sign_request)
@pytest.mark.asyncio
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_verify_bad_req_error(mock_verify_request, mock_response, error):
test_module.verify_credential = async_mock.CoroutineMock(side_effect=error())
await test_module.verify(mock_verify_request())
assert "error" in mock_response.call_args[0][0]
@pytest.mark.parametrize(
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_verify_bad_req_http_error(mock_verify_request, mock_response, error):
test_module.verify_credential = async_mock.CoroutineMock(side_effect=error())
with pytest.raises(web.HTTPForbidden):
await test_module.verify(mock_verify_request())
@pytest.mark.asyncio
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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)
await test_module.verify(mock_verify_request())
assert "error" in mock_response.call_args[0][0]
@pytest.mark.asyncio
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_send_schema_no_ledger(self):
self.request.json = async_mock.CoroutineMock(
return_value={
"schema_name": "schema_name",
"schema_version": "1.0",
"attributes": ["table", "drink", "colour"],
}
)
self.context.injector.clear_binding(BaseLedger)
with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.schemas_send_schema(self.request)
async def test_send_schema_x_ledger(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_send_schema_x_ledger(self):
self.request.json = async_mock.CoroutineMock(
return_value={
"schema_name": "schema_name",
"schema_version": "1.0",
"attributes": ["table", "drink", "colour"],
}
)
self.request.query = {"create_transaction_for_endorser": "false"}
self.ledger.create_and_send_schema = async_mock.CoroutineMock(
side_effect=test_module.LedgerError("Down for routine maintenance")
)
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.schemas_send_schema(self.request)
async def test_created(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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(
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:
result = await test_module.schemas_get_schema(self.request)
assert result == mock_response.return_value
mock_response.assert_called_once_with(
{"schema": {"schema": "def", "signed_txn": "..."}}
)
async def test_get_schema_no_ledger(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_get_schema_no_ledger(self):
self.profile_injector.bind_instance(
IndyLedgerRequestsExecutor,
async_mock.MagicMock(
get_ledger_for_identifier=async_mock.CoroutineMock(
return_value=(None, None)
)
),
)
self.request.match_info = {"schema_id": SCHEMA_ID}
self.ledger.get_schema = async_mock.CoroutineMock(
side_effect=test_module.LedgerError("Down for routine maintenance")
)
self.context.injector.clear_binding(BaseLedger)
with self.assertRaises(test_module.web.HTTPForbidden):
await test_module.schemas_get_schema(self.request)
async def test_get_schema_x_ledger(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_get_schema_x_ledger(self):
self.profile_injector.bind_instance(
IndyLedgerRequestsExecutor,
async_mock.MagicMock(
get_ledger_for_identifier=async_mock.CoroutineMock(
return_value=(None, self.ledger)
)
),
)
self.request.match_info = {"schema_id": SCHEMA_ID}
self.ledger.get_schema = async_mock.CoroutineMock(
side_effect=test_module.LedgerError("Down for routine maintenance")
)
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.schemas_get_schema(self.request)
async def test_register(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_wallet_create_x(self):
body = {}
self.request.json = async_mock.CoroutineMock(return_value=body)
self.mock_multitenant_mgr.create_wallet.side_effect = MultitenantManagerError()
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.wallet_create(self.request)
async def test_wallet_create_schema_validation_fails_indy_no_name_key(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_wallet_update_wallet_settings_x(self):
self.request.match_info = {"wallet_id": "test-wallet-id"}
body = {
"wallet_webhook_urls": ["test-webhook-url"],
"label": "test-label",
"image_url": "test-image-url",
}
self.request.json = async_mock.CoroutineMock(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(
side_effect=test_module.WalletSettingsError("bad settings")
)
with self.assertRaises(test_module.web.HTTPBadRequest) as context:
await test_module.wallet_update(self.request)
assert "bad settings" in str(context.exception)
async def test_wallet_update_no_params(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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)
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.wallet_update(self.request)
async def test_wallet_update_not_found(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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(
side_effect=StorageNotFoundError()
)
with self.assertRaises(test_module.web.HTTPNotFound):
await test_module.wallet_update(self.request)
async def test_wallet_get(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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()
) as mock_wallet_record_retrieve_by_id:
mock_wallet_record_retrieve_by_id.side_effect = StorageNotFoundError()
with self.assertRaises(test_module.web.HTTPNotFound):
await test_module.wallet_get(self.request)
async def test_wallet_get_x(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def test_wallet_remove_managed_wallet_key_provided_throws(self):
self.request.match_info = {"wallet_id": "dummy"}
self.request.json = async_mock.CoroutineMock(
return_value={"wallet_key": "dummy_key"}
)
mock_wallet_record = async_mock.MagicMock()
mock_wallet_record.requires_external_key = False
with async_mock.patch.object(
test_module.WalletRecord, "retrieve_by_id", async_mock.CoroutineMock()
) as mock_wallet_record_retrieve_by_id:
mock_wallet_record_retrieve_by_id.return_value = mock_wallet_record
with self.assertRaises(test_module.web.HTTPBadRequest):
await test_module.wallet_remove(self.request)
async def test_wallet_remove_x(self):
3
Source : test_askar_profile_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def setUp(self):
self.profile = InMemoryProfile.test_profile()
self.context = self.profile.context
self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock())
self.context.injector.bind_instance(BaseResponder, self.responder)
self.manager = AskarProfileMultitenantManager(self.profile)
async def test_get_wallet_profile_should_open_store_and_return_profile_with_wallet_context(
3
Source : test_base.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def setUp(self):
self.profile = InMemoryProfile.test_profile()
self.context = self.profile.context
self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock())
self.context.injector.bind_instance(BaseResponder, self.responder)
self.manager = BaseMultitenantManager(self.profile)
async def test_init_throws_no_profile(self):
3
Source : test_manager.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
async def setUp(self):
self.profile = InMemoryProfile.test_profile()
self.context = self.profile.context
self.responder = async_mock.CoroutineMock(send=async_mock.CoroutineMock())
self.context.injector.bind_instance(BaseResponder, self.responder)
self.manager = MultitenantManager(self.profile)
async def test_get_wallet_profile_returns_from_cache(self):
3
Source : test_routes.py
with Apache License 2.0
from hyperledger
with Apache License 2.0
from hyperledger
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(),
}
self.request = async_mock.MagicMock(
app={},
match_info={},
query={},
__getitem__=lambda _, k: self.request_dict[k],
)
async def test_actionmenu_close(self):
See More Examples