def test_handle_read(self):
        frame_handler = FakeFrameHandler()
        headers = {Headers.CONTENT_LENGTH: '78',
                   Headers.DESTINATION: 'jms.topic.vdsm_responses',
                   Headers.CONTENT_TYPE: 'application/json',
                   Headers.SUBSCRIPTION: 'ad052acb-a934-4e10-8ec3-00c7417ef8d'}
        body = ('{"jsonrpc": "2.0", "id": "e8a936a6-d886-4cfa-97b9-2d54209053f'
                'f", "result": []}')
        frame = Frame(command=Command.MESSAGE, headers=headers, body=body)
        dispatcher = AsyncDispatcher(FakeConnection(), frame_handler)
        dispatcher.handle_read(FakeAsyncDispatcher(None, data=frame.encode()))

        self.assertTrue(frame_handler.has_outgoing_messages)
        recv_frame = frame_handler.pop_message()
        self.assertEqual(Command.MESSAGE, recv_frame.command)
        self.assertEqual(body, recv_frame.body)
Esempio n. 2
0
def test_handle_read():
    frame_handler = FakeFrameHandler()
    headers = {Headers.CONTENT_LENGTH: '78',
               Headers.DESTINATION: 'jms.topic.vdsm_responses',
               Headers.CONTENT_TYPE: 'application/json',
               Headers.SUBSCRIPTION: 'ad052acb-a934-4e10-8ec3-00c7417ef8d'}
    body = json.dumps({
        "jsonrpc": "2.0",
        "id": "e8a936a6-d886-4cfa-97b9-2d54209053ff",
        "result": [],
    }).encode("utf-8")
    frame = Frame(command=Command.MESSAGE, headers=headers, body=body)
    dispatcher = AsyncDispatcher(FakeConnection(), frame_handler)
    dispatcher.handle_read(FakeAsyncDispatcher(None, data=frame.encode()))

    assert frame_handler.has_outgoing_messages
    recv_frame = frame_handler.pop_message()
    assert Command.MESSAGE == recv_frame.command
    assert body == recv_frame.body