cubicweb/server/test/unittest_migractions.py
changeset 11899 bf6106b91633
parent 11767 432f87a63057
child 11929 fcbd6b251d81
equal deleted inserted replaced
11898:c5d3382f14e9 11899:bf6106b91633
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """unit tests for module cubicweb.server.migractions"""
    18 """unit tests for module cubicweb.server.migractions"""
    19 
    19 
    20 import os
    20 import os
    21 import os.path as osp
    21 import os.path as osp
       
    22 import sys
    22 from datetime import date
    23 from datetime import date
    23 from contextlib import contextmanager
    24 from contextlib import contextmanager
    24 import tempfile
    25 import tempfile
    25 
    26 
    26 from logilab.common.testlib import unittest_main, Tags, tag
    27 from logilab.common.testlib import unittest_main, Tags, tag
    75     def _init_repo(self):
    76     def _init_repo(self):
    76         super(MigrationTC, self)._init_repo()
    77         super(MigrationTC, self)._init_repo()
    77         # we have to read schema from the database to get eid for schema entities
    78         # we have to read schema from the database to get eid for schema entities
    78         self.repo.set_schema(self.repo.deserialize_schema(), resetvreg=False)
    79         self.repo.set_schema(self.repo.deserialize_schema(), resetvreg=False)
    79         # hack to read the schema from data/migrschema
    80         # hack to read the schema from data/migrschema
    80         config = self.config
    81 
    81         config.appid = osp.join(self.appid, 'migratedapp')
    82         @contextmanager
    82         config._apphome = osp.join(HERE, config.appid)
    83         def temp_app(config, appid, apphome):
    83         global migrschema
    84             old = config.apphome, config.appid
    84         migrschema = config.load_schema()
    85             sys.path.remove(old[0])
    85         config.appid = self.appid
    86             sys.path.insert(0, apphome)
    86         config._apphome = osp.join(HERE, self.appid)
    87             config._apphome, config.appid = apphome, appid
       
    88             try:
       
    89                 yield config
       
    90             finally:
       
    91                 sys.path.remove(apphome)
       
    92                 sys.path.insert(0, old[0])
       
    93                 config._apphome, config.appid = old
       
    94 
       
    95         appid = osp.join(self.appid, 'migratedapp')
       
    96         apphome = osp.join(HERE, appid)
       
    97         with temp_app(self.config, appid, apphome) as config:
       
    98             global migrschema
       
    99             migrschema = config.load_schema()
    87 
   100 
    88     def setUp(self):
   101     def setUp(self):
    89         self.configcls.cls_adjust_sys_path()
   102         self.configcls.cls_adjust_sys_path()
    90         super(MigrationTC, self).setUp()
   103         super(MigrationTC, self).setUp()
    91 
   104