Commits

Anonymous committed 62ffe71

Support micro-seconds as added by Trac in revision 9210 for upcoming 0.12. Fixes the two instances where we query the database, fixes an unspotted conversion bug, and adds getRecentChanges tests for both wiki and ticket that pass for both Trac 0.11 and 0.12.

  • Participants
  • Parent commits 409eb5e

Comments (0)

Files changed (1)

t5437/t5437-protocol_api-r7194.diff

 diff --git a/trunk/tracrpc/tests/ticket.py b/trunk/tracrpc/tests/ticket.py
 --- a/trunk/tracrpc/tests/ticket.py
 +++ b/trunk/tracrpc/tests/ticket.py
-@@ -32,7 +32,11 @@
+@@ -10,6 +10,7 @@
+ import xmlrpclib
+ import os
+ import shutil
++import time
+ 
+ from tracrpc.tests import rpc_testenv
+ 
+@@ -32,7 +33,11 @@
                    [['action_reassign_reassign_owner', 'admin', []]]],
                    ['accept', 'accept',
                    "The owner will change from (none) to admin. Next status will be 'accepted'.", []]]
          self.admin.ticket.delete(tid)
  
      def test_getAvailableActions_DeleteTicket(self):
-@@ -41,9 +45,11 @@
+@@ -41,9 +46,11 @@
          self.assertEquals(False,
                  'delete' in self.admin.ticket.getAvailableActions(tid))
          env = rpc_testenv.get_trac_environment()
          env.config.set('ticket', 'workflow',
                  'ConfigurableTicketWorkflow,DeleteTicketActionController')
          env.config.save()
-@@ -57,6 +63,9 @@
+@@ -57,6 +64,9 @@
          rpc_testenv.restart()
          self.assertEquals(False,
                  'delete' in self.admin.ticket.getAvailableActions(tid))
  
      def test_FineGrainedSecurity(self):
          self.assertEquals(1, self.admin.ticket.create('abc', '123', {}))
+@@ -101,7 +111,19 @@
+         self.assertEquals(0, self.admin.ticket.delete(1))
+         self.assertEquals(0, self.admin.ticket.delete(2))
+         self.assertEquals(0, self.admin.ticket.delete(3))
+-        
++
++    def test_getRecentChanges(self):
++        tid1 = self.admin.ticket.create("ticket_getRecentChanges", "one", {})
++        time.sleep(1)
++        tid2 = self.admin.ticket.create("ticket_getRecentChanges", "two", {})
++        _id, created, modified, attributes = self.admin.ticket.get(tid2)
++        changes = self.admin.ticket.getRecentChanges(created)
++        try:
++            self.assertEquals(changes, [tid2])
++        finally:
++            self.admin.ticket.delete(tid1)
++            self.admin.ticket.delete(tid2)
++
+ def suite():
+     return unittest.makeSuite(RpcTicketTestCase)
+ 
 diff --git a/trunk/tracrpc/tests/wiki.py b/trunk/tracrpc/tests/wiki.py
 --- a/trunk/tracrpc/tests/wiki.py
 +++ b/trunk/tracrpc/tests/wiki.py
-@@ -9,11 +9,11 @@
+@@ -9,11 +9,12 @@
  
  import xmlrpclib
  import os
 -from StringIO import StringIO
++import time
  
  from trac.util.compat import sorted
  
  
  class RpcWikiTestCase(unittest.TestCase):
      
+@@ -46,6 +47,19 @@
+         # List attachments again
+         self.assertEquals([], self.admin.wiki.listAttachments('TitleIndex'))
+ 
++    def test_getRecentChanges(self):
++        self.admin.wiki.putPage('WikiOne', 'content one', {})
++        time.sleep(1)
++        self.admin.wiki.putPage('WikiTwo', 'content two', {})
++        attrs2 = self.admin.wiki.getPageInfo('WikiTwo')
++        changes = self.admin.wiki.getRecentChanges(attrs2['lastModified'])
++        self.assertEquals(1, len(changes))
++        self.assertEquals('WikiTwo', changes[0]['name'])
++        self.assertEquals('admin', changes[0]['author'])
++        self.assertEquals(1, changes[0]['version'])
++        self.admin.wiki.deletePage('WikiOne')
++        self.admin.wiki.deletePage('WikiTwo')
++
+ def suite():
+     return unittest.makeSuite(RpcWikiTestCase)
+ 
 diff --git a/trunk/tracrpc/tests/xml.py b/trunk/tracrpc/tests/xml_rpc.py
 rename from trunk/tracrpc/tests/xml.py
 rename to trunk/tracrpc/tests/xml_rpc.py
 diff --git a/trunk/tracrpc/ticket.py b/trunk/tracrpc/ticket.py
 --- a/trunk/tracrpc/ticket.py
 +++ b/trunk/tracrpc/ticket.py
-@@ -6,10 +6,15 @@
+@@ -6,25 +6,27 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
  import trac.ticket.model as model
  import trac.ticket.query as query
  from trac.ticket.api import TicketSystem
-@@ -18,13 +23,10 @@
+ from trac.ticket.notification import TicketNotifyEmail
+ from trac.ticket.web_ui import TicketModule
  from trac.web.chrome import add_warning
- from trac.util.datefmt import to_datetime, to_timestamp, utc
+-from trac.util.datefmt import to_datetime, to_timestamp, utc
++from trac.util.datefmt import to_datetime, utc
  
 -import genshi
 +from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
-+from tracrpc.util import StringIO
++from tracrpc.util import StringIO, to_utimestamp
  
 -import inspect
 -import xmlrpclib
                 self.putAttachment)
          yield (None, ((bool, int, str),), self.deleteAttachment)
          yield ('TICKET_VIEW', ((list,),), self.getTicketFields)
+@@ -68,7 +70,7 @@
+ 
+     def getRecentChanges(self, req, since):
+         """Returns a list of IDs of tickets that have changed since timestamp."""
+-        since = to_timestamp(since)
++        since = to_utimestamp(since)
+         db = self.env.get_db_cnx()
+         cursor = db.cursor()
+         cursor.execute('SELECT id FROM ticket'
 @@ -243,13 +245,13 @@
          """ returns the content of an attachment. """
          attachment = Attachment(self.env, 'ticket', ticket, filename)
  
  try:
      # Method only available in Trac 0.11.3 or higher
-@@ -44,3 +32,13 @@
+@@ -44,3 +32,21 @@
      from trac.util.text import empty
  except ImportError:
      empty = None
 +def prepare_docs(text, indent=4):
 +    r"""Remove leading whitespace"""
 +    return ''.join(l[indent:] for l in text.splitlines(True))
++
++try:
++    # Micro-second support added to 0.12dev r9210
++    from trac.util.datefmt import to_utimestamp, from_utimestamp
++except ImportError:
++    from trac.util.datefmt import to_timestamp, to_datetime, utc
++    to_utimestamp = to_timestamp
++    from_utimestamp = lambda x: to_datetime(x, utc)
 diff --git a/trunk/tracrpc/web_ui.py b/trunk/tracrpc/web_ui.py
 --- a/trunk/tracrpc/web_ui.py
 +++ b/trunk/tracrpc/web_ui.py
 diff --git a/trunk/tracrpc/wiki.py b/trunk/tracrpc/wiki.py
 --- a/trunk/tracrpc/wiki.py
 +++ b/trunk/tracrpc/wiki.py
-@@ -6,22 +6,21 @@
+@@ -6,22 +6,20 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
 +from trac.attachment import Attachment
  from trac.core import *
 -from trac.resource import Resource
+-from trac.util.datefmt import to_timestamp, to_datetime, utc
 +from trac.resource import Resource, ResourceNotFound
- from trac.util.datefmt import to_timestamp, to_datetime, utc
  from trac.wiki.api import WikiSystem
  from trac.wiki.model import WikiPage
  from trac.wiki.formatter import wiki_to_html
  
 -from tracrpc.api import IXMLRPCHandler, expose_rpc
 +from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
-+from tracrpc.util import StringIO
++from tracrpc.util import StringIO, to_utimestamp, from_utimestamp
 +
 +__all__ = ['WikiRPC']
  
  class WikiRPC(Component):
      """Superset of the
-@@ -36,7 +35,7 @@
+@@ -36,7 +34,7 @@
          return 'wiki'
  
      def xmlrpc_methods(self):
          yield ('WIKI_VIEW', ((int,),), self.getRPCVersionSupported)
          yield (None, ((str, str), (str, str, int),), self.getPage)
          yield (None, ((str, str, int),), self.getPage, 'getPageVersion')
-@@ -47,10 +46,10 @@
+@@ -47,10 +45,10 @@
          yield (None, ((dict, str, int),), self.getPageInfo, 'getPageInfoVersion')
          yield (None, ((bool, str, str, dict),), self.putPage)
          yield (None, ((list, str),), self.listAttachments)
                                 self.putAttachmentEx)
          yield (None, ((bool, str),(bool, str, int)), self.deletePage)
          yield (None, ((bool, str),), self.deleteAttachment)
+@@ -58,12 +56,12 @@
+         yield ('WIKI_VIEW', ((str, str),), self.wikiToHtml)
+ 
+     def _page_info(self, name, when, author, version, comment):
+-        return dict(name=name, lastModified=to_datetime(when, utc),
++        return dict(name=name, lastModified=when,
+                     author=author, version=int(version), comment=comment)
+ 
+     def getRecentChanges(self, req, since):
+         """ Get list of changed pages since timestamp """
+-        since = to_timestamp(since)
++        since = to_utimestamp(since)
+         wiki_realm = Resource('wiki')
+         db = self.env.get_db_cnx()
+         cursor = db.cursor()
+@@ -73,7 +71,8 @@
+         for name, when, author, version, comment in cursor:
+             if 'WIKI_VIEW' in req.perm(wiki_realm(id=name, version=version)):
+                 result.append(
+-                    self._page_info(name, when, author, version, comment))
++                    self._page_info(name, from_utimestamp(when),
++                                    author, version, comment))
+         return result
+ 
+     def getRPCVersionSupported(self, req):
 @@ -90,7 +89,7 @@
              msg = 'Wiki page "%s" does not exist' % pagename
              if version is not None: