68 lines
2.0 KiB
Python
Raw Normal View History

import re
2012-05-21 16:32:35 -04:00
import sys
import fixtures
from six import moves
from testtools import matchers
from cinderclient import exceptions
2012-05-21 16:32:35 -04:00
import cinderclient.shell
from cinderclient.tests import utils
2012-05-21 16:32:35 -04:00
class ShellTest(utils.TestCase):
FAKE_ENV = {
'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where',
}
2012-05-21 16:32:35 -04:00
# Patch os.environ to avoid required auth info.
def setUp(self):
super(ShellTest, self).setUp()
for var in self.FAKE_ENV:
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
2012-05-21 16:32:35 -04:00
def shell(self, argstr):
orig = sys.stdout
try:
sys.stdout = moves.StringIO()
2012-05-21 16:32:35 -04:00
_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 test_help_unknown_command(self):
self.assertRaises(exceptions.CommandError, self.shell, 'help foofoo')
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',
2012-05-21 16:32:35 -04:00
]
help_text = self.shell('help')
for r in required:
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
2012-05-21 16:32:35 -04:00
def test_help_on_subcommand(self):
required = [
'.*?^usage: cinder list',
'.*?(?m)^List all the volumes.',
2012-05-21 16:32:35 -04:00
]
help_text = self.shell('help list')
for r in required:
self.assertThat(help_text,
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))