test/unittest_selectors.py
changeset 3418 7b49fa7e942d
parent 2773 b2530e3e0afb
child 4252 6c4f109c2b03
equal deleted inserted replaced
3412:368c68ffb99e 3418:7b49fa7e942d
   105 
   105 
   106 class MatchUserGroupsTC(CubicWebTC):
   106 class MatchUserGroupsTC(CubicWebTC):
   107     def test_owners_group(self):
   107     def test_owners_group(self):
   108         """tests usage of 'owners' group with match_user_group"""
   108         """tests usage of 'owners' group with match_user_group"""
   109         class SomeAction(action.Action):
   109         class SomeAction(action.Action):
   110             id = 'yo'
   110             __regid__ = 'yo'
   111             category = 'foo'
   111             category = 'foo'
   112             __select__ = match_user_groups('owners')
   112             __select__ = match_user_groups('owners')
   113         self.vreg._loadedmods[__name__] = {}
   113         self.vreg._loadedmods[__name__] = {}
   114         self.vreg.register_appobject_class(SomeAction)
   114         self.vreg.register_appobject_class(SomeAction)
   115         self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
   115         self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions'])
   116         try:
   116         try:
   117             # login as a simple user
   117             # login as a simple user
   118             self.create_user('john')
   118             self.create_user('john')
   119             self.login('john')
   119             self.login('john')
   120             # it should not be possible to use SomeAction not owned objects
   120             # it should not be possible to use SomeAction not owned objects
   121             rset, req = self.rset_and_req('Any G WHERE G is CWGroup, G name "managers"')
   121             req = self.request()
       
   122             rset = req.execute('Any G WHERE G is CWGroup, G name "managers"')
   122             self.failIf('yo' in dict(self.pactions(req, rset)))
   123             self.failIf('yo' in dict(self.pactions(req, rset)))
   123             # insert a new card, and check that we can use SomeAction on our object
   124             # insert a new card, and check that we can use SomeAction on our object
   124             self.execute('INSERT Card C: C title "zoubidou"')
   125             self.execute('INSERT Card C: C title "zoubidou"')
   125             self.commit()
   126             self.commit()
   126             rset, req = self.rset_and_req('Card C WHERE C title "zoubidou"')
   127             req = self.request()
       
   128             rset = req.execute('Card C WHERE C title "zoubidou"')
   127             self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset))
   129             self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset))
   128             # make sure even managers can't use the action
   130             # make sure even managers can't use the action
   129             self.restore_connection()
   131             self.restore_connection()
   130             rset, req = self.rset_and_req('Card C WHERE C title "zoubidou"')
   132             req = self.request()
       
   133             rset = req.execute('Card C WHERE C title "zoubidou"')
   131             self.failIf('yo' in dict(self.pactions(req, rset)))
   134             self.failIf('yo' in dict(self.pactions(req, rset)))
   132         finally:
   135         finally:
   133             del self.vreg[SomeAction.__registry__][SomeAction.id]
   136             del self.vreg[SomeAction.__registry__][SomeAction.__regid__]
   134 
   137 
   135 if __name__ == '__main__':
   138 if __name__ == '__main__':
   136     unittest_main()
   139     unittest_main()
   137 
   140