More comprehensive unit tests for os-client-config

This includes ensuring that yaml of a sane format can be loaded.

Change-Id: I698b3139b7e44f000d2a413d17e79914ef542a22
This commit is contained in:
Clint Byrum 2015-02-27 11:23:16 -08:00
parent 076e9bd9be
commit e483abccbb
2 changed files with 43 additions and 0 deletions

View File

@ -12,13 +12,54 @@
# License for the specific language governing permissions and limitations
# under the License.
import tempfile
import extras
import fixtures
import testtools
import yaml
from os_client_config import cloud_config
from os_client_config import config
class TestConfig(testtools.TestCase):
def get_config(self):
config = {
'clouds': {
'_test_cloud_': {
'auth': {
'username': 'testuser',
'password': 'testpass',
'project_name': 'testproject',
},
'region_name': 'test-region',
},
},
'cache': {'max_age': 1},
}
tdir = self.useFixture(fixtures.TempDir())
config['cache']['path'] = tdir.path
return config
def test_get_one_cloud(self):
c = config.OpenStackConfig()
self.assertIsInstance(c.get_one_cloud(), cloud_config.CloudConfig)
def test_get_one_cloud_with_config_files(self):
self.useFixture(fixtures.NestedTempfile())
with tempfile.NamedTemporaryFile() as cloud_yaml:
cloud_yaml.write(yaml.safe_dump(self.get_config()).encode('utf-8'))
cloud_yaml.flush()
c = config.OpenStackConfig(config_files=[cloud_yaml.name])
self.assertIsInstance(c.cloud_config, dict)
self.assertIn('cache', c.cloud_config)
self.assertIsInstance(c.cloud_config['cache'], dict)
self.assertIn('max_age', c.cloud_config['cache'])
self.assertIn('path', c.cloud_config['cache'])
cc = c.get_one_cloud('_test_cloud_')
self.assertIsInstance(cc, cloud_config.CloudConfig)
self.assertTrue(extras.safe_hasattr(cc, 'auth'))
self.assertIsInstance(cc.auth, dict)
self.assertIn('username', cc.auth)
self.assertEqual('testuser', cc.auth['username'])

View File

@ -5,6 +5,8 @@
hacking>=0.9.2,<0.10
coverage>=3.6
extras
fixtures>=0.3.14
discover
python-subunit
sphinx>=1.1.2