server/test/unittest_checkintegrity.py
branchstable
changeset 5958 9bfa823735e0
parent 5954 987086484876
child 6631 26c303c3f1aa
equal deleted inserted replaced
5957:b30946d1afa1 5958:9bfa823735e0
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """
       
    19 
    18 
    20 """
       
    21 import sys
    19 import sys
    22 from StringIO import StringIO
    20 from StringIO import StringIO
    23 from logilab.common.testlib import TestCase, unittest_main
    21 from logilab.common.testlib import TestCase, unittest_main
    24 from cubicweb.devtools import init_test_database
    22 from cubicweb.devtools import init_test_database
    25 
    23 
    26 
    24 
    27 from cubicweb.server.checkintegrity import check
    25 from cubicweb.server.checkintegrity import check, reindex_entities
    28 
    26 
    29 class CheckIntegrityTC(TestCase):
    27 class CheckIntegrityTC(TestCase):
    30     def test(self):
    28     def setUp(self):
    31         repo, cnx = init_test_database()
    29         self.repo, self.cnx = init_test_database()
       
    30         self.execute = self.cnx.cursor().execute
       
    31         self.session = self.repo._sessions[self.cnx.sessionid]
    32         sys.stderr = sys.stdout = StringIO()
    32         sys.stderr = sys.stdout = StringIO()
    33         try:
    33 
    34             check(repo, cnx, ('entities', 'relations', 'text_index', 'metadata'),
    34     def tearDown(self):
    35                   reindex=True, fix=True, withpb=False)
    35         sys.stderr = sys.__stderr__
    36         finally:
    36         sys.stdout = sys.__stdout__
    37             sys.stderr = sys.__stderr__
    37         self.cnx.close()
    38             sys.stdout = sys.__stdout__
    38         self.repo.shutdown()
    39         repo.shutdown()
    39 
       
    40     def test_checks(self):
       
    41         check(self.repo, self.cnx, ('entities', 'relations', 'text_index', 'metadata'),
       
    42               reindex=False, fix=True, withpb=False)
       
    43 
       
    44     def test_reindex_all(self):
       
    45         self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')
       
    46         self.session.commit(False)
       
    47         self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
       
    48         reindex_entities(self.repo.schema, self.session, withpb=False)
       
    49         self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
       
    50 
       
    51     def test_reindex_etype(self):
       
    52         self.execute('INSERT Personne X: X nom "toto", X prenom "tutu"')
       
    53         self.execute('INSERT Affaire X: X ref "toto"')
       
    54         self.session.commit(False)
       
    55         reindex_entities(self.repo.schema, self.session, withpb=False,
       
    56                          etypes=('Personne',))
       
    57         self.failUnless(self.execute('Any X WHERE X has_text "tutu"'))
       
    58         self.failUnless(self.execute('Any X WHERE X has_text "toto"'))
    40 
    59 
    41 if __name__ == '__main__':
    60 if __name__ == '__main__':
    42     unittest_main()
    61     unittest_main()