cubicweb/server/test/unittest_migractions.py
changeset 11414 69ea7be0373a
parent 11362 ebe75d73acdd
child 11415 f87da59faea1
--- a/cubicweb/server/test/unittest_migractions.py	Thu Jun 30 13:42:16 2016 +0200
+++ b/cubicweb/server/test/unittest_migractions.py	Thu Jul 07 14:10:45 2016 +0200
@@ -22,6 +22,7 @@
 from datetime import date
 from contextlib import contextmanager
 import tempfile
+from hashlib import md5
 
 from logilab.common.testlib import unittest_main, Tags, tag, with_tempdir
 from logilab.common import tempattr
@@ -113,6 +114,14 @@
         assert result, 'no table %s' % tablename
         return dict((x[0], (x[1], x[2])) for x in result)
 
+    def table_constraints(self, mh, tablename):
+        result = mh.sqlexec(
+            "SELECT DISTINCT constraint_name FROM information_schema.constraint_column_usage "
+            "WHERE LOWER(table_name) = '%(table)s' AND constraint_name LIKE 'cstr%%'"
+            % {'table': tablename.lower()})
+        assert result, 'no table %s' % tablename
+        return set(x[0] for x in result)
+
 
 class MigrationCommandsTC(MigrationTC):
 
@@ -585,6 +594,15 @@
             relations = [r.name for r in rset.get_entity(0, 0).relations]
             self.assertCountEqual(relations, ('nom', 'prenom', 'datenaiss'))
 
+            # serialized constraint changed
+            constraints = self.table_constraints(mh, 'cw_Personne')
+            self.assertEqual(len(constraints), 1, constraints)
+            rdef = migrschema['promo'].rdefs['Personne', 'String']
+            cstr = rdef.constraint_by_type('StaticVocabularyConstraint')
+            cstrname = 'cstr' + md5((rdef.subject.type + rdef.rtype.type + cstr.type() +
+                                     (cstr.serialize() or '')).encode('ascii')).hexdigest()
+            self.assertIn(cstrname, constraints)
+
     def _erqlexpr_rset(self, cnx, action, ertype):
         rql = 'RQLExpression X WHERE ET is CWEType, ET %s_permission X, ET name %%(name)s' % action
         return cnx.execute(rql, {'name': ertype})