Commits

osimons  committed 409eb5e

Added unit test for general provider error, and fixing a missing import discovered by test. Also added some debug logging to identify the protocol being called.

  • Participants
  • Parent commits 9b81bf0

Comments (0)

Files changed (1)

File t5437/t5437-protocol_api-r7194.diff

 new file mode 100644
 --- /dev/null
 +++ b/trunk/tracrpc/tests/api.py
-@@ -0,0 +1,78 @@
+@@ -0,0 +1,107 @@
 +# -*- coding: utf-8 -*-
 +"""
 +License: BSD
 +            os.unlink(provider)
 +            rpc_testenv.restart()
 +
++    def test_general_provider_error(self):
++        # Make a new plugin and restart server
++        provider = os.path.join(rpc_testenv.tracdir, 'plugins', 'DummyProvider.py')
++        open(provider, 'w').write(
++            "from trac.core import *\n"
++            "from tracrpc.api import *\n"
++            "class DummyProvider(Component):\n"
++            "    implements(IRPCProtocol)\n"
++            "    def rpc_info(self):\n"
++            "        yield ('TEST-RPC', 'No Docs!')\n"
++            "    def rpc_match(self):\n"
++            "        yield ('rpc', 'application/x-tracrpc-test')\n"
++            "    def rpc_process(self, req, content_type):\n"
++            "        raise RPCError('No good.')")
++        rpc_testenv.restart()
++        # Make the request
++        try:
++            req = urllib2.Request(rpc_testenv.url_anon,
++                        headers={'Content-Type': 'application/x-tracrpc-test'})
++            resp = urllib2.urlopen(req)
++        except urllib2.HTTPError, e:
++            self.assertEquals(500, e.code)
++            self.assertEquals("No good.", e.fp.read())
++            self.assertTrue(e.hdrs['Content-Type'].startswith('text/plain'))
++        finally:
++            # Clean up so that provider don't affect further tests
++            os.unlink(provider)
++            rpc_testenv.restart()
++
 +def suite():
 +    return unittest.makeSuite(ProtocolProviderTestCase)
 +
 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
-@@ -6,305 +6,139 @@
+@@ -6,305 +6,142 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
  from trac.core import *
 -from trac.perm import PermissionError
 -from trac.util.datefmt import utc
--from trac.util.text import to_unicode
+ from trac.util.text import to_unicode
 +from trac.util.translation import _
 +from trac.web.api import RequestDone, HTTPUnsupportedMediaType
  from trac.web.main import IRequestHandler
 +        content_type = req.get_header('Content-Type') or 'text/html'
 +        if protocol:
 +            # Perform the method call
++            self.log.debug("RPC incoming request of content type '%s' " \
++                    "dispatched to %s" % (content_type, repr(protocol)))
 +            try:
 +                protocol.rpc_process(req, content_type)
 +            except Exception, e: