Commits

Olemis Lang committed 228ef43

TracRpc: API v2: Test cases for XML-RPC ... PASS

Comments (0)

Files changed (1)

t5437/t5437-protocol_api_v2-r7194.diff

 RPC Protocol API version 2
 
-diff -r 8b6987624152 trunk/setup.py
---- a/trunk/setup.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/setup.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/setup.py
+--- a/trunk/setup.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/setup.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -28,7 +28,7 @@
      url='http://trac-hacks.org/wiki/XmlRpcPlugin',
      description='RPC interface to Trac',
      tests_require = test_deps,
      packages=find_packages(exclude=['*.tests']),
      package_data={
-diff -r 8b6987624152 trunk/tracrpc/api.py
---- a/trunk/tracrpc/api.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/api.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/api.py
+--- a/trunk/tracrpc/api.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/api.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -21,13 +21,34 @@
      """ RPC Binary type. Currently == xmlrpclib.Binary. """
      pass
  
  class IXMLRPCHandler(Interface):
  
-diff -r 8b6987624152 trunk/tracrpc/json_rpc.py
---- a/trunk/tracrpc/json_rpc.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/json_rpc.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/json_rpc.py
+--- a/trunk/tracrpc/json_rpc.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/json_rpc.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -5,8 +5,9 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
              return self._json_error(e, r_id=r_id)
  
      def _json_error(self, e, c=None, r_id=None):
-diff -r 8b6987624152 trunk/tracrpc/tests/__init__.py
---- a/trunk/tracrpc/tests/__init__.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/__init__.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/tests/__init__.py
+--- a/trunk/tracrpc/tests/__init__.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/__init__.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -35,6 +35,7 @@
              print "Enabling RPC plugin and permissions..."
              env.config.set('components', 'tracrpc.*', 'enabled')
 +                raise self.failureException, "Expected %s\n\nNothing raised" % excName
 +
 +        assertRaises = failUnlessRaises
-diff -r 8b6987624152 trunk/tracrpc/tests/api.py
---- a/trunk/tracrpc/tests/api.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/api.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/tests/api.py
+--- a/trunk/tracrpc/tests/api.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/api.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -9,14 +9,14 @@
  import unittest
  import urllib2
  if __name__ == '__main__':
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
-diff -r 8b6987624152 trunk/tracrpc/tests/json_rpc.py
---- a/trunk/tracrpc/tests/json_rpc.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/json_rpc.py	Thu Mar 18 12:50:41 2010 -0500
-@@ -14,9 +14,9 @@
+diff -r b5e897b63dc2 trunk/tracrpc/tests/json_rpc.py
+--- a/trunk/tracrpc/tests/json_rpc.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/json_rpc.py	Thu Mar 18 13:46:27 2010 -0500
+@@ -14,10 +14,10 @@
  from tracrpc.util import StringIO
  
  if json:
 +    from tracrpc.tests import rpc_testenv, TracRpcTestCase
  
 -    class JsonTestCase(unittest.TestCase):
+-        
 +    class JsonTestCase(TracRpcTestCase):
-         
++
          def _anon_req(self, data):
              req = urllib2.Request(rpc_testenv.url_anon,
+                         headers={'Content-Type': 'application/json'})
 @@ -167,11 +167,11 @@
              self.assertEquals(result['error']['message'],
                       'Wiki page "Test" does not exist at version 10')
  if __name__ == '__main__':
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
-diff -r 8b6987624152 trunk/tracrpc/tests/ticket.py
---- a/trunk/tracrpc/tests/ticket.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/ticket.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/tests/ticket.py
+--- a/trunk/tracrpc/tests/ticket.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/ticket.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -12,9 +12,9 @@
  import shutil
  import time
  if __name__ == '__main__':
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
-diff -r 8b6987624152 trunk/tracrpc/tests/wiki.py
---- a/trunk/tracrpc/tests/wiki.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/wiki.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/tests/wiki.py
+--- a/trunk/tracrpc/tests/wiki.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/wiki.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -13,10 +13,10 @@
  
  from trac.util.compat import sorted
  if __name__ == '__main__':
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
-diff -r 8b6987624152 trunk/tracrpc/tests/xml_rpc.py
---- a/trunk/tracrpc/tests/xml_rpc.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/tests/xml_rpc.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/tests/xml_rpc.py
+--- a/trunk/tracrpc/tests/xml_rpc.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/tests/xml_rpc.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -9,9 +9,9 @@
  
  import xmlrpclib
      
      def setUp(self):
          self.anon = xmlrpclib.ServerProxy(rpc_testenv.url_anon)
+@@ -81,7 +81,7 @@
+         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)
++        self.assertEquals(str(xmlrpc_now), now.strftime("%Y%m%dT%H:%M:%S"))
+         now_from_xmlrpc = from_xmlrpc_datetime(xmlrpc_now)
+         self.assertTrue(isinstance(now_from_xmlrpc, datetime),
+                 "Expected now_from_xmlrpc to be a datetime")
 @@ -104,8 +104,8 @@
              self.assertEquals(e.faultString,
                      'Wiki page "Test" does not exist at version 10')
  if __name__ == '__main__':
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
-diff -r 8b6987624152 trunk/tracrpc/web_ui.py
---- a/trunk/tracrpc/web_ui.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/web_ui.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/web_ui.py
+--- a/trunk/tracrpc/web_ui.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/web_ui.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -6,6 +6,10 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
      def _dump_docs(self, req):
          # Dump RPC documentation
          req.perm.require('XML_RPC') # Need at least XML_RPC
-@@ -128,6 +132,53 @@
+@@ -128,6 +132,57 @@
              return "Error rendering protocol documentation. " \
                         "Contact your '''Trac''' administrator for details"
  
 +    def _rpc_process(self, req, protocol, content_type):
 +        """Process incoming RPC request and finalize response."""
-+        req.perm.require('XML_RPC') # Need at least XML_RPC
 +        proto_id = protocol.rpc_info()[0]
 +        rpcreq = {'mimetype': content_type}
 +        try :
 +            self.log.debug("RPC(%s) call by '%s'", proto_id, req.authname)
++            req.perm.require('XML_RPC') # Need at least XML_RPC
 +            rpcreq = protocol.parse_rpc_request(req, content_type)
 +            rpcreq['mimetype'] = content_type
 +            method_name = rpcreq.get('method')
 +                protocol.send_rpc_result(req, rpcreq, result)
 +        except (RPCError, PermissionError, ResourceNotFound), e:
 +            self.log.exception("RPC(%s) Error", proto_id)
-+            protocol.send_rpc_error(req, rpcreq, e)
++            try :
++                protocol.send_rpc_error(req, rpcreq, e)
++            except Exception, e :
++                self.log.exception("RPC(%s) Unhandled protocol error", proto_id)
++                self._send_unknown_error(req, rpcreq, e)
 +        except Exception, e :
 +            self.log.exception("RPC(%s) Unhandled protocol error", proto_id)
 +            self._send_unknown_error(req, rpcreq, e)
      # ITemplateProvider methods
  
      def get_htdocs_dirs(self):
-diff -r 8b6987624152 trunk/tracrpc/xml_rpc.py
---- a/trunk/tracrpc/xml_rpc.py	Thu Mar 18 12:49:00 2010 -0500
-+++ b/trunk/tracrpc/xml_rpc.py	Thu Mar 18 12:50:41 2010 -0500
+diff -r b5e897b63dc2 trunk/tracrpc/xml_rpc.py
+--- a/trunk/tracrpc/xml_rpc.py	Thu Mar 18 12:50:57 2010 -0500
++++ b/trunk/tracrpc/xml_rpc.py	Thu Mar 18 13:46:27 2010 -0500
 @@ -19,7 +19,7 @@
  from trac.util.text import to_unicode
  
              self.log.error(e)
              import traceback
              from tracrpc.util import StringIO
+@@ -123,6 +128,7 @@
+             traceback.print_exc(file = out)
+             self.log.error(out.getvalue())
+             err_code = hasattr(e, 'code') and e.code or 1
++            method = rpcreq.get('method')
+             self._send_response(req,
+                     xmlrpclib.dumps(
+                         xmlrpclib.Fault(err_code,