diff options
author | Jenkins <jenkins@review.openstack.org> | 2012-05-21 16:32:35 -0400 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2012-05-21 16:32:35 -0400 |
commit | 471704df644eced17026c280b0aab9e549718e14 (patch) | |
tree | c2d8d0ec74fa45e0b61ca4b2153fb5b0e7bf490d /tests/test_shell.py | |
download | python-cinderclient-0.0.tar.gz |
Initial split from python-novaclient.0.0
Diffstat (limited to 'tests/test_shell.py')
-rw-r--r-- | tests/test_shell.py | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/tests/test_shell.py b/tests/test_shell.py new file mode 100644 index 0000000..902aec5 --- /dev/null +++ b/tests/test_shell.py @@ -0,0 +1,75 @@ +import cStringIO +import os +import httplib2 +import sys + +from cinderclient import exceptions +import cinderclient.shell +from tests import utils + + +class ShellTest(utils.TestCase): + + # Patch os.environ to avoid required auth info. + def setUp(self): + global _old_env + fake_env = { + 'OS_USERNAME': 'username', + 'OS_PASSWORD': 'password', + 'OS_TENANT_NAME': 'tenant_name', + 'OS_AUTH_URL': 'http://no.where', + } + _old_env, os.environ = os.environ, fake_env.copy() + + def shell(self, argstr): + orig = sys.stdout + try: + sys.stdout = cStringIO.StringIO() + _shell = cinderclient.shell.OpenStackCinderShell() + _shell.main(argstr.split()) + except SystemExit: + exc_type, exc_value, exc_traceback = sys.exc_info() + self.assertEqual(exc_value.code, 0) + finally: + out = sys.stdout.getvalue() + sys.stdout.close() + sys.stdout = orig + + return out + + def tearDown(self): + global _old_env + os.environ = _old_env + + def test_help_unknown_command(self): + self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo') + + def test_debug(self): + httplib2.debuglevel = 0 + self.shell('--debug help') + assert httplib2.debuglevel == 1 + + def test_help(self): + required = [ + '^usage: ', + '(?m)^\s+create\s+Add a new volume.', + '(?m)^See "cinder help COMMAND" for help on a specific command', + ] + for argstr in ['--help', 'help']: + help_text = self.shell(argstr) + for r in required: + self.assertRegexpMatches(help_text, r) + + def test_help_on_subcommand(self): + required = [ + '^usage: cinder list', + '(?m)^List all the volumes.', + ] + argstrings = [ + 'list --help', + 'help list', + ] + for argstr in argstrings: + help_text = self.shell(argstr) + for r in required: + self.assertRegexpMatches(help_text, r) |