test/unittest_schema.py
branchstable
changeset 7640 85ebdbbcb321
parent 7603 1302aa6ba4da
child 7642 64eee2a83bfa
--- a/test/unittest_schema.py	Thu Jul 07 16:47:34 2011 +0200
+++ b/test/unittest_schema.py	Mon Jul 11 09:18:18 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 PyFileReader
@@ -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')
 
@@ -319,5 +320,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()