Commits

Azoff committed 491b564

Added a few testcases containing both group and order parameters and their
default values.
Somehow, the type of QueryModule.default_group was changed to 'Option' in last
commit, reverted back to 'ListOption'.

Comments (0)

Files changed (1)

 # HG changeset patch
-# Parent 80f408330393ca0b84d685e4a6ed7ee0dc1228fa
+# Parent 835aa541145bca6334f55c0b74822381760d337b
 
 diff --git a/trac/ticket/query.py b/trac/ticket/query.py
 --- a/trac/ticket/query.py
                  groups.setdefault(group_key, []).append(ticket)
                  if not groupsequence or group_key not in groupsequence:
                      groupsequence.append(group_key)
-@@ -866,11 +903,14 @@ class QueryModule(Component):
+@@ -864,13 +901,16 @@ class QueryModule(Component):
+             Default is to let Trac calculate this internally.
+             (''since 0.13'')""")
  
-     default_order = Option('query', 'default_order',
+-    default_order = Option('query', 'default_order',
++    default_order = ListOption('query', 'default_order',
          default='priority',
 -        doc="""The default order to use for queries. (''since 0.13'')""")
 +        doc="""The default order to use for queries. Use `-field` for
  
      def test_default_cols_with_config_no_request(self):
          self.env.config.set('query', 'default_columns', 'id,time,changetime,summary,milestone,type')
-@@ -741,6 +747,53 @@ ORDER BY COALESCE(priority.value,'')='',
+@@ -741,6 +747,160 @@ ORDER BY COALESCE(priority.value,'')='',
          self.assertEqual([], args)
          tickets = query.execute(self.req)
  
 +        self.assertEqual(True, query.group)
 +        self.assertEqual(('milestone', True), query.get_group())
 +
++    def test_group_and_order_1(self):
++        query = Query(self.env)
++        self.assertEqual(False, query.group)
++        self.assertEqual((None, None), query.get_group())
++        self.assertEqual(['priority'], query.order)
++        self.assertEqual([('priority', False)], query.get_order())
++
++    def test_group_and_order_2(self):
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env)
++        self.assertEqual(False, query.group)
++        self.assertEqual((None, None), query.get_group())
++        self.assertEqual(['-time', 'priority'], query.order)
++        self.assertEqual([('time', True), ('priority', False)], query.get_order())
++
++    def test_group_and_order_3(self):
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, group='component')
++        self.assertEqual(True, query.group)
++        self.assertEqual(('component', False), query.get_group())
++        self.assertEqual(['component', '-time', 'priority'], query.order)
++        self.assertEqual([('component', False), ('time', True), ('priority', False)], query.get_order())
++
++    def test_group_and_order_4(self):
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, order=['owner', 'id'])
++        self.assertEqual(False, query.group)
++        self.assertEqual((None, None), query.get_group())
++        self.assertEqual(['owner', 'id'], query.order)
++        self.assertEqual([('owner', False), ('id', False)], query.get_order())
++
++    def test_group_and_order_5(self):
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, group='milestone', order=['owner', 'id'])
++        self.assertEqual(True, query.group)
++        self.assertEqual(('milestone', False), query.get_group())
++        self.assertEqual(['milestone', 'owner', 'id'], query.order)
++        self.assertEqual([('milestone', False), ('owner', False), ('id', False)], query.get_order())
++
++    def test_group_and_order_6(self):
++        self.env.config.set('query', 'default_group', 'component')
++        query = Query(self.env)
++        self.assertEqual(True, query.group)
++        self.assertEqual(('component', False), query.get_group())
++        self.assertEqual(['component', 'priority'], query.order)
++        self.assertEqual([('component', False), ('priority', False)], query.get_order())
++
++    def test_group_and_order_7(self):
++        self.env.config.set('query', 'default_group', 'component')
++        query = Query(self.env, group='milestone')
++        self.assertEqual(True, query.group)
++        self.assertEqual(('milestone', False), query.get_group())
++        self.assertEqual(['milestone', 'priority'], query.order)
++        self.assertEqual([('milestone', False), ('priority', False)], query.get_order())
++
++    def test_group_and_order_8(self):
++        self.env.config.set('query', 'default_group', 'component')
++        query = Query(self.env, order=['owner', 'id'])
++        self.assertEqual(True, query.group)
++        self.assertEqual(('component', False), query.get_group())
++        self.assertEqual(['component', 'owner', 'id'], query.order)
++        self.assertEqual([('component', False), ('owner', False), ('id', False)], query.get_order())
++
++    def test_group_and_order_9(self):
++        self.env.config.set('query', 'default_group', 'component')
++        query = Query(self.env, group='milestone', order=['owner', 'id'])
++        self.assertEqual(True, query.group)
++        self.assertEqual(('milestone', False), query.get_group())
++        self.assertEqual(['milestone', 'owner', 'id'], query.order)
++        self.assertEqual([('milestone', False), ('owner', False), ('id', False)], query.get_order())
++
++    def test_group_and_order_10(self):
++        self.env.config.set('query', 'default_group', 'component')
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env)
++        self.assertEqual(True, query.group)
++        self.assertEqual(('component', False), query.get_group())
++        self.assertEqual(['component', '-time', 'priority'], query.order)
++        self.assertEqual([('component', False), ('time', True), ('priority', False)], query.get_order())
++
++    def test_group_and_order_11(self):
++        self.env.config.set('query', 'default_group', 'component')
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, group='milestone')
++        self.assertEqual(True, query.group)
++        self.assertEqual(('milestone', False), query.get_group())
++        self.assertEqual(['milestone', '-time', 'priority'], query.order)
++        self.assertEqual([('milestone', False), ('time', True), ('priority', False)], query.get_order())
++
++    def test_group_and_order_12(self):
++        self.env.config.set('query', 'default_group', 'component')
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, order=['owner', 'id'])
++        self.assertEqual(True, query.group)
++        self.assertEqual(('component', False), query.get_group())
++        self.assertEqual(['component', 'owner', 'id'], query.order)
++        self.assertEqual([('component', False), ('owner', False), ('id', False)], query.get_order())
++
++    def test_group_and_order_13(self):
++        self.env.config.set('query', 'default_group', 'component')
++        self.env.config.set('query', 'default_order', '-time,priority')
++        query = Query(self.env, group='milestone', order=['owner', 'id'])
++        self.assertEqual(True, query.group)
++        self.assertEqual(('milestone', False), query.get_group())
++        self.assertEqual(['milestone', 'owner', 'id'], query.order)
++        self.assertEqual([('milestone', False), ('owner', False), ('id', False)], query.get_order())
++
 +    def test_get_href_1(self):
 +        query = Query(self.env, group='milestone', order='type')
 +        self.assertEqual('foo/query?group=milestone&order=type', query.get_href(Href('foo')))