| 1 |
# (C) Copyright 2014-2017 Hewlett Packard Enterprise Development LP |
| 2 |
# Copyright 2017 FUJITSU LIMITED |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 13 |
# implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
|
| 17 |
from unittest import mock |
| 18 |
|
| 19 |
from oslotest import base |
| 20 |
|
| 21 |
from monascaclient import shell |
| 22 |
|
| 23 |
|
| 24 |
class TestMonascaShell(base.BaseTestCase): |
| 25 |
|
| 26 |
@mock.patch('monascaclient.shell.auth') |
| 27 |
def test_should_use_auth_plugin_option_parser(self, auth): |
| 28 |
auth.build_auth_plugins_option_parser = apop = mock.Mock() |
| 29 |
shell.MonascaShell().run([]) |
| 30 |
apop.assert_called_once() |
| 31 |
|
| 32 |
def test_should_specify_monasca_args(self): |
| 33 |
expected_args = [ |
| 34 |
'--monasca-api-url', |
| 35 |
'--monasca-api-version', |
| 36 |
'--monasca_api_url', |
| 37 |
'--monasca_api_version', |
| 38 |
] |
| 39 |
|
| 40 |
parser = mock.Mock() |
| 41 |
parser.add_argument = aa = mock.Mock() |
| 42 |
shell.MonascaShell._append_monasca_args(parser) |
| 43 |
|
| 44 |
aa.assert_called() |
| 45 |
for mc in aa.mock_calls: |
| 46 |
name = mc[1][0] |
| 47 |
self.assertIn(name, expected_args) |
| 48 |
|
| 49 |
@mock.patch('monascaclient.shell.importutils') |
| 50 |
def test_should_load_commands_based_on_api_version(self, iu): |
| 51 |
iu.import_versioned_module = ivm = mock.Mock() |
| 52 |
|
| 53 |
instance = shell.MonascaShell() |
| 54 |
instance.options = mock.Mock() |
| 55 |
instance.options.monasca_api_version = version = mock.Mock() |
| 56 |
|
| 57 |
instance._find_actions = mock.Mock() |
| 58 |
|
| 59 |
instance._load_commands() |
| 60 |
|
| 61 |
ivm.assert_called_once_with('monascaclient', version, 'shell') |