Commits

osimons  committed ba25724

Fixed 3 bugs identified by Steffen Pingel (from Mylyn test suite), and also added a test case for the xmlrpc datetime conversions.

  • Participants
  • Parent commits 1ef92ca

Comments (0)

Files changed (1)

File t5437/t5437-protocol_api-r7194.diff

              self.assertTrue("listMethods() takes exactly 2 arguments" \
                                      in e.faultString)
  
+@@ -67,6 +67,22 @@
+         self.assertEquals(unicode, type(result[3]['summary']))
+         self.admin.ticket.delete(t_id)
+ 
++    def test_to_and_from_datetime(self):
++        from datetime import datetime
++        from trac.util.datefmt import to_datetime, utc
++        from tracrpc.xml_rpc import to_xmlrpc_datetime, from_xmlrpc_datetime
++        now = to_datetime(None, utc)
++        now_timetuple = now.timetuple()[:6]
++        xmlrpc_now = to_xmlrpc_datetime(now)
++        self.assertTrue(isinstance(xmlrpc_now, xmlrpclib.DateTime),
++                "Expected xmlprc_now to be an xmlrpclib.DateTime")
++        self.assertEquals(xmlrpc_now.timetuple()[:6], now_timetuple)
++        now_from_xmlrpc = from_xmlrpc_datetime(xmlrpc_now)
++        self.assertTrue(isinstance(now_from_xmlrpc, datetime),
++                "Expected now_from_xmlrpc to be a datetime")
++        self.assertEquals(now_from_xmlrpc.timetuple()[:6], now_timetuple)
++        self.assertEquals(now_from_xmlrpc.tzinfo, utc)
++
+ def suite():
+     return unittest.makeSuite(RpcXmlTestCase)
+ 
 diff --git a/trunk/tracrpc/ticket.py b/trunk/tracrpc/ticket.py
 --- a/trunk/tracrpc/ticket.py
 +++ b/trunk/tracrpc/ticket.py
                 self.putAttachment)
          yield (None, ((bool, int, str),), self.deleteAttachment)
          yield ('TICKET_VIEW', ((list,),), self.getTicketFields)
+@@ -243,7 +245,7 @@
+         """ returns the content of an attachment. """
+         attachment = Attachment(self.env, 'ticket', ticket, filename)
+         req.perm(attachment.resource).require('ATTACHMENT_VIEW')
+-        return xmlrpclib.Binary(attachment.open().read())
++        return Binary(attachment.open().read())
+ 
+     def putAttachment(self, req, ticket, filename, description, data, replace=True):
+         """ Add an attachment, optionally (and defaulting to) overwriting an
 diff --git a/trunk/tracrpc/util.py b/trunk/tracrpc/util.py
 --- a/trunk/tracrpc/util.py
 +++ b/trunk/tracrpc/util.py
-@@ -6,24 +6,10 @@
+@@ -6,24 +6,12 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
 -import datetime
 -import time
 -import xmlrpclib
--
++from trac.util.compat import any
+ 
 -from trac.util.datefmt import utc
 -
 -### PUBLIC
  
  try:
      # Method only available in Trac 0.11.3 or higher
-@@ -44,3 +30,13 @@
+@@ -44,3 +32,13 @@
      from trac.util.text import empty
  except ImportError:
      empty = None
 new file mode 100644
 --- /dev/null
 +++ b/trunk/tracrpc/xml_rpc.py
-@@ -0,0 +1,176 @@
+@@ -0,0 +1,177 @@
 +# -*- coding: utf-8 -*-
 +"""
 +License: BSD
 +
 +from trac.core import *
 +from trac.perm import PermissionError
++from trac.util.datefmt import utc
 +from trac.util.text import to_unicode
 +
 +from tracrpc.api import XMLRPCSystem, IRPCProtocol, Binary