6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 |
8 |
9 from logilab.common.testlib import TestCase, unittest_main |
9 from logilab.common.testlib import TestCase, unittest_main |
10 |
10 |
11 from cubicweb.devtools.testlib import EnvBasedTC |
11 from cubicweb.devtools.testlib import CubicWebTC |
12 from cubicweb.appobject import Selector, AndSelector, OrSelector |
12 from cubicweb.appobject import Selector, AndSelector, OrSelector |
13 from cubicweb.selectors import implements, match_user_groups |
13 from cubicweb.selectors import implements, match_user_groups |
14 from cubicweb.interfaces import IDownloadable |
14 from cubicweb.interfaces import IDownloadable |
15 from cubicweb.web import action |
15 from cubicweb.web import action |
16 |
16 |
86 self.assertIs(csel.search_selector(implements), sel) |
86 self.assertIs(csel.search_selector(implements), sel) |
87 csel = AndSelector(Selector(), sel) |
87 csel = AndSelector(Selector(), sel) |
88 self.assertIs(csel.search_selector(implements), sel) |
88 self.assertIs(csel.search_selector(implements), sel) |
89 |
89 |
90 |
90 |
91 class ImplementsSelectorTC(EnvBasedTC): |
91 class ImplementsSelectorTC(CubicWebTC): |
92 def test_etype_priority(self): |
92 def test_etype_priority(self): |
93 req = self.request() |
93 req = self.request() |
94 cls = self.vreg['etypes'].etype_class('File') |
94 cls = self.vreg['etypes'].etype_class('File') |
95 anyscore = implements('Any').score_class(cls, req) |
95 anyscore = implements('Any').score_class(cls, req) |
96 idownscore = implements(IDownloadable).score_class(cls, req) |
96 idownscore = implements(IDownloadable).score_class(cls, req) |
101 def test_etype_inheritance_no_yams_inheritance(self): |
101 def test_etype_inheritance_no_yams_inheritance(self): |
102 cls = self.vreg['etypes'].etype_class('Personne') |
102 cls = self.vreg['etypes'].etype_class('Personne') |
103 self.failIf(implements('Societe').score_class(cls, self.request())) |
103 self.failIf(implements('Societe').score_class(cls, self.request())) |
104 |
104 |
105 |
105 |
106 class MatchUserGroupsTC(EnvBasedTC): |
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 id = 'yo' |
111 category = 'foo' |
111 category = 'foo' |
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.env.get_rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
121 rset, req = self.rset_and_req('Any G WHERE G is CWGroup, G name "managers"') |
122 self.failIf('yo' in dict(self.pactions(req, rset))) |
122 self.failIf('yo' in dict(self.pactions(req, rset))) |
123 # insert a new card, and check that we can use SomeAction on our object |
123 # insert a new card, and check that we can use SomeAction on our object |
124 self.execute('INSERT Card C: C title "zoubidou"') |
124 self.execute('INSERT Card C: C title "zoubidou"') |
125 self.commit() |
125 self.commit() |
126 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
126 rset, req = self.rset_and_req('Card C WHERE C title "zoubidou"') |
127 self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset)) |
127 self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset)) |
128 # make sure even managers can't use the action |
128 # make sure even managers can't use the action |
129 self.restore_connection() |
129 self.restore_connection() |
130 rset, req = self.env.get_rset_and_req('Card C WHERE C title "zoubidou"') |
130 rset, req = self.rset_and_req('Card C WHERE C title "zoubidou"') |
131 self.failIf('yo' in dict(self.pactions(req, rset))) |
131 self.failIf('yo' in dict(self.pactions(req, rset))) |
132 finally: |
132 finally: |
133 del self.vreg[SomeAction.__registry__][SomeAction.id] |
133 del self.vreg[SomeAction.__registry__][SomeAction.id] |
134 |
134 |
135 if __name__ == '__main__': |
135 if __name__ == '__main__': |