9 |
9 |
10 from cubicweb.devtools.testlib import EnvBasedTC |
10 from cubicweb.devtools.testlib import EnvBasedTC |
11 from cubicweb.vregistry import Selector, AndSelector, OrSelector |
11 from cubicweb.vregistry import Selector, AndSelector, OrSelector |
12 from cubicweb.selectors import implements |
12 from cubicweb.selectors import implements |
13 from cubicweb.interfaces import IDownloadable |
13 from cubicweb.interfaces import IDownloadable |
|
14 from cubicweb.web import action |
14 |
15 |
15 class _1_(Selector): |
16 class _1_(Selector): |
16 def __call__(self, *args, **kwargs): |
17 def __call__(self, *args, **kwargs): |
17 return 1 |
18 return 1 |
18 |
19 |
98 |
99 |
99 def test_etype_inheritance_no_yams_inheritance(self): |
100 def test_etype_inheritance_no_yams_inheritance(self): |
100 cls = self.vreg.etype_class('Personne') |
101 cls = self.vreg.etype_class('Personne') |
101 self.failIf(implements('Societe').score_class(cls, self.request())) |
102 self.failIf(implements('Societe').score_class(cls, self.request())) |
102 |
103 |
|
104 |
|
105 class MatchUserGroupsTC(EnvBasedTC): |
|
106 def test_owners_group(self): |
|
107 """tests usage of 'owners' group with match_user_group""" |
|
108 class SomeAction(action.Action): |
|
109 id = 'yo' |
|
110 category = 'foo' |
|
111 __select__ = match_user_groups('owners') |
|
112 self.vreg.register_vobject_class(SomeAction) |
|
113 self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
|
114 try: |
|
115 # login as a simple user |
|
116 self.create_user('john') |
|
117 self.login('john') |
|
118 # it should not be possible to use SomeAction not owned objects |
|
119 rset, req = self.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
|
120 self.failIf('foo' in self.pactions(req, rset)) |
|
121 # insert a new card, and check that we can use SomeAction on our object |
|
122 self.execute('INSERT Card C: C title "zoubidou"') |
|
123 self.commit() |
|
124 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
|
125 self.failUnless('foo' in self.pactions(req, rset)) |
|
126 # make sure even managers can't use the action |
|
127 self.restore_connection() |
|
128 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
|
129 self.failIf('foo' in self.pactions(req, rset)) |
|
130 finally: |
|
131 del self.vreg[SomeAction.__registry__][SomeAction.id] |
|
132 |
103 if __name__ == '__main__': |
133 if __name__ == '__main__': |
104 unittest_main() |
134 unittest_main() |
105 |
135 |