--- a/server/test/unittest_migractions.py Tue Jul 02 17:09:04 2013 +0200
+++ b/server/test/unittest_migractions.py Mon Jan 13 13:47:47 2014 +0100
@@ -71,6 +71,22 @@
CubicWebTC.tearDown(self)
self.repo.vreg['etypes'].clear_caches()
+ def test_add_attribute_bool(self):
+ self.assertFalse('yesno' in self.schema)
+ self.session.create_entity('Note')
+ self.commit()
+ self.mh.cmd_add_attribute('Note', 'yesno')
+ self.assertTrue('yesno' in self.schema)
+ self.assertEqual(self.schema['yesno'].subjects(), ('Note',))
+ self.assertEqual(self.schema['yesno'].objects(), ('Boolean',))
+ self.assertEqual(self.schema['Note'].default('yesno'), False)
+ # test default value set on existing entities
+ note = self.session.execute('Note X').get_entity(0, 0)
+ self.assertEqual(note.yesno, False)
+ # test default value set for next entities
+ self.assertEqual(self.session.create_entity('Note').yesno, False)
+ self.mh.rollback()
+
def test_add_attribute_int(self):
self.assertFalse('whatever' in self.schema)
self.session.create_entity('Note')
@@ -81,12 +97,13 @@
self.assertTrue('whatever' in self.schema)
self.assertEqual(self.schema['whatever'].subjects(), ('Note',))
self.assertEqual(self.schema['whatever'].objects(), ('Int',))
- self.assertEqual(self.schema['Note'].default('whatever'), 2)
+ self.assertEqual(self.schema['Note'].default('whatever'), 0)
# test default value set on existing entities
note = self.session.execute('Note X').get_entity(0, 0)
- self.assertEqual(note.whatever, 2)
+ self.assertIsInstance(note.whatever, int)
+ self.assertEqual(note.whatever, 0)
# test default value set for next entities
- self.assertEqual(self.session.create_entity('Note').whatever, 2)
+ self.assertEqual(self.session.create_entity('Note').whatever, 0)
# test attribute order
orderdict2 = dict(self.mh.rqlexec('Any RTN, O WHERE X name "Note", RDEF from_entity X, '
'RDEF relation_type RT, RDEF ordernum O, RT name RTN'))
@@ -126,9 +143,14 @@
def test_add_datetime_with_default_value_attribute(self):
self.assertFalse('mydate' in self.schema)
- self.assertFalse('shortpara' in self.schema)
+ self.assertFalse('oldstyledefaultdate' in self.schema)
+ self.assertFalse('newstyledefaultdate' in self.schema)
self.mh.cmd_add_attribute('Note', 'mydate')
+ self.mh.cmd_add_attribute('Note', 'oldstyledefaultdate')
+ self.mh.cmd_add_attribute('Note', 'newstyledefaultdate')
self.assertTrue('mydate' in self.schema)
+ self.assertTrue('oldstyledefaultdate' in self.schema)
+ self.assertTrue('newstyledefaultdate' in self.schema)
self.assertEqual(self.schema['mydate'].subjects(), ('Note', ))
self.assertEqual(self.schema['mydate'].objects(), ('Date', ))
testdate = date(2005, 12, 13)
@@ -136,8 +158,13 @@
eid2 = self.mh.rqlexec('INSERT Note N: N mydate %(mydate)s', {'mydate' : testdate})[0][0]
d1 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid1})[0][0]
d2 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X mydate D', {'x': eid2})[0][0]
+ d3 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X oldstyledefaultdate D', {'x': eid1})[0][0]
+ d4 = self.mh.rqlexec('Any D WHERE X eid %(x)s, X newstyledefaultdate D', {'x': eid1})[0][0]
self.assertEqual(d1, date.today())
self.assertEqual(d2, testdate)
+ myfavoritedate = date(2013, 1, 1)
+ self.assertEqual(d3, myfavoritedate)
+ self.assertEqual(d4, myfavoritedate)
self.mh.rollback()
def test_drop_chosen_constraints_ctxmanager(self):
@@ -369,14 +396,14 @@
'X description D')[0][0],
'title for this person')
rinorder = [n for n, in cursor.execute(
- 'Any N ORDERBY O WHERE X is CWAttribute, X relation_type RT, RT name N,'
+ 'Any N ORDERBY O,N WHERE X is CWAttribute, X relation_type RT, RT name N,'
'X from_entity FE, FE name "Personne",'
'X ordernum O')]
expected = [u'nom', u'prenom', u'sexe', u'promo', u'ass', u'adel', u'titre',
- u'web', u'tel', u'fax', u'datenaiss', u'tzdatenaiss', u'test',
+ u'web', u'tel', u'fax', u'datenaiss', u'test', u'tzdatenaiss',
u'description', u'firstname',
u'creation_date', u'cwuri', u'modification_date']
- self.assertEqual(rinorder, expected)
+ self.assertEqual(expected, rinorder)
# test permissions synchronization ####################################
# new rql expr to add note entity
@@ -388,8 +415,8 @@
self.assertEqual(eexpr.reverse_read_permission, ())
self.assertEqual(eexpr.reverse_delete_permission, ())
self.assertEqual(eexpr.reverse_update_permission, ())
- # no more rqlexpr to delete and add para attribute
- self.assertFalse(self._rrqlexpr_rset('add', 'para'))
+ self.assertTrue(self._rrqlexpr_rset('add', 'para'))
+ # no rqlexpr to delete para attribute
self.assertFalse(self._rrqlexpr_rset('delete', 'para'))
# new rql expr to add ecrit_par relation
rexpr = self._rrqlexpr_entity('add', 'ecrit_par')
@@ -417,28 +444,33 @@
self.assertEqual(len(self._rrqlexpr_rset('delete', 'concerne')), len(delete_concerne_rqlexpr))
self.assertEqual(len(self._rrqlexpr_rset('add', 'concerne')), len(add_concerne_rqlexpr))
# * migrschema involve:
- # * 7 rqlexprs deletion (2 in (Affaire read + Societe + travaille) + 1
- # in para attribute)
+ # * 7 erqlexprs deletions (2 in (Affaire + Societe + Note.para) + 1 Note.something
+ # * 2 rrqlexprs deletions (travaille)
# * 1 update (Affaire update)
# * 2 new (Note add, ecrit_par add)
- # * 2 implicit new for attributes update_permission (Note.para, Personne.test)
+ # * 2 implicit new for attributes (Note.para, Person.test)
# remaining orphan rql expr which should be deleted at commit (composite relation)
- self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression, '
- 'NOT ET1 read_permission X, NOT ET2 add_permission X, '
- 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0],
- 7+1)
+ # unattached expressions -> pending deletion on commit
+ self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "ERQLExpression",'
+ 'NOT ET1 read_permission X, NOT ET2 add_permission X, '
+ 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0],
+ 7)
+ self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression, X exprtype "RRQLExpression",'
+ 'NOT ET1 read_permission X, NOT ET2 add_permission X, '
+ 'NOT ET3 delete_permission X, NOT ET4 update_permission X')[0][0],
+ 2)
# finally
self.assertEqual(cursor.execute('Any COUNT(X) WHERE X is RQLExpression')[0][0],
- nbrqlexpr_start + 1 + 2 + 2)
+ nbrqlexpr_start + 1 + 2 + 2 + 2)
self.mh.commit()
# unique_together test
self.assertEqual(len(self.schema.eschema('Personne')._unique_together), 1)
- self.assertItemsEqual(self.schema.eschema('Personne')._unique_together[0],
+ self.assertCountEqual(self.schema.eschema('Personne')._unique_together[0],
('nom', 'prenom', 'datenaiss'))
rset = cursor.execute('Any C WHERE C is CWUniqueTogetherConstraint, C constraint_of ET, ET name "Personne"')
self.assertEqual(len(rset), 1)
relations = [r.name for r in rset.get_entity(0, 0).relations]
- self.assertItemsEqual(relations, ('nom', 'prenom', 'datenaiss'))
+ self.assertCountEqual(relations, ('nom', 'prenom', 'datenaiss'))
def _erqlexpr_rset(self, action, ertype):
rql = 'RQLExpression X WHERE ET is CWEType, ET %s_permission X, ET name %%(name)s' % action