Files
python-blazarclient/blazarclient/tests/test_shell.py
Masahito Muroi 581c1170a3 Migrate Python namespace from climateclient to blazarclient
The python-blazarclient repository has been using the climateclient
namespace.

This patch converts the climateclient namespace to the blazarclient
namespace. Additionally, some classes, methods and variables that
include 'climate' in their name are also changed to 'blazar'.

Change-Id: Ibf900f9a8a7a7bfb0b6b213545b9cbf121ce0df7
Closes-Bug: #1662735
Closes-Bug: #1311746
2017-02-21 21:53:05 +00:00

95 lines
3.0 KiB
Python

# Copyright (c) 2014 Mirantis Inc.
#
# 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.
import re
import six
import sys
import fixtures
#note(n.s.): you may need it later
#import mock
import testtools
#note(n.s.): you may need it later
#from blazarclient import client as blazar_client
#from blazarclient import exception
from blazarclient import shell
from blazarclient import tests
FAKE_ENV = {'OS_USERNAME': 'username',
'OS_PASSWORD': 'password',
'OS_TENANT_NAME': 'tenant_name',
'OS_AUTH_URL': 'http://no.where'}
class BlazarShellTestCase(tests.TestCase):
def make_env(self, exclude=None, fake_env=FAKE_ENV):
env = dict((k, v) for k, v in fake_env.items() if k != exclude)
self.useFixture(fixtures.MonkeyPatch('os.environ', env))
def setUp(self):
super(BlazarShellTestCase, self).setUp()
#Create shell for non-specific tests
self.blazar_shell = shell.BlazarShell()
def shell(self, argstr, exitcodes=(0,)):
orig = sys.stdout
orig_stderr = sys.stderr
try:
sys.stdout = six.StringIO()
sys.stderr = six.StringIO()
_shell = shell.BlazarShell()
_shell.initialize_app(argstr.split())
except SystemExit:
exc_type, exc_value, exc_traceback = sys.exc_info()
self.assertIn(exc_value.code, exitcodes)
finally:
stdout = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = orig
stderr = sys.stderr.getvalue()
sys.stderr.close()
sys.stderr = orig_stderr
return (stdout, stderr)
def test_help_unknown_command(self):
self.assertRaises(ValueError, self.shell, 'bash-completion')
@testtools.skip('lol')
def test_bash_completion(self):
stdout, stderr = self.shell('bash-completion')
# just check we have some output
required = [
'.*--matching',
'.*--wrap',
'.*help',
'.*secgroup-delete-rule',
'.*--priority']
for r in required:
self.assertThat((stdout + stderr),
testtools.matchers.MatchesRegex(
r, re.DOTALL | re.MULTILINE))
@testtools.skip('lol')
def test_authenticate_user(self):
obj = shell.BlazarShell()
obj.initialize_app('list-leases')
obj.options.os_token = 'aaaa-bbbb-cccc'
obj.options.os_cacert = 'cert'
obj.authenticate_user()