Commits

Anonymous committed 3220b17

Add an `order` subcommand to the `priority`, `severity` and `ticket_type` commands in [wiki:TracAdmin trac-admin]. Closes #1909.

Comments (0)

Files changed (3)

trac/scripts/admin.py

                          ('ticket_type add <value>', 'Add a ticket type'),
                          ('ticket_type change <value> <newvalue>',
                           'Change a ticket type'),
-                         ('ticket_type remove <value>', 'Remove a ticket type')]
- 
+                         ('ticket_type remove <value>', 'Remove a ticket type'),
+                         ('ticket_type order <value> up|down',
+                          'Move a ticket type up or down in the list')]
+
     def complete_ticket_type (self, text, line, begidx, endidx):
         if begidx == 16:
             comp = self.get_enum_list ('ticket_type')
         elif begidx < 15:
-            comp = ['list', 'add', 'change', 'remove']
+            comp = ['list', 'add', 'change', 'remove', 'order']
         return self.word_complete(text, comp)
  
     def do_ticket_type(self, line):
                        ('priority add <value>', 'Add a priority value option'),
                        ('priority change <value> <newvalue>',
                         'Change a priority value'),
-                       ('priority remove <value>', 'Remove priority value')]
+                       ('priority remove <value>', 'Remove priority value'),
+                       ('priority order <value> up|down',
+                        'Move a priority value up or down in the list')]
 
     def complete_priority (self, text, line, begidx, endidx):
         if begidx == 16:
             comp = self.get_enum_list ('priority')
         elif begidx < 15:
-            comp = ['list', 'add', 'change', 'remove']
+            comp = ['list', 'add', 'change', 'remove', 'order']
         return self.word_complete(text, comp)
 
     def do_priority(self, line):
                       ('severity add <value>', 'Add a severity value option'),
                       ('severity change <value> <newvalue>',
                        'Change a severity value'),
-                      ('severity remove <value>', 'Remove severity value')]
+                      ('severity remove <value>', 'Remove severity value'),
+                      ('severity order <value> up|down',
+                       'Move a severity value up or down in the list')]
 
     def complete_severity (self, text, line, begidx, endidx):
         if begidx == 16:
             comp = self.get_enum_list ('severity')
         elif begidx < 15:
-            comp = ['list', 'add', 'change', 'remove']
+            comp = ['list', 'add', 'change', 'remove', 'order']
         return self.word_complete(text, comp)
 
     def do_severity(self, line):
         arg = self.arg_tokenize(line)
         if arg[0]  == 'list':
             self._do_enum_list(type)
-        elif arg[0] == 'add' and len(arg)==2:
+        elif arg[0] == 'add' and len(arg) == 2:
             name = arg[1]
             self._do_enum_add(type, name)
-        elif arg[0] == 'change'  and len(arg)==3:
+        elif arg[0] == 'change' and len(arg) == 3:
             name = arg[1]
             newname = arg[2]
             self._do_enum_change(type, name, newname)
-        elif arg[0] == 'remove'  and len(arg)==2:
+        elif arg[0] == 'remove' and len(arg) == 2:
             name = arg[1]
             self._do_enum_remove(type, name)
+        elif arg[0] == 'order' and len(arg) == 3 and arg[2] in ('up', 'down'):
+            name = arg[1]
+            if arg[2] == 'up':
+                direction = -1
+            else:
+                direction = 1
+            self._do_enum_order(type, name, direction)
         else:    
-            self.do_help (type)
+            self.do_help(type)
 
     def _do_enum_list(self, type):
         enum_cls = self._enum_map[type]
         enum = enum_cls(self.env_open(), name)
         enum.delete()
 
+    def _do_enum_order(self, type, name, direction):
+        env = self.env_open()
+        enum_cls = self._enum_map[type]
+        enum1 = enum_cls(env, name)
+        enum1.value = int(enum1.value) + direction
+        for enum2 in enum_cls.select(env):
+            if int(enum2.value) == int(enum1.value):
+                enum2.value = int(enum2.value) - direction
+                break
+        else:
+            return
+        enum1.update()
+        enum2.update()
 
     ## Milestone
+
     _help_milestone = [('milestone list', 'Show milestones'),
                        ('milestone add <name> [due]', 'Add milestone'),
                        ('milestone rename <name> <newname>',

trac/scripts/tests/admin-tests.txt

 ticket_type add <value>                                -- Add a ticket type
 ticket_type change <value> <newvalue>                  -- Change a ticket type
 ticket_type remove <value>                             -- Remove a ticket type
+ticket_type order <value> up|down                      -- Move a ticket type up or down in the list
 priority list                                          -- Show possible ticket priorities
 priority add <value>                                   -- Add a priority value option
 priority change <value> <newvalue>                     -- Change a priority value
 priority remove <value>                                -- Remove priority value
+priority order <value> up|down                         -- Move a priority value up or down in the list
 severity list                                          -- Show possible ticket severities
 severity add <value>                                   -- Add a severity value option
 severity change <value> <newvalue>                     -- Change a severity value
 severity remove <value>                                -- Remove severity value
+severity order <value> up|down                         -- Move a severity value up or down in the list
 version list                                           -- Show versions
 version add <name> [time]                              -- Add version
 version rename <name> <newname>                        -- Rename version
 
 ===== test_ticket_type_remove_error_bad_type =====
 Command failed: ticket_type bad_type does not exist.
+===== test_ticket_type_order_down_ok =====
+
+Possible Values
+---------------
+enhancement
+defect
+task
+
+===== test_ticket_type_order_up_ok =====
+
+Possible Values
+---------------
+enhancement
+defect
+task
+
+===== test_ticket_type_order_error_bad_type =====
+Command failed: ticket_type bad_type does not exist.
 ===== test_priority_list_ok =====
 
 Possible Values
 
 ===== test_priority_remove_error_bad_priority =====
 Command failed: priority bad_priority does not exist.
+===== test_priority_order_down_ok =====
+
+Possible Values
+---------------
+critical
+blocker
+major
+minor
+trivial
+
+===== test_priority_order_up_ok =====
+
+Possible Values
+---------------
+critical
+blocker
+major
+minor
+trivial
+
+===== test_priority_order_error_bad_priority =====
+Command failed: priority bad_priority does not exist.
 ===== test_severity_list_ok =====
 
 Possible Values
 
 ===== test_severity_remove_error_bad_severity =====
 Command failed: severity bad_severity does not exist.
+===== test_severity_order_down_ok =====
+
+Possible Values
+---------------
+bar
+foo
+
+===== test_severity_order_up_ok =====
+
+Possible Values
+---------------
+bar
+foo
+
+===== test_severity_order_error_bad_severity =====
+Command failed: severity bad_severity does not exist.
 ===== test_version_list_ok =====
 
 Name  Time

trac/scripts/tests/admin.py

         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
+    def test_ticket_type_order_down_ok(self):
+        """
+        Tests the 'ticket_type order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('ticket_type order defect down')
+        rv, output = self._execute('ticket_type list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_ticket_type_order_up_ok(self):
+        """
+        Tests the 'ticket_type order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('ticket_type order enhancement up')
+        rv, output = self._execute('ticket_type list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_ticket_type_order_error_bad_type(self):
+        """
+        Tests the 'priority order' command in trac-admin.  This particular
+        test tries to reorder a priority that does not exist.
+        """
+        test_name = sys._getframe().f_code.co_name
+        rv, output = self._execute('ticket_type order bad_type up')
+        self.assertEqual(2, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
     # Priority tests
 
     def test_priority_list_ok(self):
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
+    def test_priority_order_down_ok(self):
+        """
+        Tests the 'priority order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('priority order blocker down')
+        rv, output = self._execute('priority list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_priority_order_up_ok(self):
+        """
+        Tests the 'priority order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('priority order critical up')
+        rv, output = self._execute('priority list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_priority_order_error_bad_priority(self):
+        """
+        Tests the 'priority order' command in trac-admin.  This particular
+        test tries to reorder a priority that does not exist.
+        """
+        test_name = sys._getframe().f_code.co_name
+        rv, output = self._execute('priority remove bad_priority')
+        self.assertEqual(2, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
     # Severity tests
 
     def test_severity_list_ok(self):
         self.assertEqual(2, rv)
         self.assertEqual(self.expected_results[test_name], output)
 
+    def test_severity_order_down_ok(self):
+        """
+        Tests the 'severity order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('severity add foo')
+        self._execute('severity add bar')
+        self._execute('severity order foo down')
+        rv, output = self._execute('severity list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_severity_order_up_ok(self):
+        """
+        Tests the 'severity order' command in trac-admin.  This particular
+        test passes a valid argument and checks for success.
+        """
+        test_name = sys._getframe().f_code.co_name
+        self._execute('severity add foo')
+        self._execute('severity add bar')
+        self._execute('severity order bar up')
+        rv, output = self._execute('severity list')
+        self.assertEqual(0, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
+    def test_severity_order_error_bad_severity(self):
+        """
+        Tests the 'severity order' command in trac-admin.  This particular
+        test tries to reorder a priority that does not exist.
+        """
+        test_name = sys._getframe().f_code.co_name
+        rv, output = self._execute('severity remove bad_severity')
+        self.assertEqual(2, rv)
+        self.assertEqual(self.expected_results[test_name], output)
+
     # Version tests
 
     def test_version_list_ok(self):