@@ -66,6 +66,29 @@ def test_apijson_get():
66
66
>>> print(d)
67
67
{'code': 200, 'msg': 'success', 'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'is_superuser': True, 'id': 1}}
68
68
69
+ >>> #query with @column which have a non existing column name
70
+ >>> data ='''{
71
+ ... "user":{
72
+ ... "@role":"OWNER",
73
+ ... "@column": "id,username,email,nickname,is_superuser,nonexisting"
74
+ ... }
75
+ ... }'''
76
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
77
+ >>> d = json_loads(r.data)
78
+ >>> print(d)
79
+ {'code': 200, 'msg': 'success', 'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'is_superuser': True, 'id': 1}}
80
+
81
+ >>> #query with a non existing column property
82
+ >>> data ='''{
83
+ ... "user":{
84
+ ... "nonexisting": 1
85
+ ... }
86
+ ... }'''
87
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
88
+ >>> d = json_loads(r.data)
89
+ >>> print(d)
90
+ {'code': 400, 'msg': "'user' have no attribute 'nonexisting'"}
91
+
69
92
>>> #query one with a non existing model
70
93
>>> data ='''{
71
94
... "nonexist":{
@@ -120,7 +143,7 @@ def test_apijson_get():
120
143
>>> r = handler.post('/apijson/get', data=data, middlewares=[])
121
144
>>> d = json_loads(r.data)
122
145
>>> print(d)
123
- {'code': 400, 'msg': "no user for role 'OWNER'"}
146
+ {'code': 400, 'msg': "no login user for role 'OWNER'"}
124
147
125
148
>>> #query one with OWNER but cannot filter with OWNER
126
149
>>> data ='''{
@@ -200,6 +223,72 @@ def test_apijson_get():
200
223
>>> print(d)
201
224
{'code': 400, 'msg': "'user' not accessible by role 'superuser'"}
202
225
226
+ >>> #query array
227
+ >>> data ='''{
228
+ ... "[]":{
229
+ ... "user": {"@role":"ADMIN"}
230
+ ... }
231
+ ... }'''
232
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
233
+ >>> d = json_loads(r.data)
234
+ >>> print(d)
235
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'is_superuser': True, 'last_login': None, 'date_join': '2018-11-01 00:00:00', 'image': '', 'active': False, 'locked': False, 'deleted': False, 'auth_type': 'default', 'timezone': '', 'id': 1}}, {'user': {'username': 'usera', 'nickname': 'User A', 'email': 'usera@localhost', 'is_superuser': False, 'last_login': None, 'date_join': '2018-02-02 00:00:00', 'image': '', 'active': False, 'locked': False, 'deleted': False, 'auth_type': 'default', 'timezone': '', 'id': 2}}, {'user': {'username': 'userb', 'nickname': 'User B', 'email': 'userb@localhost', 'is_superuser': False, 'last_login': None, 'date_join': '2018-03-03 00:00:00', 'image': '', 'active': False, 'locked': False, 'deleted': False, 'auth_type': 'default', 'timezone': '', 'id': 3}}, {'user': {'username': 'userc', 'nickname': 'User C', 'email': 'userc@localhost', 'is_superuser': False, 'last_login': None, 'date_join': '2018-04-04 00:00:00', 'image': '', 'active': False, 'locked': False, 'deleted': False, 'auth_type': 'default', 'timezone': '', 'id': 4}}]}
236
+
237
+ >>> #query array
238
+ >>> data ='''{
239
+ ... "[]":{
240
+ ... "user": {
241
+ ... "@role":"ADMIN",
242
+ ... "@column":"id,username,nickname,email"
243
+ ... }
244
+ ... }
245
+ ... }'''
246
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
247
+ >>> d = json_loads(r.data)
248
+ >>> print(d)
249
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'id': 1}}, {'user': {'username': 'usera', 'nickname': 'User A', 'email': 'usera@localhost', 'id': 2}}, {'user': {'username': 'userb', 'nickname': 'User B', 'email': 'userb@localhost', 'id': 3}}, {'user': {'username': 'userc', 'nickname': 'User C', 'email': 'userc@localhost', 'id': 4}}]}
250
+
251
+ >>> #query array with non existing role
252
+ >>> data ='''{
253
+ ... "[]":{
254
+ ... "user": {
255
+ ... "@role":"NONEXISTING",
256
+ ... "@column":"id,username,nickname,email"
257
+ ... }
258
+ ... }
259
+ ... }'''
260
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
261
+ >>> d = json_loads(r.data)
262
+ >>> print(d)
263
+ {'code': 400, 'msg': "'user' not accessible by role 'NONEXISTING'"}
264
+
265
+ >>> #query array with UNKNOWN
266
+ >>> data ='''{
267
+ ... "[]":{
268
+ ... "user": {
269
+ ... "@column":"id,username,nickname,email"
270
+ ... }
271
+ ... }
272
+ ... }'''
273
+ >>> r = handler.post('/apijson/get', data=data, middlewares=[])
274
+ >>> d = json_loads(r.data)
275
+ >>> print(d)
276
+ {'code': 400, 'msg': "'user' not accessible by role 'UNKNOWN'"}
277
+
278
+ >>> #query array without login user
279
+ >>> data ='''{
280
+ ... "[]":{
281
+ ... "user": {
282
+ ... "@role":"ADMIN",
283
+ ... "@column":"id,username,nickname,email"
284
+ ... }
285
+ ... }
286
+ ... }'''
287
+ >>> r = handler.post('/apijson/get', data=data, middlewares=[])
288
+ >>> d = json_loads(r.data)
289
+ >>> print(d)
290
+ {'code': 400, 'msg': "no login user for role 'ADMIN'"}
291
+
203
292
>>> #Association query: Two tables, one to one,ref path is absolute path
204
293
>>> data ='''{
205
294
... "moment":{},
0 commit comments