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
1=== modified file 'frameworks/python/src/ladon/interfaces/jsonrpc10.py'
2--- frameworks/python/src/ladon/interfaces/jsonrpc10.py 2012-10-26 11:28:06 +0000
3+++ frameworks/python/src/ladon/interfaces/jsonrpc10.py 2012-10-30 14:27:22 +0000
4@@ -30,6 +30,26 @@
5
6 def __str__(self):
7 return self.faultstring
8+
9+class MethodArgsCountFault(ServiceFault):
10+ def __init__(self,methodname,targsscount,gargscount,passback_dict):
11+ self.methodname = methodname
12+ self.targsscount = targsscount
13+ self.gargscount = gargscount
14+ self.passback_dict = passback_dict
15+ super(MethodArgsCountFault,self).__init__('service','Method "%s" takes exactly %s arguments, %s given.' % \
16+ (self.methodname,self.targsscount,self.gargscount), None, 2)
17+
18+ def __str__(self):
19+ return self.faultstring
20+
21+class RequestParamsArrayFault(ServiceFault):
22+ def __init__(self,passback_dict):
23+ self.passback_dict = passback_dict
24+ super(RequestParamsArrayFault,self).__init__('service','Params must be array of objects.',None,2)
25+
26+ def __str__(self):
27+ return self.faultstring
28
29 class JSONRPCServiceDescriptor(ServiceDescriptor):
30 javascript_type_map = type_to_jsontype
31@@ -120,17 +140,21 @@
32 if 'id' not in req_dict:
33 raise RequestPropFault('id',passback_dict)
34 minfo = sinfo.methods[req_dict['method']]
35- if (req_dict['params'] is None or len(req_dict['params']) == 0) and len(minfo.args()) > 0:
36+ params = req_dict['params']
37+ if params is not None and type(params) is not list:
38+ raise RequestParamsArrayFault(passback_dict)
39+ params_len = len(params) if params is not None else 0
40+ args_len = len(minfo.args())
41+ if params_len == 0 and args_len> 0:
42 raise RequestParamFault(minfo.args()[0]['name'],passback_dict)
43- else:
44- for arg in minfo.args():
45- isgiven = False
46- for param in req_dict['params']:
47- if param == arg['name']:
48- isgiven = True
49- if not isgiven:
50- raise RequestParamFault(arg['name'],passback_dict)
51- req_dict['args'] = req_dict['params']
52+ elif params_len < args_len:
53+ raise RequestParamFault(minfo.args()[params_len]['name'],passback_dict)
54+ elif params_len > args_len:
55+ raise MethodArgsCountFault(req_dict['method'], args_len, params_len,passback_dict)
56+ req_dict['args'] = {}
57+ if params is not None:
58+ for i in range(len(params)):
59+ req_dict['args'][minfo.args()[i]['name']] = params[i]
60 req_dict['methodname'] = req_dict['method']
61 del req_dict['params']
62 del req_dict['method']
63
64=== modified file 'frameworks/python/tests/testjsonrpc10.py'
65--- frameworks/python/tests/testjsonrpc10.py 2012-10-23 12:25:57 +0000
66+++ frameworks/python/tests/testjsonrpc10.py 2012-10-30 14:27:22 +0000
67@@ -79,7 +79,7 @@
68
69 def test_passback_string(self):
70 val = 'Yo!!!'
71- req = {'method':'passback_string','params':{'arg':val},'id':0}
72+ req = {'method':'passback_string','params':[val],'id':0}
73 jreq = json.dumps(req)
74
75 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
76@@ -91,7 +91,7 @@
77
78 def test_passback_int(self):
79 val = 11
80- req = {'method':'passback_int','params':{'arg':val},'id':0}
81+ req = {'method':'passback_int','params':[val],'id':0}
82 jreq = json.dumps(req)
83
84 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
85@@ -103,7 +103,7 @@
86
87 def test_passback_float(self):
88 val = 11.11
89- req = {'method':'passback_float','params':{'arg':val},'id':0}
90+ req = {'method':'passback_float','params':[val],'id':0}
91 jreq = json.dumps(req)
92
93 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
94@@ -115,7 +115,7 @@
95
96 def test_passback_bool(self):
97 val = True
98- req = {'method':'passback_bool','params':{'arg':val},'id':0}
99+ req = {'method':'passback_bool','params':[val],'id':0}
100 jreq = json.dumps(req)
101
102 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
103@@ -127,7 +127,7 @@
104
105 def test_passback_bytes(self):
106 val = 'Yo!!!'
107- req = {'method':'passback_bytes','params':{'arg':val},'id':0}
108+ req = {'method':'passback_bytes','params':[val],'id':0}
109 jreq = json.dumps(req)
110
111 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
112@@ -198,7 +198,7 @@
113 self.assertEqual(res['id'], '0')
114 self.assertIs(res['result'], None)
115
116- req = {'method':'passback_string','params':{'arg': 'Yo!!!'},'id':0}
117+ req = {'method':'passback_string','params':['Yo!!!'],'id':0}
118 jreq = json.dumps(req)
119
120 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
121@@ -210,7 +210,7 @@
122 self.assertEqual(res['id'], '0')
123 self.assertEqual(res['result'], 'Yo!!!')
124
125- req = {'method':'params','params':{},'id':0}
126+ req = {'method':'params','params':[],'id':0}
127 jreq = json.dumps(req)
128
129 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
130@@ -222,7 +222,7 @@
131 self.assertEqual(res['id'], '0')
132 self.assertTrue('"arg0"' in res['error']['string'])
133
134- req = {'method':'params','params':{'arg0':11},'id':0}
135+ req = {'method':'params','params':[11],'id':0}
136 jreq = json.dumps(req)
137
138 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
139@@ -234,7 +234,7 @@
140 self.assertEqual(res['id'], '0')
141 self.assertTrue('"arg1"' in res['error']['string'])
142
143- req = {'method':'params','params':{'arg0':11, 'arg1':11.11},'id':0}
144+ req = {'method':'params','params':[11, 11.11],'id':0}
145 jreq = json.dumps(req)
146
147 status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
148@@ -245,6 +245,31 @@
149 self.assertIs(type(res['error']), dict)
150 self.assertEqual(res['id'], '0')
151 self.assertTrue('"arg2"' in res['error']['string'])
152+
153+ req = {'method':'params','params':[11,11.11,'Yo!!!','Yo!!!'],'id':0}
154+ jreq = json.dumps(req)
155+
156+ status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
157+
158+ self.assertEqual(status, 200)
159+ res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
160+
161+ self.assertIs(type(res['error']), dict)
162+ self.assertEqual(res['id'], '0')
163+ self.assertTrue('3' in res['error']['string'])
164+ self.assertTrue('4' in res['error']['string'])
165+
166+ req = {'method':'params','params':{},'id':0}
167+ jreq = json.dumps(req)
168+
169+ status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
170+
171+ self.assertEqual(status, 200)
172+ res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
173+
174+ self.assertIs(type(res['error']), dict)
175+ self.assertEqual(res['id'], '0')
176+ self.assertTrue('Params must be array of objects.' == res['error']['string'])
177
178 if __name__ == '__main__':
179 import servicerunner

Subscribers

People subscribed via source and target branches

to all changes: