@@ -316,7 +316,7 @@ def create_stati(self):
316316 except ValueError :
317317 pass
318318
319- def create_sampledata (self ):
319+ def create_sampledata (self , data_max = 3 ):
320320 """ Create sample data common to some test cases
321321 """
322322 self .create_stati ()
@@ -338,6 +338,34 @@ def create_sampledata(self):
338338 priority = self .db .priority .lookup ('critical' )
339339 )
340340
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+
341369 def test_no_next_link_on_full_last_page (self ):
342370 """Make sure that there is no next link
343371 on the last page where the total number of entries
@@ -971,6 +999,47 @@ def testSorting(self):
971999 results = self .server .get_collection ('issue' , form )
9721000 self .assertDictEqual (expected , results )
9731001
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+
9741043 def testTransitiveField (self ):
9751044 """ Test a transitive property in @fields """
9761045 base_path = self .db .config ['TRACKER_WEB' ] + 'rest/data/'
0 commit comments