17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """cubicweb.server.hooks.syncschema unit and functional tests""" |
18 """cubicweb.server.hooks.syncschema unit and functional tests""" |
19 |
19 |
20 from logilab.common.testlib import unittest_main |
20 from logilab.common.testlib import unittest_main |
21 |
21 |
|
22 from yams.constraints import BoundaryConstraint |
22 from cubicweb import ValidationError, Binary |
23 from cubicweb import ValidationError, Binary |
23 from cubicweb.schema import META_RTYPES |
24 from cubicweb.schema import META_RTYPES |
24 from cubicweb.devtools import startpgcluster, stoppgcluster, PostgresApptestConfiguration |
25 from cubicweb.devtools import startpgcluster, stoppgcluster, PostgresApptestConfiguration |
25 from cubicweb.devtools.testlib import CubicWebTC |
26 from cubicweb.devtools.testlib import CubicWebTC |
26 from cubicweb.server.sqlutils import SQL_PREFIX |
27 from cubicweb.server.sqlutils import SQL_PREFIX |
380 cnx.commit() |
381 cnx.commit() |
381 cstr = rdef.constraint_by_type('StaticVocabularyConstraint') |
382 cstr = rdef.constraint_by_type('StaticVocabularyConstraint') |
382 self.assertEqual(cstr.values, (u'normal', u'auto', u'new')) |
383 self.assertEqual(cstr.values, (u'normal', u'auto', u'new')) |
383 cnx.execute('INSERT Transition T: T name "hop", T type "new"') |
384 cnx.execute('INSERT Transition T: T name "hop", T type "new"') |
384 |
385 |
|
386 def test_add_constraint(self): |
|
387 with self.admin_access.repo_cnx() as cnx: |
|
388 rdef = self.schema['EmailPart'].rdef('ordernum') |
|
389 cstr = BoundaryConstraint('>=', 0) |
|
390 cnx.execute('INSERT CWConstraint X: X value %(v)s, X cstrtype CT, ' |
|
391 'EDEF constrained_by X WHERE CT name %(ct)s, EDEF eid %(x)s', |
|
392 {'ct': cstr.__class__.__name__, 'v': cstr.serialize(), 'x': rdef.eid}) |
|
393 cnx.commit() |
|
394 cstr2 = rdef.constraint_by_type('BoundaryConstraint') |
|
395 self.assertEqual(cstr, cstr2) |
|
396 cstr3 = BoundaryConstraint('<=', 1000) |
|
397 cnx.execute('INSERT CWConstraint X: X value %(v)s, X cstrtype CT, ' |
|
398 'EDEF constrained_by X WHERE CT name %(ct)s, EDEF eid %(x)s', |
|
399 {'ct': cstr3.__class__.__name__, 'v': cstr3.serialize(), 'x': rdef.eid}) |
|
400 cnx.commit() |
|
401 self.assertCountEqual(rdef.constraints, [cstr, cstr3]) |
|
402 |
|
403 |
385 if __name__ == '__main__': |
404 if __name__ == '__main__': |
386 unittest_main() |
405 unittest_main() |