[test] drop some warnings introduced by new test dabase handling stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 06 Apr 2011 16:00:56 +0200
branchstable
changeset 7186 287f2273917f
parent 7185 6e42b595e5df
child 7188 b2c45b7396fb
[test] drop some warnings introduced by new test dabase handling
server/__init__.py
server/test/unittest_checkintegrity.py
server/test/unittest_repository.py
--- a/server/__init__.py	Wed Apr 06 10:17:48 2011 +0200
+++ b/server/__init__.py	Wed Apr 06 16:00:56 2011 +0200
@@ -181,6 +181,7 @@
     session.execute('SET X owned_by U WHERE X is IN (CWGroup,CWSource), U eid %(u)s',
                     {'u': admin.eid})
     session.commit()
+    session.close()
     repo.shutdown()
     # reloging using the admin user
     config._cubes = None # avoid assertion error
@@ -204,7 +205,6 @@
     repo.system_source.init_creating()
     cnx.commit()
     cnx.close()
-    session.close()
     repo.shutdown()
     # restore initial configuration
     config.creating = False
--- a/server/test/unittest_checkintegrity.py	Wed Apr 06 10:17:48 2011 +0200
+++ b/server/test/unittest_checkintegrity.py	Wed Apr 06 16:00:56 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -19,14 +19,16 @@
 import sys
 from StringIO import StringIO
 from logilab.common.testlib import TestCase, unittest_main
-from cubicweb.devtools import init_test_database
+from cubicweb.devtools import get_test_db_handler, TestServerConfiguration
 
 
 from cubicweb.server.checkintegrity import check, reindex_entities
 
 class CheckIntegrityTC(TestCase):
     def setUp(self):
-        self.repo, self.cnx = init_test_database(apphome=self.datadir)
+        handler = get_test_db_handler(TestServerConfiguration(apphome=self.datadir))
+        handler.build_db_cache()
+        self.repo, self.cnx = handler.get_repo_and_cnx()
         self.execute = self.cnx.cursor().execute
         self.session = self.repo._sessions[self.cnx.sessionid]
         sys.stderr = sys.stdout = StringIO()
--- a/server/test/unittest_repository.py	Wed Apr 06 10:17:48 2011 +0200
+++ b/server/test/unittest_repository.py	Wed Apr 06 16:00:56 2011 +0200
@@ -1,5 +1,5 @@
 # -*- coding: iso-8859-1 -*-
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -105,7 +105,9 @@
         self.failIf(self.execute('Any X WHERE NOT X cw_source S'))
 
     def test_connect(self):
-        self.assert_(self.repo.connect(self.admlogin, password=self.admpassword))
+        cnxid = self.repo.connect(self.admlogin, password=self.admpassword)
+        self.assert_(cnxid)
+        self.repo.close(cnxid)
         self.assertRaises(AuthenticationError,
                           self.repo.connect, self.admlogin, password='nimportnawak')
         self.assertRaises(AuthenticationError,
@@ -133,7 +135,9 @@
                      {'login': u"barnabé", 'passwd': u"héhéhé".encode('UTF8')})
         repo.commit(cnxid)
         repo.close(cnxid)
-        self.assert_(repo.connect(u"barnabé", password=u"héhéhé".encode('UTF8')))
+        cnxid = repo.connect(u"barnabé", password=u"héhéhé".encode('UTF8'))
+        self.assert_(cnxid)
+        repo.close(cnxid)
 
     def test_rollback_on_commit_error(self):
         cnxid = self.repo.connect(self.admlogin, password=self.admpassword)
@@ -142,6 +146,7 @@
                           {'login': u"tutetute", 'passwd': 'tutetute'})
         self.assertRaises(ValidationError, self.repo.commit, cnxid)
         self.failIf(self.repo.execute(cnxid, 'CWUser X WHERE X login "tutetute"'))
+        self.repo.close(cnxid)
 
     def test_rollback_on_execute_validation_error(self):
         class ValidationErrorAfterHook(Hook):
@@ -234,6 +239,7 @@
         repo.commit(cnxid)
         result = repo.execute(cnxid, 'Personne X')
         self.assertEqual(result.rowcount, 1)
+        repo.close(cnxid)
 
     def test_transaction_base2(self):
         repo = self.repo
@@ -245,6 +251,7 @@
         repo.rollback(cnxid)
         result = repo.execute(cnxid, "Any U WHERE U in_group G, U login 'admin', G name 'guests'")
         self.assertEqual(result.rowcount, 0, result.rows)
+        repo.close(cnxid)
 
     def test_transaction_base3(self):
         repo = self.repo
@@ -259,6 +266,7 @@
         repo.rollback(cnxid)
         rset = repo.execute(cnxid, 'TrInfo T WHERE T wf_info_for X, X eid %(x)s', {'x': user.eid})
         self.assertEqual(len(rset), 0)
+        repo.close(cnxid)
 
     def test_transaction_interleaved(self):
         self.skipTest('implement me')
@@ -378,6 +386,7 @@
         self.assertEqual(repo.eid2extid(repo.system_source, 2, session), None)
         class dummysource: uri = 'toto'
         self.assertRaises(UnknownEid, repo.eid2extid, dummysource, 2, session)
+        repo.close(cnxid)
 
     def test_public_api(self):
         self.assertEqual(self.repo.get_schema(), self.repo.schema)