Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2ab647

Browse files
committed
fix "AttributeError: 'Request' object has no attribute 'user'"; add 4 test cases for apijson-head
1 parentf0c5026 commitd2ab647

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

‎tests/test.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
deftest_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+
"""

‎uliweb_apijson/apijson/views.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ def _head(self,key):
295295
else:
296296
params_role="UNKNOWN"
297297
ifparams_rolenotinroles:
298-
returnjson({"code":400,"msg":"'%s' notaccessible by role'%s'"%(model_name,params_role)})
298+
returnjson({"code":400,"msg":"role'%s' nothave permission HEAD for'%s'"%(params_role,model_name)})
299299
ifparams_role=="UNKNOWN":
300300
permission_check_ok=True
301+
elifnothasattr(request,"user"):
302+
returnjson({"code":400,"msg":"no login user for role '%s'"%(params_role)})
301303
eliffunctions.has_role(request.user,params_role):
302304
permission_check_ok=True
303305
else:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp