equal
deleted
inserted
replaced
311 test_db_id = DEFAULT_EMPTY_DB_ID |
311 test_db_id = DEFAULT_EMPTY_DB_ID |
312 |
312 |
313 # anonymous is logged by default in cubicweb test cases |
313 # anonymous is logged by default in cubicweb test cases |
314 anonymous_allowed = True |
314 anonymous_allowed = True |
315 |
315 |
|
316 @classmethod |
|
317 def setUpClass(cls): |
|
318 test_module_file = sys.modules[cls.__module__].__file__ |
|
319 assert 'config' not in cls.__dict__, ( |
|
320 '%s has a config class attribute before entering setUpClass. ' |
|
321 'Let CubicWebTC.setUpClass instantiate it and modify it afterwards.' % cls) |
|
322 cls.config = cls.configcls(cls.appid, test_module_file) |
|
323 cls.config.mode = 'test' |
|
324 |
316 def __init__(self, *args, **kwargs): |
325 def __init__(self, *args, **kwargs): |
317 self._admin_session = None |
326 self._admin_session = None |
318 self.repo = None |
327 self.repo = None |
319 self._open_access = set() |
328 self._open_access = set() |
320 super(CubicWebTC, self).__init__(*args, **kwargs) |
329 super(CubicWebTC, self).__init__(*args, **kwargs) |
362 login = text_type(db_handler.config.default_admin_config['login']) |
371 login = text_type(db_handler.config.default_admin_config['login']) |
363 self.admin_access = self.new_access(login) |
372 self.admin_access = self.new_access(login) |
364 self._admin_session = self.admin_access._session |
373 self._admin_session = self.admin_access._session |
365 |
374 |
366 # config management ######################################################## |
375 # config management ######################################################## |
367 |
|
368 @classproperty |
|
369 def config(cls): |
|
370 """return the configuration object |
|
371 |
|
372 Configuration is cached on the test class. |
|
373 """ |
|
374 if cls is CubicWebTC: |
|
375 # Prevent direct use of CubicWebTC directly to avoid database |
|
376 # caching issues |
|
377 return None |
|
378 try: |
|
379 return cls.__dict__['_config'] |
|
380 except KeyError: |
|
381 test_module_file = sys.modules[cls.__module__].__file__ |
|
382 config = cls._config = cls.configcls(cls.appid, test_module_file) |
|
383 config.mode = 'test' |
|
384 return config |
|
385 |
376 |
386 @classmethod # XXX could be turned into a regular method |
377 @classmethod # XXX could be turned into a regular method |
387 def init_config(cls, config): |
378 def init_config(cls, config): |
388 """configuration initialization hooks. |
379 """configuration initialization hooks. |
389 |
380 |
439 return server.debugged(debugmode) |
430 return server.debugged(debugmode) |
440 |
431 |
441 # default test setup and teardown ######################################### |
432 # default test setup and teardown ######################################### |
442 |
433 |
443 def setUp(self): |
434 def setUp(self): |
|
435 assert hasattr(self, 'config'), ( |
|
436 'It seems that CubicWebTC.setUpClass has not been called. ' |
|
437 'Missing super() call in %s?' % self.setUpClass) |
444 # monkey patch send mail operation so emails are sent synchronously |
438 # monkey patch send mail operation so emails are sent synchronously |
445 self._patch_SendMailOp() |
439 self._patch_SendMailOp() |
446 previous_failure = self.__class__.__dict__.get('_repo_init_failed') |
440 previous_failure = self.__class__.__dict__.get('_repo_init_failed') |
447 if previous_failure is not None: |
441 if previous_failure is not None: |
448 self.skipTest('repository is not initialised: %r' % previous_failure) |
442 self.skipTest('repository is not initialised: %r' % previous_failure) |