本文整理汇总了Python中jsonrpclib.Server.foobar方法的典型用法代码示例。如果您正苦于以下问题:Python Server.foobar方法的具体用法?Python Server.foobar怎么用?Python Server.foobar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonrpclib.Server
的用法示例。
在下文中一共展示了Server.foobar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCompatibility
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import foobar [as 别名]
class TestCompatibility(unittest.TestCase):
client = None
port = None
server = None
def setUp(self):
self.port = get_port()
self.server = server_set_up(addr=('', self.port))
self.client = Server('http://localhost:%d' % self.port)
# v1 tests forthcoming
# Version 2.0 Tests
def test_positional(self):
""" Positional arguments in a single call """
result = self.client.subtract(23, 42)
self.assertTrue(result == -19)
result = self.client.subtract(42, 23)
self.assertTrue(result == 19)
request = json.loads(history.request)
response = json.loads(history.response)
verify_request = {
"jsonrpc": "2.0", "method": "subtract",
"params": [42, 23], "id": request['id']
}
verify_response = {
"jsonrpc": "2.0", "result": 19, "id": request['id']
}
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_named(self):
""" Named arguments in a single call """
result = self.client.subtract(subtrahend=23, minuend=42)
self.assertTrue(result == 19)
result = self.client.subtract(minuend=42, subtrahend=23)
self.assertTrue(result == 19)
request = json.loads(history.request)
response = json.loads(history.response)
verify_request = {
"jsonrpc": "2.0", "method": "subtract",
"params": {"subtrahend": 23, "minuend": 42},
"id": request['id']
}
verify_response = {
"jsonrpc": "2.0", "result": 19, "id": request['id']
}
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_notification(self):
""" Testing a notification (response should be null) """
result = self.client._notify.update(1, 2, 3, 4, 5)
self.assertTrue(result is None)
request = json.loads(history.request)
response = history.response
verify_request = {
"jsonrpc": "2.0", "method": "update", "params": [1, 2, 3, 4, 5]
}
verify_response = ''
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_non_existent_method(self):
with self.assertRaises(ProtocolError):
self.client.foobar()
request = json.loads(history.request)
response = json.loads(history.response)
verify_request = {
"jsonrpc": "2.0", "method": "foobar", "id": request['id']
}
verify_response = {
"jsonrpc": "2.0",
"error":
{"code": -32601, "message": response['error']['message']},
"id": request['id']
}
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_invalid_json(self):
invalid_json = '{"jsonrpc": "2.0", "method": "foobar, ' + \
'"params": "bar", "baz]'
response = self.client._run_request(invalid_json)
response = json.loads(history.response)
verify_response = json.loads(
'{"jsonrpc": "2.0", "error": {"code": -32700,' +
' "message": "Parse error."}, "id": null}'
)
verify_response['error']['message'] = response['error']['message']
self.assertTrue(response == verify_response)
def test_invalid_request(self):
invalid_request = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'
response = self.client._run_request(invalid_request)
response = json.loads(history.response)
verify_response = json.loads(
'{"jsonrpc": "2.0", "error": {"code": -32600, ' +
#.........这里部分代码省略.........