176 appid = 'data' |
176 appid = 'data' |
177 configcls = devtools.ApptestConfiguration |
177 configcls = devtools.ApptestConfiguration |
178 tags = TestCase.tags | Tags('cubicweb', 'cw_repo') |
178 tags = TestCase.tags | Tags('cubicweb', 'cw_repo') |
179 test_db_id = DEFAULT_EMPTY_DB_ID |
179 test_db_id = DEFAULT_EMPTY_DB_ID |
180 _cnxs = set() # establised connection |
180 _cnxs = set() # establised connection |
181 _cnx = None # current connection |
181 # stay on connection for leak detection purpose |
|
182 |
|
183 def __init__(self, *args, **kwargs): |
|
184 self._cnx = None # current connection |
|
185 self.repo = None |
|
186 self.websession = None |
|
187 super(CubicWebTC, self).__init__(*args, **kwargs) |
182 |
188 |
183 # Too much complicated stuff. the class doesn't need to bear the repo anymore |
189 # Too much complicated stuff. the class doesn't need to bear the repo anymore |
184 @classmethod |
190 def set_cnx(self, cnx): |
185 def set_cnx(cls, cnx): |
191 self._cnxs.add(cnx) |
186 cls._cnxs.add(cnx) |
192 self._cnx = cnx |
187 cls._cnx = cnx |
|
188 |
193 |
189 @property |
194 @property |
190 def cnx(self): |
195 def cnx(self): |
191 return self.__class__._cnx |
196 return self._cnx |
192 |
197 |
193 @classproperty |
198 @classproperty |
194 def config(cls): |
199 def config(cls): |
195 """return the configuration object |
200 """return the configuration object |
196 |
201 |
235 config.global_set_option('embed-allowed', re.compile('.*')) |
240 config.global_set_option('embed-allowed', re.compile('.*')) |
236 except Exception: # not in server only configuration |
241 except Exception: # not in server only configuration |
237 pass |
242 pass |
238 |
243 |
239 #XXX this doesn't need to a be classmethod anymore |
244 #XXX this doesn't need to a be classmethod anymore |
240 @classmethod |
245 def _init_repo(self): |
241 def _init_repo(cls): |
|
242 """init the repository and connection to it. |
246 """init the repository and connection to it. |
243 """ |
247 """ |
244 # setup configuration for test |
248 # setup configuration for test |
245 cls.init_config(cls.config) |
249 self.init_config(self.config) |
246 # get or restore and working db. |
250 # get or restore and working db. |
247 db_handler = devtools.get_test_db_handler(cls.config) |
251 db_handler = devtools.get_test_db_handler(self.config) |
248 db_handler.build_db_cache(cls.test_db_id, cls.pre_setup_database) |
252 db_handler.build_db_cache(self.test_db_id, self.pre_setup_database) |
249 |
253 |
250 cls.repo, cnx = db_handler.get_repo_and_cnx(cls.test_db_id) |
254 self.repo, cnx = db_handler.get_repo_and_cnx(self.test_db_id) |
251 # no direct assignation to cls.cnx anymore. |
255 # no direct assignation to cls.cnx anymore. |
252 # cnx is now an instance property that use a class protected attributes. |
256 # cnx is now an instance property that use a class protected attributes. |
253 cls.set_cnx(cnx) |
257 self.set_cnx(cnx) |
254 cls.websession = dbapi.DBAPISession(cnx, cls.admlogin) |
258 self.websession = dbapi.DBAPISession(cnx, self.admlogin) |
255 cls._orig_cnx = (cnx, cls.websession) |
259 self._orig_cnx = (cnx, self.websession) |
256 cls.config.repository = lambda x=None: cls.repo |
260 self.config.repository = lambda x=None: self.repo |
257 |
261 |
258 @classproperty |
262 @property |
259 def vreg(cls): |
263 def vreg(self): |
260 return cls.repo.vreg |
264 return self.repo.vreg |
261 |
265 |
262 def _close_cnx(self): |
266 def _close_cnx(self): |
263 for cnx in list(self._cnxs): |
267 for cnx in list(self._cnxs): |
264 if not cnx._closed: |
268 if not cnx._closed: |
265 cnx.rollback() |
269 cnx.rollback() |