[schema] #847739: test and fix bad permission on TrInfo.comment stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 08 Apr 2010 09:07:54 +0200
branchstable
changeset 5179 f08943f22334
parent 5178 42285e33b01c
child 5180 25c3269b2232
[schema] #847739: test and fix bad permission on TrInfo.comment
schemas/bootstrap.py
test/unittest_schema.py
--- a/schemas/bootstrap.py	Wed Apr 07 14:53:35 2010 +0200
+++ b/schemas/bootstrap.py	Thu Apr 08 09:07:54 2010 +0200
@@ -311,8 +311,9 @@
 def post_build_callback(schema):
     """set attributes permissions for schema/workflow entities"""
     from cubicweb.schema import SCHEMA_TYPES, WORKFLOW_TYPES, META_RTYPES
+    wftypes = WORKFLOW_TYPES - set(('TrInfo',))
     for eschema in schema.entities():
-        if eschema in SCHEMA_TYPES or eschema in WORKFLOW_TYPES:
+        if eschema in SCHEMA_TYPES or eschema in wftypes:
             for rschema in eschema.subject_relations():
                 if rschema.final and not rschema in META_RTYPES:
                     rdef = eschema.rdef(rschema)
--- a/test/unittest_schema.py	Wed Apr 07 14:53:35 2010 +0200
+++ b/test/unittest_schema.py	Thu Apr 08 09:07:54 2010 +0200
@@ -241,6 +241,17 @@
         self.failUnless('has_text' in schema['CWUser'].subject_relations())
         self.failIf('has_text' in schema['EmailAddress'].subject_relations())
 
+    def test_permission_settings(self):
+        schema = loader.load(config)
+        aschema = schema['TrInfo'].rdef('comment')
+        self.assertEquals(aschema.get_groups('read'),
+                          set(('managers', 'users', 'guests')))
+        self.assertEquals(aschema.get_rqlexprs('read'),
+                          ())
+        self.assertEquals(aschema.get_groups('update'),
+                          set(('managers',)))
+        self.assertEquals([x.expression for x in aschema.get_rqlexprs('update')],
+                          ['U has_update_permission X'])
 
 class BadSchemaRQLExprTC(TestCase):
     def setUp(self):
@@ -257,16 +268,20 @@
         self.assertEquals(str(ex), msg)
 
     def test_rrqlexpr_on_etype(self):
-        self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on ToTo, use an ERQLExpression")
+        self._test('rrqlexpr_on_eetype.py',
+                   "can't use RRQLExpression on ToTo, use an ERQLExpression")
 
     def test_erqlexpr_on_rtype(self):
-        self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression")
+        self._test('erqlexpr_on_ertype.py',
+                   "can't use ERQLExpression on relation ToTo toto TuTu, use a RRQLExpression")
 
     def test_rqlexpr_on_rtype_read(self):
-        self._test('rqlexpr_on_ertype_read.py', "can't use rql expression for read permission of relation ToTo toto TuTu")
+        self._test('rqlexpr_on_ertype_read.py',
+                   "can't use rql expression for read permission of relation ToTo toto TuTu")
 
     def test_rrqlexpr_on_attr(self):
-        self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
+        self._test('rrqlexpr_on_attr.py',
+                   "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
 
 
 class NormalizeExpressionTC(TestCase):
@@ -277,8 +292,10 @@
 
 class RQLExpressionTC(TestCase):
     def test_comparison(self):
-        self.assertEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWUser', 'X', 0))
-        self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0), ERQLExpression('X is CWGroup', 'X', 0))
+        self.assertEquals(ERQLExpression('X is CWUser', 'X', 0),
+                          ERQLExpression('X is CWUser', 'X', 0))
+        self.assertNotEquals(ERQLExpression('X is CWUser', 'X', 0),
+                             ERQLExpression('X is CWGroup', 'X', 0))
 
 class GuessRrqlExprMainVarsTC(TestCase):
     def test_exists(self):