|
| 1 | +# Copyright 2013 Nebula Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | +# not use this file except in compliance with the License. You may obtain |
| 5 | +# a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | +# License for the specific language governing permissions and limitations |
| 13 | +# under the License. |
| 14 | +# |
| 15 | + |
| 16 | +"""Test module module""" |
| 17 | + |
| 18 | +import mock |
| 19 | + |
| 20 | +from openstackclient.common import module as osc_module |
| 21 | +from openstackclient.tests import fakes |
| 22 | +from openstackclient.tests import utils |
| 23 | + |
| 24 | + |
| 25 | +# NOTE(dtroyer): module_1 must match the version list filter (not --all) |
| 26 | +# currently == '*client*' |
| 27 | +module_name_1 = 'fakeclient' |
| 28 | +module_version_1 = '0.1.2' |
| 29 | +MODULE_1 = { |
| 30 | + '__version__': module_version_1, |
| 31 | +} |
| 32 | + |
| 33 | +module_name_2 = 'zlib' |
| 34 | +module_version_2 = '1.1' |
| 35 | +MODULE_2 = { |
| 36 | + '__version__': module_version_2, |
| 37 | +} |
| 38 | + |
| 39 | +MODULES = { |
| 40 | + module_name_1: fakes.FakeModule(module_name_1, module_version_1), |
| 41 | + module_name_2: fakes.FakeModule(module_name_2, module_version_2), |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | +@mock.patch.dict( |
| 46 | + 'openstackclient.common.module.sys.modules', |
| 47 | + values=MODULES, |
| 48 | + clear=True, |
| 49 | +) |
| 50 | +class TestModuleList(utils.TestCommand): |
| 51 | + |
| 52 | + def setUp(self): |
| 53 | + super(TestModuleList, self).setUp() |
| 54 | + |
| 55 | + # Get the command object to test |
| 56 | + self.cmd = osc_module.ListModule(self.app, None) |
| 57 | + |
| 58 | + def test_module_list_no_options(self): |
| 59 | + arglist = [] |
| 60 | + verifylist = [ |
| 61 | + ('all', False), |
| 62 | + ] |
| 63 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 64 | + |
| 65 | + # DisplayCommandBase.take_action() returns two tuples |
| 66 | + columns, data = self.cmd.take_action(parsed_args) |
| 67 | + |
| 68 | + # Additional modules may be present, just check our additions |
| 69 | + self.assertTrue(module_name_1 in columns) |
| 70 | + self.assertTrue(module_version_1 in data) |
| 71 | + |
| 72 | + def test_module_list_all(self): |
| 73 | + arglist = [ |
| 74 | + '--all', |
| 75 | + ] |
| 76 | + verifylist = [ |
| 77 | + ('all', True), |
| 78 | + ] |
| 79 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 80 | + |
| 81 | + # DisplayCommandBase.take_action() returns two tuples |
| 82 | + columns, data = self.cmd.take_action(parsed_args) |
| 83 | + |
| 84 | + # Additional modules may be present, just check our additions |
| 85 | + self.assertTrue(module_name_1 in columns) |
| 86 | + self.assertTrue(module_name_2 in columns) |
| 87 | + self.assertTrue(module_version_1 in data) |
| 88 | + self.assertTrue(module_version_2 in data) |
0 commit comments