1. Olemis Lang
  2. bloodhound-rpc

Commits

Olemis Lang  committed 56563df

Trac Rpc [ refs rpc-307 ] Test cases for attachment methods in Milestone RPC ... (failures=1)

  • Participants
  • Parent commits ab2e8e9
  • Branches bloodhound_rpc

Comments (0)

Files changed (1)

File trunk/tracrpc/tests/ticket.py

View file
 Contains modifications for Apache(TM) Bloodhound compatibility
 """
 
-import unittest
-
-import xmlrpclib
+import datetime
 import os
 import shutil
-import datetime
+from StringIO import StringIO
 import time
+import unittest
 import urllib
+import xmlrpclib
 
 from tracrpc.tests import TracRpcTestCase
 
         self.assertEquals({'time': dt, 'description': desc, 'name': '9.99'},
                            self.admin.ticket.version.get('9.99'))
 
+class RpcTicketMilestoneTestCase(TracRpcTestCase):
+    
+    def setUp(self):
+        TracRpcTestCase.setUp(self)
+        self.anon = self._tester.server_proxy(self.url_anon)
+        self.user = self._tester.server_proxy(self.url_auth, user='user')
+        self.admin = self._tester.server_proxy(self.url_auth, user='admin')
+
+    def tearDown(self):
+        TracRpcTestCase.tearDown(self)
+
+    def test_create(self):
+        dt = xmlrpclib.DateTime(datetime.datetime.utcnow())
+        desc = "test milestone"
+        v = self.admin.ticket.milestone.create('9.99',
+                            {'due': dt, 'description': desc})
+        self.failUnless('9.99' in self.admin.ticket.milestone.getAll())
+        self.assertEquals({'due': dt, 'description': desc, 'name': '9.99',
+                           'completed' : 0},
+                          self.admin.ticket.milestone.get('9.99'))
+
+    def test_milestone_attachments(self):
+        # Note: Quite similar to the tracrpc.tests.json.JsonTestCase.test_binary
+        image_url = os.path.join(self._testenv.trac_src, 'trac',
+                                 'htdocs', 'feed.png')
+        image_in = StringIO(open(image_url, 'r').read())
+        # Add new milestone
+        mname = 'test_milestone_attachments'
+        self.admin.ticket.milestone.create(mname, {})
+        # Create attachment
+        self.admin.ticket.milestone.putAttachment(mname, 'feed2.png', 'upload1',
+                                        xmlrpclib.Binary(image_in.getvalue()))
+        self.assertEquals(image_in.getvalue(), 
+                          self.admin.ticket.milestone.getAttachment(mname,
+                                                           'feed2.png').data)
+        # Assertions for attachment metadata
+        attachments = self.admin.ticket.milestone.listAttachments(mname)
+        self.assertEquals(1, len(attachments))
+        attachment = attachments[0]
+        self.assertEquals('feed2.png', attachment[0])
+        self.assertEquals('upload1', attachment[1])
+        self.assertEquals(len(image_in.getvalue()), attachment[2])
+        self.assertEquals('admin', attachment[4])
+        # Update attachment (adding new)
+        self.admin.ticket.milestone.putAttachment(mname, 'feed2.png', 'upload2',
+                                        xmlrpclib.Binary(image_in.getvalue()),
+                                        False)
+        self.assertEquals(image_in.getvalue(), 
+                          self.admin.ticket.milestone.getAttachment(mname,
+                                                            'feed2.2.png').data)
+        # List attachments
+        self.assertEquals(['feed2.2.png', 'feed2.png'], 
+                          sorted([m[0] for m in
+                           self.admin.ticket.milestone.listAttachments(mname)]))
+        # Delete both attachments
+        self.admin.ticket.milestone.deleteAttachment(mname, 'feed2.png')
+        self.admin.ticket.milestone.deleteAttachment(mname, 'feed2.2.png')
+        # List attachments again
+        self.assertEquals([],
+                          self.admin.ticket.milestone.listAttachments(mname))
+
+
 def test_suite(suite=None):
     if suite is None:
         from tracrpc.tests import functionalSuite
         suite = functionalSuite()
     # FIXME: Improve
     for ts in [unittest.makeSuite(RpcTicketTestCase),
+               unittest.makeSuite(RpcTicketMilestoneTestCase),
                unittest.makeSuite(RpcTicketVersionTestCase)]:
         for test in ts._tests:
             suite.addTest(test)