Пример #1
0
 def test_http_post_broken_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     data = 'POST / HTTP/1.1\r\nContent-Length: 1024\r\n\r\nTest broken data'
     client.send(data)
     base.loop(count=5)
     client.close()
     self.assertEqual(self.server.resp_code, 408)
Пример #2
0
 def test_notify_method_list_params(self):
     params = ['abc', 123, {'a': 1, 'b': 2, 'c': 3}]
     self.client.foo_list.notify(params)
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo_list')
     self.assertEqual(self._request.params, params)
Пример #3
0
    def test_call_method_few_times(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 85\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_result", "params": [123, "abc"]}'''
        client.send(data)
        client.send(data)
        client.send(data)
        base.loop(count=3)
        # First
        resp = http_client.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        self.assertEqual(self.server.resp_code, 200)
        response = base.loads(data, [base.JsonRpcResponse])
        self.assertTrue(isinstance(response, base.JsonRpcResponse))
        self.assertEqual(response.id, '12345abc')
        self.assertEqual(response.result, {
            'status': 'OK',
            'params': {
                'a': 123,
                'b': 'abc'
            }
        })
        # Second...
        resp = http_client.HTTPResponse(client)
        try:
            resp.begin()
        except http_client.BadStatusLine as err:
            self.assertEqual(str(err), "''")
        else:
            self.assertFalse(True)
        finally:
            client.close()
Пример #4
0
    def test_call_method_few_times(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 85\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_result", "params": [123, "abc"]}'''
        client.send(data)
        client.send(data)
        client.send(data)
        base.loop()
        # First
        resp = httplib.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        self.assertEqual(self.server.resp_code, 200)
        response = base.loads(data, [base.JsonRpcResponse])
        self.assertTrue(isinstance(response, base.JsonRpcResponse))
        self.assertEqual(response.id, '12345abc')
        self.assertEqual(response.result, {'status': 'OK',
                                           'params': {'a': 123, 'b': 'abc'}})
        # Second...
        resp = httplib.HTTPResponse(client)
        try:
            resp.begin()
        except httplib.BadStatusLine, err:
            self.assertEqual(str(err), '')
Пример #5
0
 def test_notify_method_list_params(self):
     params = ['abc', 123, {'a': 1, 'b': 2, 'c': 3}]
     self.client.foo_list.notify(params)
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo_list')
     self.assertEqual(self._request.params, params)
Пример #6
0
 def test_notify_method_dict_params(self):
     params = {'a': 1, 'b': 'def', 'c': [3, 6, 9]}
     self.client.foo_dict.notify(params)
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo_dict')
     self.assertEqual(self._request.params, params)
Пример #7
0
 def test_http_post_broken_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     data = 'POST / HTTP/1.1\r\nContent-Length: 1024\r\n\r\nTest broken data'
     client.send(data)
     base.loop()
     client.close()
     self.assertEqual(self.server.resp_code, 408)
Пример #8
0
    def test_call_invalid_dict_params(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 106\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_result", "params": {"a": 123, "b": "abc", "c": true}}'''
        client.send(data)
        base.loop(count=3)
        resp = http_client.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError as err:
            self.assertEqual(err.code, -32602)
            self.assertEqual(err.message, 'Invalid params.')
            self.assertEqual(
                err.data, {
                    'method': 'test_result',
                    'params': {
                        'a': 123,
                        'b': 'abc',
                        'c': True
                    }
                })
Пример #9
0
 def test_notify_method_dict_params(self):
     params = {'a': 1, 'b': 'def', 'c': [3, 6, 9]}
     self.client.foo_dict.notify(params)
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo_dict')
     self.assertEqual(self._request.params, params)
Пример #10
0
 def test_notify_method(self):
     context = self.client.foo.notify()
     self.assertTrue(isinstance(context, client.JsonRpcContext))
     self.assertTrue(context.closed())
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo')
     self.assertEqual(self._request.params, None)
Пример #11
0
 def test_notify_method(self):
     context = self.client.foo.notify()
     self.assertTrue(isinstance(context, client.JsonRpcContext))
     self.assertTrue(context.closed())
     base.loop()
     self._assert_message(self._request, base.JsonRpcNotification)
     self.assertEqual(self._request.method, 'foo')
     self.assertEqual(self._request.params, None)
Пример #12
0
 def test_request_method(self):
     context = self.client.foo()
     self.assertTrue(isinstance(context, client.JsonRpcContext))
     self.assertFalse(context.closed())
     base.loop()
     self._assert_message(self._request, base.JsonRpcRequest)
     self.assertEqual(self._request.id, context.request.id)
     self.assertEqual(self._request.method, 'foo')
     self.assertEqual(self._request.params, None)
Пример #13
0
 def test_request_method(self):
     context = self.client.foo()
     self.assertTrue(isinstance(context, client.JsonRpcContext))
     self.assertFalse(context.closed())
     base.loop()
     self._assert_message(self._request, base.JsonRpcRequest)
     self.assertEqual(self._request.id, context.request.id)
     self.assertEqual(self._request.method, 'foo')
     self.assertEqual(self._request.params, None)
Пример #14
0
 def test_notify_method_error(self):
     params = [1]
     self.client.notifier = True
     self.client.test_exception(params)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcNotification))
     self.assertEqual(self.server.request.method, 'test_exception')
     self.assertEqual(self.server.request.params, params)
     self.assertEqual(self._result, None)
     self.assertEqual(self._error, None)
Пример #15
0
 def test_notify_method_list_params(self):
     params = ['abc', {'a': 1, 'b': 2, 'c': 3}]
     self.client.notifier = True
     self.client.test_result(params)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcNotification))
     self.assertEqual(self.server.request.method, 'test_result')
     self.assertEqual(self.server.request.params, params)
     self.assertEqual(self._result, None)
     self.assertEqual(self._error, None)
Пример #16
0
 def test_notify_method_dict_params(self):
     params = {'b': 'def', 'a': [3, 6, 9]}
     self.client.notifier = True
     self.client.test_result(params)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcNotification))
     self.assertEqual(self.server.request.method, 'test_result')
     self.assertEqual(self.server.request.params, params)
     self.assertEqual(self._result, None)
     self.assertEqual(self._error, None)
Пример #17
0
 def test_request_method_dict_params(self):
     params = {'b': 'def', 'a': [3, 6, 9]}
     self.client.test_result(params, on_result=self._on_result,
                             on_error=self._on_error)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcRequest))
     self.assertEqual(self.server.request.method, 'test_result')
     self.assertEqual(self.server.request.params, params)
     self.assertEqual(self._result, {'status': 'OK',
                                     'params': params})
     self.assertEqual(self._error, None)
Пример #18
0
    def test_notification(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 67\r
\r
{"jsonrpc": "2.0", "method": "test_result", "params": [123, "abc"]}'''
        client.send(data)
        base.loop(count=3)
        resp = http_client.HTTPResponse(client)
        self.assertRaises(http_client.BadStatusLine, resp.begin)
        self.assertEqual(self.server.resp_code, None)
        client.close()
Пример #19
0
 def test_request_method_list_params(self):
     params = ['abc', {'a': 1, 'b': 2, 'c': 3}]
     self.client.test_result(params, on_result=self._on_result,
                             on_error=self._on_error)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcRequest))
     self.assertEqual(self.server.request.method, 'test_result')
     self.assertEqual(self.server.request.params, params)
     self.assertEqual(self._result, {'status': 'OK',
                                     'params': {'a': params[0],
                                                'b': params[1]}})
     self.assertEqual(self._error, None)
Пример #20
0
    def test_notification(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 67\r
\r
{"jsonrpc": "2.0", "method": "test_result", "params": [123, "abc"]}'''
        client.send(data)
        base.loop(count=1)
        resp = httplib.HTTPResponse(client)
        self.assertRaises(httplib.BadStatusLine, resp.begin)
        self.assertEqual(self.server.resp_code, None)
        client.close()
Пример #21
0
 def test_request_method_error(self):
     params = [1]
     self.client.test_exception(params, on_result=self._on_result,
                                on_error=self._on_error)
     base.loop()
     self.assertTrue(isinstance(self.server.request, base.JsonRpcRequest))
     self.assertEqual(self.server.request.method, 'test_exception')
     self.assertEqual(self.server.request.params, params)
     self.assertTrue(isinstance(self._error, errors.JsonRpcError))
     self.assertEqual(self.server.request.id, self._error.id)
     self.assertEqual(self._error.marshal()['error'], {'code': -32603,
                                              'message': 'Internal error.',
                                              'data': {'exception': '1'}})
     self.assertEqual(self._result, None)
Пример #22
0
    def test_response_timeout(self):
        def on_error(error):
            self._result = error

        self.client.timeout = 0.1
        self.server.del_channel()

        context = self.client.foo(on_error=on_error)
        self.assertTrue(isinstance(context, client.JsonRpcContext))
        base.loop()
        self._assert_message(context.request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcProtocolError)
        self.assertEqual(self._result.id, context.request.id)
        self.assertEqual(self._result.code, 110)
Пример #23
0
    def test_response_timeout(self):
        def on_error(error):
            self._result = error

        self.client.timeout = 0.1
        self.server.del_channel()

        context = self.client.foo(on_error=on_error)
        self.assertTrue(isinstance(context, client.JsonRpcContext))
        base.loop()
        self._assert_message(context.request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcProtocolError)
        self.assertEqual(self._result.id, context.request.id)
        self.assertEqual(self._result.code, 110)
Пример #24
0
 def test_http_post_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     data = 'POST / HTTP/1.1\r\nContent-Length: 14\r\n\r\nTest text data'
     client.send(data)
     base.loop()
     resp = httplib.HTTPResponse(client)
     resp.begin()
     data = resp.read()
     client.close()
     self.assertEqual(self.server.resp_code, 200)
     try:
         base.loads(data)
     except errors.JsonRpcError, err:
         self.assertEqual(err.code, -32700)
         self.assertEqual(err.message, 'Parse error.')
Пример #25
0
    def test_request_method_result(self):
        def callback(data):
            self._request_callback(data)
            msg = base.JsonRpcResponse(self._request.id, result)
            return self._format_response(msg)

        def on_result(result):
            self._result = result

        result = {'status': 'OK'}
        self.server.connect_callback(callback)
        self.client.foo(on_result=on_result)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self.assertEqual(self._result, result)
Пример #26
0
    def test_request_method_result(self):
        def callback(data):
            self._request_callback(data)
            msg = base.JsonRpcResponse(self._request.id, result)
            return self._format_response(msg)

        def on_result(result):
            self._result = result

        result = {'status': 'OK'}
        self.server.connect_callback(callback)
        self.client.foo(on_result=on_result)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self.assertEqual(self._result, result)
Пример #27
0
 def test_http_post_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     data = 'POST / HTTP/1.1\r\nContent-Length: 14\r\n\r\nTest text data'
     client.send(data)
     base.loop(count=3)
     resp = http_client.HTTPResponse(client)
     resp.begin()
     data = resp.read()
     client.close()
     self.assertEqual(self.server.resp_code, 200)
     try:
         base.loads(data)
     except errors.JsonRpcError as err:
         self.assertEqual(err.code, -32700)
         self.assertEqual(err.message, 'Parse error.')
Пример #28
0
    def test_http_get_response(self):
        def callback(data):
            self._request_callback(data)
            return 'GET / HTTP/1.1\r\n\r\n'

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcParseError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.data,
                {'exception': 'No JSON object could be decoded'})
Пример #29
0
    def test_empty_tcp_response(self):
        def callback(data):
            self._request_callback(data)
            return ''

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcResponseError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, -32650)
        self.assertEqual(self._result.message, 'Invalid response.')
        self.assertEqual(self._result.data, {'exception': "''"})
Пример #30
0
    def test_empty_tcp_response(self):
        def callback(data):
            self._request_callback(data)
            return ''

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcResponseError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, -32650)
        self.assertEqual(self._result.message, 'Invalid response.')
        self.assertEqual(self._result.data, {'exception': "''"})
Пример #31
0
    def test_request_method_invalid_response_id(self):
        def callback(data):
            self._request_callback(data)
            msg = base.JsonRpcResponse('a1b2c3d4', None)
            return self._format_response(msg)

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcResponseError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, -32650)
        self.assertEqual(self._result.message, 'Invalid response.')
        self.assertEqual(self._result.data, {'id': 'a1b2c3d4'})
Пример #32
0
    def test_request_method_invalid_response_id(self):
        def callback(data):
            self._request_callback(data)
            msg = base.JsonRpcResponse('a1b2c3d4', None)
            return self._format_response(msg)

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcResponseError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, -32650)
        self.assertEqual(self._result.message, 'Invalid response.')
        self.assertEqual(self._result.data, {'id': 'a1b2c3d4'})
Пример #33
0
    def test_interface_on_result(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 88\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_on_result", "params": [123, "abc"]}'''
        client.send(data)
        base.loop()
        resp = httplib.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        response = base.loads(data, [base.JsonRpcResponse])
        self.assertTrue(isinstance(response, base.JsonRpcResponse))
        self.assertEqual(response.id, '12345abc')
        self.assertEqual(response.result, {'status': 'OK',
                                           'params': {'a': 123, 'b': 'abc'}})
Пример #34
0
    def test_call_method_not_found(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 102\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "method_not_found", "params": {"a": "abc", "b": "efg"}}'''
        client.send(data)
        base.loop()
        resp = httplib.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError, err:
            self.assertEqual(err.code, -32601)
            self.assertEqual(err.message, 'Method not found.')
            self.assertEqual(err.data, {'method': 'method_not_found'})
Пример #35
0
    def test_interface_on_error(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 82\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_on_error", "params": ["efg"]}'''
        client.send(data)
        base.loop(count=3)
        resp = http_client.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError as err:
            self.assertEqual(err.code, -32603)
            self.assertEqual(err.message, 'Internal error.')
            self.assertEqual(err.data, {'exception': 'efg'})
Пример #36
0
    def test_interface_on_error(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 82\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_on_error", "params": ["efg"]}'''
        client.send(data)
        base.loop()
        resp = httplib.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError, err:
            self.assertEqual(err.code, -32603)
            self.assertEqual(err.message, 'Internal error.')
            self.assertEqual(err.data, {'exception': 'efg'})
Пример #37
0
    def test_call_private_method_not_found(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 96\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "_on_result", "params": {"a": "abc", "b": "efg"}}'''
        client.send(data)
        base.loop(count=3)
        resp = http_client.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError as err:
            self.assertEqual(err.code, -32601)
            self.assertEqual(err.message, 'Method not found.')
            self.assertEqual(err.data, {'method': '_on_result'})
Пример #38
0
    def test_call_invalid_dict_params(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 106\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_result", "params": {"a": 123, "b": "abc", "c": true}}'''
        client.send(data)
        base.loop()
        resp = httplib.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        try:
            base.loads(data, [base.JsonRpcResponse])
        except errors.JsonRpcError, err:
            self.assertEqual(err.code, -32602)
            self.assertEqual(err.message, 'Invalid params.')
            self.assertEqual(err.data, {'method': 'test_result',
                                        'params': {'a': 123, 'b': 'abc', 'c': True}})
Пример #39
0
    def test_request_method_error(self):
        def callback(data):
            self._request_callback(data)
            msg = errors.JsonRpcError(id=self._request.id, **error)
            return self._format_response(msg.marshal())

        def on_error(error):
            self._result = error

        error = {
            'code': -12345,
            'message': 'Test error message',
            'data': {'exception': 'Test exception'}
        }
        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.marshal()['error'], error)
Пример #40
0
    def test_request_method_http_error(self):
        def callback(data):
            self._request_callback(data)
            return '''HTTP/1.1 501 Unsupported method ('GET')\r
Content-Type: application/json-rpc\r
Content-Length: 15\r
\r
<html />'''

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcProtocolError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, 501)
        self.assertEqual(self._result.message, "Unsupported method ('GET')")
        self.assertEqual(self._result.data, {'exception': '<html />'})
Пример #41
0
    def test_request_method_error(self):
        def callback(data):
            self._request_callback(data)
            msg = errors.JsonRpcError(id=self._request.id, **error)
            return self._format_response(msg.marshal())

        def on_error(error):
            self._result = error

        error = {
            'code': -12345,
            'message': 'Test error message',
            'data': {'exception': 'Test exception'}
        }
        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.marshal()['error'], error)
Пример #42
0
    def test_request_method_http_error(self):
        def callback(data):
            self._request_callback(data)
            return '''HTTP/1.1 501 Unsupported method ('GET')\r
Content-Type: application/json-rpc\r
Content-Length: 15\r
\r
<html />'''

        def on_error(error):
            self._result = error

        self.server.connect_callback(callback)
        self.client.foo(on_error=on_error)
        base.loop()
        self._assert_message(self._request, base.JsonRpcRequest)
        self._assert_message(self._result, errors.JsonRpcProtocolError)
        self.assertEqual(self._result.id, self._request.id)
        self.assertEqual(self._result.code, 501)
        self.assertEqual(self._result.message, "Unsupported method ('GET')")
        self.assertEqual(self._result.data, {'exception': '<html />'})
Пример #43
0
    def test_interface_on_result(self):
        client = socket.create_connection(('localhost', self.port), 1)
        data = '''POST / HTTP/1.1\r
Content-Length: 88\r
\r
{"jsonrpc": "2.0", "id": "12345abc", "method": "test_on_result", "params": [123, "abc"]}'''
        client.send(data)
        base.loop(count=3)
        resp = http_client.HTTPResponse(client)
        resp.begin()
        data = resp.read()
        client.close()
        self.assertEqual(self.server.resp_code, 200)
        response = base.loads(data, [base.JsonRpcResponse])
        self.assertTrue(isinstance(response, base.JsonRpcResponse))
        self.assertEqual(response.id, '12345abc')
        self.assertEqual(response.result, {
            'status': 'OK',
            'params': {
                'a': 123,
                'b': 'abc'
            }
        })
Пример #44
0
 def test_tcp_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     client.send('Test tcp data\n')
     base.loop()
     client.close()
     self.assertEqual(self.server.resp_code, 400)
Пример #45
0
 def test_tcp_empty(self):
     client = socket.create_connection(('localhost', self.port), 1)
     base.loop(count=3)
     client.close()
     self.assertEqual(self.server.resp_code, 408)
Пример #46
0
 def test_tcp_empty(self):
     client = socket.create_connection(('localhost', self.port), 1)
     base.loop()
     client.close()
     self.assertEqual(self.server.resp_code, 408)
Пример #47
0
 def test_tcp_data(self):
     client = socket.create_connection(('localhost', self.port), 1)
     client.send('Test tcp data\n')
     base.loop(count=3)
     client.close()
     self.assertEqual(self.server.resp_code, 400)
Пример #48
0
 def test_http_get(self):
     client = socket.create_connection(('localhost', self.port), 1)
     client.send('GET / HTTP/1.1\r\n\r\n')
     base.loop()
     client.close()
     self.assertEqual(self.server.resp_code, 501)
Пример #49
0
 def test_http_get(self):
     client = socket.create_connection(('localhost', self.port), 1)
     client.send('GET / HTTP/1.1\r\n\r\n')
     base.loop(count=3)
     client.close()
     self.assertEqual(self.server.resp_code, 501)