@@ -453,6 +453,120 @@ def test_apijson_get():
453
453
>>> print(d)
454
454
{'code': 200, 'msg': 'success', '[]': [{'moment': {'user_id': 2, 'date': '2018-11-01 00:00:00', 'content': 'test moment', 'picture_list': '[]', 'id': 1}}]}
455
455
456
+ >>> #query array with some filter column
457
+ >>> data ='''{
458
+ ... "[]":{
459
+ ... "@count":4,
460
+ ... "@page":0,
461
+ ... "user":{
462
+ ... "@column":"id,username,nickname,email",
463
+ ... "@order":"id-",
464
+ ... "@role":"ADMIN",
465
+ ... "username":"admin"
466
+ ... }
467
+ ... }
468
+ ... }'''
469
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
470
+ >>> d = json_loads(r.data)
471
+ >>> print(d)
472
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'id': 1}}]}
473
+
474
+ >>> #query array with reference, @query = 1
475
+ >>> data ='''{
476
+ ... "[]":{
477
+ ... "@count":2,
478
+ ... "@page":0,
479
+ ... "@query":1,
480
+ ... "user":{
481
+ ... "@column":"id,username,nickname,email",
482
+ ... "@order":"id-",
483
+ ... "@role":"ADMIN"
484
+ ... }
485
+ ... },
486
+ ... "total@":"/[]/total"
487
+ ... }'''
488
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
489
+ >>> d = json_loads(r.data)
490
+ >>> print(d)
491
+ {'code': 200, 'msg': 'success', 'total': 4}
492
+
493
+ >>> #query array with reference, @query = 2
494
+ >>> data ='''{
495
+ ... "[]":{
496
+ ... "@count":2,
497
+ ... "@page":0,
498
+ ... "@query":2,
499
+ ... "user":{
500
+ ... "@column":"id,username,nickname,email",
501
+ ... "@order":"id-",
502
+ ... "@role":"ADMIN"
503
+ ... }
504
+ ... },
505
+ ... "total@":"/[]/total"
506
+ ... }'''
507
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
508
+ >>> d = json_loads(r.data)
509
+ >>> print(d)
510
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'userc', 'nickname': 'User C', 'email': 'userc@localhost', 'id': 4}}, {'user': {'username': 'userb', 'nickname': 'User B', 'email': 'userb@localhost', 'id': 3}}], 'total': 4}
511
+
512
+ >>> #query array with @order +
513
+ >>> data ='''{
514
+ ... "[]":{
515
+ ... "@count":2,
516
+ ... "@page":0,
517
+ ... "@query":2,
518
+ ... "user":{
519
+ ... "@column":"id,username,nickname,email",
520
+ ... "@order":"id+",
521
+ ... "@role":"ADMIN"
522
+ ... }
523
+ ... },
524
+ ... "total@":"/[]/total"
525
+ ... }'''
526
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
527
+ >>> d = json_loads(r.data)
528
+ >>> print(d)
529
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'admin', 'nickname': 'Administrator', 'email': 'admin@localhost', 'id': 1}}, {'user': {'username': 'usera', 'nickname': 'User A', 'email': 'usera@localhost', 'id': 2}}], 'total': 4}
530
+
531
+ >>> #query array with @order having a non existing column
532
+ >>> data ='''{
533
+ ... "[]":{
534
+ ... "@count":2,
535
+ ... "@page":0,
536
+ ... "@query":2,
537
+ ... "user":{
538
+ ... "@column":"id,username,nickname,email",
539
+ ... "@order":"nonexist+",
540
+ ... "@role":"ADMIN"
541
+ ... }
542
+ ... },
543
+ ... "total@":"/[]/total"
544
+ ... }'''
545
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
546
+ >>> d = json_loads(r.data)
547
+ >>> print(d)
548
+ {'code': 400, 'msg': "'user' doesn't have column 'nonexist'"}
549
+
550
+ >>> #query array with @expr
551
+ >>> data ='''{
552
+ ... "[]":{
553
+ ... "@count":4,
554
+ ... "@page":0,
555
+ ... "user":{
556
+ ... "@column":"id,username,nickname,email",
557
+ ... "@order":"id-",
558
+ ... "@role":"ADMIN",
559
+ ... "@expr":["username$","|","nickname$"],
560
+ ... "username$":"%b%",
561
+ ... "nickname$":"%c%"
562
+ ... }
563
+ ... }
564
+ ... }'''
565
+ >>> r = handler.post('/apijson/get', data=data, pre_call=pre_call_as("admin"), middlewares=[])
566
+ >>> d = json_loads(r.data)
567
+ >>> print(d)
568
+ {'code': 200, 'msg': 'success', '[]': [{'user': {'username': 'userc', 'nickname': 'User C', 'email': 'userc@localhost', 'id': 4}}, {'user': {'username': 'userb', 'nickname': 'User B', 'email': 'userb@localhost', 'id': 3}}]}
569
+
456
570
>>> #Association query: Two tables, one to one,ref path is absolute path
457
571
>>> data ='''{
458
572
... "moment":{},
0 commit comments