Beispiel #1
0
 def test_stomp_message_encoding_with_headers_with_body(self):
     connect_message = StompFrame(u'CONNECT', headers={
        u'accept-version': u'1.2',
        u'host': u'localhost',
     }, body=b'extra')
     result = connect_message.to_bytes()
     self.assertEqual(b'CONNECT\naccept-version:1.2\nhost:localhost\n\nextra\x00', result)
Beispiel #2
0
 def test_stomp_message_encoding_with_headers_without_body(self):
     connect_message = StompFrame(u'CONNECT',
                                  headers={
                                      u'accept-version': u'1.2',
                                      u'host': u'localhost',
                                  })
     result = connect_message.to_bytes()
     self.assertEqual(
         b'CONNECT\naccept-version:1.2\nhost:localhost\n\n\x00', result)
Beispiel #3
0
 def test_stomp_message_decoding_with_headers_with_body(self):
     data = b'CONNECT\naccept-version:1.2\n\nlalala\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({
         u'accept-version': u'1.2',
     }, connect_message.headers)
     self.assertEqual(connect_message.body, b'lalala')
Beispiel #4
0
 def test_stomp_message_decoding_with_headers_with_body(self):
     data = b'CONNECT\naccept-version:1.2\n\nlalala\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({
         u'accept-version': u'1.2',
     }, connect_message.headers)
     self.assertEqual(connect_message.body, b'lalala')
Beispiel #5
0
 def test_stomp_message_decoding_without_body(self):
     data = b'CONNECT\naccept-version:1.2\nhost:localhost\n\n\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({
         u'accept-version': u'1.2',
         u'host': u'localhost',
     }, connect_message.headers)
     self.assertEqual(connect_message.body, b'')
Beispiel #6
0
 def test_stomp_message_decoding_without_body(self):
     data = b'CONNECT\naccept-version:1.2\nhost:localhost\n\n\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({
        u'accept-version': u'1.2',
        u'host': u'localhost',
     }, connect_message.headers)
     self.assertEqual(connect_message.body, b'')
Beispiel #7
0
 def test_jsonrpc_client_errs_on_error_json(self):
     with patch('virtwho.virt.vdsm.jsonrpc.StompClient'
                ) as mock_client_factory:
         with patch('uuid.uuid4') as mock_uuid:
             mock_uuid.return_value = 42
             mock_stomp_client = MagicMock()
             mock_client_factory.return_value = mock_stomp_client
             mock_stomp_client.receive.return_value = StompFrame(
                 'MESSAGE', body=b'{"error":{"message":"foo"}}')
             jsonrpc_client = JsonRpcClient('localhost', '54321')
             jsonrpc_client.connect()
             self.assertRaises(RuntimeError, jsonrpc_client.call, 'test')
Beispiel #8
0
 def test_jsonrpc_client_payload_encoding_without_params(self):
     with patch('virtwho.virt.vdsm.jsonrpc.StompClient'
                ) as mock_client_factory:
         with patch('uuid.uuid4') as mock_uuid:
             mock_uuid.return_value = 42
             mock_stomp_client = MagicMock()
             mock_client_factory.return_value = mock_stomp_client
             mock_stomp_client.receive.return_value = StompFrame(
                 'MESSAGE', body=b'{"result":"bar"}')
             jsonrpc_client = JsonRpcClient('localhost', '54321')
             jsonrpc_client.connect()
             result = jsonrpc_client.call('test')
             self.assertEqual(result, u'bar')
             mock_stomp_client.send.assert_called_with(
                 u'SEND', {
                     u'content-length': 48,
                     u'destination': u'jms.topic.vdsm_requests',
                     u'reply-to': u'42'
                 }, b'{"jsonrpc": "2.0", "method": "test", "id": "42"}')
Beispiel #9
0
    def test_jsonrpc_client_payload_encoding_with_params(self):
        with patch('virtwho.virt.vdsm.jsonrpc.StompClient'
                   ) as mock_client_factory:
            with patch('uuid.uuid4') as mock_uuid:
                mock_uuid.return_value = 42
                mock_stomp_client = MagicMock()
                mock_client_factory.return_value = mock_stomp_client
                mock_stomp_client.receive.return_value = StompFrame(
                    'MESSAGE', body=b'{"result":"bar"}')
                jsonrpc_client = JsonRpcClient('localhost', '54321')
                jsonrpc_client.connect()
                result = jsonrpc_client.call('test', foo='bar')
                self.assertEquals(result, u'bar')
                expected_command = u'SEND'
                expected_headers = {
                    u'content-length': 74,
                    u'destination': u'jms.topic.vdsm_requests',
                    u'reply-to': u'42'
                }
                expected_data = {
                    "params": {
                        "foo": "bar"
                    },
                    "jsonrpc": "2.0",
                    "method": "test",
                    "id": "42"
                }

                # The data in the stomp_client.send call (2nd, and 3rd arguments) are dicts dumped
                # as json to a bytes object. Because dictionaries are not guaranteed to be iterated
                # over in the same order, these dicts do not appear equal on python 3.
                # Comparing these using assertEqual will call the registered method associated with
                # dicts (which does not care about order).
                send_args = mock_stomp_client.send.call_args
                self.assertEqual(send_args[0][0], expected_command)
                self.assertEqual(send_args[0][1], expected_headers)
                actual_data = json.loads(send_args[0][2])
                self.assertEqual(actual_data, expected_data)
Beispiel #10
0
 def test_stomp_message_decoding_without_headers_without_body(self):
     data = b'CONNECT\n\n\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({}, connect_message.headers)
     self.assertEqual(connect_message.body, b'')
Beispiel #11
0
 def test_stomp_message_encoding_without_headers_with_body(self):
     connect_message = StompFrame(u'CONNECT', body=b'test')
     result = connect_message.to_bytes()
     self.assertEqual(b'CONNECT\n\ntest\x00', result)
Beispiel #12
0
 def test_stomp_message_decoding_without_headers_without_body(self):
     data = b'CONNECT\n\n\x00'
     connect_message = StompFrame.from_bytes(data)
     self.assertEqual(u'CONNECT', connect_message.command)
     self.assertEqual({}, connect_message.headers)
     self.assertEqual(connect_message.body, b'')
Beispiel #13
0
 def test_stomp_message_encoding_without_headers_with_body(self):
     connect_message = StompFrame(u'CONNECT', body=b'test')
     result = connect_message.to_bytes()
     self.assertEqual(b'CONNECT\n\ntest\x00', result)