--- a/test/unittest_schema.py Wed Nov 18 09:16:38 2009 +0100
+++ b/test/unittest_schema.py Thu Nov 19 12:55:47 2009 +0100
@@ -19,7 +19,7 @@
from yams.reader import PyFileReader
from cubicweb.schema import CubicWebSchema, CubicWebEntitySchema, \
- RQLConstraint, CubicWebSchemaLoader, ERQLExpression, RRQLExpression, \
+ RQLConstraint, CubicWebSchemaLoader, RQLExpression, ERQLExpression, RRQLExpression, \
normalize_expression, order_eschemas
from cubicweb.devtools import TestServerConfiguration as TestConfiguration
@@ -44,7 +44,7 @@
schema = CubicWebSchema('Test Schema')
enote = schema.add_entity_type(EntityType('Note'))
eaffaire = schema.add_entity_type(EntityType('Affaire'))
-eperson = schema.add_entity_type(EntityType('Personne', permissions=PERSONNE_PERMISSIONS))
+eperson = schema.add_entity_type(EntityType('Personne', __permissions__=PERSONNE_PERMISSIONS))
esociete = schema.add_entity_type(EntityType('Societe'))
RELS = (
@@ -73,12 +73,13 @@
for rel in RELS:
_from, _type, _to = rel.split()
if not _type.lower() in done:
- if _type == 'concerne':
- schema.add_relation_type(RelationType(_type, permissions=CONCERNE_PERMISSIONS))
- else:
- schema.add_relation_type(RelationType(_type))
+ schema.add_relation_type(RelationType(_type))
done[_type.lower()] = True
- schema.add_relation_def(RelationDefinition(_from, _type, _to))
+ if _type == 'concerne':
+ schema.add_relation_def(RelationDefinition(_from, _type, _to,
+ __permissions__=CONCERNE_PERMISSIONS))
+ else:
+ schema.add_relation_def(RelationDefinition(_from, _type, _to))
class CubicWebSchemaTC(TestCase):
@@ -94,26 +95,24 @@
self.assertEqual(schema.rschema('concerne').type, 'concerne')
def test_entity_perms(self):
- eperson.set_default_groups()
self.assertEqual(eperson.get_groups('read'), set(('managers', 'users', 'guests')))
self.assertEqual(eperson.get_groups('update'), set(('managers', 'owners',)))
self.assertEqual(eperson.get_groups('delete'), set(('managers', 'owners')))
self.assertEqual(eperson.get_groups('add'), set(('managers',)))
self.assertEqual([str(e) for e in eperson.get_rqlexprs('add')],
['Any X WHERE X travaille S, S owned_by U, X eid %(x)s, U eid %(u)s'])
- eperson.set_groups('read', ('managers',))
+ eperson.set_action_permissions('read', ('managers',))
self.assertEqual(eperson.get_groups('read'), set(('managers',)))
def test_relation_perms(self):
- rconcerne = schema.rschema('concerne')
- rconcerne.set_default_groups()
+ rconcerne = schema.rschema('concerne').rdef('Personne', 'Societe')
self.assertEqual(rconcerne.get_groups('read'), set(('managers', 'users', 'guests')))
self.assertEqual(rconcerne.get_groups('delete'), set(('managers',)))
self.assertEqual(rconcerne.get_groups('add'), set(('managers', )))
- rconcerne.set_groups('read', ('managers',))
+ rconcerne.set_action_permissions('read', ('managers',))
self.assertEqual(rconcerne.get_groups('read'), set(('managers',)))
self.assertEqual([str(e) for e in rconcerne.get_rqlexprs('add')],
- ['Any S WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s'])
+ ['Any S,U WHERE U has_update_permission S, S eid %(s)s, U eid %(u)s'])
def test_erqlexpression(self):
self.assertRaises(RQLSyntaxError, ERQLExpression, '1')
@@ -124,7 +123,7 @@
self.assertRaises(Exception, RRQLExpression, '1')
self.assertRaises(RQLSyntaxError, RRQLExpression, 'O X Y')
expr = RRQLExpression('U has_update_permission O')
- self.assertEquals(str(expr), 'Any O WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s')
+ self.assertEquals(str(expr), 'Any O,U WHERE U has_update_permission O, O eid %(o)s, U eid %(u)s')
loader = CubicWebSchemaLoader()
config = TestConfiguration('data')
@@ -215,9 +214,9 @@
self.assertListEquals(rels, ['bookmarked_by', 'created_by', 'for_user',
'identity', 'owned_by', 'wf_info_for'])
rschema = schema.rschema('relation_type')
- properties = rschema.rproperties('CWAttribute', 'CWRType')
- self.assertEquals(properties['cardinality'], '1*')
- constraints = properties['constraints']
+ properties = rschema.rdef('CWAttribute', 'CWRType')
+ self.assertEquals(properties.cardinality, '1*')
+ constraints = properties.constraints
self.failUnlessEqual(len(constraints), 1, constraints)
constraint = constraints[0]
self.failUnless(isinstance(constraint, RQLConstraint))
@@ -246,13 +245,13 @@
self._test('rrqlexpr_on_eetype.py', "can't use RRQLExpression on an entity type, use an ERQLExpression (ToTo)")
def test_erqlexpr_on_rtype(self):
- self._test('erqlexpr_on_ertype.py', "can't use ERQLExpression on a relation type, use a RRQLExpression (toto)")
+ 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 a relation type (toto)")
+ 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 a final relation type (eg attribute relation), use an ERQLExpression (attr)")
+ self._test('rrqlexpr_on_attr.py', "can't use RRQLExpression on attribute ToTo.attr[String], use an ERQLExpression")
class NormalizeExpressionTC(TestCase):
@@ -261,5 +260,9 @@
self.assertEquals(normalize_expression('X bla Y,Y blur Z , Z zigoulou X '),
'X bla Y, Y blur Z, Z zigoulou X')
+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))
if __name__ == '__main__':
unittest_main()