Merge lp:~roger-lp/ladon/trunk into lp:ladon

Proposed by roger
Status: Merged
Approved by: jsgaarde
Approved revision: 96
Merged at revision: 96
Proposed branch: lp:~roger-lp/ladon/trunk
Merge into: lp:ladon
Diff against target: 179 lines (+68/-19)
2 files modified
frameworks/python/src/ladon/interfaces/jsonrpc10.py (+34/-10)
frameworks/python/tests/testjsonrpc10.py (+34/-9)
To merge this branch: bzr merge lp:~roger-lp/ladon/trunk
Reviewer Review Type Date Requested Status
jsgaarde Approve
Review via email: mp+132114@code.launchpad.net

Description of the change

Bug #1071807 was fixed.

To post a comment you must log in.
Revision history for this message
jsgaarde (jakob-simon-gaarde) wrote :

Tested service succesfully with http://json-rpc.org/wiki/python-json-rpc

Closing bug and merging fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'frameworks/python/src/ladon/interfaces/jsonrpc10.py'
--- frameworks/python/src/ladon/interfaces/jsonrpc10.py 2012-10-26 11:28:06 +0000
+++ frameworks/python/src/ladon/interfaces/jsonrpc10.py 2012-10-30 14:27:22 +0000
@@ -30,6 +30,26 @@
3030
31 def __str__(self):31 def __str__(self):
32 return self.faultstring32 return self.faultstring
33
34class MethodArgsCountFault(ServiceFault):
35 def __init__(self,methodname,targsscount,gargscount,passback_dict):
36 self.methodname = methodname
37 self.targsscount = targsscount
38 self.gargscount = gargscount
39 self.passback_dict = passback_dict
40 super(MethodArgsCountFault,self).__init__('service','Method "%s" takes exactly %s arguments, %s given.' % \
41 (self.methodname,self.targsscount,self.gargscount), None, 2)
42
43 def __str__(self):
44 return self.faultstring
45
46class RequestParamsArrayFault(ServiceFault):
47 def __init__(self,passback_dict):
48 self.passback_dict = passback_dict
49 super(RequestParamsArrayFault,self).__init__('service','Params must be array of objects.',None,2)
50
51 def __str__(self):
52 return self.faultstring
3353
34class JSONRPCServiceDescriptor(ServiceDescriptor): 54class JSONRPCServiceDescriptor(ServiceDescriptor):
35 javascript_type_map = type_to_jsontype55 javascript_type_map = type_to_jsontype
@@ -120,17 +140,21 @@
120 if 'id' not in req_dict:140 if 'id' not in req_dict:
121 raise RequestPropFault('id',passback_dict)141 raise RequestPropFault('id',passback_dict)
122 minfo = sinfo.methods[req_dict['method']]142 minfo = sinfo.methods[req_dict['method']]
123 if (req_dict['params'] is None or len(req_dict['params']) == 0) and len(minfo.args()) > 0:143 params = req_dict['params']
144 if params is not None and type(params) is not list:
145 raise RequestParamsArrayFault(passback_dict)
146 params_len = len(params) if params is not None else 0
147 args_len = len(minfo.args())
148 if params_len == 0 and args_len> 0:
124 raise RequestParamFault(minfo.args()[0]['name'],passback_dict)149 raise RequestParamFault(minfo.args()[0]['name'],passback_dict)
125 else:150 elif params_len < args_len:
126 for arg in minfo.args():151 raise RequestParamFault(minfo.args()[params_len]['name'],passback_dict)
127 isgiven = False152 elif params_len > args_len:
128 for param in req_dict['params']:153 raise MethodArgsCountFault(req_dict['method'], args_len, params_len,passback_dict)
129 if param == arg['name']:154 req_dict['args'] = {}
130 isgiven = True155 if params is not None:
131 if not isgiven:156 for i in range(len(params)):
132 raise RequestParamFault(arg['name'],passback_dict)157 req_dict['args'][minfo.args()[i]['name']] = params[i]
133 req_dict['args'] = req_dict['params']
134 req_dict['methodname'] = req_dict['method']158 req_dict['methodname'] = req_dict['method']
135 del req_dict['params']159 del req_dict['params']
136 del req_dict['method']160 del req_dict['method']
137161
=== modified file 'frameworks/python/tests/testjsonrpc10.py'
--- frameworks/python/tests/testjsonrpc10.py 2012-10-23 12:25:57 +0000
+++ frameworks/python/tests/testjsonrpc10.py 2012-10-30 14:27:22 +0000
@@ -79,7 +79,7 @@
79 79
80 def test_passback_string(self):80 def test_passback_string(self):
81 val = 'Yo!!!'81 val = 'Yo!!!'
82 req = {'method':'passback_string','params':{'arg':val},'id':0}82 req = {'method':'passback_string','params':[val],'id':0}
83 jreq = json.dumps(req)83 jreq = json.dumps(req)
84 84
85 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')85 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -91,7 +91,7 @@
91 91
92 def test_passback_int(self):92 def test_passback_int(self):
93 val = 1193 val = 11
94 req = {'method':'passback_int','params':{'arg':val},'id':0}94 req = {'method':'passback_int','params':[val],'id':0}
95 jreq = json.dumps(req)95 jreq = json.dumps(req)
96 96
97 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')97 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -103,7 +103,7 @@
103 103
104 def test_passback_float(self):104 def test_passback_float(self):
105 val = 11.11105 val = 11.11
106 req = {'method':'passback_float','params':{'arg':val},'id':0}106 req = {'method':'passback_float','params':[val],'id':0}
107 jreq = json.dumps(req)107 jreq = json.dumps(req)
108 108
109 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')109 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -115,7 +115,7 @@
115 115
116 def test_passback_bool(self):116 def test_passback_bool(self):
117 val = True117 val = True
118 req = {'method':'passback_bool','params':{'arg':val},'id':0}118 req = {'method':'passback_bool','params':[val],'id':0}
119 jreq = json.dumps(req)119 jreq = json.dumps(req)
120 120
121 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')121 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -127,7 +127,7 @@
127 127
128 def test_passback_bytes(self):128 def test_passback_bytes(self):
129 val = 'Yo!!!'129 val = 'Yo!!!'
130 req = {'method':'passback_bytes','params':{'arg':val},'id':0}130 req = {'method':'passback_bytes','params':[val],'id':0}
131 jreq = json.dumps(req)131 jreq = json.dumps(req)
132 132
133 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')133 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -198,7 +198,7 @@
198 self.assertEqual(res['id'], '0')198 self.assertEqual(res['id'], '0')
199 self.assertIs(res['result'], None)199 self.assertIs(res['result'], None)
200 200
201 req = {'method':'passback_string','params':{'arg': 'Yo!!!'},'id':0}201 req = {'method':'passback_string','params':['Yo!!!'],'id':0}
202 jreq = json.dumps(req)202 jreq = json.dumps(req)
203 203
204 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')204 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -210,7 +210,7 @@
210 self.assertEqual(res['id'], '0')210 self.assertEqual(res['id'], '0')
211 self.assertEqual(res['result'], 'Yo!!!')211 self.assertEqual(res['result'], 'Yo!!!')
212 212
213 req = {'method':'params','params':{},'id':0}213 req = {'method':'params','params':[],'id':0}
214 jreq = json.dumps(req)214 jreq = json.dumps(req)
215 215
216 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')216 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -222,7 +222,7 @@
222 self.assertEqual(res['id'], '0')222 self.assertEqual(res['id'], '0')
223 self.assertTrue('"arg0"' in res['error']['string'])223 self.assertTrue('"arg0"' in res['error']['string'])
224 224
225 req = {'method':'params','params':{'arg0':11},'id':0}225 req = {'method':'params','params':[11],'id':0}
226 jreq = json.dumps(req)226 jreq = json.dumps(req)
227 227
228 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')228 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -234,7 +234,7 @@
234 self.assertEqual(res['id'], '0')234 self.assertEqual(res['id'], '0')
235 self.assertTrue('"arg1"' in res['error']['string'])235 self.assertTrue('"arg1"' in res['error']['string'])
236 236
237 req = {'method':'params','params':{'arg0':11, 'arg1':11.11},'id':0}237 req = {'method':'params','params':[11, 11.11],'id':0}
238 jreq = json.dumps(req)238 jreq = json.dumps(req)
239 239
240 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')240 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -245,6 +245,31 @@
245 self.assertIs(type(res['error']), dict)245 self.assertIs(type(res['error']), dict)
246 self.assertEqual(res['id'], '0')246 self.assertEqual(res['id'], '0')
247 self.assertTrue('"arg2"' in res['error']['string'])247 self.assertTrue('"arg2"' in res['error']['string'])
248
249 req = {'method':'params','params':[11,11.11,'Yo!!!','Yo!!!'],'id':0}
250 jreq = json.dumps(req)
251
252 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
253
254 self.assertEqual(status, 200)
255 res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
256
257 self.assertIs(type(res['error']), dict)
258 self.assertEqual(res['id'], '0')
259 self.assertTrue('3' in res['error']['string'])
260 self.assertTrue('4' in res['error']['string'])
261
262 req = {'method':'params','params':{},'id':0}
263 jreq = json.dumps(req)
264
265 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
266
267 self.assertEqual(status, 200)
268 res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
269
270 self.assertIs(type(res['error']), dict)
271 self.assertEqual(res['id'], '0')
272 self.assertTrue('Params must be array of objects.' == res['error']['string'])
248273
249if __name__ == '__main__':274if __name__ == '__main__':
250 import servicerunner275 import servicerunner

Subscribers

People subscribed via source and target branches

to all changes: