示例#1
0
    async def test_invoke_handler(self, communicate, handler):
        ret = asyncio.Future()
        ret.set_result(handlers.HandlerResponse(123, data={'bar': 'baz'}))
        handler.return_value = ret

        comm = communicate(self.application, f'/workflows/{self.workflow.id}/')
        connected, _ = await comm.connect()
        await comm.receive_from()  # ignore initial workflow delta

        await comm.send_to('''
            {
                "requestId": 123,
                "path": "foo.bar",
                "arguments": { "foo": "bar" }
            }
        ''')
        response = json.loads(await comm.receive_from())
        self.assertEqual(
            response,
            {'response': {
                'requestId': 123,
                'data': {
                    'bar': 'baz'
                },
            }})

        handler.assert_called()
        request = handler.call_args[0][0]
        self.assertEqual(request.request_id, 123)
        self.assertEqual(request.path, 'foo.bar')
        self.assertEqual(request.arguments, {'foo': 'bar'})
示例#2
0
 async def mock_handler(*args, **kwargs):
     return handlers.HandlerResponse(123, data={"bar": "baz"})