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())
 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
 async def test_ping_not_ready(self, request_context):
     request_context.message_receipt = MessageReceipt()
     request_context.message = Ping(response_requested=False)
     request_context.connection_ready = False
     handler = PingHandler()
     responder = MockResponder()
     assert not await handler.handle(request_context, responder)
     messages = responder.messages
     assert len(messages) == 0
Example #4
0
 async def test_ping_response(self, request_context):
     request_context.message_receipt = MessageReceipt()
     request_context.message = PingResponse()
     request_context.settings = {"debug.monitor_ping": True}
     request_context.connection_ready = True
     handler = PingResponseHandler()
     responder = MockResponder()
     await handler.handle(request_context, responder)
     messages = responder.messages
     assert len(messages) == 0
Example #5
0
 async def test_problem_report(self, request_context):
     request_context.message_receipt = MessageReceipt()
     request_context.message = ProblemReport()
     request_context.connection_ready = True
     handler = ProblemReportHandler()
     responder = MockResponder()
     await handler.handle(request_context, responder)
     messages = responder.messages
     assert len(messages) == 0
     hooks = responder.webhooks
     assert len(hooks) == 1
     assert hooks[0] == ("problem_report",
                         request_context.message.serialize())
 async def test_ping_response(self, request_context):
     request_context.message_receipt = MessageReceipt()
     request_context.message = Ping(response_requested=True)
     request_context.connection_ready = True
     handler = PingHandler()
     responder = MockResponder()
     await handler.handle(request_context, responder)
     messages = responder.messages
     assert len(messages) == 1
     result, target = messages[0]
     assert isinstance(result, PingResponse)
     assert result._thread_id == request_context.message._thread_id
     assert not target
Example #7
0
    async def test_handle_cannot_resolve_recipient(self):
        self.context.message_receipt = MessageReceipt(
            recipient_verkey=TEST_VERKEY)
        handler = test_module.ForwardHandler()

        responder = MockResponder()
        with async_mock.patch.object(test_module,
                                     "RoutingManager",
                                     autospec=True) as mock_mgr:
            mock_mgr.return_value.get_recipient = async_mock.CoroutineMock(
                side_effect=test_module.RoutingManagerError())

            await handler.handle(self.context, responder)

            messages = responder.messages
            assert not messages
Example #8
0
    async def test_handle(self):
        self.context.message_receipt = MessageReceipt(
            recipient_verkey=TEST_VERKEY)
        handler = test_module.ForwardHandler()

        responder = MockResponder()
        with async_mock.patch.object(test_module,
                                     "RoutingManager",
                                     autospec=True) as mock_mgr:
            mock_mgr.return_value.get_recipient = async_mock.CoroutineMock(
                return_value=RouteRecord(connection_id="dummy"))

            await handler.handle(self.context, responder)

            messages = responder.messages
            assert len(messages) == 1
            (result, target) = messages[0]
            assert json.loads(result) == self.context.message.msg
            assert target["connection_id"] == "dummy"
def request_context() -> RequestContext:
    ctx = RequestContext()
    ctx.message_receipt = MessageReceipt()
    yield ctx
Example #10
0
 async def test_handle_receipt_no_recipient_verkey(self):
     self.context.message_receipt = MessageReceipt()
     handler = test_module.ForwardHandler()
     with self.assertRaises(HandlerException):
         await handler.handle(self.context, None)