Commits

Anonymous committed 839be86

Fixed a test error following a recent Trac 0.12dev workflow action change, added a placeholder exception class for RPC-related errors, cleaned imports in all files.

  • Participants
  • Parent commits 42f9cbe

Comments (0)

Files changed (1)

t5437/t5437-protocol_api-r7194.diff

 diff --git a/trunk/tracrpc/api.py b/trunk/tracrpc/api.py
 --- a/trunk/tracrpc/api.py
 +++ b/trunk/tracrpc/api.py
-@@ -10,19 +10,22 @@
+@@ -6,23 +6,29 @@
+ (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
+ """
+ 
++import inspect
++import types
++from datetime import datetime
++import xmlrpclib
++
+ from trac.core import *
  from trac.perm import IPermissionRequestor
- import inspect
- import types
-+from datetime import datetime
- import xmlrpclib
+-import inspect
+-import types
+-import xmlrpclib
 -import datetime
  
 -try:
 -except:
 -    from sets import Set as set
 +__all__ = ['expose_rpc', 'IRPCProtocol', 'IXMLRPCHandler', 'AbstractRPCHandler',
-+            'Method', 'XMLRPCSystem', 'Binary']
-+
-+from tracrpc.util import set
++            'Method', 'XMLRPCSystem', 'Binary', 'RPCError']
 +
 +class Binary(xmlrpclib.Binary):
 +    """ RPC Binary type. Currently == xmlrpclib.Binary. """
 +    pass
++
++class RPCError(TracError):
++    """ Error class for general RPC-related errors. """
++    pass
  
  RPC_TYPES = {int: 'int', bool: 'boolean', str: 'string', float: 'double',
 -             xmlrpclib.DateTime: 'dateTime.iso8601', xmlrpclib.Binary: 'base64',
  def expose_rpc(permission, return_type, *arg_types):
      """ Decorator for exposing a method as an RPC call with the given
      signature. """
-@@ -35,7 +38,29 @@
+@@ -35,7 +41,29 @@
      return decorator
  
  
      def xmlrpc_namespace():
          """ Provide the namespace in which a set of methods lives.
              This can be overridden if the 'name' element is provided by
-@@ -56,7 +81,6 @@
+@@ -56,7 +84,6 @@
          followed by argument types.
          """
  
  class AbstractRPCHandler(Component):
      implements(IXMLRPCHandler)
      abstract = True
-@@ -180,7 +204,7 @@
+@@ -180,7 +207,7 @@
                  p = Method(provider, *candidate)
                  if p.name == method:
                      return p
 -        raise xmlrpclib.Fault(1, 'RPC method "%s" not found' % method)
-+        raise TracError('RPC method "%s" not found' % method)
++        raise RPCError('RPC method "%s" not found' % method)
          
      # Exported methods
      def all_methods(self, req):
-@@ -199,10 +223,8 @@
+@@ -199,10 +226,8 @@
          for signature in signatures:
              try:
                  yield self.get_method(signature['methodName'])(req, signature['params'])
 -from tracrpc.api import IXMLRPCHandler
  from trac.search.api import ISearchSource
  from trac.search.web_ui import SearchModule
++from trac.util.compat import set
  
 -try:
 -    a = set()
 -except:
 -    from sets import Set as set
 +from tracrpc.api import IXMLRPCHandler
-+from tracrpc.util import set
 +
 +__all__ = ['SearchRPC']
  
 rename to trunk/tracrpc/tests/json_rpc.py
 --- a/trunk/tracrpc/tests/json.py
 +++ b/trunk/tracrpc/tests/json_rpc.py
-@@ -11,7 +11,7 @@
+@@ -9,9 +9,9 @@
+ import os
+ import shutil
  import urllib2
- from StringIO import StringIO
+-from StringIO import StringIO
  
 -from tracrpc.web_ui import json
 +from tracrpc.json_rpc import json
++from tracrpc.util import StringIO
  
  if json:
      from tracrpc.tests import rpc_testenv
 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
-@@ -41,9 +41,11 @@
+@@ -32,7 +32,11 @@
+                   [['action_reassign_reassign_owner', 'admin', []]]],
+                   ['accept', 'accept',
+                   "The owner will change from (none) to admin. Next status will be 'accepted'.", []]]
+-        self.assertEquals(default, actions)
++        # Some action text was changed in trac:changeset:9041 - adjust default for test
++        if 'will be changed' in actions[2][2]:
++            default[2][2] = default[2][2].replace('will change', 'will be changed')
++            default[3][2] = default[3][2].replace('will change', 'will be changed')
++        self.assertEquals(actions, default)
+         self.admin.ticket.delete(tid)
+ 
+     def test_getAvailableActions_DeleteTicket(self):
+@@ -41,9 +45,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 +59,9 @@
+@@ -57,6 +63,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', {}))
+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 @@
+ 
+ import xmlrpclib
+ import os
+-from StringIO import StringIO
+ 
+ from trac.util.compat import sorted
+ 
+ from tracrpc.tests import rpc_testenv
++from tracrpc.util import StringIO
+ 
+ class RpcWikiTestCase(unittest.TestCase):
+     
 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
-@@ -21,10 +21,12 @@
- import genshi
+@@ -6,6 +6,11 @@
+ (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
+ """
  
- import inspect
++import inspect
++from datetime import datetime
++
++import genshi
++
+ from trac.attachment import Attachment
+ from trac.core import *
+ from trac.perm import PermissionError
+@@ -18,13 +23,10 @@
+ from trac.web.chrome import add_warning
+ from trac.util.datefmt import to_datetime, to_timestamp, utc
+ 
+-import genshi
++from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
++from tracrpc.util import StringIO
+ 
+-import inspect
 -import xmlrpclib
 -from StringIO import StringIO
-+from datetime import datetime
-+from util import StringIO
- 
+-
 -from tracrpc.api import IXMLRPCHandler, expose_rpc
-+from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
-+
 +__all__ = ['TicketRPC']
  
  class TicketRPC(Component):
  
  try:
      # Method only available in Trac 0.11.3 or higher
-@@ -44,3 +30,21 @@
+@@ -44,3 +30,13 @@
      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:
-+    # Should work with Py >= 2.4
-+    set = set
-+except:
-+    # Should work with Py >= 2.3
-+    from sets import Set as set
-+
 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
 +                            method.description, self.env, req=req),
 +                        method.permission))
 +            except Exception, e:
-+                from util import StringIO
++                from tracrpc.util import StringIO
 +                import traceback
 +                out = StringIO()
 +                traceback.print_exc(file=out)
 diff --git a/trunk/tracrpc/wiki.py b/trunk/tracrpc/wiki.py
 --- a/trunk/tracrpc/wiki.py
 +++ b/trunk/tracrpc/wiki.py
-@@ -6,11 +6,8 @@
+@@ -6,22 +6,21 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
 -except ImportError:
 -    from StringIO import StringIO
 -import xmlrpclib
-+from util import StringIO
+ import os
 +from datetime import datetime
- import os
  
++from trac.attachment import Attachment
  from trac.core import *
-@@ -21,7 +18,9 @@
+ from trac.resource import Resource
+ 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 trac.attachment import Attachment
+-from trac.attachment import Attachment
  
 -from tracrpc.api import IXMLRPCHandler, expose_rpc
 +from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
++from tracrpc.util import StringIO
 +
 +__all__ = ['WikiRPC']
  
 +        except Exception, e:
 +            self.log.error(e)
 +            import traceback
-+            from util import StringIO
++            from tracrpc.util import StringIO
 +            out = StringIO()
 +            traceback.print_exc(file = out)
 +            self.log.error(out.getvalue())