222 read_instance_schema = True # read schema from database |
222 read_instance_schema = True # read schema from database |
223 |
223 |
224 |
224 |
225 # test database handling ####################################################### |
225 # test database handling ####################################################### |
226 |
226 |
227 def init_test_database(config=None, configdir='data'): |
227 def init_test_database(config=None, appid='data', apphome=None): |
228 """init a test database for a specific driver""" |
228 """init a test database for a specific driver""" |
229 from cubicweb.dbapi import in_memory_cnx |
229 from cubicweb.dbapi import in_memory_cnx |
230 config = config or TestServerConfiguration(configdir) |
230 config = config or TestServerConfiguration(appid, apphome=apphome) |
231 sources = config.sources() |
231 sources = config.sources() |
232 driver = sources['system']['db-driver'] |
232 driver = sources['system']['db-driver'] |
233 if config.db_require_setup: |
233 if config.db_require_setup: |
234 if driver == 'sqlite': |
234 if driver == 'sqlite': |
235 init_test_database_sqlite(config) |
235 init_test_database_sqlite(config) |
333 return False |
333 return False |
334 |
334 |
335 def init_test_database_sqlite(config): |
335 def init_test_database_sqlite(config): |
336 """initialize a fresh sqlite databse used for testing purpose""" |
336 """initialize a fresh sqlite databse used for testing purpose""" |
337 # remove database file if it exists |
337 # remove database file if it exists |
|
338 dbfile = join(config.apphome, config.sources()['system']['db-name']) |
|
339 config.sources()['system']['db-name'] = dbfile |
338 if not reset_test_database_sqlite(config): |
340 if not reset_test_database_sqlite(config): |
339 # initialize the database |
341 # initialize the database |
340 import shutil |
342 import shutil |
341 from cubicweb.server import init_repository |
343 from cubicweb.server import init_repository |
342 init_repository(config, interactive=False) |
344 init_repository(config, interactive=False) |
343 dbfile = config.sources()['system']['db-name'] |
|
344 shutil.copy(dbfile, '%s-template' % dbfile) |
345 shutil.copy(dbfile, '%s-template' % dbfile) |
345 |
346 |
346 def install_sqlite_patch(querier): |
347 def install_sqlite_patch(querier): |
347 """This patch hotfixes the following sqlite bug : |
348 """This patch hotfixes the following sqlite bug : |
348 - http://www.sqlite.org/cvstrac/tktview?tn=1327,33 |
349 - http://www.sqlite.org/cvstrac/tktview?tn=1327,33 |