@@ -118,6 +118,46 @@ def get_header (self, header, not_found=None):
118118 except (AttributeError , KeyError , TypeError ):
119119 return not_found
120120
121+ def create_stati (self ):
122+ try :
123+ self .db .status .create (name = 'open' , order = '9' )
124+ except ValueError :
125+ pass
126+ try :
127+ self .db .status .create (name = 'closed' , order = '91' )
128+ except ValueError :
129+ pass
130+ try :
131+ self .db .priority .create (name = 'normal' )
132+ except ValueError :
133+ pass
134+ try :
135+ self .db .priority .create (name = 'critical' )
136+ except ValueError :
137+ pass
138+
139+ def create_sampledata (self ):
140+ """ Create sample data common to some test cases
141+ """
142+ self .create_stati ()
143+ self .db .issue .create (
144+ title = 'foo1' ,
145+ status = self .db .status .lookup ('open' ),
146+ priority = self .db .priority .lookup ('normal' ),
147+ nosy = [ "1" , "2" ]
148+ )
149+ issue_open_norm = self .db .issue .create (
150+ title = 'foo2' ,
151+ status = self .db .status .lookup ('open' ),
152+ priority = self .db .priority .lookup ('normal' ),
153+ assignedto = "3"
154+ )
155+ issue_open_crit = self .db .issue .create (
156+ title = 'foo5' ,
157+ status = self .db .status .lookup ('open' ),
158+ priority = self .db .priority .lookup ('critical' )
159+ )
160+
121161 def testGet (self ):
122162 """
123163 Retrieve all three users
@@ -167,40 +207,7 @@ def testOutputFormat(self):
167207 """ test of @fields and @verbose implementation """
168208
169209 self .maxDiff = 4000
170- # create sample data
171- try :
172- self .db .status .create (name = 'open' )
173- except ValueError :
174- pass
175- try :
176- self .db .status .create (name = 'closed' )
177- except ValueError :
178- pass
179- try :
180- self .db .priority .create (name = 'normal' )
181- except ValueError :
182- pass
183- try :
184- self .db .priority .create (name = 'critical' )
185- except ValueError :
186- pass
187- self .db .issue .create (
188- title = 'foo1' ,
189- status = self .db .status .lookup ('open' ),
190- priority = self .db .priority .lookup ('normal' ),
191- nosy = [ "1" , "2" ]
192- )
193- issue_open_norm = self .db .issue .create (
194- title = 'foo2' ,
195- status = self .db .status .lookup ('open' ),
196- priority = self .db .priority .lookup ('normal' ),
197- assignedto = "3"
198- )
199- issue_open_crit = self .db .issue .create (
200- title = 'foo5' ,
201- status = self .db .status .lookup ('open' ),
202- priority = self .db .priority .lookup ('critical' )
203- )
210+ self .create_sampledata ()
204211 base_path = self .db .config ['TRACKER_WEB' ] + 'rest/data/issue/'
205212
206213
@@ -425,28 +432,41 @@ def testOutputFormat(self):
425432 results ['data' ]['@etag' ] = '' # etag depends on date, set to empty
426433 self .assertDictEqual (expected ,results )
427434
435+ def testSorting (self ):
436+ self .maxDiff = 4000
437+ self .create_sampledata ()
438+ self .db .issue .set ('1' , status = '7' )
439+ self .db .issue .set ('2' , status = '2' )
440+ self .db .issue .set ('3' , status = '2' )
441+ self .db .commit ()
442+ base_path = self .db .config ['TRACKER_WEB' ] + 'rest/data/issue/'
443+ # change some data for sorting on later
444+ form = cgi .FieldStorage ()
445+ form .list = [
446+ cgi .MiniFieldStorage ('@fields' , 'status' ),
447+ cgi .MiniFieldStorage ('@sort' , 'status,-id' ),
448+ cgi .MiniFieldStorage ('@verbose' , '0' )
449+ ]
450+
451+ # status is sorted by orderprop (property 'order')
452+ # which provides the same ordering as the status ID
453+ expected = {'data' : {
454+ '@total_size' : 3 ,
455+ 'collection' : [
456+ {'link' : base_path + '3' , 'status' : '2' , 'id' : '3' },
457+ {'link' : base_path + '2' , 'status' : '2' , 'id' : '2' },
458+ {'link' : base_path + '1' , 'status' : '7' , 'id' : '1' }]}}
459+
460+ results = self .server .get_collection ('issue' , form )
461+ self .assertDictEqual (expected , results )
462+
428463 def testFilter (self ):
429464 """
430465 Retrieve all three users
431466 obtain data for 'joe'
432467 """
433468 # create sample data
434- try :
435- self .db .status .create (name = 'open' )
436- except ValueError :
437- pass
438- try :
439- self .db .status .create (name = 'closed' )
440- except ValueError :
441- pass
442- try :
443- self .db .priority .create (name = 'normal' )
444- except ValueError :
445- pass
446- try :
447- self .db .priority .create (name = 'critical' )
448- except ValueError :
449- pass
469+ self .create_stati ()
450470 self .db .issue .create (
451471 title = 'foo4' ,
452472 status = self .db .status .lookup ('closed' ),
0 commit comments