Mercurial > p > roundup > code
comparison test/rest_common.py @ 7854:171ff2e487df
Add @group for grouping in rest interface.
Helpful for using optgroup in select boxes.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Mon, 01 Apr 2024 14:42:36 -0400 |
| parents | 03c1b7ae3a68 |
| children | 8e310a7b5e09 |
comparison
equal
deleted
inserted
replaced
| 7853:03c1b7ae3a68 | 7854:171ff2e487df |
|---|---|
| 314 try: | 314 try: |
| 315 self.db.priority.create(name='critical') | 315 self.db.priority.create(name='critical') |
| 316 except ValueError: | 316 except ValueError: |
| 317 pass | 317 pass |
| 318 | 318 |
| 319 def create_sampledata(self): | 319 def create_sampledata(self, data_max=3): |
| 320 """ Create sample data common to some test cases | 320 """ Create sample data common to some test cases |
| 321 """ | 321 """ |
| 322 self.create_stati() | 322 self.create_stati() |
| 323 self.db.issue.create( | 323 self.db.issue.create( |
| 324 title='foo1', | 324 title='foo1', |
| 335 issue_open_crit = self.db.issue.create( | 335 issue_open_crit = self.db.issue.create( |
| 336 title='foo5', | 336 title='foo5', |
| 337 status=self.db.status.lookup('open'), | 337 status=self.db.status.lookup('open'), |
| 338 priority=self.db.priority.lookup('critical') | 338 priority=self.db.priority.lookup('critical') |
| 339 ) | 339 ) |
| 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 | |
| 340 | 368 |
| 341 def test_no_next_link_on_full_last_page(self): | 369 def test_no_next_link_on_full_last_page(self): |
| 342 """Make sure that there is no next link | 370 """Make sure that there is no next link |
| 343 on the last page where the total number of entries | 371 on the last page where the total number of entries |
| 344 is a multiple of the page size. | 372 is a multiple of the page size. |
| 969 {'link': base_path + '1', 'status': '7', 'id': '1'}]}} | 997 {'link': base_path + '1', 'status': '7', 'id': '1'}]}} |
| 970 | 998 |
| 971 results = self.server.get_collection('issue', form) | 999 results = self.server.get_collection('issue', form) |
| 972 self.assertDictEqual(expected, results) | 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 def testTransitiveField(self): | 1043 def testTransitiveField(self): |
| 975 """ Test a transitive property in @fields """ | 1044 """ Test a transitive property in @fields """ |
| 976 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' | 1045 base_path = self.db.config['TRACKER_WEB'] + 'rest/data/' |
| 977 # create sample data | 1046 # create sample data |
| 978 self.create_stati() | 1047 self.create_stati() |
