Commits

Olemis Lang committed 4bcb204

Trac RPC [ refs rpc-307 ] Test that ticket.create when arg overrides exec_as timestamp

Comments (0)

Files changed (1)

trunk/tracrpc/tests/admin.py

         self.assertEquals('user', attributes['reporter'])
         self.admin.ticket.delete(tid)
 
-#    def test_FineGrainedSecurity(self):
-#        self.assertEquals(1, self.admin.ticket.create('abc', '123', {}))
-#        self.assertEquals(2, self.admin.ticket.create('def', '456', {}))
-#        # First some non-restricted tests for comparison:
-#        self.assertRaises(xmlrpclib.Fault, self.anon.ticket.create, 'abc', 'def')
-#        self.assertEquals([1,2], self.user.ticket.query())
-#        self.assertTrue(self.user.ticket.get(2))
-#        self.assertTrue(self.user.ticket.update(1, "ok"))
-#        self.assertTrue(self.user.ticket.update(2, "ok"))
-#        # Enable security policy and test
-#        from trac.core import Component, implements
-#        from trac.perm import IPermissionPolicy
-#        policy = os.path.join(self._testenv.tracdir, 'plugins', 'TicketPolicy.py')
-#        open(policy, 'w').write(
-#        "from trac.core import *\n"
-#        "from trac.perm import IPermissionPolicy\n"
-#        "class TicketPolicy(Component):\n"
-#        "    implements(IPermissionPolicy)\n"
-#        "    def check_permission(self, action, username, resource, perm):\n"
-#        "        if username == 'user' and resource and resource.id == 2:\n"
-#        "            return False\n"
-#        "        if username == 'anonymous' and action == 'TICKET_CREATE':\n"
-#        "            return True\n")
-#        env = self._testenv.env
-#        env.config.set('components', 'TicketPolicy.TicketPolicy', 'enabled')
-#
-#        _old_conf = env.config.get('trac', 'permission_policies')
-#        env.config.set('trac', 'permission_policies', 'TicketPolicy,'+_old_conf)
-#        env.config.save()
-#        self._testenv.restart()
-#        self.assertEquals([1], self.user.ticket.query())
-#        self.assertTrue(self.user.ticket.get(1))
-#        self.assertRaises(xmlrpclib.Fault, self.user.ticket.get, 2)
-#        self.assertTrue(self.user.ticket.update(1, "ok"))
-#        self.assertRaises(xmlrpclib.Fault, self.user.ticket.update, 2, "not ok")
-#        self.assertEquals(3, self.anon.ticket.create('efg', '789', {}))
-#        # Clean, reset and simple verification
-#        env.config.set('trac', 'permission_policies', _old_conf)
-#        env.config.save()
-#        os.unlink(policy)
-#        self._testenv.restart()
-#        self.assertEquals([1,2,3], self.user.ticket.query())
-#        self.assertEquals(0, self.admin.ticket.delete(1))
-#        self.assertEquals(0, self.admin.ticket.delete(2))
-#        self.assertEquals(0, self.admin.ticket.delete(3))
-
     def test_admin_ticket_getRecentChanges(self):
         timestamp1 = datetime.datetime(2000, 1, 1, 10, 20, 30)
         timestamp1 = xmlrpclib.DateTime(to_datetime(timestamp1, utc))
                 self.assertEquals('user', who)
         self.admin.ticket.delete(tid)
 
-#    def test_create_at_time(self):
-#        now = to_datetime(None, utc)
-#        minus1 = now - datetime.timedelta(days=1)
-#        # create the tickets (user ticket will not be permitted to change time)
-#        one = self.admin.ticket.create("create_at_time1", "ok", {}, False,
-#                                        xmlrpclib.DateTime(minus1))
-#        two = self.user.ticket.create("create_at_time3", "ok", {}, False,
-#                                        xmlrpclib.DateTime(minus1))
-#        # get the tickets
-#        t1 = self.admin.ticket.get(one)
-#        t2 = self.admin.ticket.get(two)
-#        # check timestamps
-#        self.assertTrue(t1[1] < t2[1])
-#        self.admin.ticket.delete(one)
-#        self.admin.ticket.delete(two)
-#
+    def test_admin_create_at_time(self):
+        now = to_datetime(None, utc)
+        minus1 = now - datetime.timedelta(days=1)
+        minus2 = now - datetime.timedelta(days=2)
+        # create the tickets
+        one, two = self.admin.admin.exec_as([{'methodName' : 'ticket.create',
+                                              'params' : ["create_at_time1",
+                                                          "ok", {}, False]},
+                                             {'methodName' : 'ticket.create',
+                                              'params' : ["create_at_time3",
+                                                          "ok", {}, False,
+                                                          xmlrpclib.DateTime(minus2)
+                                                         ]}],
+                                            'auser', xmlrpclib.DateTime(minus1))
+        self.assertTrue(all(not isinstance(x, xmlrpclib.Fault) for x in (one, two)))
+        one, = one
+        two, = two
+        # get the tickets
+        t1 = self.admin.ticket.get(one)
+        t2 = self.admin.ticket.get(two)
+        # check timestamps
+        self.assertTrue(t2[1] < t1[1])
+        self.admin.ticket.delete(one)
+        self.admin.ticket.delete(two)
+
 #    def test_update_at_time(self):
 #        from trac.util.datefmt import to_datetime, utc
 #        now = to_datetime(None, utc)