From b78dc19d9b47f3347a99394ee839c02f5127a986 Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Fri, 31 Oct 2014 13:58:39 +0100 Subject: Take plugin params from ENV rather than default The way the argparse options were being structured, if there was a default value set on the option it would use this value as the default and not check the environment variables. This is wrong, we expect the environment variables to be used and the default value to be the final fallback. Change-Id: Ifbd68c9de329c2e0c70824ba873caa579e8e86d0 Closes-Bug: #1388076 --- keystoneclient/tests/auth/test_cli.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'keystoneclient/tests/auth/test_cli.py') diff --git a/keystoneclient/tests/auth/test_cli.py b/keystoneclient/tests/auth/test_cli.py index fc09195..33c2868 100644 --- a/keystoneclient/tests/auth/test_cli.py +++ b/keystoneclient/tests/auth/test_cli.py @@ -13,6 +13,7 @@ import argparse import uuid +import fixtures import mock from oslo.config import cfg @@ -43,6 +44,13 @@ class CliTests(utils.TestCase): super(CliTests, self).setUp() self.p = argparse.ArgumentParser() + def env(self, name, value=None): + if value is not None: + # environment variables are always strings + value = str(value) + + return self.useFixture(fixtures.EnvironmentVariable(name, value)) + def test_creating_with_no_args(self): ret = cli.register_argparse_arguments(self.p, []) self.assertIsNone(ret) @@ -140,6 +148,18 @@ class CliTests(utils.TestCase): self.assertIs(utils.MockPlugin, klass) m.assert_called_once_with(name) + @utils.mock_plugin + def test_env_overrides_default_opt(self, m): + name = uuid.uuid4().hex + val = uuid.uuid4().hex + self.env('OS_A_STR', val) + + klass = cli.register_argparse_arguments(self.p, [], default=name) + opts = self.p.parse_args([]) + a = klass.load_from_argparse_arguments(opts) + + self.assertEqual(val, a['a_str']) + def test_deprecated_cli_options(self): TesterPlugin.register_argparse_arguments(self.p) val = uuid.uuid4().hex -- cgit v1.2.1