Skip to content
Merged

Sync #41

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add 4 test cases for apijson-head, now 9 cases
  • Loading branch information
zhangchunlin committed Oct 11, 2019
commit b27ad9bb0e7794a9716642196bd930b4f90b9d7d
46 changes: 46 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,50 @@ def test_apijson_head():
>>> d = json_loads(r.data)
>>> print(d)
{'code': 400, 'msg': "role 'UNKNOWN' not have permission HEAD for 'privacy'"}

>>> #apijson head, user don't have role
>>> data ='''{
... "privacy": {
... "@role":"ADMIN",
... "id": 1
... }
... }'''
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
>>> d = json_loads(r.data)
>>> print(d)
{'code': 400, 'msg': "user doesn't have role 'ADMIN'"}

>>> #apijson head, with OWNER
>>> data ='''{
... "moment": {
... "@role":"OWNER"
... }
... }'''
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
Moment: owner_condition
>>> d = json_loads(r.data)
>>> print(d)
{'code': 200, 'msg': 'success', 'moment': {'code': 200, 'msg': 'success', 'count': 1}}

>>> #apijson head, with OWNER but cannot filter with OWNER
>>> data ='''{
... "publicnotice": {
... "@role":"OWNER"
... }
... }'''
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("usera"), middlewares=[])
>>> d = json_loads(r.data)
>>> print(d)
{'code': 400, 'msg': "'publicnotice' cannot filter with owner"}

>>> #apijson head, with a nonexistant column
>>> data ='''{
... "moment": {
... "nonexist": 2
... }
... }'''
>>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("admin"), middlewares=[])
>>> d = json_loads(r.data)
>>> print(d)
{'code': 400, 'msg': "'moment' don't have field 'nonexist'"}
"""
1 change: 1 addition & 0 deletions uliweb_apijson/apijson/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ def _head(self,key):
permission_check_ok = True
else:
return json({"code":400,"msg":"user doesn't have role '%s'"%(params_role)})
#current implementation won't run here, but keep for safe
if not permission_check_ok:
return json({"code":400,"msg":"no permission"})

Expand Down