Skip to content

Commit b27ad9b

Browse files
committed
add 4 test cases for apijson-head, now 9 cases
1 parent 9461f44 commit b27ad9b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

tests/test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,50 @@ def test_apijson_head():
875875
>>> d = json_loads(r.data)
876876
>>> print(d)
877877
{'code': 400, 'msg': "role 'UNKNOWN' not have permission HEAD for 'privacy'"}
878+
879+
>>> #apijson head, user don't have role
880+
>>> data ='''{
881+
... "privacy": {
882+
... "@role":"ADMIN",
883+
... "id": 1
884+
... }
885+
... }'''
886+
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
887+
>>> d = json_loads(r.data)
888+
>>> print(d)
889+
{'code': 400, 'msg': "user doesn't have role 'ADMIN'"}
890+
891+
>>> #apijson head, with OWNER
892+
>>> data ='''{
893+
... "moment": {
894+
... "@role":"OWNER"
895+
... }
896+
... }'''
897+
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
898+
Moment: owner_condition
899+
>>> d = json_loads(r.data)
900+
>>> print(d)
901+
{'code': 200, 'msg': 'success', 'moment': {'code': 200, 'msg': 'success', 'count': 1}}
902+
903+
>>> #apijson head, with OWNER but cannot filter with OWNER
904+
>>> data ='''{
905+
... "publicnotice": {
906+
... "@role":"OWNER"
907+
... }
908+
... }'''
909+
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
910+
>>> d = json_loads(r.data)
911+
>>> print(d)
912+
{'code': 400, 'msg': "'publicnotice' cannot filter with owner"}
913+
914+
>>> #apijson head, with a nonexistant column
915+
>>> data ='''{
916+
... "moment": {
917+
... "nonexist": 2
918+
... }
919+
... }'''
920+
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("admin"), middlewares=[])
921+
>>> d = json_loads(r.data)
922+
>>> print(d)
923+
{'code': 400, 'msg': "'moment' don't have field 'nonexist'"}
878924
"""

uliweb_apijson/apijson/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def _head(self,key):
304304
permission_check_ok = True
305305
else:
306306
return json({"code":400,"msg":"user doesn't have role '%s'"%(params_role)})
307+
#current implementation won't run here, but keep for safe
307308
if not permission_check_ok:
308309
return json({"code":400,"msg":"no permission"})
309310

0 commit comments

Comments
 (0)