--- a/test/unittest_schema.py Mon Jul 11 09:15:54 2011 +0200
+++ b/test/unittest_schema.py Mon Jul 11 09:21:44 2011 +0200
@@ -26,7 +26,7 @@
from rql import RQLSyntaxError
-from yams import BadSchemaDefinition
+from yams import ValidationError, BadSchemaDefinition
from yams.constraints import SizeConstraint, StaticVocabularyConstraint
from yams.buildobjs import RelationDefinition, EntityType, RelationType
from yams.reader import fill_schema
@@ -37,6 +37,7 @@
RQLExpression, ERQLExpression, RRQLExpression,
normalize_expression, order_eschemas, guess_rrqlexpr_mainvars)
from cubicweb.devtools import TestServerConfiguration as TestConfiguration
+from cubicweb.devtools.testlib import CubicWebTC
DATADIR = join(dirname(__file__), 'data')
@@ -324,5 +325,14 @@
self.assertEqual(mainvars, set(['S', 'O']))
+class RQLConstraintTC(CubicWebTC):
+ def test_user_constraint(self):
+ cstr = RQLConstraint('U identity O')
+ anoneid = self.execute('Any X WHERE X login "anon"')[0][0]
+ self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid)
+ self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid),
+ None) # no validation error, constraint checked
+
+
if __name__ == '__main__':
unittest_main()