# HG changeset patch # User Sylvain Thénault # Date 1294384423 -3600 # Node ID f4f67ea5436a6af4d948527c7b88f35f315cca5a # Parent f38963f7c91d2a52cd0fc3336bd0e78d80f4d06d [schema migration] add a test to ensure default value are considered diff -r f38963f7c91d -r f4f67ea5436a server/test/data/migratedapp/schema.py --- a/server/test/data/migratedapp/schema.py Thu Jan 06 18:53:00 2011 +0100 +++ b/server/test/data/migratedapp/schema.py Fri Jan 07 08:13:43 2011 +0100 @@ -15,9 +15,7 @@ # # You should have received a copy of the GNU Lesser General Public License along # with CubicWeb. If not, see . -""" - -""" +"""cw.server.migraction test""" from yams.buildobjs import (EntityType, RelationType, RelationDefinition, SubjectRelation, RichString, String, Int, Boolean, Datetime, Date) @@ -68,7 +66,7 @@ type = String(maxsize=1) unique_id = String(maxsize=1, required=True, unique=True) mydate = Date(default='TODAY') - shortpara = String(maxsize=64) + shortpara = String(maxsize=64, default='hop') ecrit_par = SubjectRelation('Personne', constraints=[RQLConstraint('S concerne A, O concerne A')]) attachment = SubjectRelation('File') diff -r f38963f7c91d -r f4f67ea5436a server/test/unittest_migractions.py --- a/server/test/unittest_migractions.py Thu Jan 06 18:53:00 2011 +0100 +++ b/server/test/unittest_migractions.py Fri Jan 07 08:13:43 2011 +0100 @@ -108,6 +108,8 @@ self.mh.rollback() def test_add_attribute_varchar(self): + self.request().create_entity('Note') + self.commit() self.failIf('shortpara' in self.schema) self.mh.cmd_add_attribute('Note', 'shortpara') self.failUnless('shortpara' in self.schema) @@ -117,6 +119,11 @@ notesql = self.mh.sqlexec("SELECT sql FROM sqlite_master WHERE type='table' and name='%sNote'" % SQL_PREFIX)[0][0] fields = dict(x.strip().split()[:2] for x in notesql.split('(', 1)[1].rsplit(')', 1)[0].split(',')) self.assertEqual(fields['%sshortpara' % SQL_PREFIX], 'varchar(64)') + req = self.request() + # test default value set on existing entities + self.assertEqual(req.execute('Note X').get_entity(0, 0).shortpara, 'hop') + # test default value set for next entities + self.assertEqual(req.create_entity('Note').shortpara, 'hop') self.mh.rollback() def test_add_datetime_with_default_value_attribute(self):