test: Split configuration generation so we can tweak values

Use get_default_config and write_config_file (which can be handed an optional
config object), so we can manipulate configuration options easily from within
the test function.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-02-16 09:31:14 +01:00
parent c1f75a6c94
commit 75ea403278

View File

@ -54,23 +54,36 @@ class OLITestLib():
cls.testdir = os.path.abspath( cls.testdir = os.path.abspath(
tempfile.mkdtemp(prefix='tmp_%s_'%suffix, tempfile.mkdtemp(prefix='tmp_%s_'%suffix,
dir=os.path.dirname(cls.cred_file))) dir=os.path.dirname(cls.cred_file)))
cls.create_config_file() cls.write_config_file()
return cls.testdir return cls.testdir
@classmethod @classmethod
def create_config_file(cls): def get_default_config(cls):
"""Creates a OLI configuration file """Creates a default ConfigParser file and returns it
It is created in testdir (so create_test_dir has to be called The returned config can be manipulated and then saved with
earlier) using the credentials information given (so they had to write_config_file()"""
be set earlier). Failure to do either of them will raise an
AssertionException."""
assert cls.cred_file != None assert cls.cred_file != None
assert cls.testdir != None assert cls.testdir != None
config = SafeConfigParser() config = SafeConfigParser()
config.readfp(default_conf) config.readfp(default_conf)
default_conf.seek(0) # rewind config_file to start
config.read(cls.cred_file) config.read(cls.cred_file)
config.set("general", "metadata", cls.testdir) config.set("general", "metadata", cls.testdir)
return config
@classmethod
def write_config_file(cls, config=None):
"""Creates a OLI configuration file
It is created in testdir (so create_test_dir has to be called
earlier) using the credentials information given (so they had
to be set earlier). Failure to do either of them will raise an
AssertionException. If config is None, a default one will be
used via get_default_config, otherwise it needs to be a config
object derived from that."""
if config is None:
config = cls.get_default_config()
localfolders = os.path.join(cls.testdir, 'mail') localfolders = os.path.join(cls.testdir, 'mail')
config.set("Repository Maildir", "localfolders", localfolders) config.set("Repository Maildir", "localfolders", localfolders)
with open(os.path.join(cls.testdir, 'offlineimap.conf'), "wa") as f: with open(os.path.join(cls.testdir, 'offlineimap.conf'), "wa") as f: