diff options
author | Dean Troyer <dtroyer@gmail.com> | 2015-05-11 17:29:42 -0500 |
---|---|---|
committer | Dean Troyer <dtroyer@gmail.com> | 2015-05-12 13:44:10 -0500 |
commit | 948aa01d0c15c1728deb954b2764682705176c9c (patch) | |
tree | b738b0e7db02a6eff87635a154f0f818a299e107 | |
parent | 2f1e6c13bee31a7d43ef80847d764648afdb9578 (diff) | |
download | os-client-config-948aa01d0c15c1728deb954b2764682705176c9c.tar.gz |
Add tests for OSC usage
OSC uses os-client-config as an intermediate handler in the
argparse-to-final-options sequence.
* Validate the expected usage of the argparse arguement to get_one_cloud().
This turned out to be a problem with the way set_defaults() was implemented
and has been withdrawn until set_defaults is re-worked as a kwarg to
OpenStackCloud.__init__()
* Validate setting the default auth_type value
Change-Id: Idae91962f05d787cecf4a59fac01e9321bc69687
-rw-r--r-- | os_client_config/tests/test_config.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py index ae573a6..f4bf6db 100644 --- a/os_client_config/tests/test_config.py +++ b/os_client_config/tests/test_config.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse import os import fixtures @@ -61,3 +62,52 @@ class TestConfig(base.TestCase): cc = c.get_one_cloud(cloud='_test_cloud_', auth={'username': 'user'}) self.assertEqual('user', cc.auth['username']) self.assertEqual('testpass', cc.auth['password']) + + +class TestConfigArgparse(base.TestCase): + + def setUp(self): + super(TestConfigArgparse, self).setUp() + + self.options = argparse.Namespace( + region_name='other-test-region', + snack_type='cookie', + ) + + def test_get_one_cloud_argparse(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + + cc = c.get_one_cloud(cloud='_test_cloud_', argparse=self.options) + self._assert_cloud_details(cc) + self.assertEqual(cc.region_name, 'other-test-region') + self.assertEqual(cc.snack_type, 'cookie') + + def test_get_one_cloud_just_argparse(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + + cc = c.get_one_cloud(cloud='', argparse=self.options) + self.assertIsNone(cc.cloud) + self.assertNotIn('username', cc.auth) + self.assertEqual(cc.region_name, 'other-test-region') + self.assertEqual(cc.snack_type, 'cookie') + + def test_get_one_cloud_no_argparse(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + + cc = c.get_one_cloud(cloud='_test_cloud_', argparse=None) + self._assert_cloud_details(cc) + self.assertEqual(cc.region_name, 'test-region') + self.assertIsNone(cc.snack_type) + + +class TestConfigDefault(base.TestCase): + + def test_set_no_default(self): + c = config.OpenStackConfig(config_files=[self.cloud_yaml], + vendor_files=[self.vendor_yaml]) + cc = c.get_one_cloud(cloud='_test_cloud_', argparse=None) + self._assert_cloud_details(cc) + self.assertEqual(cc.auth_type, 'password') |