2014-07-07 17:48:35 +03:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2013-09-02 23:42:41 -04:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import fixtures
|
2014-06-25 11:48:37 +03:00
|
|
|
from six import moves
|
2013-09-02 23:42:41 -04:00
|
|
|
from testtools import matchers
|
|
|
|
|
2013-09-03 14:37:34 +03:00
|
|
|
from manilaclient import exceptions
|
2014-10-20 11:51:16 +03:00
|
|
|
from manilaclient import shell
|
|
|
|
from manilaclient.tests.unit import utils
|
2013-09-02 23:42:41 -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',
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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:
|
2014-06-25 11:48:37 +03:00
|
|
|
sys.stdout = moves.StringIO()
|
2014-10-20 11:51:16 +03:00
|
|
|
_shell = shell.OpenStackManilaShell()
|
2013-09-02 23:42:41 -04:00
|
|
|
_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: ',
|
2015-02-13 11:11:44 +08:00
|
|
|
'.*?^\s+create\s+Creates a new share '
|
|
|
|
'\(NFS, CIFS, GlusterFS or HDFS\).',
|
2014-05-27 21:51:39 +02:00
|
|
|
'.*?(?m)^See "manila help COMMAND" for help '
|
2014-07-07 17:28:58 +03:00
|
|
|
'on a specific command.',
|
2013-09-02 23:42:41 -04:00
|
|
|
]
|
|
|
|
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 = [
|
2013-09-05 13:32:38 +03:00
|
|
|
'.*?^usage: manila list',
|
2014-09-30 04:34:07 -04:00
|
|
|
'.*?(?m)^List NAS shares with filters.',
|
2013-09-02 23:42:41 -04:00
|
|
|
]
|
|
|
|
help_text = self.shell('help list')
|
|
|
|
for r in required:
|
|
|
|
self.assertThat(help_text,
|
|
|
|
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
|