equal
deleted
inserted
replaced
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
188 sourcefile = join(self.apphome, sourcefile) |
188 sourcefile = join(self.apphome, sourcefile) |
189 else: |
189 else: |
190 sourcefile = super(TestServerConfiguration, self).sources_file() |
190 sourcefile = super(TestServerConfiguration, self).sources_file() |
191 return sourcefile |
191 return sourcefile |
192 |
192 |
193 def sources(self): |
193 def read_sources_file(self): |
194 """By default, we run tests with the sqlite DB backend. One may use its |
194 """By default, we run tests with the sqlite DB backend. One may use its |
195 own configuration by just creating a 'sources' file in the test |
195 own configuration by just creating a 'sources' file in the test |
196 directory from wich tests are launched or by specifying an alternative |
196 directory from wich tests are launched or by specifying an alternative |
197 sources file using self.sourcefile. |
197 sources file using self.sourcefile. |
198 """ |
198 """ |
199 try: |
199 try: |
200 sources = super(TestServerConfiguration, self).sources() |
200 sources = super(TestServerConfiguration, self).read_sources_file() |
201 except ExecutionError: |
201 except ExecutionError: |
202 sources = {} |
202 sources = {} |
203 if not sources: |
203 if not sources: |
204 sources = DEFAULT_SOURCES |
204 sources = DEFAULT_SOURCES |
205 if 'admin' not in sources: |
205 if 'admin' not in sources: |
386 |
386 |
387 def get_cnx(self): |
387 def get_cnx(self): |
388 """return Connection object on the current repository""" |
388 """return Connection object on the current repository""" |
389 from cubicweb.dbapi import _repo_connect |
389 from cubicweb.dbapi import _repo_connect |
390 repo = self.get_repo() |
390 repo = self.get_repo() |
391 sources = self.config.sources() |
391 sources = self.config.read_sources_file() |
392 login = unicode(sources['admin']['login']) |
392 login = unicode(sources['admin']['login']) |
393 password = sources['admin']['password'] or 'xxx' |
393 password = sources['admin']['password'] or 'xxx' |
394 cnx = _repo_connect(repo, login, password=password) |
394 cnx = _repo_connect(repo, login, password=password) |
395 return cnx |
395 return cnx |
396 |
396 |
407 cnx = self.get_cnx() |
407 cnx = self.get_cnx() |
408 return repo, cnx |
408 return repo, cnx |
409 |
409 |
410 @property |
410 @property |
411 def system_source(self): |
411 def system_source(self): |
412 sources = self.config.sources() |
412 return self.config.system_source_config |
413 return sources['system'] |
|
414 |
413 |
415 @property |
414 @property |
416 def dbname(self): |
415 def dbname(self): |
417 return self.system_source['db-name'] |
416 return self.system_source['db-name'] |
418 |
417 |
689 return self.system_source['global-db-name'] |
688 return self.system_source['global-db-name'] |
690 |
689 |
691 def absolute_dbfile(self): |
690 def absolute_dbfile(self): |
692 """absolute path of current database file""" |
691 """absolute path of current database file""" |
693 dbfile = join(self._ensure_test_backup_db_dir(), |
692 dbfile = join(self._ensure_test_backup_db_dir(), |
694 self.config.sources()['system']['db-name']) |
693 self.system_source['db-name']) |
695 self.config.sources()['system']['db-name'] = dbfile |
694 self.system_source['db-name'] = dbfile |
696 return dbfile |
695 return dbfile |
697 |
696 |
698 def process_cache_entry(self, directory, dbname, db_id, entry): |
697 def process_cache_entry(self, directory, dbname, db_id, entry): |
699 return entry.get('sqlite') |
698 return entry.get('sqlite') |
700 |
699 |
820 # XXX a class method on Test ? |
819 # XXX a class method on Test ? |
821 def get_test_db_handler(config): |
820 def get_test_db_handler(config): |
822 handler = HCACHE.get(config) |
821 handler = HCACHE.get(config) |
823 if handler is not None: |
822 if handler is not None: |
824 return handler |
823 return handler |
825 sources = config.sources() |
824 driver = config.system_source_config['db-driver'] |
826 driver = sources['system']['db-driver'] |
|
827 key = (driver, config) |
825 key = (driver, config) |
828 handlerkls = HANDLERS.get(driver, None) |
826 handlerkls = HANDLERS.get(driver, None) |
829 if handlerkls is not None: |
827 if handlerkls is not None: |
830 handler = handlerkls(config) |
828 handler = handlerkls(config) |
831 if config.skip_db_create_and_restore: |
829 if config.skip_db_create_and_restore: |