Commits

osimons  committed 490a762

[svn r6106] XmlRpcPlugin: Removing use of `posixpath` and replacing with `os.path`. Also added tests for wiki attachments where this code was used.

Closes #2818.

  • Participants
  • Parent commits 700e2be

Comments (0)

Files changed (3)

File trunk/tracrpc/tests/__init__.py

         suite.addTest(tracrpc.tests.json.suite())
         import tracrpc.tests.ticket
         suite.addTest(tracrpc.tests.ticket.suite())
+        import tracrpc.tests.wiki
+        suite.addTest(tracrpc.tests.wiki.suite())
         return suite
 
 except Exception, e:

File trunk/tracrpc/tests/wiki.py

+# -*- coding: utf-8 -*-
+"""
+License: BSD
+
+(c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
+"""
+
+import unittest
+
+import xmlrpclib
+import os
+from StringIO import StringIO
+
+from trac.util.compat import sorted
+
+from tracrpc.tests import rpc_testenv
+
+class RpcWikiTestCase(unittest.TestCase):
+    
+    def 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 test_attachments(self):
+        # Note: Quite similar to the tracrpc.tests.json.JsonTestCase.test_binary
+        image_url = os.path.join(rpc_testenv.trac_src, 'trac',
+                             'htdocs', 'feed.png')
+        image_in = StringIO(open(image_url, 'r').read())
+        # Create attachment
+        self.admin.wiki.putAttachmentEx('TitleIndex', 'feed2.png', 'test image',
+            xmlrpclib.Binary(image_in.getvalue()))
+        self.assertEquals(image_in.getvalue(), self.admin.wiki.getAttachment(
+                                                'TitleIndex/feed2.png').data)
+        # Update attachment (adding new)
+        self.admin.wiki.putAttachmentEx('TitleIndex', 'feed2.png', 'test image',
+            xmlrpclib.Binary(image_in.getvalue()), False)
+        self.assertEquals(image_in.getvalue(), self.admin.wiki.getAttachment(
+                                                'TitleIndex/feed2.2.png').data)
+        # List attachments
+        self.assertEquals(['TitleIndex/feed2.2.png', 'TitleIndex/feed2.png'],
+                        sorted(self.admin.wiki.listAttachments('TitleIndex')))
+        # Delete both attachments
+        self.admin.wiki.deleteAttachment('TitleIndex/feed2.png')
+        self.admin.wiki.deleteAttachment('TitleIndex/feed2.2.png')
+        # List attachments again
+        self.assertEquals([], self.admin.wiki.listAttachments('TitleIndex'))
+
+def suite():
+    return unittest.makeSuite(RpcWikiTestCase)
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='suite')

File trunk/tracrpc/wiki.py

 except ImportError:
     from StringIO import StringIO
 import xmlrpclib
-import posixpath
+import os
 
 from trac.core import *
 from trac.resource import Resource
 
     def getAttachment(self, req, path):
         """ returns the content of an attachment. """
-        pagename, filename = posixpath.split(path)
+        pagename, filename = os.path.split(path)
         attachment = Attachment(self.env, 'wiki', pagename, filename)
         req.perm(attachment.resource).require('ATTACHMENT_VIEW')
         return xmlrpclib.Binary(attachment.open().read())
         
         This method is compatible with WikiRPC.  `putAttachmentEx` has a more
         extensive set of (Trac-specific) features. """
-        pagename, filename = posixpath.split(path)
+        pagename, filename = os.path.split(path)
         self.putAttachmentEx(req, pagename, filename, None, data)
         return True
 
 
     def deleteAttachment(self, req, path):
         """ Delete an attachment. """
-        pagename, filename = posixpath.split(path)
+        pagename, filename = os.path.split(path)
         if not WikiPage(self.env, pagename).exists:
             raise TracError, 'Wiki page "%s" does not exist' % pagename
         attachment = Attachment(self.env, 'wiki', pagename, filename)