Commits

Olemis Lang  committed 820bb1a

TracRpc: API v2: Fixing previous patch, tests/xml_rpc considered as binary

  • Participants
  • Parent commits de717d8

Comments (0)

Files changed (1)

File t5437/t5437-protocol_api_v2-r7194.diff

 
 diff -r 203e791a70bf trunk/setup.py
 --- a/trunk/setup.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/setup.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/setup.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -28,7 +28,7 @@
      url='http://trac-hacks.org/wiki/XmlRpcPlugin',
      description='RPC interface to Trac',
      package_data={
 diff -r 203e791a70bf trunk/tracrpc/api.py
 --- a/trunk/tracrpc/api.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/api.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/api.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -21,13 +21,34 @@
      """ RPC Binary type. Currently == xmlrpclib.Binary. """
      pass
  
 diff -r 203e791a70bf trunk/tracrpc/json_rpc.py
 --- a/trunk/tracrpc/json_rpc.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/json_rpc.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/json_rpc.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -5,8 +5,9 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
      def _json_error(self, e, c=None, r_id=None):
 diff -r 203e791a70bf trunk/tracrpc/tests/__init__.py
 --- a/trunk/tracrpc/tests/__init__.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/tests/__init__.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/tests/__init__.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -35,6 +35,7 @@
              print "Enabling RPC plugin and permissions..."
              env.config.set('components', 'tracrpc.*', 'enabled')
 +        assertRaises = failUnlessRaises
 diff -r 203e791a70bf trunk/tracrpc/tests/api.py
 --- a/trunk/tracrpc/tests/api.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/tests/api.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/tests/api.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -9,14 +9,14 @@
  import unittest
  import urllib2
 +    unittest.main(defaultTest='test_suite')
 diff -r 203e791a70bf trunk/tracrpc/tests/json_rpc.py
 --- a/trunk/tracrpc/tests/json_rpc.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/tests/json_rpc.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/tests/json_rpc.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -14,9 +14,9 @@
  from tracrpc.util import StringIO
  
 +    unittest.main(defaultTest='test_suite')
 diff -r 203e791a70bf trunk/tracrpc/tests/ticket.py
 --- a/trunk/tracrpc/tests/ticket.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/tests/ticket.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/tests/ticket.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -12,11 +12,12 @@
  import shutil
  import time
 +    unittest.main(defaultTest='test_suite')
 diff -r 203e791a70bf trunk/tracrpc/tests/wiki.py
 --- a/trunk/tracrpc/tests/wiki.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/tests/wiki.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/tests/wiki.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -13,12 +13,13 @@
  
  from trac.util.compat import sorted
 -    unittest.main(defaultTest='suite')
 +    unittest.main(defaultTest='test_suite')
 diff -r 203e791a70bf trunk/tracrpc/tests/xml_rpc.py
-Binary file trunk/tracrpc/tests/xml_rpc.py has changed
+--- a/trunk/tracrpc/tests/xml_rpc.py	Tue Mar 16 11:04:09 2010 -0500
++++ b/trunk/tracrpc/tests/xml_rpc.py	Wed Mar 17 16:05:57 2010 -0500
+@@ -9,11 +9,12 @@
+ 
+ import xmlrpclib
+ 
+-from tracrpc.tests import rpc_testenv
++from tracrpc.tests import rpc_testenv, TracRpcTestCase
+ 
+-class RpcXmlTestCase(unittest.TestCase):
++class RpcXmlTestCase(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)
+@@ -22,44 +23,48 @@
+         # Test returned response if not XML_RPC permission
+         rpc_testenv._tracadmin('permission', 'remove', 'anonymous',
+                                 'XML_RPC')
+-        try:
++
++        def testcall():
+             self.anon.system.listMethods()
+             rpc_testenv._tracadmin('permission', 'add', 'anonymous',
+                                         'XML_RPC')
+             self.fail("Revoked permissions not taken effect???")
+-        except xmlrpclib.Fault, e:
+-            self.assertEquals(403, e.faultCode)
+-            self.assertTrue('XML_RPC' in e.faultString)
+-            rpc_testenv._tracadmin('permission', 'add', 'anonymous',
+-                                        'XML_RPC')
++
++        e = self.assertRaises(xmlrpclib.Fault, testcall)
++        self.assertEquals(403, e.faultCode)
++        self.assertTrue('XML_RPC' in e.faultString)
++        rpc_testenv._tracadmin('permission', 'add', 'anonymous',
++                                    'XML_RPC')
+ 
+     def test_method_not_found(self):
+-        try:
++        def testcall():
+             self.admin.system.doesNotExist()
+             self.fail("What? Method exists???")
+-        except xmlrpclib.Fault, e:
+-            self.assertEquals(-32601, e.faultCode)
+-            self.assertTrue("not found" in e.faultString)
++
++        e = self.assertRaises(xmlrpclib.Fault, testcall)
++        self.assertEquals(-32601, e.faultCode)
++        self.assertTrue("not found" in e.faultString)
+ 
+     def test_wrong_argspec(self):
+-        try:
++        def testcall():
+             self.admin.system.listMethods("hello")
+             self.fail("Oops. Wrong argspec accepted???")
+-        except xmlrpclib.Fault, e:
+-            self.assertEquals(1, e.faultCode)
+-            self.assertTrue("listMethods() takes exactly 2 arguments" \
++
++        e = self.assertRaises(xmlrpclib.Fault, testcall)
++        self.assertEquals(1, e.faultCode)
++        self.assertTrue("listMethods() takes exactly 2 arguments" \
+                                     in e.faultString)
+ 
+     def test_content_encoding(self):
+         test_string = "øæåØÆÅàéüoö"
+         # No encoding / encoding error
+-        try:
++        def testcall():
+             t_id = self.admin.ticket.create(test_string, test_string[::-1], {})
+             self.admin.ticket.delete(t_id)
+             self.fail("Expected ticket create to fail...")
+-        except Exception, e:
+-            self.assertTrue(isinstance(e, xmlrpclib.Fault))
+-            self.assertEquals(-32700, e.faultCode)
++        e = self.assertRaises(xmlrpclib.Fault, testcall)
++        self.assertEquals(-32700, e.faultCode)
++
+         # Unicode version (encodable)
+         from trac.util.text import to_unicode
+         test_string = to_unicode(test_string)
+@@ -81,7 +86,8 @@
+         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(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")
+@@ -90,22 +96,19 @@
+ 
+     def test_resource_not_found(self):
+         # A Ticket resource
+-        try:
+-            self.admin.ticket.get(2147483647)
+-        except Exception, e:
+-            self.assertEquals(e.faultCode, 404)
+-            self.assertEquals(e.faultString, 
+-                    'Ticket 2147483647 does not exist.')
++        e = self.assertRaises(xmlrpclib.Fault, lambda : self.admin.ticket.get(2147483647))
++        self.assertEquals(e.faultCode, 404)
++        self.assertEquals(e.faultString, 
++                'Ticket 2147483647 does not exist.')
+         # A Wiki resource
+-        try:
+-            self.admin.wiki.getPage("Test", 10)
+-        except Exception, e:
+-            self.assertEquals(e.faultCode, 404)
+-            self.assertEquals(e.faultString,
+-                    'Wiki page "Test" does not exist at version 10')
++        e = self.assertRaises(xmlrpclib.Fault, lambda : self.admin.wiki.getPage("Test", 10))
++        self.assertEquals(e.faultCode, 404)
++        self.assertEquals(e.faultString,
++                'Wiki page "Test" does not exist at version 10')
+ 
+-def suite():
++def test_suite():
+     return unittest.makeSuite(RpcXmlTestCase)
+ 
+ if __name__ == '__main__':
+-    unittest.main(defaultTest='suite')
++    unittest.main(defaultTest='test_suite')
++
 diff -r 203e791a70bf trunk/tracrpc/web_ui.py
 --- a/trunk/tracrpc/web_ui.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/web_ui.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/web_ui.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -6,6 +6,10 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
      def get_htdocs_dirs(self):
 diff -r 203e791a70bf trunk/tracrpc/xml_rpc.py
 --- a/trunk/tracrpc/xml_rpc.py	Tue Mar 16 11:04:09 2010 -0500
-+++ b/trunk/tracrpc/xml_rpc.py	Wed Mar 17 15:41:29 2010 -0500
++++ b/trunk/tracrpc/xml_rpc.py	Wed Mar 17 16:05:57 2010 -0500
 @@ -17,9 +17,10 @@
  from trac.resource import ResourceNotFound
  from trac.util.datefmt import utc