@@ -813,3 +813,55 @@ def test_apijson_get():
813813 >>> print(d)
814814 {'code': 200, 'msg': 'success', 'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}, 'user': {'username': 'usera', 'email': 'usera@localhost', 'id': 2}}
815815 """
816+
817+ def test_apijson_head ():
818+ """
819+ >>> application = make_simple_application(project_dir='.')
820+ >>> handler = application.handler()
821+
822+ >>> #apijson head
823+ >>> data ='''{
824+ ... "moment": {
825+ ... "user_id": 2
826+ ... }
827+ ... }'''
828+ >>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("admin"), middlewares=[])
829+ >>> d = json_loads(r.data)
830+ >>> print(d)
831+ {'code': 200, 'msg': 'success', 'moment': {'code': 200, 'msg': 'success', 'count': 1}}
832+
833+ >>> #apijson head, with a nonexistant model
834+ >>> data ='''{
835+ ... "nonexist": {
836+ ... "user_id": 2
837+ ... }
838+ ... }'''
839+ >>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("admin"), middlewares=[])
840+ >>> d = json_loads(r.data)
841+ >>> print(d)
842+ {'code': 400, 'msg': "model 'nonexist' not found"}
843+
844+ >>> #apijson head, without permission of HEAD
845+ >>> data ='''{
846+ ... "privacy": {
847+ ... "@role":"LOGIN",
848+ ... "id": 1
849+ ... }
850+ ... }'''
851+ >>> r = handler.post('/apijson/head', data=data, pre_call=pre_call_as("admin"), middlewares=[])
852+ >>> d = json_loads(r.data)
853+ >>> print(d)
854+ {'code': 400, 'msg': "role 'LOGIN' not have permission HEAD for 'privacy'"}
855+
856+ >>> #apijson head, without user
857+ >>> data ='''{
858+ ... "privacy": {
859+ ... "@role":"ADMIN",
860+ ... "id": 1
861+ ... }
862+ ... }'''
863+ >>> r = handler.post('/apijson/head', data=data, middlewares=[])
864+ >>> d = json_loads(r.data)
865+ >>> print(d)
866+ {'code': 400, 'msg': "no login user for role 'ADMIN'"}
867+ """
0 commit comments