24 |
24 |
25 from logilab.common.testlib import TestCase, unittest_main |
25 from logilab.common.testlib import TestCase, unittest_main |
26 |
26 |
27 from rql import RQLSyntaxError |
27 from rql import RQLSyntaxError |
28 |
28 |
29 from yams import BadSchemaDefinition |
29 from yams import ValidationError, BadSchemaDefinition |
30 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
30 from yams.constraints import SizeConstraint, StaticVocabularyConstraint |
31 from yams.buildobjs import RelationDefinition, EntityType, RelationType |
31 from yams.buildobjs import RelationDefinition, EntityType, RelationType |
32 from yams.reader import fill_schema |
32 from yams.reader import fill_schema |
33 |
33 |
34 from cubicweb.schema import ( |
34 from cubicweb.schema import ( |
35 CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader, |
35 CubicWebSchema, CubicWebEntitySchema, CubicWebSchemaLoader, |
36 RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint, |
36 RQLConstraint, RQLUniqueConstraint, RQLVocabularyConstraint, |
37 RQLExpression, ERQLExpression, RRQLExpression, |
37 RQLExpression, ERQLExpression, RRQLExpression, |
38 normalize_expression, order_eschemas, guess_rrqlexpr_mainvars) |
38 normalize_expression, order_eschemas, guess_rrqlexpr_mainvars) |
39 from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
39 from cubicweb.devtools import TestServerConfiguration as TestConfiguration |
|
40 from cubicweb.devtools.testlib import CubicWebTC |
40 |
41 |
41 DATADIR = join(dirname(__file__), 'data') |
42 DATADIR = join(dirname(__file__), 'data') |
42 |
43 |
43 # build a dummy schema ######################################################## |
44 # build a dummy schema ######################################################## |
44 |
45 |
322 def test_exists(self): |
323 def test_exists(self): |
323 mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3, C concerns S)')) |
324 mainvars = guess_rrqlexpr_mainvars(normalize_expression('NOT EXISTS(O team_competition C, C level < 3, C concerns S)')) |
324 self.assertEqual(mainvars, set(['S', 'O'])) |
325 self.assertEqual(mainvars, set(['S', 'O'])) |
325 |
326 |
326 |
327 |
|
328 class RQLConstraintTC(CubicWebTC): |
|
329 def test_user_constraint(self): |
|
330 cstr = RQLConstraint('U identity O') |
|
331 anoneid = self.execute('Any X WHERE X login "anon"')[0][0] |
|
332 self.assertRaises(ValidationError, cstr.repo_check, self.session, 1, 'rel', anoneid) |
|
333 self.assertEqual(cstr.repo_check(self.session, 1, self.session.user.eid), |
|
334 None) # no validation error, constraint checked |
|
335 |
|
336 |
327 if __name__ == '__main__': |
337 if __name__ == '__main__': |
328 unittest_main() |
338 unittest_main() |