Skip to content

Sync #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 10, 2019
Merged

Sync #40

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
fix "NameError: name 'model_name' is not defined"; add 3 test cases
  • Loading branch information
zhangchunlin committed Oct 10, 2019
commit 0fb0711f8dd67cb7c0d338c76cda42c883927bbb
43 changes: 43 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,49 @@ def test_apijson_get():
>>> print(d)
{'code': 400, 'msg': "page should >0, but get '-2'"}

>>> #query array with @count/@page/@query, @query bad param
>>> data ='''{
... "[]":{
... "@count":2,
... "@page":1,
... "@query":3,
... "user": {
... }
... }
... }'''
>>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("usera"), middlewares=[])
>>> d = json_loads(r.data)
>>> print(d)
{'code': 400, 'msg': "bad param 'query': 3"}

>>> #query array with @count/@page/@query, @query = 0
>>> data ='''{
... "[]":{
... "@count":2,
... "@page":1,
... "@query":0,
... "user": {
... }
... }
... }'''
>>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("usera"), middlewares=[])
>>> d = json_loads(r.data)
>>> print(d)
{'code': 200, 'msg': 'success', '[]': [{'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}}]}

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

>>> #Association query: Two tables, one to one,ref path is absolute path
>>> data ='''{
... "moment":{},
Expand Down
2 changes: 1 addition & 1 deletion uliweb_apijson/apijson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _filter_owner(self,q):
q = q.filter(getattr(model.c,user_id_field)==request.user.id)
owner_filtered = True
if not owner_filtered:
raise UliwebError("'%s' cannot filter with owner"%(model_name))
raise UliwebError("'%s' cannot filter with owner"%(self.name))
return q

def _get_array_q(self,params):
Expand Down