async def test_is_saving_record(self):
        context = RequestContext()
        storage = BasicStorage()

        context.injector.bind_instance(BaseStorage, storage)
        context.connection_ready = True
        context.message = CredentialRequest(
            credential={
                "credential_type": "TEST",
                "credential_values": {
                    "test": "one",
                    "value": "two"
                },
            })

        responder = MockResponder()
        responder.connection_id = "1234"

        handler_inst = CredentialRequestHandler()
        await handler_inst.handle(context, responder)

        assert len(responder.messages) == 0
        assert 1 == len(responder.webhooks)

        id = responder.webhooks[0][1]["credential_exchange_id"]
        exchange = await CredentialExchangeRecord.retrieve_by_id(context, id)
        assert exchange != None
        assert exchange.connection_id == responder.connection_id
        assert exchange.state == CredentialExchangeRecord.STATE_REQUEST_RECEIVED
        assert exchange.credential_request == context.message.credential
class TestInvitationRequestHandler(AsyncTestCase):
    async def setUp(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))

        self.context.connection_ready = True
        self.context.message = InvitationRequest(
            responder="test-agent",
            message="Hello World",
        )
        self.context.update_settings({"accept_requests": False})

    async def test_handle(self):
        handler = test_module.InvitationRequestHandler()

        responder = MockResponder()
        inv_req = InvitationRequest(responder=responder, message="Hello")

        with async_mock.patch.object(test_module,
                                     "ConnectionManager",
                                     autospec=True) as mock_mgr:
            await handler.handle(self.context, responder)

    async def test_handle_auto_accept(self):
        handler = test_module.InvitationRequestHandler()
        self.context.update_settings({"accept_requests": True})

        conn_invitation = ConnectionInvitation(
            label=TEST_LABEL,
            did=TEST_DID,
            recipient_keys=[TEST_VERKEY],
            endpoint=TEST_ENDPOINT,
            routing_keys=[TEST_ROUTE_VERKEY],
            image_url=TEST_IMAGE_URL,
        )
        mock_conn_rec = async_mock.MagicMock(connection_id="dummy")

        responder = MockResponder()
        with async_mock.patch.object(test_module,
                                     "ConnectionManager",
                                     autospec=True) as mock_mgr:
            mock_mgr.return_value.create_invitation = async_mock.CoroutineMock(
                return_value=(mock_conn_rec, conn_invitation))

            await handler.handle(self.context, responder)
            assert mock_mgr.return_value.create_invitation.called_once_with()

            messages = responder.messages
            assert len(messages) == 1
            (result, _) = messages[0]
            assert type(result) == Invitation
            assert result._thread._thid == self.context.message._message_id

    async def test_handle_not_ready(self):
        handler = test_module.InvitationRequestHandler()
        self.context.connection_ready = False

        with self.assertRaises(HandlerException):
            await handler.handle(self.context, None)
Exemple #3
0
    async def test_connections_receive_invitation_forbidden(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        context.update_settings({"admin.no_receive_invites": True})
        mock_req = async_mock.MagicMock()

        with self.assertRaises(test_module.web.HTTPForbidden):
            await test_module.connections_receive_invitation(mock_req)
def context():
    """Fixture for context used in tests."""
    # pylint: disable=W0621
    context = RequestContext()
    context.message = ProvideData(goal_code="test_goal", data=[TEST_DATA])
    context.connection_record = ConnectionRecord(connection_id=TEST_CONN_ID)
    context.connection_ready = True
    yield context
    async def setUp(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))

        self.context.connection_ready = True
        self.context.message = InvitationRequest(
            responder="test-agent",
            message="Hello World",
        )
        self.context.update_settings({"accept_requests": False})
    async def test_is_handler_saving_record(self):
        context = RequestContext()
        # wallet is required for issuer to sign stuff cause it holds keys
        wallet = BasicWallet()
        # storage is required to save exchange record and save credential
        storage = BasicStorage(wallet)
        # issuer required to create credential
        issuer = PDSIssuer(wallet)
        # holder requiered to save credential
        holder = PDSHolder(context)

        context.injector.bind_instance(BaseWallet, wallet)
        context.injector.bind_instance(BaseStorage, storage)
        context.injector.bind_instance(BaseIssuer, issuer)
        context.injector.bind_instance(BaseHolder, holder)

        record = CredentialExchangeRecord(
            connection_id=connection_id,
            initiator=CredentialExchangeRecord.INITIATOR_SELF,
            role=CredentialExchangeRecord.ROLE_HOLDER,
            state=CredentialExchangeRecord.STATE_REQUEST_SENT,
            thread_id=thread_id,
            credential_request=credential_request,
        )
        await record.save(context)

        credential = await create_credential(context,
                                             credential_request,
                                             their_public_did="1234-theirdid")
        context.message: CredentialIssue = CredentialIssue(
            credential=credential)
        context.message.assign_thread_id(thread_id)
        context.connection_ready = True

        handler_inst = CredentialIssueHandler()
        responder = MockResponder()
        responder.connection_id = connection_id

        await handler_inst.handle(context, responder)

        credential_id = responder.webhooks[0][1]["credential_id"]
        assert credential_id
        credential = await holder.get_credential(credential_id)
        credential = json.loads(credential)
        assert credential["credentialSubject"]

        for key in credential_request["credential_values"]:
            if (credential["credentialSubject"][key] !=
                    credential_request["credential_values"][key]):
                raise Exception(
                    f"""Requested Credential VALUES differ from Issued Credential,
                    RequestedCredential: {credential_request},
                    IssuedCredential: {credential}""")
    async def test_disclose(self):
        ctx = RequestContext()
        registry = ProtocolRegistry()
        registry.register_message_types({TEST_MESSAGE_TYPE: object()})
        ctx.injector.bind_instance(ProtocolRegistry, registry)
        ctx.message = Disclose(protocols=[{
            "pid": "did:sov:BzCbsNYhMrjHiqZDTUASHg;test_proto/test_message",
            "roles": [],
        }])

        handler = DiscloseHandler()
        mock_responder = MockResponder()
        await handler.handle(ctx, mock_responder)
        assert not mock_responder.messages
Exemple #8
0
    async def test_connections_list(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        context.default_endpoint = "http://1.2.3.4:8081"  # for coverage
        assert context.default_endpoint == "http://1.2.3.4:8081"  # for coverage
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
        }
        mock_req.query = {
            "invitation_id": "dummy",
            "initiator": ConnectionRecord.INITIATOR_SELF,
        }

        with async_mock.patch.object(test_module,
                                     "ConnectionRecord",
                                     autospec=True) as mock_conn_rec:
            mock_conn_rec.STATE_INVITATION = ConnectionRecord.STATE_INVITATION
            mock_conn_rec.STATE_INACTIVE = ConnectionRecord.STATE_INACTIVE
            mock_conn_rec.query = async_mock.CoroutineMock()
            conns = [  # in order here
                async_mock.MagicMock(serialize=async_mock.MagicMock(
                    return_value={
                        "state": ConnectionRecord.STATE_ACTIVE,
                        "created_at": "1234567890",
                    })),
                async_mock.MagicMock(serialize=async_mock.MagicMock(
                    return_value={
                        "state": ConnectionRecord.STATE_INVITATION,
                        "created_at": "1234567890",
                    })),
                async_mock.MagicMock(serialize=async_mock.MagicMock(
                    return_value={
                        "state": ConnectionRecord.STATE_INACTIVE,
                        "created_at": "1234567890",
                    })),
            ]
            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:
                await test_module.connections_list(mock_req)
                mock_response.assert_called_once_with({
                    "results": [{
                        k: c.serialize.return_value[k]
                        for k in ["state", "created_at"]
                    } for c in conns]
                }  # sorted
                                                      )
    async def test_perform_menu_action(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))

        self.responder = MockResponder()
        self.context.injector.bind_instance(test_module.BaseResponder,
                                            self.responder)

        self.menu_service = await (
            test_module.DriverMenuService.service_handler()(self.context))

        action_name = "action"
        action_params = {"a": 1, "b": 2}
        connection = async_mock.MagicMock()
        connection.connection_id = "connid"
        thread_id = "thid"

        await self.menu_service.perform_menu_action(action_name, action_params,
                                                    connection, thread_id)

        webhooks = self.responder.webhooks
        assert len(webhooks) == 1
        (result, target) = webhooks[0]
        assert result == "perform-menu-action"
        assert target == {
            "connection_id": connection.connection_id,
            "thread_id": thread_id,
            "action_name": action_name,
            "action_params": action_params,
        }
    async def test_get_active_menu(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))

        self.responder = MockResponder()
        self.context.injector.bind_instance(test_module.BaseResponder,
                                            self.responder)

        self.menu_service = await (
            test_module.DriverMenuService.service_handler()(self.context))

        connection = async_mock.MagicMock()
        connection.connection_id = "connid"
        thread_id = "thid"

        await self.menu_service.get_active_menu(connection, thread_id)

        webhooks = self.responder.webhooks
        assert len(webhooks) == 1
        (result, target) = webhooks[0]
        assert result == "get-active-menu"
        assert target == {
            "connection_id": connection.connection_id,
            "thread_id": thread_id,
        }
    async def test_called(self):
        self.context = RequestContext(
            base_context=InjectionContext(enforce_typing=False)
        )
        MenuService = async_mock.MagicMock(handler.BaseMenuService, autospec=True)
        self.menu_service = MenuService()
        self.context.injector.bind_instance(handler.BaseMenuService, self.menu_service)
        self.context.inject = async_mock.CoroutineMock(return_value=self.menu_service)

        self.context.connection_record = async_mock.MagicMock()
        self.context.connection_record.connection_id = "dummy"

        responder = MockResponder()
        self.context.message = handler.MenuRequest()
        self.menu_service.get_active_menu = async_mock.CoroutineMock(
            return_value="menu"
        )

        handler_inst = handler.MenuRequestHandler()
        await handler_inst.handle(self.context, responder)

        messages = responder.messages
        assert len(messages) == 1
        (result, target) = messages[0]
        assert result == "menu"
        assert target == {}
Exemple #12
0
    async def test_connections_establish_inbound_x(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }
        mock_req.match_info = {"conn_id": "dummy", "ref_id": "ref"}
        mock_req.query = {
            "my_endpoint": "http://endpoint.ca",
        }
        mock_conn_rec = async_mock.MagicMock()

        with async_mock.patch.object(
                test_module.ConnectionRecord, "retrieve_by_id",
                async_mock.CoroutineMock(
                )) as mock_conn_rec_retrieve_by_id, async_mock.patch.object(
                    test_module, "ConnectionManager",
                    autospec=True) as mock_conn_mgr:
            mock_conn_rec_retrieve_by_id.return_value = mock_conn_rec
            mock_conn_mgr.return_value.establish_inbound = async_mock.CoroutineMock(
                side_effect=test_module.ConnectionManagerError())
            with self.assertRaises(test_module.web.HTTPBadRequest):
                await test_module.connections_establish_inbound(mock_req)
Exemple #13
0
    async def test_connections_receive_invitation(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
        }
        mock_req.json = async_mock.CoroutineMock()
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
        }

        mock_conn_rec = async_mock.MagicMock()
        mock_conn_rec.serialize = async_mock.MagicMock()

        with async_mock.patch.object(
                test_module.ConnectionInvitation, "deserialize",
                autospec=True) as mock_inv_deser, 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.receive_invitation = async_mock.CoroutineMock(
                return_value=mock_conn_rec)

            await test_module.connections_receive_invitation(mock_req)
            mock_response.assert_called_once_with(
                mock_conn_rec.serialize.return_value)
Exemple #14
0
    async def test_connections_establish_inbound(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
            "outbound_message_router": async_mock.CoroutineMock(),
        }
        mock_req.match_info = {"conn_id": "dummy", "ref_id": "ref"}
        mock_req.query = {
            "my_endpoint": "http://endpoint.ca",
        }

        mock_conn_rec = async_mock.MagicMock()

        with async_mock.patch.object(
                test_module.ConnectionRecord, "retrieve_by_id",
                async_mock.CoroutineMock(
                )) 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.establish_inbound = async_mock.CoroutineMock(
            )

            await test_module.connections_establish_inbound(mock_req)
            mock_response.assert_called_once_with({})
Exemple #15
0
async def session():
    """Fixture for session used in tests."""
    # pylint: disable=W0621
    context = RequestContext.test_context()
    context.message_receipt = MessageReceipt(sender_verkey=TEST_VERKEY)
    context.connection_record = ConnRecord(connection_id=TEST_CONN_ID)
    yield await context.session()
Exemple #16
0
    async def test_introduction_start_no_service(self):
        context = RequestContext(base_context=InjectionContext(enforce_typing=False))

        mock_req = async_mock.MagicMock()
        mock_req.app = {"request_context": context, "outbound_message_router": None}
        mock_req.json = async_mock.CoroutineMock(
            return_value={
                "my_seed": "my_seed",
                "my_did": "my_did",
                "their_seed": "their_seed",
                "their_did": "their_did",
                "their_verkey": "their_verkey",
                "their_endpoint": "their_endpoint",
                "their_role": "their_role",
                "alias": "alias",
            }
        )
        mock_req.match_info = {"conn_id": "dummy"}
        mock_req.query = {
            "target_connection_id": "dummy",
            "message": "Hello",
        }

        with self.assertRaises(test_module.web.HTTPForbidden):
            await test_module.introduction_start(mock_req)
    async def test_connections_list_x(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
        }
        mock_req.query = {
            "their_role": ConnRecord.Role.REQUESTER.rfc160,
            "alias": "my connection",
            "state": ConnRecord.State.COMPLETED.rfc23,
        }

        STATE_COMPLETED = ConnRecord.State.COMPLETED
        ROLE_REQUESTER = ConnRecord.Role.REQUESTER
        with async_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(
                COMPLETED=STATE_COMPLETED,
                get=async_mock.MagicMock(
                    return_value=ConnRecord.State.COMPLETED),
            )
            mock_conn_rec.query = async_mock.CoroutineMock(
                side_effect=test_module.StorageError())

            with self.assertRaises(test_module.web.HTTPBadRequest):
                await test_module.connections_list(mock_req)
Exemple #18
0
    async def test_connections_receive_invitation_bad(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
        }
        mock_req.json = async_mock.CoroutineMock()
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
        }

        mock_conn_rec = async_mock.MagicMock()
        mock_conn_rec.serialize = async_mock.MagicMock()

        with async_mock.patch.object(
                test_module.ConnectionInvitation, "deserialize",
                autospec=True) as mock_inv_deser, async_mock.patch.object(
                    test_module, "ConnectionManager",
                    autospec=True) as mock_conn_mgr:
            mock_inv_deser.side_effect = test_module.BaseModelError()

            with self.assertRaises(test_module.web.HTTPBadRequest):
                await test_module.connections_receive_invitation(mock_req)
Exemple #19
0
    async def test_connections_create_invitation_public_forbidden(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        context.update_settings({"public_invites": False})
        mock_req.app = {
            "request_context": context,
        }
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
            "public": "true",
            "multi_use": "true",
        }

        with self.assertRaises(test_module.web.HTTPForbidden):
            await test_module.connections_create_invitation(mock_req)
Exemple #20
0
 async def setUp(self):
     self.context = RequestContext(
         base_context=InjectionContext(enforce_typing=False)
     )
     self.context.connection_ready = True
     self.context.connection_record = ConnectionRecord(connection_id="conn-id")
     self.context.message_receipt = MessageReceipt(sender_verkey=TEST_VERKEY)
     self.context.injector.bind_instance(BaseStorage, BasicStorage())
Exemple #21
0
    async def test_called(self):
        request_context = RequestContext()
        request_context.connection_record = async_mock.MagicMock()
        request_context.connection_record.connection_id = "dummy"

        handler.save_connection_menu = async_mock.CoroutineMock()
        responder = MockResponder()

        request_context.message = handler.Menu()
        handler_inst = handler.MenuHandler()
        await handler_inst.handle(request_context, responder)

        handler.save_connection_menu.assert_called_once_with(
            request_context.message,
            request_context.connection_record.connection_id,
            request_context,
        )
    async def setUp(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))

        self.context.connection_ready = True
        self.context.message = ForwardInvitation(
            invitation=ConnectionInvitation(
                label=TEST_LABEL,
                did=TEST_DID,
                recipient_keys=[TEST_VERKEY],
                endpoint=TEST_ENDPOINT,
                routing_keys=[TEST_ROUTE_VERKEY],
                image_url=TEST_IMAGE_URL,
            ),
            message="Hello World",
        )
        self.context.update_settings({"accept_invites": False})
 async def setUp(self):
     self.context = RequestContext(base_context=InjectionContext(
         enforce_typing=False))
     self.context.message_receipt = MessageReceipt(
         sender_verkey=TEST_VERKEY)
     self.storage = BasicStorage()
     self.context.injector.bind_instance(BaseStorage, self.storage)
     self.manager = RoutingManager(self.context)
     assert self.manager.context
Exemple #24
0
    async def test_connections_create_static(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        mock_req.app = {
            "request_context": context,
        }
        mock_req.json = async_mock.CoroutineMock(
            return_value={
                "my_seed": "my_seed",
                "my_did": "my_did",
                "their_seed": "their_seed",
                "their_did": "their_did",
                "their_verkey": "their_verkey",
                "their_endpoint": "their_endpoint",
                "their_role": "their_role",
                "alias": "alias",
            })
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
        }
        mock_req.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_my_info.did = "my_did"
        mock_my_info.verkey = "my_verkey"
        mock_their_info = async_mock.MagicMock()
        mock_their_info.did = "their_did"
        mock_their_info.verkey = "their_verkey"

        with 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_static_connection = (
                async_mock.CoroutineMock(return_value=(mock_my_info,
                                                       mock_their_info,
                                                       mock_conn_rec)))

            await test_module.connections_create_static(mock_req)
            mock_response.assert_called_once_with({
                "my_did":
                mock_my_info.did,
                "my_verkey":
                mock_my_info.verkey,
                "their_did":
                mock_their_info.did,
                "their_verkey":
                mock_their_info.verkey,
                "my_endpoint":
                context.settings.get("default_endpoint"),
                "record":
                mock_conn_rec.serialize.return_value,
            })
    async def test_connections_create_invitation(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        context.update_settings({"public_invites": True})
        mock_req.app = {
            "request_context": context,
        }
        mock_req.json = async_mock.CoroutineMock()
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
            "public": "true",
            "multi_use": "true",
        }

        with 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_invitation = async_mock.CoroutineMock(
                return_value=(
                    async_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"),
                    ),
                ))

            await test_module.connections_create_invitation(mock_req)
            mock_response.assert_called_once_with({
                "connection_id": "dummy",
                "invitation": {
                    "a": "value"
                },
                "invitation_url": "http://endpoint.ca",
                "alias": "conn-alias",
            })
 async def testSend(self):
     context = RequestContext(base_context=InjectionContext())
     requestMock = async_mock.MagicMock()
     requestMock.app = {
         "request_context": context,
         "outbound_message_router": async_mock.CoroutineMock(),
     }
     params = {"connection_id": "1234", "payload": "test, test"}
     hash_id = hashlib.sha256(params["payload"].encode("UTF-8")).hexdigest()
     requestMock.json = async_mock.CoroutineMock(return_value=params)
    async def setUp(self):
        self.storage = BasicStorage()

        self.context = RequestContext(
            base_context=InjectionContext(enforce_typing=False)
        )
        self.context.injector.bind_instance(BaseStorage, self.storage)

        self.context.connection_ready = True
        self.context.message = Forward(to="sample-did", msg={"msg": "sample-message"})
Exemple #28
0
    async def test_connections_create_invitation_x(self):
        context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        mock_req = async_mock.MagicMock()
        context.update_settings({"public_invites": True})
        mock_req.app = {
            "request_context": context,
        }
        mock_req.query = {
            "auto_accept": "true",
            "alias": "alias",
            "public": "true",
            "multi_use": "true",
        }

        with async_mock.patch.object(test_module,
                                     "ConnectionManager",
                                     autospec=True) as mock_conn_mgr:
            mock_conn_mgr.return_value.create_invitation = async_mock.CoroutineMock(
                side_effect=test_module.ConnectionManagerError())

            with self.assertRaises(test_module.web.HTTPBadRequest):
                await test_module.connections_create_invitation(mock_req)
Exemple #29
0
    async def test_controller(self):
        self.context = RequestContext(base_context=InjectionContext(
            enforce_typing=False))
        MenuService = async_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.CoroutineMock(
            return_value=self.menu_service)

        controller = test_module.Controller("protocol")

        assert await controller.determine_roles(self.context) == ["provider"]
Exemple #30
0
 async def handle(self, context: RequestContext, responder: BaseResponder):
     """Handle status request message."""
     if not self.transport or self.transport.return_route != "all":
         raise HandlerException(
             "StatusRequest must have transport decorator with return "
             "route set to all")
     recipient_key = self.recipient_key
     manager = context.inject(InboundTransportManager)
     assert manager
     count = manager.undelivered_queue.message_count_for_key(
         recipient_key or context.message_receipt.sender_verkey)
     response = Status(message_count=count, recipient_key=recipient_key)
     response.assign_thread_from(self)
     await responder.send_reply(response)