diff options
| author | Zuul <zuul@review.opendev.org> | 2019-05-18 18:47:43 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2019-05-18 18:47:43 +0000 |
| commit | 91bc0f35def33d49d293be4bd517678222c6b791 (patch) | |
| tree | 26315509feced3a47e1dd889563a5cabb2c7617f /openstackclient/tests | |
| parent | 875335b610091ebc5f2ae7704539e2ddf6d956bd (diff) | |
| parent | 1b2595a9594e1a6965e6086aad7782cf3e39bafa (diff) | |
| download | python-openstackclient-91bc0f35def33d49d293be4bd517678222c6b791.tar.gz | |
Merge "Remove code migrated to osc-lib long ago"
Diffstat (limited to 'openstackclient/tests')
| -rw-r--r-- | openstackclient/tests/unit/api/test_utils.py | 115 | ||||
| -rw-r--r-- | openstackclient/tests/unit/common/test_commandmanager.py | 107 | ||||
| -rw-r--r-- | openstackclient/tests/unit/image/v1/test_image.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/unit/image/v2/test_image.py | 2 |
4 files changed, 2 insertions, 224 deletions
diff --git a/openstackclient/tests/unit/api/test_utils.py b/openstackclient/tests/unit/api/test_utils.py deleted file mode 100644 index 1f528558..00000000 --- a/openstackclient/tests/unit/api/test_utils.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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. -# - -"""API Utilities Library Tests""" - -import copy - -from openstackclient.api import api -from openstackclient.api import utils as api_utils -from openstackclient.tests.unit.api import fakes as api_fakes - - -class TestBaseAPIFilter(api_fakes.TestSession): - """The filters can be tested independently""" - - def setUp(self): - super(TestBaseAPIFilter, self).setUp() - self.api = api.BaseAPI( - session=self.sess, - endpoint=self.BASE_URL, - ) - - self.input_list = [ - api_fakes.RESP_ITEM_1, - api_fakes.RESP_ITEM_2, - api_fakes.RESP_ITEM_3, - ] - - def test_simple_filter_none(self): - output = api_utils.simple_filter( - ) - self.assertIsNone(output) - - def test_simple_filter_no_attr(self): - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - ) - self.assertEqual(self.input_list, output) - - def test_simple_filter_attr_only(self): - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='status', - ) - self.assertEqual(self.input_list, output) - - def test_simple_filter_attr_value(self): - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='status', - value='', - ) - self.assertEqual([], output) - - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='status', - value='UP', - ) - self.assertEqual( - [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_3], - output, - ) - - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='fred', - value='UP', - ) - self.assertEqual([], output) - - def test_simple_filter_prop_attr_only(self): - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='b', - property_field='props', - ) - self.assertEqual(self.input_list, output) - - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='status', - property_field='props', - ) - self.assertEqual(self.input_list, output) - - def test_simple_filter_prop_attr_value(self): - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='b', - value=2, - property_field='props', - ) - self.assertEqual( - [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_2], - output, - ) - - output = api_utils.simple_filter( - copy.deepcopy(self.input_list), - attr='b', - value=9, - property_field='props', - ) - self.assertEqual([], output) diff --git a/openstackclient/tests/unit/common/test_commandmanager.py b/openstackclient/tests/unit/common/test_commandmanager.py deleted file mode 100644 index 0c6c99c0..00000000 --- a/openstackclient/tests/unit/common/test_commandmanager.py +++ /dev/null @@ -1,107 +0,0 @@ -# Copyright 2012-2013 OpenStack Foundation -# -# 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 mock - -from openstackclient.common import commandmanager -from openstackclient.tests.unit import utils - - -class FakeCommand(object): - - @classmethod - def load(cls): - return cls - - def __init__(self): - return - -FAKE_CMD_ONE = FakeCommand -FAKE_CMD_TWO = FakeCommand -FAKE_CMD_ALPHA = FakeCommand -FAKE_CMD_BETA = FakeCommand - - -class FakeCommandManager(commandmanager.CommandManager): - commands = {} - - def load_commands(self, namespace): - if namespace == 'test': - self.commands['one'] = FAKE_CMD_ONE - self.commands['two'] = FAKE_CMD_TWO - self.group_list.append(namespace) - elif namespace == 'greek': - self.commands['alpha'] = FAKE_CMD_ALPHA - self.commands['beta'] = FAKE_CMD_BETA - self.group_list.append(namespace) - - -class TestCommandManager(utils.TestCase): - - def test_add_command_group(self): - mgr = FakeCommandManager('test') - - # Make sure add_command() still functions - mock_cmd_one = mock.Mock() - mgr.add_command('mock', mock_cmd_one) - cmd_mock, name, args = mgr.find_command(['mock']) - self.assertEqual(mock_cmd_one, cmd_mock) - - # Find a command added in initialization - cmd_one, name, args = mgr.find_command(['one']) - self.assertEqual(FAKE_CMD_ONE, cmd_one) - - # Load another command group - mgr.add_command_group('greek') - - # Find a new command - cmd_alpha, name, args = mgr.find_command(['alpha']) - self.assertEqual(FAKE_CMD_ALPHA, cmd_alpha) - - # Ensure that the original commands were not overwritten - cmd_two, name, args = mgr.find_command(['two']) - self.assertEqual(FAKE_CMD_TWO, cmd_two) - - def test_get_command_groups(self): - mgr = FakeCommandManager('test') - - # Make sure add_command() still functions - mock_cmd_one = mock.Mock() - mgr.add_command('mock', mock_cmd_one) - cmd_mock, name, args = mgr.find_command(['mock']) - self.assertEqual(mock_cmd_one, cmd_mock) - - # Load another command group - mgr.add_command_group('greek') - - gl = mgr.get_command_groups() - self.assertEqual(['test', 'greek'], gl) - - def test_get_command_names(self): - mock_cmd_one = mock.Mock() - mock_cmd_one.name = 'one' - mock_cmd_two = mock.Mock() - mock_cmd_two.name = 'cmd two' - mock_pkg_resources = mock.Mock( - return_value=[mock_cmd_one, mock_cmd_two], - ) - with mock.patch( - 'pkg_resources.iter_entry_points', - mock_pkg_resources, - ) as iter_entry_points: - mgr = commandmanager.CommandManager('test') - iter_entry_points.assert_called_once_with('test') - cmds = mgr.get_command_names('test') - self.assertEqual(['one', 'cmd two'], cmds) diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py index ae578d91..6babd4ff 100644 --- a/openstackclient/tests/unit/image/v1/test_image.py +++ b/openstackclient/tests/unit/image/v1/test_image.py @@ -417,7 +417,7 @@ class TestImageList(TestImage): ), ) self.assertEqual(datalist, tuple(data)) - @mock.patch('openstackclient.api.utils.simple_filter') + @mock.patch('osc_lib.api.utils.simple_filter') def test_image_list_property_option(self, sf_mock): sf_mock.side_effect = [ [self.image_info], [], diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 16a393df..4cc8f448 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -734,7 +734,7 @@ class TestImageList(TestImage): ), ) self.assertEqual(datalist, tuple(data)) - @mock.patch('openstackclient.api.utils.simple_filter') + @mock.patch('osc_lib.api.utils.simple_filter') def test_image_list_property_option(self, sf_mock): sf_mock.return_value = [copy.deepcopy(self._image)] |
