@@ -316,7 +316,7 @@ def create_stati(self):
316
316
except ValueError :
317
317
pass
318
318
319
- def create_sampledata (self ):
319
+ def create_sampledata (self , data_max = 3 ):
320
320
""" Create sample data common to some test cases
321
321
"""
322
322
self .create_stati ()
@@ -338,6 +338,34 @@ def create_sampledata(self):
338
338
priority = self .db .priority .lookup ('critical' )
339
339
)
340
340
341
+ if data_max > 10 :
342
+ raise ValueError ('data_max must be less than 10' )
343
+
344
+ if data_max == 3 :
345
+ return
346
+
347
+ sample_data = [
348
+ ["foo6" , "normal" , "closed" ],
349
+ ["foo7" , "critical" , "open" ],
350
+ ["foo8" , "normal" , "open" ],
351
+ ["foo9" , "critical" , "open" ],
352
+ ["foo10" , "normal" , "closed" ],
353
+ ["foo11" , "critical" , "open" ],
354
+ ["foo12" , "normal" , "closed" ],
355
+ ["foo13" , "normal" , "open" ],
356
+
357
+ ]
358
+
359
+ for title , priority , status in sample_data :
360
+ new_issue = self .db .issue .create (
361
+ title = title ,
362
+ status = self .db .status .lookup (status ),
363
+ priority = self .db .priority .lookup (priority )
364
+ )
365
+
366
+ if int (new_issue ) == data_max :
367
+ break
368
+
341
369
def test_no_next_link_on_full_last_page (self ):
342
370
"""Make sure that there is no next link
343
371
on the last page where the total number of entries
@@ -971,6 +999,47 @@ def testSorting(self):
971
999
results = self .server .get_collection ('issue' , form )
972
1000
self .assertDictEqual (expected , results )
973
1001
1002
+ def testGrouping (self ):
1003
+ self .maxDiff = 4000
1004
+ self .create_sampledata (data_max = 5 )
1005
+ self .db .issue .set ('1' , status = '7' , priority = '4' )
1006
+ self .db .issue .set ('2' , status = '2' , priority = '4' )
1007
+ self .db .issue .set ('3' , status = '2' , priority = '4' )
1008
+ self .db .issue .set ('4' , status = '2' , priority = '2' )
1009
+ self .db .issue .set ('5' , status = '2' , priority = '2' )
1010
+ self .db .commit ()
1011
+ base_path = self .db .config ['TRACKER_WEB' ] + 'rest/data/issue/'
1012
+ # change some data for sorting on later
1013
+ form = cgi .FieldStorage ()
1014
+ form .list = [
1015
+ cgi .MiniFieldStorage ('@fields' , 'status,priority' ),
1016
+ cgi .MiniFieldStorage ('@sort' , '-id' ),
1017
+ cgi .MiniFieldStorage ('@group' , '-status,priority' ),
1018
+ cgi .MiniFieldStorage ('@verbose' , '0' )
1019
+ ]
1020
+
1021
+ # status is sorted by orderprop (property 'order')
1022
+ expected = {'data' : {
1023
+ '@total_size' : 5 ,
1024
+ 'collection' : [
1025
+ {'link' : base_path + '1' , 'priority' : '4' ,
1026
+ 'status' : '7' , 'id' : '1' },
1027
+ {'link' : base_path + '5' , 'priority' : '2' ,
1028
+ 'status' : '2' , 'id' : '5' },
1029
+ {'link' : base_path + '4' , 'priority' : '2' ,
1030
+ 'status' : '2' , 'id' : '4' },
1031
+ {'link' : base_path + '3' , 'priority' : '4' ,
1032
+ 'status' : '2' , 'id' : '3' },
1033
+ {'link' : base_path + '2' , 'priority' : '4' ,
1034
+ 'status' : '2' , 'id' : '2' },
1035
+ ]
1036
+ }}
1037
+
1038
+
1039
+ results = self .server .get_collection ('issue' , form )
1040
+ print (results )
1041
+ self .assertDictEqual (expected , results )
1042
+
974
1043
def testTransitiveField (self ):
975
1044
""" Test a transitive property in @fields """
976
1045
base_path = self .db .config ['TRACKER_WEB' ] + 'rest/data/'
0 commit comments