test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...) stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 29 Jun 2009 21:15:07 +0200
branchstable
changeset 2200 25bb65dc4559
parent 2199 bd0a0f219751
child 2201 ddc1f58c8e8b
test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
devtools/repotest.py
server/session.py
server/test/unittest_extlite.py
server/test/unittest_repository.py
server/test/unittest_schemaserial.py
--- a/devtools/repotest.py	Mon Jun 29 21:13:54 2009 +0200
+++ b/devtools/repotest.py	Mon Jun 29 21:15:07 2009 +0200
@@ -208,6 +208,7 @@
 
 
 class BasePlannerTC(BaseQuerierTC):
+    newsources = 0
     def setup(self):
         clear_cache(self.repo, 'rel_type_sources')
         clear_cache(self.repo, 'rel_type_sources')
@@ -220,7 +221,6 @@
         self.schema = self.o.schema
         self.sources = self.o._repo.sources
         self.system = self.sources[-1]
-        self.newsources = 0
         do_monkey_patch()
 
     def add_source(self, sourcecls, uri):
--- a/server/session.py	Mon Jun 29 21:13:54 2009 +0200
+++ b/server/session.py	Mon Jun 29 21:15:07 2009 +0200
@@ -266,6 +266,7 @@
             assert not self.pending_operations
             self.transaction_data.clear()
             self._touch()
+            self.debug('commit session %s done (no db activity)', self.id)
             return
         if self.commit_state:
             return
@@ -307,6 +308,7 @@
             assert not self.pending_operations
             self.transaction_data.clear()
             self._touch()
+            self.debug('rollback session %s done (no db activity)', self.id)
             return
         try:
             while self.pending_operations:
--- a/server/test/unittest_extlite.py	Mon Jun 29 21:13:54 2009 +0200
+++ b/server/test/unittest_extlite.py	Mon Jun 29 21:15:07 2009 +0200
@@ -7,37 +7,32 @@
     sqlite_file = '_extlite_test.sqlite'
     def setUp(self):
         cnx1 = get_connection('sqlite', database=self.sqlite_file)
-        print 'SET IP'
         cu = cnx1.cursor()
         cu.execute('CREATE TABLE toto(name integer);')
         cnx1.commit()
         cnx1.close()
-        
+
     def tearDown(self):
         try:
             os.remove(self.sqlite_file)
         except:
             pass
+        
     def test(self):
         lock = threading.Lock()
-        
+
         def run_thread():
-            print 'run_thread'
             cnx2 = get_connection('sqlite', database=self.sqlite_file)
             lock.acquire()
-            print 't2 sel1'
             cu = cnx2.cursor()
             cu.execute('SELECT name FROM toto')
             self.failIf(cu.fetchall())
             cnx2.commit()
-            print 'done'
             lock.release()
             time.sleep(0.1)
             lock.acquire()
-            print 't2 sel2'
             cu.execute('SELECT name FROM toto')
             self.failUnless(cu.fetchall())
-            print 'done'
             lock.release()
 
         cnx1 = get_connection('sqlite', database=self.sqlite_file)
@@ -45,17 +40,13 @@
         thread = threading.Thread(target=run_thread)
         thread.start()
         cu = cnx1.cursor()
-        print 't1 sel'
         cu.execute('SELECT name FROM toto')
-        print 'done'
         lock.release()
         time.sleep(0.1)
         cnx1.commit()
         lock.acquire()
-        print 't1 insert'
         cu.execute("INSERT INTO toto(name) VALUES ('toto')")
         cnx1.commit()
-        print 'done'
         lock.release()
 
 if __name__ == '__main__':
--- a/server/test/unittest_repository.py	Mon Jun 29 21:13:54 2009 +0200
+++ b/server/test/unittest_repository.py	Mon Jun 29 21:15:07 2009 +0200
@@ -56,13 +56,12 @@
         namecol = SQL_PREFIX + 'name'
         finalcol = SQL_PREFIX + 'final'
         try:
-            sqlcursor = pool['system']
-            sqlcursor.execute('SELECT %s FROM %s WHERE %s is NULL' % (
+            cu = self.session.system_sql('SELECT %s FROM %s WHERE %s is NULL' % (
                 namecol, table, finalcol))
-            self.assertEquals(sqlcursor.fetchall(), [])
-            sqlcursor.execute('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s'
+            self.assertEquals(cu.fetchall(), [])
+            cu = self.session.system_sql('SELECT %s FROM %s WHERE %s=%%(final)s ORDER BY %s'
                               % (namecol, table, finalcol, namecol), {'final': 'TRUE'})
-            self.assertEquals(sqlcursor.fetchall(), [(u'Boolean',), (u'Bytes',),
+            self.assertEquals(cu.fetchall(), [(u'Boolean',), (u'Bytes',),
                                                      (u'Date',), (u'Datetime',),
                                                      (u'Decimal',),(u'Float',),
                                                      (u'Int',),
@@ -358,38 +357,36 @@
         entity.eid = -1
         entity.complete = lambda x: None
         self.repo.add_info(self.session, entity, self.repo.sources_by_uri['system'])
-        cursor = self.session.pool['system']
-        cursor.execute('SELECT * FROM entities WHERE eid = -1')
-        data = cursor.fetchall()
+        cu = self.session.system_sql('SELECT * FROM entities WHERE eid = -1')
+        data = cu.fetchall()
         self.assertIsInstance(data[0][3], datetime)
         data[0] = list(data[0])
         data[0][3] = None
         self.assertEquals(tuplify(data), [(-1, 'Personne', 'system', None, None)])
         self.repo.delete_info(self.session, -1)
         #self.repo.commit()
-        cursor.execute('SELECT * FROM entities WHERE eid = -1')
-        data = cursor.fetchall()
+        cu = self.session.system_sql('SELECT * FROM entities WHERE eid = -1')
+        data = cu.fetchall()
         self.assertEquals(data, [])
 
 
 class FTITC(RepositoryBasedTC):
 
     def test_reindex_and_modified_since(self):
-        cursor = self.session.pool['system']
         eidp = self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')[0][0]
         self.commit()
         ts = datetime.now()
         self.assertEquals(len(self.execute('Personne X WHERE X has_text "tutu"')), 1)
-        cursor.execute('SELECT mtime, eid FROM entities WHERE eid = %s' % eidp)
-        omtime = cursor.fetchone()[0]
+        cu = self.session.system_sql('SELECT mtime, eid FROM entities WHERE eid = %s' % eidp)
+        omtime = cu.fetchone()[0]
         # our sqlite datetime adapter is ignore seconds fraction, so we have to
         # ensure update is done the next seconds
         time.sleep(1 - (ts.second - int(ts.second)))
         self.execute('SET X nom "tata" WHERE X eid %(x)s', {'x': eidp}, 'x')
         self.commit()
         self.assertEquals(len(self.execute('Personne X WHERE X has_text "tutu"')), 1)
-        cursor.execute('SELECT mtime FROM entities WHERE eid = %s' % eidp)
-        mtime = cursor.fetchone()[0]
+        cu = self.session.system_sql('SELECT mtime FROM entities WHERE eid = %s' % eidp)
+        mtime = cu.fetchone()[0]
         self.failUnless(omtime < mtime)
         self.commit()
         date, modified, deleted = self.repo.entities_modified_since(('Personne',), omtime)
--- a/server/test/unittest_schemaserial.py	Mon Jun 29 21:13:54 2009 +0200
+++ b/server/test/unittest_schemaserial.py	Mon Jun 29 21:15:07 2009 +0200
@@ -94,7 +94,7 @@
             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
              {'rt': 'cardinality', 'oe': 'String', 'ctname': u'SizeConstraint', 'se': 'CWAttribute', 'value': u'max=2'}),
             ('INSERT CWConstraint X: X value %(value)s, X cstrtype CT, EDEF constrained_by X WHERE CT name %(ctname)s, EDEF relation_type ER, EDEF from_entity SE, EDEF to_entity OE, ER name %(rt)s, SE name %(se)s, OE name %(oe)s, EDEF is CWAttribute',
-             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'StaticVocabularyConstraint', 'se': 'CWAttribute', 'value': u"u'?1', u'11', u'??', u'1?'"}),
+             {'rt': 'cardinality', 'oe': 'String', 'ctname': u'StaticVocabularyConstraint', 'se': 'CWAttribute', 'value': u"u'?1', u'11'"}),
             ])