--- a/test/unittest_selectors.py Thu May 07 16:33:22 2009 +0200
+++ b/test/unittest_selectors.py Thu May 07 16:42:34 2009 +0200
@@ -9,8 +9,9 @@
from cubicweb.devtools.testlib import EnvBasedTC
from cubicweb.vregistry import Selector, AndSelector, OrSelector
-from cubicweb.selectors import implements
+from cubicweb.selectors import implements, match_user_groups
from cubicweb.interfaces import IDownloadable
+from cubicweb.web import action
class _1_(Selector):
def __call__(self, *args, **kwargs):
@@ -100,6 +101,36 @@
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._loadedmods[__name__] = {}
+ 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('yo' in dict(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('yo' in dict(self.pactions(req, rset)), 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('yo' in dict(self.pactions(req, rset)))
+ finally:
+ del self.vreg[SomeAction.__registry__][SomeAction.id]
+
if __name__ == '__main__':
unittest_main()