Source

trac-1942 / ct-tests.patch

# HG changeset patch
# Parent 5ffda3c2392c73b914c902e4ea0303ee5d462a19
Add some tests for custom time fields implementation.

diff --git a/trac/ticket/tests/api.py b/trac/ticket/tests/api.py
--- a/trac/ticket/tests/api.py
+++ b/trac/ticket/tests/api.py
@@ -70,6 +70,16 @@
                           'order': 0, 'format': 'wiki', 'custom': True},
                          fields[0])
 
+    def test_custom_field_time(self):
+        self.env.config.set('ticket-custom', 'test', 'time')
+        self.env.config.set('ticket-custom', 'test.label', 'Test')
+        self.env.config.set('ticket-custom', 'test.value', '')
+        fields = TicketSystem(self.env).get_custom_fields()
+        self.assertEqual({'name': 'test', 'type': 'time', 'label': 'Test',
+                          'value': '', 'order': 0, 'format': 'datetime',
+                          'custom': True},
+                         fields[0])
+
     def test_custom_field_order(self):
         self.env.config.set('ticket-custom', 'test1', 'text')
         self.env.config.set('ticket-custom', 'test1.order', '2')
diff --git a/trac/ticket/tests/model.py b/trac/ticket/tests/model.py
--- a/trac/ticket/tests/model.py
+++ b/trac/ticket/tests/model.py
@@ -298,6 +298,26 @@
         self.assertEqual('on', ticket['cbon'])
         self.assertEqual('0', ticket['cboff'])
 
+    def test_custom_time(self):
+        # Add a custom field of type 'time'
+        self.env.config.set('ticket-custom', 'due', 'time')
+        ticket = Ticket(self.env)
+        self.assertFalse('due' in ticket.std_fields)
+        self.assertTrue('due' in ticket.time_fields)
+        ticket['reporter'] = 'john'
+        ticket['summary'] = 'Task1'
+        tktid = ticket.insert()
+        ticket = Ticket(self.env, tktid)
+        # Empty string is default value, but not a time stamp
+        self.assertEqual(None, ticket['due'])
+        ts = datetime(2011, 11, 11, 0, 0, 0, 0, utc)
+        ticket['due'] = ts
+        ticket.save_changes('joe')
+        self.assertEqual(ts, ticket['due'])
+        ticket['due'] = ''
+        ticket.save_changes('joe')
+        self.assertEqual('', ticket['due'])
+
     def test_changelog(self):
         tkt_id = self._insert_ticket('Test', reporter='joe', component='foo',
                                      milestone='bar')