devtools/testlib.py
branchstable
changeset 7039 df0e8581b06f
parent 7038 fe0afc4e8ebb
child 7040 9b1f9bc74f5d
child 7060 f26a1cbddc91
equal deleted inserted replaced
7038:fe0afc4e8ebb 7039:df0e8581b06f
   433         self.session.set_pool()
   433         self.session.set_pool()
   434         return self.session.execute(rql, args)
   434         return self.session.execute(rql, args)
   435 
   435 
   436     # other utilities #########################################################
   436     # other utilities #########################################################
   437 
   437 
       
   438     def grant_permission(self, entity, group, pname, plabel=None):
       
   439         """insert a permission on an entity. Will have to commit the main
       
   440         connection to be considered
       
   441         """
       
   442         pname = unicode(pname)
       
   443         plabel = plabel and unicode(plabel) or unicode(group)
       
   444         e = entity.eid
       
   445         with security_enabled(self.session, False, False):
       
   446             peid = self.execute(
       
   447             'INSERT CWPermission X: X name %(pname)s, X label %(plabel)s,'
       
   448             'X require_group G, E require_permission X '
       
   449             'WHERE G name %(group)s, E eid %(e)s',
       
   450             locals())[0][0]
       
   451         return peid
       
   452 
   438     @contextmanager
   453     @contextmanager
   439     def temporary_appobjects(self, *appobjects):
   454     def temporary_appobjects(self, *appobjects):
   440         self.vreg._loadedmods.setdefault(self.__module__, {})
   455         self.vreg._loadedmods.setdefault(self.__module__, {})
   441         for obj in appobjects:
   456         for obj in appobjects:
   442             self.vreg.register(obj)
   457             self.vreg.register(obj)
   444             yield
   459             yield
   445         finally:
   460         finally:
   446             for obj in appobjects:
   461             for obj in appobjects:
   447                 self.vreg.unregister(obj)
   462                 self.vreg.unregister(obj)
   448 
   463 
   449     # vregistry inspection utilities ###########################################
   464     def assertModificationDateGreater(self, entity, olddate):
       
   465         entity.cw_attr_cache.pop('modification_date', None)
       
   466         self.failUnless(entity.modification_date > olddate)
       
   467 
       
   468 
       
   469     # workflow utilities #######################################################
       
   470 
       
   471     def assertPossibleTransitions(self, entity, expected):
       
   472         transitions = entity.cw_adapt_to('IWorkflowable').possible_transitions()
       
   473         self.assertListEqual(sorted(tr.name for tr in transitions),
       
   474                              sorted(expected))
       
   475 
       
   476 
       
   477     # views and actions registries inspection ##################################
   450 
   478 
   451     def pviews(self, req, rset):
   479     def pviews(self, req, rset):
   452         return sorted((a.__regid__, a.__class__)
   480         return sorted((a.__regid__, a.__class__)
   453                       for a in self.vreg['views'].possible_views(req, rset=rset))
   481                       for a in self.vreg['views'].possible_views(req, rset=rset))
   454 
   482