devtools/testlib.py
branchstable
changeset 7039 df0e8581b06f
parent 7038 fe0afc4e8ebb
child 7040 9b1f9bc74f5d
child 7060 f26a1cbddc91
--- a/devtools/testlib.py	Mon Mar 07 10:40:07 2011 +0100
+++ b/devtools/testlib.py	Mon Mar 07 10:41:04 2011 +0100
@@ -435,6 +435,21 @@
 
     # other utilities #########################################################
 
+    def grant_permission(self, entity, group, pname, plabel=None):
+        """insert a permission on an entity. Will have to commit the main
+        connection to be considered
+        """
+        pname = unicode(pname)
+        plabel = plabel and unicode(plabel) or unicode(group)
+        e = entity.eid
+        with security_enabled(self.session, False, False):
+            peid = self.execute(
+            'INSERT CWPermission X: X name %(pname)s, X label %(plabel)s,'
+            'X require_group G, E require_permission X '
+            'WHERE G name %(group)s, E eid %(e)s',
+            locals())[0][0]
+        return peid
+
     @contextmanager
     def temporary_appobjects(self, *appobjects):
         self.vreg._loadedmods.setdefault(self.__module__, {})
@@ -446,7 +461,20 @@
             for obj in appobjects:
                 self.vreg.unregister(obj)
 
-    # vregistry inspection utilities ###########################################
+    def assertModificationDateGreater(self, entity, olddate):
+        entity.cw_attr_cache.pop('modification_date', None)
+        self.failUnless(entity.modification_date > olddate)
+
+
+    # workflow utilities #######################################################
+
+    def assertPossibleTransitions(self, entity, expected):
+        transitions = entity.cw_adapt_to('IWorkflowable').possible_transitions()
+        self.assertListEqual(sorted(tr.name for tr in transitions),
+                             sorted(expected))
+
+
+    # views and actions registries inspection ##################################
 
     def pviews(self, req, rset):
         return sorted((a.__regid__, a.__class__)