@@ -11,9 +11,6 @@ def setup():
11
11
manage .call ('uliweb reset -v -y' )
12
12
manage .call ('uliweb dbinit -v' )
13
13
14
- def teardown ():
15
- pass
16
-
17
14
def pre_call_as (username ):
18
15
from uliweb import models
19
16
User = models .user
@@ -22,7 +19,6 @@ def pre_call(request):
22
19
request .user = user
23
20
return pre_call
24
21
25
- @with_setup (setup ,teardown )
26
22
def test_apijson_get ():
27
23
"""
28
24
>>> application = make_simple_application(project_dir='.')
@@ -747,7 +743,7 @@ def test_apijson_get():
747
743
>>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
748
744
>>> d = json_loads(r.data)
749
745
>>> print(d)
750
- {'code': 400, 'msg': "model does not havethis column: 'nonexist'"}
746
+ {'code': 400, 'msg': "model does not have column: 'nonexist'"}
751
747
752
748
>>> #query array with a nonexist column
753
749
>>> data ='''{
@@ -767,6 +763,224 @@ def test_apijson_get():
767
763
>>> print(d)
768
764
{'code': 400, 'msg': "non-existent column or not support item: 'nonexist'"}
769
765
766
+ >>> #query array, {} with list
767
+ >>> data ='''{
768
+ ... "[]":{
769
+ ... "moment": {
770
+ ... "id{}": [1, 2]
771
+ ... }
772
+ ... }
773
+ ... }'''
774
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
775
+ >>> d = json_loads(r.data)
776
+ >>> print(d)
777
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}}, {'moment': {'user_id': 3, 'date': '2018-11-02 00:00:00', 'content': 'test moment from b', 'picture_list': '[]', 'id': 2}}]}
778
+
779
+ >>> #query array, !{} with list
780
+ >>> data ='''{
781
+ ... "[]":{
782
+ ... "moment": {
783
+ ... "id!{}": [1, 2]
784
+ ... }
785
+ ... }
786
+ ... }'''
787
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
788
+ >>> d = json_loads(r.data)
789
+ >>> print(d)
790
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 4, 'date': '2018-11-06 00:00:00', 'content': 'test moment from c', 'picture_list': '[]', 'id': 3}}]}
791
+
792
+ >>> #query array, {} with a non-exist column name
793
+ >>> data ='''{
794
+ ... "[]":{
795
+ ... "moment": {
796
+ ... "nonexist{}": [1, 2]
797
+ ... }
798
+ ... }
799
+ ... }'''
800
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
801
+ >>> d = json_loads(r.data)
802
+ >>> print(d)
803
+ {'code': 400, 'msg': "model does not have column: 'nonexist'"}
804
+
805
+ >>> #query array, {} >=
806
+ >>> data ='''{
807
+ ... "[]":{
808
+ ... "moment": {
809
+ ... "id{}": ">=2"
810
+ ... }
811
+ ... }
812
+ ... }'''
813
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
814
+ >>> d = json_loads(r.data)
815
+ >>> print(d)
816
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 3, 'date': '2018-11-02 00:00:00', 'content': 'test moment from b', 'picture_list': '[]', 'id': 2}}, {'moment': {'user_id': 4, 'date': '2018-11-06 00:00:00', 'content': 'test moment from c', 'picture_list': '[]', 'id': 3}}]}
817
+
818
+ >>> #query array, {} =
819
+ >>> data ='''{
820
+ ... "[]":{
821
+ ... "moment": {
822
+ ... "id{}": "=2"
823
+ ... }
824
+ ... }
825
+ ... }'''
826
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
827
+ >>> d = json_loads(r.data)
828
+ >>> print(d)
829
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 3, 'date': '2018-11-02 00:00:00', 'content': 'test moment from b', 'picture_list': '[]', 'id': 2}}]}
830
+
831
+ >>> #query array, {} >
832
+ >>> data ='''{
833
+ ... "[]":{
834
+ ... "moment": {
835
+ ... "id{}": ">2"
836
+ ... }
837
+ ... }
838
+ ... }'''
839
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
840
+ >>> d = json_loads(r.data)
841
+ >>> print(d)
842
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 4, 'date': '2018-11-06 00:00:00', 'content': 'test moment from c', 'picture_list': '[]', 'id': 3}}]}
843
+
844
+ >>> #query array, {} <=
845
+ >>> data ='''{
846
+ ... "[]":{
847
+ ... "moment": {
848
+ ... "id{}": "<=2"
849
+ ... }
850
+ ... }
851
+ ... }'''
852
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
853
+ >>> d = json_loads(r.data)
854
+ >>> print(d)
855
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}}, {'moment': {'user_id': 3, 'date': '2018-11-02 00:00:00', 'content': 'test moment from b', 'picture_list': '[]', 'id': 2}}]}
856
+
857
+ >>> #query array, {} <
858
+ >>> data ='''{
859
+ ... "[]":{
860
+ ... "moment": {
861
+ ... "id{}": "<2"
862
+ ... }
863
+ ... }
864
+ ... }'''
865
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
866
+ >>> d = json_loads(r.data)
867
+ >>> print(d)
868
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}}]}
869
+
870
+ >>> #query array, !{} <
871
+ >>> data ='''{
872
+ ... "[]":{
873
+ ... "moment": {
874
+ ... "id!{}": "<2"
875
+ ... }
876
+ ... }
877
+ ... }'''
878
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
879
+ >>> d = json_loads(r.data)
880
+ >>> print(d)
881
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 3, 'date': '2018-11-02 00:00:00', 'content': 'test moment from b', 'picture_list': '[]', 'id': 2}}, {'moment': {'user_id': 4, 'date': '2018-11-06 00:00:00', 'content': 'test moment from c', 'picture_list': '[]', 'id': 3}}]}
882
+
883
+ >>> #query array, {} !=
884
+ >>> data ='''{
885
+ ... "[]":{
886
+ ... "moment": {
887
+ ... "id{}": "!=2"
888
+ ... }
889
+ ... }
890
+ ... }'''
891
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
892
+ >>> d = json_loads(r.data)
893
+ >>> print(d)
894
+ {'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}}, {'moment': {'user_id': 4, 'date': '2018-11-06 00:00:00', 'content': 'test moment from c', 'picture_list': '[]', 'id': 3}}]}
895
+
896
+ >>> #query array, {} with wrong operator
897
+ >>> data ='''{
898
+ ... "[]":{
899
+ ... "moment": {
900
+ ... "id{}": "%=2"
901
+ ... }
902
+ ... }
903
+ ... }'''
904
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
905
+ >>> d = json_loads(r.data)
906
+ >>> print(d)
907
+ {'code': 400, 'msg': "not support '%=2'"}
908
+
909
+ >>> #query array, {} condition list
910
+ >>> data ='''{
911
+ ... "[]":{
912
+ ... "user": {
913
+ ... "@role": "ADMIN",
914
+ ... "id{}": "<=2,>3",
915
+ ... "@column": "username,nickname,id"
916
+ ... }
917
+ ... }
918
+ ... }'''
919
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
920
+ >>> d = json_loads(r.data)
921
+ >>> print(d)
922
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'id': 1}}, {'user': {'username': 'usera', 'nickname': 'User A', 'id': 2}}, {'user': {'username': 'userc', 'nickname': 'User C', 'id': 4}}]}
923
+
924
+ >>> #query array, |{} condition list
925
+ >>> data ='''{
926
+ ... "[]":{
927
+ ... "user": {
928
+ ... "@role": "ADMIN",
929
+ ... "id|{}": "<=2,>3",
930
+ ... "@column": "username,nickname,id"
931
+ ... }
932
+ ... }
933
+ ... }'''
934
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
935
+ >>> d = json_loads(r.data)
936
+ >>> print(d)
937
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'id': 1}}, {'user': {'username': 'usera', 'nickname': 'User A', 'id': 2}}, {'user': {'username': 'userc', 'nickname': 'User C', 'id': 4}}]}
938
+
939
+ >>> #query array, &{} condition list
940
+ >>> data ='''{
941
+ ... "[]":{
942
+ ... "user": {
943
+ ... "@role": "ADMIN",
944
+ ... "id&{}": ">2,<=4",
945
+ ... "@column": "username,nickname,id"
946
+ ... }
947
+ ... }
948
+ ... }'''
949
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
950
+ >>> d = json_loads(r.data)
951
+ >>> print(d)
952
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'userb', 'nickname': 'User B', 'id': 3}}, {'user': {'username': 'userc', 'nickname': 'User C', 'id': 4}}]}
953
+
954
+ >>> #query array, !{} condition list
955
+ >>> data ='''{
956
+ ... "[]":{
957
+ ... "user": {
958
+ ... "@role": "ADMIN",
959
+ ... "id!{}": ">2,<=4",
960
+ ... "@column": "username,nickname,id"
961
+ ... }
962
+ ... }
963
+ ... }'''
964
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
965
+ >>> d = json_loads(r.data)
966
+ >>> print(d)
967
+ {'code': 400, 'msg': "'!' not supported in condition list"}
968
+
969
+ >>> #query array, |{} condition list, item more than 2
970
+ >>> data ='''{
971
+ ... "[]":{
972
+ ... "user": {
973
+ ... "@role": "ADMIN",
974
+ ... "id|{}": "=1,=2,>=4",
975
+ ... "@column": "username,id"
976
+ ... }
977
+ ... }
978
+ ... }'''
979
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
980
+ >>> d = json_loads(r.data)
981
+ >>> print(d)
982
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'id': 1}}, {'user': {'username': 'usera', 'id': 2}}, {'user': {'username': 'userc', 'id': 4}}]}
983
+
770
984
>>> #Association query: Two tables, one to one,ref path is absolute path
771
985
>>> data ='''{
772
986
... "moment":{},