update tests to work with latest changes

This commit is contained in:
Martin Zibricky 2011-09-11 22:40:30 +02:00
parent 50e1964795
commit eef786f85c

View File

@ -34,14 +34,13 @@ import os
import sys import sys
import subprocess import subprocess
import logging import logging
import random
import string
import py.path import py.path
from PyQt4 import QtCore from PyQt4 import QtCore
from sqlalchemy.orm import clear_mappers from sqlalchemy.orm import clear_mappers
from openlp.core import main as openlp_main from openlp.core import main as openlp_main
from openlp.core.utils import AppLocation
from openlp.core.lib.db import Manager from openlp.core.lib.db import Manager
from openlp.plugins.songs.lib.db import init_schema from openlp.plugins.songs.lib.db import init_schema
@ -86,30 +85,29 @@ def pytest_funcarg__openlpapp(request):
return request.cached_setup(setup=setup, teardown=teardown, scope='module') return request.cached_setup(setup=setup, teardown=teardown, scope='module')
def _get_unique_qsettings(): # Clean up QSettings for all plugins
# unique QSettings group def _cleanup_qsettings():
unique = ''.join(random.choice(string.letters + string.digits) s = QtCore.QSettings()
for i in range(8)) keys = s.allKeys()
group_name = 'test_%s' % unique for k in keys:
settings = QtCore.QSettings() s.setValue(k, QtCore.QVariant(None))
settings.beginGroup(group_name)
settings.setValue(u'db type', QtCore.QVariant(u'sqlite'))
settings.endGroup()
return group_name
# Test function argument giving access to empty song database. # Test function argument giving access to empty song database.
def pytest_funcarg__empty_songs_db(request): def pytest_funcarg__empty_songs_db(request):
#def get_data_dir(section):
# return request.getfuncargvalue('tmpdir').strpath
def setup(): def setup():
tmpdir = request.getfuncargvalue('tmpdir') tmpdir = request.getfuncargvalue('tmpdir')
db_file_path = tmpdir.join('songs.sqlite') # override data dir
plugin_name = _get_unique_qsettings() AppLocation.BaseDir = tmpdir.strpath
manager = Manager(plugin_name, init_schema, manager = Manager('songs', init_schema)
db_file_path=db_file_path.strpath)
return manager return manager
def teardown(manager): def teardown(manager):
_cleanup_qsettings()
# sqlalchemy allows to map classess to only one database at a time # sqlalchemy allows to map classess to only one database at a time
clear_mappers() clear_mappers()
AppLocation.BaseDir = None
return request.cached_setup(setup=setup, teardown=teardown, scope='function') return request.cached_setup(setup=setup, teardown=teardown, scope='function')
@ -117,17 +115,19 @@ def pytest_funcarg__empty_songs_db(request):
def pytest_funcarg__songs_db(request): def pytest_funcarg__songs_db(request):
def setup(): def setup():
tmpdir = request.getfuncargvalue('tmpdir') tmpdir = request.getfuncargvalue('tmpdir')
db_file_path = tmpdir.join('songs.sqlite') # override data dir
AppLocation.BaseDir = tmpdir.strpath
datadir = tmpdir.mkdir(u'data').mkdir( u'songs')
# copy test data to tmpdir # copy test data to tmpdir
orig_db = py.path.local(SONGS_PATH).join('songs.sqlite') orig_db = py.path.local(SONGS_PATH).join('songs.sqlite')
orig_db.copy(db_file_path) orig_db.copy(datadir)
plugin_name = _get_unique_qsettings() manager = Manager('songs', init_schema)
manager = Manager(plugin_name, init_schema,
db_file_path=db_file_path.strpath)
return manager return manager
def teardown(manager): def teardown(manager):
_cleanup_qsettings()
# sqlalchemy allows to map classess to only one database at a time # sqlalchemy allows to map classess to only one database at a time
clear_mappers() clear_mappers()
AppLocation.BaseDir = None
return request.cached_setup(setup=setup, teardown=teardown, scope='function') return request.cached_setup(setup=setup, teardown=teardown, scope='function')