test/unittest_selectors.py
branchtls-sprint
changeset 1571 e9ad2724659d
parent 1473 717dea3362c0
child 1640 65b60f177eb1
--- 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()