1. Odd Simon Simonsen
  2. trac-rpc-mq

Commits

Olemis Lang  committed 0f11cc4
  • Participants
  • Parent commits 64750bc
  • Branches default

Comments (0)

Files changed (2)

File series

View file
+t10786/ticket10786-with-tests-xmlrpc-r12546.diff
 
 # Including keyword args in Method class
 t0000/t0000-kwargs-r7971.diff

File t10786/ticket10786-with-tests-xmlrpc-r12546.diff

View file
+diff --git a/trunk/tracrpc/json_rpc.py b/trunk/tracrpc/json_rpc.py
+index caa5887..52c8873 100644
+--- a/trunk/tracrpc/json_rpc.py
++++ b/trunk/tracrpc/json_rpc.py
+@@ -10,6 +10,12 @@ from itertools import izip
+ import re
+ from types import GeneratorType
+ 
++try:
++    import babel
++except ImportError:
++    babel = None
++import genshi
++
+ from trac.core import *
+ from trac.perm import PermissionError
+ from trac.resource import ResourceNotFound
+@@ -40,7 +46,10 @@ if json:
+         """ Extending the JSON encoder to support some additional types:
+         1. datetime.datetime => {'__jsonclass__': ["datetime", "<rfc3339str>"]}
+         2. tracrpc.api.Binary => {'__jsonclass__': ["binary", "<base64str>"]}
+-        3. empty => '' """
++        3. empty => ''
++        4. genshi.builder.Fragment|genshi.core.Markup => unicode
++        5. babel.support.LazyProxy => unicode
++        """
+ 
+         def default(self, obj):
+             if isinstance(obj, datetime.datetime):
+@@ -52,6 +61,11 @@ if json:
+                                 obj.data.encode("base64")]}
+             elif obj is empty:
+                 return ''
++            elif isinstance(obj, (genshi.builder.Fragment,
++                                  genshi.core.Markup)):
++                return unicode(obj)
++            elif babel and isinstance(obj, babel.support.LazyProxy):
++                return unicode(obj)
+             else:
+                 return json.JSONEncoder(self, obj)
+ 
+diff --git a/trunk/tracrpc/tests/__init__.py b/trunk/tracrpc/tests/__init__.py
+index c8e266d..a6e8715 100644
+--- a/trunk/tracrpc/tests/__init__.py
++++ b/trunk/tracrpc/tests/__init__.py
+@@ -76,6 +76,8 @@ try:
+         suite.addTest(tracrpc.tests.wiki.test_suite())
+         import tracrpc.tests.web_ui
+         suite.addTest(tracrpc.tests.web_ui.test_suite())
++        import tracrpc.tests.search
++        suite.addTest(tracrpc.tests.search.test_suite())
+         return suite
+ 
+ except Exception, e:
+diff --git a/trunk/tracrpc/tests/json_rpc.py b/trunk/tracrpc/tests/json_rpc.py
+index 9192927..dc7f775 100644
+--- a/trunk/tracrpc/tests/json_rpc.py
++++ b/trunk/tracrpc/tests/json_rpc.py
+@@ -152,6 +152,27 @@ else:
+                     result['result']['__jsonclass__'][1].decode("base64"))
+             self.assertEquals(image_in.getvalue(), image_out.getvalue())
+ 
++        def test_fragment(self):
++            data = {'method': 'ticket.create',
++                    'params': ['ticket10786', '',
++                               {'type': 'enhancement', 'owner': 'A'}]}
++            result = self._auth_req(data, user='admin')
++            self.assertEquals(None, result['error'])
++            tktid = result['result']
++
++            data = {'method': 'search.performSearch',
++                    'params': ['ticket10786']}
++            result = self._auth_req(data, user='admin')
++            self.assertEquals(None, result['error'])
++            self.assertEquals('<span class="new">#1</span>: enhancement: '
++                              'ticket10786 (new)',
++                              result['result'][0][1])
++            self.assertEquals(1, len(result['result']))
++
++            data = {'method': 'ticket.delete', 'params': [tktid]}
++            result = self._auth_req(data, user='admin')
++            self.assertEquals(None, result['error'])
++
+         def test_xmlrpc_permission(self):
+             # Test returned response if not XML_RPC permission
+             rpc_testenv._tracadmin('permission', 'remove', 'anonymous',
+diff --git a/trunk/tracrpc/tests/search.py b/trunk/tracrpc/tests/search.py
+new file mode 100644
+index 0000000..e9adb8b
+--- /dev/null
++++ b/trunk/tracrpc/tests/search.py
+@@ -0,0 +1,45 @@
++# -*- coding: utf-8 -*-
++"""
++License: BSD
++
++(c) 2013 ::: Jun Omae (jun66j5@gmail.com)
++"""
++
++import unittest
++
++import xmlrpclib
++import os
++import shutil
++import datetime
++import time
++
++from tracrpc.tests import rpc_testenv, TracRpcTestCase
++
++class RpcSearchTestCase(TracRpcTestCase):
++
++    def setUp(self):
++        TracRpcTestCase.setUp(self)
++        self.anon = xmlrpclib.ServerProxy(rpc_testenv.url_anon)
++        self.user = xmlrpclib.ServerProxy(rpc_testenv.url_user)
++        self.admin = xmlrpclib.ServerProxy(rpc_testenv.url_admin)
++
++    def tearDown(self):
++        TracRpcTestCase.tearDown(self)
++
++    def test_fragment_in_search(self):
++        t1 = self.admin.ticket.create("ticket10786", "",
++                        {'type': 'enhancement', 'owner': 'A'})
++        results = self.user.search.performSearch("ticket10786")
++        self.assertEquals(1, len(results))
++        self.assertEquals('<span class="new">#1</span>: enhancement: '
++                          'ticket10786 (new)',
++                          results[0][1])
++        self.assertEquals(0, self.admin.ticket.delete(t1))
++
++def test_suite():
++    test_suite = unittest.TestSuite()
++    test_suite.addTest(unittest.makeSuite(RpcSearchTestCase))
++    return test_suite
++
++if __name__ == '__main__':
++    unittest.main(defaultTest='test_suite')
+diff --git a/trunk/tracrpc/xml_rpc.py b/trunk/tracrpc/xml_rpc.py
+index fb5f253..c5703be 100644
+--- a/trunk/tracrpc/xml_rpc.py
++++ b/trunk/tracrpc/xml_rpc.py
+@@ -10,6 +10,10 @@ import datetime
+ import time
+ import xmlrpclib
+ 
++try:
++    import babel
++except ImportError:
++    babel = None
+ import genshi
+ 
+ from trac.core import *
+@@ -194,6 +198,8 @@ class XmlRpcProtocol(Component):
+             elif isinstance(res, (genshi.builder.Fragment, \
+                                   genshi.core.Markup)):
+                 new_result.append(to_unicode(res))
++            elif babel and isinstance(res, babel.support.LazyProxy):
++                new_result.append(to_unicode(res))
+             elif isinstance(res, dict):
+                 for key, val in res.items():
+                     res[key], = self._normalize_xml_output([val])