
Python3 reorganized the standard library and moved several functions to different modules. Six provides a consistent interface to them through the fake six.moves module. However, the urlparse, urllib2, etc modules have been combined into one module which Six does not support so do it the old fashioned way. Change-Id: Ieb7cc7ee2a4a97807873cfe2fc3fa0a5cf3c3980 Signed-off-by: Chuck Short <chuck.short@canonical.com>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
import re
|
|
import sys
|
|
|
|
import fixtures
|
|
from six import moves
|
|
from testtools import matchers
|
|
|
|
from cinderclient import exceptions
|
|
import cinderclient.shell
|
|
from cinderclient.tests import utils
|
|
|
|
|
|
class ShellTest(utils.TestCase):
|
|
|
|
FAKE_ENV = {
|
|
'OS_USERNAME': 'username',
|
|
'OS_PASSWORD': 'password',
|
|
'OS_TENANT_NAME': 'tenant_name',
|
|
'OS_AUTH_URL': 'http://no.where',
|
|
}
|
|
|
|
# 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]))
|
|
|
|
def shell(self, argstr):
|
|
orig = sys.stdout
|
|
try:
|
|
sys.stdout = moves.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 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',
|
|
]
|
|
help_text = self.shell('help')
|
|
for r in required:
|
|
self.assertThat(help_text,
|
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|
|
|
|
def test_help_on_subcommand(self):
|
|
required = [
|
|
'.*?^usage: cinder list',
|
|
'.*?(?m)^List all the volumes.',
|
|
]
|
|
help_text = self.shell('help list')
|
|
for r in required:
|
|
self.assertThat(help_text,
|
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|