From 948aa01d0c15c1728deb954b2764682705176c9c Mon Sep 17 00:00:00 2001 From: Dean Troyer Date: Mon, 11 May 2015 17:29:42 -0500 Subject: 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 --- os_client_config/tests/test_config.py | 50 +++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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') -- cgit v1.2.1