# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1241080413 -7200 # Node ID e9ad2724659dae4615d67147b95f403ad3ab5cce # Parent 5c40d9fb4e8d424f10e1e08a168f0e0d17f7992b tests depends on the bootstrap cube diff -r 5c40d9fb4e8d -r e9ad2724659d test/data/bootstrap_cubes --- a/test/data/bootstrap_cubes Thu Apr 30 10:32:51 2009 +0200 +++ b/test/data/bootstrap_cubes Thu Apr 30 10:33:33 2009 +0200 @@ -1,1 +1,1 @@ -file, tag +card, file, tag diff -r 5c40d9fb4e8d -r e9ad2724659d test/unittest_selectors.py --- a/test/unittest_selectors.py Thu Apr 30 10:32:51 2009 +0200 +++ b/test/unittest_selectors.py Thu Apr 30 10:33:33 2009 +0200 @@ -11,6 +11,7 @@ from cubicweb.vregistry import Selector, AndSelector, OrSelector from cubicweb.selectors import implements from cubicweb.interfaces import IDownloadable +from cubicweb.web import action class _1_(Selector): def __call__(self, *args, **kwargs): @@ -100,6 +101,35 @@ cls = self.vreg.etype_class('Personne') self.failIf(implements('Societe').score_class(cls, self.request())) + +class MatchUserGroupsTC(EnvBasedTC): + def test_owners_group(self): + """tests usage of 'owners' group with match_user_group""" + class SomeAction(action.Action): + id = 'yo' + category = 'foo' + __select__ = match_user_groups('owners') + self.vreg.register_vobject_class(SomeAction) + self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) + try: + # login as a simple user + self.create_user('john') + self.login('john') + # it should not be possible to use SomeAction not owned objects + rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') + self.failIf('foo' in self.pactions(req, rset)) + # insert a new card, and check that we can use SomeAction on our object + self.execute('INSERT Card C: C title "zoubidou"') + self.commit() + rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') + self.failUnless('foo' in self.pactions(req, rset)) + # make sure even managers can't use the action + self.restore_connection() + rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') + self.failIf('foo' in self.pactions(req, rset)) + finally: + del self.vreg[SomeAction.__registry__][SomeAction.id] + if __name__ == '__main__': unittest_main()