From 491e295412fceead7cf0c6c9cdd44904541e4044 Mon Sep 17 00:00:00 2001 From: Jason Gerard DeRose Date: Mon, 27 Oct 2008 16:08:17 -0600 Subject: Unit test for CLI.boostrap() now checks that -e overrides and values from config files are merged in correctly --- tests/test_ipalib/test_cli.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/test_ipalib/test_cli.py') diff --git a/tests/test_ipalib/test_cli.py b/tests/test_ipalib/test_cli.py index 39959270..389bb52c 100644 --- a/tests/test_ipalib/test_cli.py +++ b/tests/test_ipalib/test_cli.py @@ -76,6 +76,24 @@ class DummyAPI(object): pass +config_cli = """ +[global] + +from_cli_conf = set in cli.conf +""" + +config_default = """ +[global] + +from_default_conf = set in default.conf + +# Make sure cli.conf is loaded first: +from_cli_conf = overridden in default.conf +""" + + + + class test_CLI(ClassChecker): """ Test the `ipalib.cli.CLI` class. @@ -147,6 +165,7 @@ class test_CLI(ClassChecker): """ Test the `ipalib.cli.CLI.bootstrap` method. """ + # Test with empty argv (o, api, home) = self.new() keys = tuple(api.env) assert api.isdone('bootstrap') is False @@ -160,3 +179,25 @@ class test_CLI(ClassChecker): assert str(e) == 'CLI.bootstrap() already called' assert api.env.verbose is False assert api.env.context == 'cli' + keys = tuple(api.env) + added = ( + 'my_key', + 'whatever', + 'from_default_conf', + 'from_cli_conf' + ) + for key in added: + assert key not in api.env + assert key not in keys + + # Test with a populated argv + argv = ['-e', 'my_key=my_val,whatever=Hello'] + (o, api, home) = self.new(argv) + home.write(config_default, '.ipa', 'default.conf') + home.write(config_cli, '.ipa', 'cli.conf') + o.bootstrap() + assert api.env.my_key == 'my_val' + assert api.env.whatever == 'Hello' + assert api.env.from_default_conf == 'set in default.conf' + assert api.env.from_cli_conf == 'set in cli.conf' + assert list(api.env) == sorted(keys + added) -- cgit